Package lepl :: Package _test
[hide private]
[frames] | no frames]

Source Code for Package lepl._test

  1   
  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 
  4  # in compliance with the License. You may obtain a copy of the License 
  5  # at http://www.mozilla.org/MPL/ 
  6  # 
  7  # Software distributed under the License is distributed on an "AS IS" 
  8  # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 
  9  # the License for the specific language governing rights and 
 10  # limitations under the License. 
 11  # 
 12  # The Original Code is LEPL (http://www.acooke.org/lepl) 
 13  # The Initial Developer of the Original Code is Andrew Cooke. 
 14  # Portions created by the Initial Developer are Copyright (C) 2009-2010 
 15  # Andrew Cooke (andrew@acooke.org). All Rights Reserved. 
 16  # 
 17  # Alternatively, the contents of this file may be used under the terms 
 18  # of the LGPL license (the GNU Lesser General Public License, 
 19  # http://www.gnu.org/licenses/lgpl.html), in which case the provisions 
 20  # of the LGPL License are applicable instead of those above. 
 21  # 
 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 
 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 
 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 
 28  # MPL or the LGPL License. 
 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  # we need to import all files used in the automated self-test 
 42   
 43  # pylint: disable-msg=E0611, W0401 
 44  #@PydevCodeAnalysisIgnore 
 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  # Number of tests if running in IDE with Python 3 
 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   
67 -def all():
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
102 -def ls_modules(parent, children):
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