forked from IronLanguages/ironpython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cgcheck.py
More file actions
95 lines (70 loc) · 2.91 KB
/
test_cgcheck.py
File metadata and controls
95 lines (70 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Licensed to the .NET Foundation under one or more agreements.
# The .NET Foundation licenses this file to you under the Apache 2.0 License.
# See the LICENSE file in the project root for more information.
from __future__ import print_function
import collections
import functools
from pathlib import Path
def test_main(level='full'):
import sys
import operator
old_args = sys.argv
if sys.argv.count('update') == 0:
sys.argv = ['checkonly']
# these generators will always be blocked
generators_to_block = ['generate_exception_factory', 'generate_indicestest']
# TODO: unblock 'generate_exception_factory' when we have
# whole Core sources in Snap/test
# these generators will be blocked if not running ironpython
generators_to_block_if_not_ipy = ['generate_alltypes',
'generate_exceptions',
'generate_walker',
'generate_comdispatch']
# 'generate_exception_factory',
# populate list of generate_*.py from folder of this script
generators = get_generators_in_folder()
# filter list to remove blocked items, ie. they will not be run
remove_blocked_generators(generators,generators_to_block)
if sys.implementation.name != "ironpython":
# filter list to remove blocked items if we are not ironpython
remove_blocked_generators(generators,generators_to_block_if_not_ipy)
failures = 0
for gen in generators:
print("Running", gen)
g = __import__(gen)
one = g.main()
if isinstance(one, collections.Sequence):
failures = functools.reduce(
operator.__add__,
map(lambda r: 0 if r else 1, one),
failures
)
else:
print(" FAIL:", gen, "generator didn't return valid result")
failures += 1
if failures > 0:
print("FAIL:", failures, "generator" + ("s" if failures > 1 else "") + " failed")
sys.exit(1)
else:
print("PASS")
sys.argv = old_args
def get_generators_in_folder():
# get the folder with this test
path_of_test = Path(__file__)
folder_of_test = path_of_test.parent
# iterate over items in this folder and add generators
generators = []
for item in folder_of_test.iterdir():
if item.is_file():
# if current item is a file, get filename by accessing last path element
filename = str(item.parts[-1])
if filename.startswith("generate_") and filename.endswith(".py"):
# found a generator, add it to our list (removing extension)
generators.append(filename.replace(".py",""))
return generators
def remove_blocked_generators(generators,blocklist):
for g in blocklist:
if g in generators:
generators.remove(g)
if __name__=="__main__":
test_main()