home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.4)
-
- """
- A much simpler testing framework than PyUnit
-
- tests a module by running all functions in it whose name starts with 'test'
-
- a test fails if it raises an exception, otherwise it passes
-
- functions are try_all and try_single
- """
- from traceback import print_exc
- from sys import modules
-
- def try_all(excludes = [], excluded_paths = []):
- '''
- tests all imported modules
-
- takes an optional list of module names and/or module objects to skip over.
- modules from files under under any of excluded_paths are also skipped.
- '''
- failed = []
- for modulename, module in modules.items():
- if not hasattr(module, '__file__'):
- continue
-
- if modulename not in excludes and module not in excludes:
- try_module(module, modulename, failed)
- continue
- None if _[1] else []
-
- print_failed(failed)
-
-
- def try_single(m):
- '''
- tests a single module
-
- accepts either a module object or a module name in string form
- '''
- if type(m) is str:
- modulename = m
- module = __import__(m)
- else:
- modulename = str(m)
- module = m
- failed = []
- try_module(module, modulename, failed)
- print_failed(failed)
-
-
- def try_module(module, modulename, failed):
- if not hasattr(module, '__dict__'):
- return None
-
- for n, func in module.__dict__.items():
- if not callable(func) or n[:4] != 'test':
- continue
-
- name = modulename + '.' + n
-
- try:
- print 'trying ' + name
- func()
- print 'passed ' + name
- continue
- print_exc()
- failed.append(name)
- print 'failed ' + name
- continue
-
-
-
-
- def print_failed(failed):
- print
- if len(failed) == 0:
- print 'everything passed'
- else:
- print 'the following tests failed:'
- for i in failed:
- print i
-
-
-