My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones  
Changes to /src/lepl/_test/__init__.py
362939563a30 vs. 5470f89bb69a Compare: vs.  Format:
Revision 5470f89bb69a
Go to: 
Project members, sign in to write a code review
/src/lepl/_test/__init__.py   362939563a30 /src/lepl/_test/__init__.py   5470f89bb69a
1 1
2 # The contents of this file are subject to the Mozilla Public License 2 # The contents of this file are subject to the Mozilla Public License
3 # (MPL) Version 1.1 (the "License"); you may not use this file except 3 # (MPL) Version 1.1 (the "License"); you may not use this file except
4 # in compliance with the License. You may obtain a copy of the License 4 # in compliance with the License. You may obtain a copy of the License
5 # at http://www.mozilla.org/MPL/ 5 # at http://www.mozilla.org/MPL/
6 # 6 #
7 # Software distributed under the License is distributed on an "AS IS" 7 # Software distributed under the License is distributed on an "AS IS"
8 # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 8 # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9 # the License for the specific language governing rights and 9 # the License for the specific language governing rights and
10 # limitations under the License. 10 # limitations under the License.
11 # 11 #
12 # The Original Code is LEPL (http://www.acooke.org/lepl) 12 # The Original Code is LEPL (http://www.acooke.org/lepl)
13 # The Initial Developer of the Original Code is Andrew Cooke. 13 # The Initial Developer of the Original Code is Andrew Cooke.
14 # Portions created by the Initial Developer are Copyright (C) 2009-2010 14 # Portions created by the Initial Developer are Copyright (C) 2009-2010
15 # Andrew Cooke (andrew@acooke.org). All Rights Reserved. 15 # Andrew Cooke (andrew@acooke.org). All Rights Reserved.
16 # 16 #
17 # Alternatively, the contents of this file may be used under the terms 17 # Alternatively, the contents of this file may be used under the terms
18 # of the LGPL license (the GNU Lesser General Public License, 18 # of the LGPL license (the GNU Lesser General Public License,
19 # http://www.gnu.org/licenses/lgpl.html), in which case the provisions 19 # http://www.gnu.org/licenses/lgpl.html), in which case the provisions
20 # of the LGPL License are applicable instead of those above. 20 # of the LGPL License are applicable instead of those above.
21 # 21 #
22 # If you wish to allow use of your version of this file only under the 22 # If you wish to allow use of your version of this file only under the
23 # terms of the LGPL License and not to allow others to use your version 23 # terms of the LGPL License and not to allow others to use your version
24 # of this file under the MPL, indicate your decision by deleting the 24 # of this file under the MPL, indicate your decision by deleting the
25 # provisions above and replace them with the notice and other provisions 25 # provisions above and replace them with the notice and other provisions
26 # required by the LGPL License. If you do not delete the provisions 26 # required by the LGPL License. If you do not delete the provisions
27 # above, a recipient may use your version of this file under either the 27 # above, a recipient may use your version of this file under either the
28 # MPL or the LGPL License. 28 # MPL or the LGPL License.
29 29
30 ''' 30 '''
31 Tests for the lepl package. 31 Tests for the lepl package.
32 ''' 32 '''
33 33
34 from logging import getLogger, basicConfig, DEBUG, WARN, ERROR 34 from logging import getLogger, basicConfig, DEBUG, WARN, ERROR
35 from sys import version 35 from sys import version
36 from types import ModuleType 36 from types import ModuleType
37 from unittest import TestSuite, TestLoader, TextTestRunner 37 from unittest import TestSuite, TestLoader, TextTestRunner
38 38
39 import lepl 39 import lepl
40 40
41 # we need to import all files used in the automated self-test 41 # we need to import all files used in the automated self-test
42 42
43 # pylint: disable-msg=E0611, W0401 43 # pylint: disable-msg=E0611, W0401
44 #@PydevCodeAnalysisIgnore 44 #@PydevCodeAnalysisIgnore
45 import lepl._test.bug_stalled_parser 45 import lepl._test.bug_stalled_parser
46 import lepl._test.magus 46 import lepl._test.magus
47 import lepl._test.wrong_cache_bug 47 import lepl._test.wrong_cache_bug
48 import lepl._test.wrong_depth_bug 48 import lepl._test.wrong_depth_bug
49 import lepl._test.wrong_regexp_bug 49 import lepl._test.wrong_regexp_bug
50 50
51 # Number of tests if running in IDE with Python 3 51 # Number of tests if running in IDE with Python 3
52 TOTAL = 429 52 TOTAL = 431
53 NOT_DISTRIBUTED = 12 53 NOT_DISTRIBUTED = 12
54 NOT_3 = 22 54 NOT_3 = 22
55 55
56 MODULES = [('apps', []), 56 MODULES = [('apps', []),
57 ('bin', []), 57 ('bin', []),
58 ('cairo', []), 58 ('cairo', []),
59 ('contrib', []), 59 ('contrib', []),
60 ('core', []), 60 ('core', []),
61 ('lexer', [('lines', [])]), 61 ('lexer', [('lines', [])]),
62 ('matchers', []), 62 ('matchers', []),
63 ('regexp', []), 63 ('regexp', []),
64 ('stream', []), 64 ('stream', []),
65 ('support', [])] 65 ('support', [])]
66 66
67 def all(): 67 def all():
68 ''' 68 '''
69 This runs all tests and examples. It is something of a compromise - seems 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 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 71 use the file system (since code may be in a zip file), and keeps the
72 number of required imports to a minimum. 72 number of required imports to a minimum.
73 ''' 73 '''
74 basicConfig(level=ERROR) 74 basicConfig(level=ERROR)
75 log = getLogger('lepl._test.all.all') 75 log = getLogger('lepl._test.all.all')
76 suite = TestSuite() 76 suite = TestSuite()
77 loader = TestLoader() 77 loader = TestLoader()
78 runner = TextTestRunner(verbosity=4) 78 runner = TextTestRunner(verbosity=4)
79 for module in ls_modules(lepl, MODULES): 79 for module in ls_modules(lepl, MODULES):
80 log.debug(module.__name__) 80 log.debug(module.__name__)
81 suite.addTest(loader.loadTestsFromModule(module)) 81 suite.addTest(loader.loadTestsFromModule(module))
82 result = runner.run(suite) 82 result = runner.run(suite)
83 print('\n\n\n----------------------------------------------------------' 83 print('\n\n\n----------------------------------------------------------'
84 '------------\n') 84 '------------\n')
85 if version[0] == '2': 85 if version[0] == '2':
86 print('Expect 2-5 failures + 2 errors in Python 2: {0:d}, {1:d} ' 86 print('Expect 2-5 failures + 2 errors in Python 2: {0:d}, {1:d} '
87 .format(len(result.failures), len(result.errors))) 87 .format(len(result.failures), len(result.errors)))
88 assert 2 <= len(result.failures) <= 5, len(result.failures) 88 assert 2 <= len(result.failures) <= 5, len(result.failures)
89 assert 1 <= len(result.errors) <= 2, len(result.errors) 89 assert 1 <= len(result.errors) <= 2, len(result.errors)
90 target = TOTAL - NOT_DISTRIBUTED - NOT_3 90 target = TOTAL - NOT_DISTRIBUTED - NOT_3
91 else: 91 else:
92 print('Expect at most 1 failure + 0 errors in Python 3: {0:d}, {1:d} ' 92 print('Expect at most 1 failure + 0 errors in Python 3: {0:d}, {1:d} '
93 .format(len(result.failures), len(result.errors))) 93 .format(len(result.failures), len(result.errors)))
94 assert 0 <= len(result.failures) <= 1, len(result.failures) 94 assert 0 <= len(result.failures) <= 1, len(result.failures)
95 assert 0 <= len(result.errors) <= 0, len(result.errors) 95 assert 0 <= len(result.errors) <= 0, len(result.errors)
96 target = TOTAL - NOT_DISTRIBUTED 96 target = TOTAL - NOT_DISTRIBUTED
97 print('Expect {0:d} tests total: {1:d}'.format(target, result.testsRun)) 97 print('Expect {0:d} tests total: {1:d}'.format(target, result.testsRun))
98 assert result.testsRun == target, result.testsRun 98 assert result.testsRun == target, result.testsRun
99 print('\nLooks OK to me!\n\n') 99 print('\nLooks OK to me!\n\n')
100 100
101 101
102 def ls_modules(parent, children): 102 def ls_modules(parent, children):
103 known = set() 103 known = set()
104 children += [('_test', []), ('_example', [])] 104 children += [('_test', []), ('_example', [])]
105 children += map(lambda module: (module, []), dir(parent)) 105 children += map(lambda module: (module, []), dir(parent))
106 for (child, unborn) in children: 106 for (child, unborn) in children:
107 name = parent.__name__ + '.' + child 107 name = parent.__name__ + '.' + child
108 try: 108 try:
109 __import__(name) 109 __import__(name)
110 module = getattr(parent, child) 110 module = getattr(parent, child)
111 if isinstance(module, ModuleType) and module not in known: 111 if isinstance(module, ModuleType) and module not in known:
112 yield module 112 yield module
113 known.add(module) 113 known.add(module)
114 for module in ls_modules(module, unborn): 114 for module in ls_modules(module, unborn):
115 yield module 115 yield module
116 except ImportError as e: 116 except ImportError as e:
117 if not str(e).startswith('No module named'): 117 if not str(e).startswith('No module named'):
118 raise 118 raise
119 119
120 if __name__ == '__main__': 120 if __name__ == '__main__':
121 all() 121 all()
Powered by Google Project Hosting