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