Mercurial > treepkg
view test/runtests.py @ 274:2676abfc0e1d
Refactoring: Implement do_package in treepkg.packager.SourcePackager.
The actual implementation in the derived classes is almost identical in
all cases so it's better to have as much of the implementation in the
base class. The update_version_numbers method is not called directly by
the base class code so is removed from the base class. OTOH,
prepare_sources_for_tarball has been added as a more general variant of
update_version_numbers that is actually called by the default
implementation of do_package.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 07 May 2009 15:19:15 +0000 |
parents | f9f15ee39ed7 |
children |
line wrap: on
line source
# Copyright (C) 2007 by Intevation GmbH # Authors: # Bernhard Herzog <bh@intevation.de> # # This program is free software under the GPL (>=v2) # Read the file COPYING coming with the software for details. """ Main entry point for the test suite. Just run this file as a python script to execute all tests """ import os import sys import unittest import optparse test_dir = os.path.dirname(__file__) sys.path.append(os.path.join(test_dir, os.pardir)) def find_test_modules(dirname, package = None): """Return a list the names of the test modules in the directory dirname The return value is a list of names that can be passed to unittest.defaultTestLoader.loadTestsFromNames. Each name of the list is the name of a pure python module, one for each file in dirname whose name starts with 'test' and ends with '.py'. The optional parameter package should be the name of the python package whose directory is dirname. If package is given all names in the returned list will be prefixed with package and a dot. """ if package: prefix = package + "." else: prefix = "" suffix = ".py" return [prefix + name[:-len(suffix)] for name in os.listdir(dirname) if name.startswith("test") and name.endswith(suffix)] def main(): """Run all the tests in the test suite""" parser = optparse.OptionParser() parser.set_defaults(verbosity=1) parser.add_option("-v", "--verbose", action="store_const", const=2, dest="verbosity") opts, rest = parser.parse_args() # Build the list of test names. If names were given on the command # line, run exactly those. Othwerwise build a default list of # names. if rest: names = rest else: # All Python files starting with 'test' in the current directory # and some directories in Extensions contain test cases. # FIXME: It should be possible to run runtests.py even when not in # the test directory names = find_test_modules(test_dir) suite = unittest.defaultTestLoader.loadTestsFromNames(names) runner = unittest.TextTestRunner(verbosity=opts.verbosity) result = runner.run(suite) sys.exit(not result.wasSuccessful()) if __name__ == "__main__": main()