12
12
from time import perf_counter
13
13
14
14
import av
15
- import numpy as np
16
15
from av import AudioStream , VideoStream
17
16
18
17
from auto_editor .ffwrapper import FileInfo
19
- from auto_editor .lang .palet import Lexer , Parser , env , interpret
20
- from auto_editor .lang .stdenv import make_standard_env
21
- from auto_editor .lib .data_structs import Char
22
- from auto_editor .lib .err import MyError
23
18
from auto_editor .utils .log import Log
24
19
from auto_editor .vanparse import ArgumentParser
25
20
@@ -29,13 +24,13 @@ class TestArgs:
29
24
only : list [str ] = field (default_factory = list )
30
25
help : bool = False
31
26
program : bool = False
32
- no_fail_fast : bool = False
27
+ no_failfast : bool = False
33
28
category : str = "cli"
34
29
35
30
36
31
def test_options (parser : ArgumentParser ) -> ArgumentParser :
37
32
parser .add_argument ("--only" , "-n" , nargs = "*" )
38
- parser .add_argument ("--no-fail-fast " , flag = True )
33
+ parser .add_argument ("--no-failfast " , flag = True )
39
34
parser .add_argument ("--program" , flag = True )
40
35
parser .add_required (
41
36
"category" ,
@@ -556,159 +551,6 @@ def test_audio_norm_ebu(self) -> None:
556
551
["example.mp4" ], ["--audio-normalize" , "ebu:i=-5,lra=20,gain=5,tp=-1" ]
557
552
)
558
553
559
- def palet_python_bridge (self ):
560
- env .update (make_standard_env ())
561
-
562
- def cases (* cases : tuple [str , object ]) -> None :
563
- for text , expected in cases :
564
- try :
565
- parser = Parser (Lexer ("repl" , text ))
566
- env ["timebase" ] = Fraction (30 )
567
- results = interpret (env , parser )
568
- except MyError as e :
569
- raise ValueError (f"{ text } \n MyError: { e } " )
570
-
571
- result_val = results [- 1 ]
572
- if isinstance (expected , np .ndarray ):
573
- if not isinstance (result_val , np .ndarray ):
574
- raise ValueError (f"{ text } : Result is not an ndarray" )
575
- if not np .array_equal (expected , result_val ):
576
- raise ValueError (f"{ text } : Numpy arrays don't match" )
577
- elif expected != result_val :
578
- raise ValueError (f"{ text } : Expected: { expected } , got { result_val } " )
579
-
580
- cases (
581
- ("345" , 345 ),
582
- ("238.5" , 238.5 ),
583
- ("-34" , - 34 ),
584
- ("-98.3" , - 98.3 ),
585
- ("3sec" , 90 ),
586
- ("-3sec" , - 90 ),
587
- ("0.2sec" , 6 ),
588
- ("(+ 4 3)" , 7 ),
589
- ("(+ 4 3 2)" , 9 ),
590
- ("(+ 10.5 3)" , 13.5 ),
591
- ("(- 4 3)" , 1 ),
592
- ("(- 3)" , - 3 ),
593
- ("(- 10.5 3)" , 7.5 ),
594
- ("(* 11.5 3)" , 34.5 ),
595
- ("(/ 3/4 4)" , Fraction (3 , 16 )),
596
- ("(/ 5)" , 0.2 ),
597
- ("(/ 6 1)" , 6.0 ),
598
- ("30/1" , Fraction (30 )),
599
- ("(pow 2 3)" , 8 ),
600
- ("(pow 4 0.5)" , 2.0 ),
601
- ("(abs 1.0)" , 1.0 ),
602
- ("(abs -1)" , 1 ),
603
- ("(bool? #t)" , True ),
604
- ("(bool? #f)" , True ),
605
- ("(bool? 0)" , False ),
606
- ("(bool? 1)" , False ),
607
- ("(bool? false)" , True ),
608
- ("(int? 2)" , True ),
609
- ("(int? 3.0)" , False ),
610
- ("(int? #t)" , False ),
611
- ("(int? #f)" , False ),
612
- ("(int? 4/5)" , False ),
613
- ('(int? "hello")' , False ),
614
- ('(int? "3")' , False ),
615
- ("(float? -23.4)" , True ),
616
- ("(float? 3.0)" , True ),
617
- ("(float? #f)" , False ),
618
- ("(float? 4/5)" , False ),
619
- ("(float? 21)" , False ),
620
- ("(frac? 4/5)" , True ),
621
- ("(frac? 3.4)" , False ),
622
- ('(& "Hello" " World")' , "Hello World" ),
623
- ('(define apple "Red Wood") apple' , "Red Wood" ),
624
- ("(= 1 1.0)" , True ),
625
- ("(= 1 2)" , False ),
626
- ("(= 1)" , True ),
627
- ("(+)" , 0 ),
628
- ("(*)" , 1 ),
629
- ('(define num 13) ; Set number to 13\n "Hello"' , "Hello" ),
630
- ('(if #t "Hello" apple)' , "Hello" ),
631
- ('(if #f mango "Hi")' , "Hi" ),
632
- ('{if (= [+ 3 4] 7) "yes" "no"}' , "yes" ),
633
- ("((if #t + -) 3 4)" , 7 ),
634
- ("((if #f + -) 3 4)" , - 1 ),
635
- ("(when (positive? 3) 17)" , 17 ),
636
- ("(string)" , "" ),
637
- ("(string #\\ a)" , "a" ),
638
- ("(string #\\ a #\\ b)" , "ab" ),
639
- ("(string #\\ a #\\ b #\\ c)" , "abc" ),
640
- (
641
- "(margin (bool-array 0 0 0 1 0 0 0) 0)" ,
642
- np .array ([0 , 0 , 0 , 1 , 0 , 0 , 0 ], dtype = np .bool_ ),
643
- ),
644
- (
645
- "(margin (bool-array 0 0 1 1 0 0 0) -2 2)" ,
646
- np .array ([0 , 0 , 0 , 0 , 1 , 1 , 0 ], dtype = np .bool_ ),
647
- ),
648
- ("(equal? 3 3)" , True ),
649
- ("(equal? 3 3.0)" , False ),
650
- ('(equal? 16.3 "Editor")' , False ),
651
- ("(equal? (bool-array 1 1 0) (bool-array 1 1 0))" , True ),
652
- ("(equal? (bool-array 0 1 0) (bool-array 1 1 0))" , False ),
653
- ("(equal? (bool-array 0 1 0) (bool-array 0 1 0 0))" , False ),
654
- ("(equal? #\\ a #\\ a)" , True ),
655
- ('(equal? "a" #\\ a)' , False ),
656
- ("(equal? (vector 1 2 3) (vector 1 2 3))" , True ),
657
- (
658
- "(or (bool-array 1 0 0) (bool-array 0 0 0 1))" ,
659
- np .array ([1 , 0 , 0 , 1 ], dtype = np .bool_ ),
660
- ),
661
- ("(len (vector 1 2 4))" , 3 ),
662
- ("(len #(1 2 4))" , 3 ),
663
- ("(len (bool-array 0 1 0))" , 3 ),
664
- ("(equal? (reverse #(0 1 2)) #(2 1 0))" , True ),
665
- ("(equal? (reverse (vector 0 1 2)) (vector 2 1 0))" , True ),
666
- ('(ref "Zyx" 1)' , Char ("y" )),
667
- ("(ref (vector 0.3 #\\ a 2) 2)" , 2 ),
668
- ("(ref (range 0 10) 2)" , 2 ),
669
- ("((range 0 10) 2)" , 2 ),
670
- ("((vector 0.3 #\\ a 17) 2)" , 17 ),
671
- ("(#(0.3 #\\ a 17) 2)" , 17 ),
672
- ("(begin)" , None ),
673
- ("(void)" , None ),
674
- ("(begin (define r 10) (* 3.14 (* r r)))" , 314.0 ),
675
- ("#(-20dB 0dB 20dB)" , [0.1 , 1 , 10 ]),
676
- ("(define ca (lambda (r) (* 3.14 (* r r)))) (ca 5)" , 78.5 ),
677
- (
678
- "(define ca (lambda (r) (void) (* 3.14 (* r r)))) (ca 5)" ,
679
- 78.5 ,
680
- ),
681
- ("(define (my-pow2 a) (* a a)) (my-pow2 30)" , 900 ),
682
- ("(define (my-pow2 a) (void) (* a a)) (my-pow2 30)" , 900 ),
683
- ("(~a 3 4 'a)" , "34a" ),
684
- ("(~s 3 4 'a)" , "3 4 a" ),
685
- ("(~v 3 4 'a)" , "3 4 'a" ),
686
- ("(define (my-func x) (define (inner) 4) (+ x (inner))) (my-func 16)" , 20 ),
687
- ("(define (text child ...) child)" , None ),
688
- ("(text)" , []),
689
- ("(text 1)" , [1 ]),
690
- ("(text 2 1)" , [2 , 1 ]),
691
- ("(text 3 2 1)" , [3 , 2 , 1 ]),
692
- ("((or/c 0 1) 1)" , True ),
693
- ("((or/c 0 1) 2)" , False ),
694
- ("((or/c 0 1) 1)" , True ),
695
- ('((or/c 0 1 string?) "hello")' , True ),
696
- ("((or/c 0 1 string?) 3)" , False ),
697
- ('"hello".title' , "Hello" ),
698
- ('"hello".upper' , "HELLO" ),
699
- ('"heLlo".lower' , "hello" ),
700
- ('(define s "hello")s.title' , "Hello" ),
701
- ("(define v #(2 0 3 -4 -2 5 1 4)) v.sort" , [- 4 , - 2 , 0 , 1 , 2 , 3 , 4 , 5 ]),
702
- ("(define v #(2 0 3 -4 -2 5 1 4)) v.sort! v" , [- 4 , - 2 , 0 , 1 , 2 , 3 , 4 , 5 ]),
703
- ('#(#("sym" "symbol?") "bool?")' , [["sym" , "symbol?" ], "bool?" ]),
704
- )
705
-
706
- def palet_scripts (self ) -> None :
707
- self .raw (["palet" , "resources/scripts/scope.pal" ])
708
- self .raw (["palet" , "resources/scripts/maxcut.pal" ])
709
- self .raw (["palet" , "resources/scripts/case.pal" ])
710
- self .raw (["palet" , "resources/scripts/testmath.pal" ])
711
-
712
554
713
555
def run_tests (tests : list [Callable ], args : TestArgs ) -> None :
714
556
if args .only != []:
@@ -763,7 +605,7 @@ def timed_test(test_func):
763
605
print (f"{ msg } [\033 [1;32mPASSED\033 [0m]" , flush = True )
764
606
else :
765
607
print (f"{ msg } \033 [1;31m[FAILED]\033 [0m" , flush = True )
766
- if args .no_fail_fast :
608
+ if args .no_failfast :
767
609
print (f"\n { exception } " )
768
610
else :
769
611
print ("" )
@@ -790,11 +632,6 @@ def main(sys_args: list[str] | None = None) -> None:
790
632
if callable (getattr (Runner , name )) and name not in ["main" , "raw" , "check" ]
791
633
}
792
634
793
- if not args .program and args .category in {"palet" , "all" }:
794
- tests .extend (
795
- [test_methods [name ] for name in ["palet_python_bridge" , "palet_scripts" ]]
796
- )
797
-
798
635
if args .category in {"sub" , "all" }:
799
636
tests .extend (
800
637
[test_methods [name ] for name in ["info" , "levels" , "subdump" , "desc" ]]
0 commit comments