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 Tests for the lepl package.
32 '''
33
34 from logging import getLogger, basicConfig, DEBUG, WARN, ERROR
35 from sys import version
36 from types import ModuleType
37 from unittest import TestSuite, TestLoader, TextTestRunner
38
39 import lepl
40
41
42
43
44
45 import lepl._test.bug_stalled_parser
46 import lepl._test.magus
47 import lepl._test.wrong_cache_bug
48 import lepl._test.wrong_depth_bug
49 import lepl._test.wrong_regexp_bug
50
51
52 TOTAL = 429
53 NOT_DISTRIBUTED = 12
54 NOT_3 = 22
55
56 MODULES = [('apps', []),
57 ('bin', []),
58 ('cairo', []),
59 ('contrib', []),
60 ('core', []),
61 ('lexer', [('lines', [])]),
62 ('matchers', []),
63 ('regexp', []),
64 ('stream', []),
65 ('support', [])]
66
68 '''
69 This runs all tests and examples. It is something of a compromise - seems
70 to be the best solution that's independent of other libraries, doesn't
71 use the file system (since code may be in a zip file), and keeps the
72 number of required imports to a minimum.
73 '''
74 basicConfig(level=ERROR)
75 log = getLogger('lepl._test.all.all')
76 suite = TestSuite()
77 loader = TestLoader()
78 runner = TextTestRunner(verbosity=4)
79 for module in ls_modules(lepl, MODULES):
80 log.debug(module.__name__)
81 suite.addTest(loader.loadTestsFromModule(module))
82 result = runner.run(suite)
83 print('\n\n\n----------------------------------------------------------'
84 '------------\n')
85 if version[0] == '2':
86 print('Expect 2-5 failures + 2 errors in Python 2: {0:d}, {1:d} '
87 .format(len(result.failures), len(result.errors)))
88 assert 2 <= len(result.failures) <= 5, len(result.failures)
89 assert 1 <= len(result.errors) <= 2, len(result.errors)
90 target = TOTAL - NOT_DISTRIBUTED - NOT_3
91 else:
92 print('Expect at most 1 failure + 0 errors in Python 3: {0:d}, {1:d} '
93 .format(len(result.failures), len(result.errors)))
94 assert 0 <= len(result.failures) <= 1, len(result.failures)
95 assert 0 <= len(result.errors) <= 0, len(result.errors)
96 target = TOTAL - NOT_DISTRIBUTED
97 print('Expect {0:d} tests total: {1:d}'.format(target, result.testsRun))
98 assert result.testsRun == target, result.testsRun
99 print('\nLooks OK to me!\n\n')
100
101
103 known = set()
104 children += [('_test', []), ('_example', [])]
105 children += map(lambda module: (module, []), dir(parent))
106 for (child, unborn) in children:
107 name = parent.__name__ + '.' + child
108 try:
109 __import__(name)
110 module = getattr(parent, child)
111 if isinstance(module, ModuleType) and module not in known:
112 yield module
113 known.add(module)
114 for module in ls_modules(module, unborn):
115 yield module
116 except ImportError as e:
117 if not str(e).startswith('No module named'):
118 raise
119
120 if __name__ == '__main__':
121 all()
122