| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #
- # Python unit test runner
- #
- # Author : Sander Mathijs van Veen <smvv@kompiler.org>
- # License: GPL version 3, see also the file `LICENSE'.
- #
- import sys
- import os
- import unittest
- from testrunner import TextTestRunner
- if len(sys.argv) < 2:
- print 'Usage: %s tests/test_COMPONENT.py' % sys.argv[0]
- sys.exit(1)
- # TODO parse verbosity option '-v', given in argv.
- verbosity = 0
- suites = []
- # Dynamic load the requested module containing the test cases.
- for testfile in sys.argv[1:]:
- module_dir, module_file = os.path.split(testfile)
- module_name, module_ext = os.path.splitext(module_file)
- module_obj = __import__(module_dir.replace('/', '.'),
- fromlist=[module_name])
- module_obj.__file__ = testfile
- globals()[module_name] = module_obj
- # Start the test runner and display the results to stdout.
- container = module_obj.__dict__[module_name]
- class_parts = module_name[5:].split('_')
- class_name = 'Test' + ''.join([p.capitalize() for p in class_parts])
- testcase = container.__dict__[class_name]
- suites += [unittest.TestLoader().loadTestsFromTestCase(testcase)]
- # Create the text runner and execute the tests.
- TextTestRunner(verbosity=verbosity).run(unittest.TestSuite(suites))
|