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 = 461 # Lepl 4 
 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   
68 -def all():
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
103 -def ls_modules(parent, children):
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