-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestdiscover.py
More file actions
58 lines (47 loc) · 1.7 KB
/
Copy pathtestdiscover.py
File metadata and controls
58 lines (47 loc) · 1.7 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
import unittest
from collections import defaultdict
import traceback
import json
import sys
# https://github.com/python/cpython/blob/main/Lib/test/test___all__.py outright says that these modules wont work with Asan
bad_modules = ['_tkinter', 'tkinter', 'test_tkinter', 'test_ttk', 'test_ttk_textonly', 'idlelib', 'test_idle']
tests_file = 'test_attributes.json'
tests_file = 'test_attributes.json'
def flatten(suite):
for test in suite:
if isinstance(test, unittest.TestSuite):
yield from flatten(test)
else:
yield test
def discoverandsave():
loader = unittest.TestLoader()
suite = loader.discover('cpython/Lib')
all_tests = list(flatten(suite))
class_tests = defaultdict(lambda:defaultdict(list))
for (_, test) in enumerate(all_tests):
if any (word in test.__module__ for word in bad_modules):
continue
else:
try:
__import__(test.__module__)
class_tests[test.__module__][test.__class__.__name__].append(test._testMethodName)
except Exception as e:
print("This failed")
traceback.print_exc(file=sys.stdout)
class_tests.pop('unittest.loader', None)
with open(tests_file, 'w') as file:
json.dump(class_tests,file)
def module_counter():
counter = defaultdict(int)
with open(tests_file, 'r') as fi:
all_tests = json.load(fi)
for module in all_tests:
try:
name = module.split('.')[1]
except Exception:
name = module
print(name)
counter[name] += 1
counter = sorted(counter.items(), key=lambda t : t[1], reverse=True)
print(counter)
module_counter()