66
77import collections
88import functools
9+ from pathlib import Path
910
1011def test_main (level = 'full' ):
1112 import sys
@@ -14,33 +15,29 @@ def test_main(level='full'):
1415 old_args = sys .argv
1516 sys .argv = ['checkonly' ]
1617
17- # !!! Instead of a whitelist, we should have a blacklist so that any newly added
18- # generators automatically get included in this tests
19- generators = [
20- 'generate_alltypes' ,
21- 'generate_calls' ,
22- 'generate_casts' ,
23- 'generate_dict_views' ,
24- 'generate_dynsites' ,
25- 'generate_encoding_aliases' ,
26- 'generate_exceptions' ,
27- 'generate_math' ,
28- 'generate_ops' ,
29- 'generate_reflected_calls' ,
30- 'generate_set' ,
31- 'generate_walker' ,
32- 'generate_typecache' ,
33- 'generate_dynamic_instructions' ,
34- 'generate_comdispatch' ,
35- # TODO: uncomment when we have whole Core sources in Snap/test
36- # 'generate_exception_factory',
37- ]
38- if sys .implementation .name != "ironpython" :
39- generators .remove ('generate_alltypes' )
40- generators .remove ('generate_exceptions' )
41- generators .remove ('generate_walker' )
42- generators .remove ('generate_comdispatch' )
18+ # these generators will always be blocked
19+ generators_to_block = ['generate_exception_factory' , 'generate_indicetest' ]
20+ # TODO: unblock 'generate_exception_factory' when we have
21+ # whole Core sources in Snap/test
22+
23+ # these generators will be blocked if not running ironpython
24+ generators_to_block_if_not_ipy = ['generate_alltypes' ,
25+ 'generate_exceptions' ,
26+ 'generate_walker' ,
27+ 'generate_comdispatch' ]
28+
4329
30+ # 'generate_exception_factory',
31+ # populate list of generate_*.py from folder of this script
32+ generators = get_generators_in_folder ()
33+
34+ # filter list to remove blocked items, ie. they will not be run
35+ remove_blocked_generators (generators ,generators_to_block )
36+
37+ if sys .implementation .name != "ironpython" :
38+ # filter list to remove blocked items if we are not ironpython
39+ remove_blocked_generators (generators ,generators_to_block_if_not_ipy )
40+
4441 failures = 0
4542
4643 for gen in generators :
@@ -66,5 +63,32 @@ def test_main(level='full'):
6663
6764 sys .argv = old_args
6865
66+
67+ def get_generators_in_folder ():
68+ # get the folder with this test
69+ path_of_test = Path (__file__ )
70+ folder_of_test = path_of_test .parent
71+
72+ # iterate over items in this folder and add generators
73+ generators = []
74+
75+ for item in folder_of_test .iterdir ():
76+
77+ if item .is_file ():
78+ # if current item is a file, get filename by accessing last path element
79+ filename = str (item .parts [- 1 ])
80+
81+ if filename .startswith ("generate_" ) and filename .endswith (".py" ):
82+ # found a generator, add it to our list (removing extension)
83+ generators .append (filename .replace (".py" ,"" ))
84+
85+ return generators
86+
87+ def remove_blocked_generators (generators ,blocklist ):
88+
89+ for g in blocklist :
90+ if g in generators :
91+ generators .remove (g )
92+
6993if __name__ == "__main__" :
7094 test_main ()
0 commit comments