diff options
author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-04-20 21:13:53 -0700 |
---|---|---|
committer | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-04-20 21:13:53 -0700 |
commit | 3e2ee32d9218f918eee2f00285f1d03c1269d97c (patch) | |
tree | 1b6ab09f389f16010381ec499fe027c3f1e9f74c | |
parent | 3e20e42308a4cfafd1190d843f7c5897245e7fe7 (diff) | |
download | pystache-3e2ee32d9218f918eee2f00285f1d03c1269d97c.tar.gz |
Replaced the TestHarness class with a run_tests() function.
-rw-r--r-- | pystache/commands/test.py | 5 | ||||
-rw-r--r-- | pystache/tests/main.py | 57 |
2 files changed, 27 insertions, 35 deletions
diff --git a/pystache/commands/test.py b/pystache/commands/test.py index 61b2a78..aec1ff6 100644 --- a/pystache/commands/test.py +++ b/pystache/commands/test.py @@ -7,12 +7,11 @@ This module provides a command to test pystache (unit tests, doctests, etc). import sys -from pystache.tests.main import TestHarness +from pystache.tests.main import run_tests def main(sys_argv=sys.argv): - harness = TestHarness() - harness.run_tests(sys_argv=sys_argv) + run_tests(sys_argv=sys_argv) if __name__=='__main__': diff --git a/pystache/tests/main.py b/pystache/tests/main.py index e460a08..c3edae0 100644 --- a/pystache/tests/main.py +++ b/pystache/tests/main.py @@ -1,7 +1,7 @@ # coding: utf-8 """ -Allows all tests to be run. +Exposes a run_tests() function that runs all tests in the project. This module is for our test console script. @@ -34,6 +34,30 @@ UNITTEST_FILE_PREFIX = "test_" # TestCase or TestSuite instances (e.g. doctests and spec tests), and then # call the base class's runTests(). +def run_tests(sys_argv): + """ + Run all tests in the project. + + Arguments: + + sys_argv: a reference to sys.argv. + + """ + if len(sys_argv) <= 1 or sys_argv[-1].startswith("-"): + # Then no explicit module or test names were provided, so + # auto-detect all unit tests. + module_names = _discover_test_modules(PACKAGE_DIR) + sys_argv.extend(module_names) + + # We pass None for the module because we do not want the unittest + # module to resolve module names relative to a given module. + # (This would require importing all of the unittest modules from + # this module.) See the loadTestsFromName() method of the + # unittest.TestLoader class for more details on this parameter. + _PystacheTestProgram(argv=sys_argv, module=None) + # No need to return since unitttest.main() exits. + + def _find_unittest_files(package_dir): """ Return a list of paths to all unit-test files in the given package directory. @@ -125,34 +149,3 @@ class _PystacheTestProgram(TestProgram): self.test.addTests(doctest_suites) TestProgram.runTests(self) - - -class TestHarness(object): - - """ - Discovers and runs unit tests. - - """ - - def run_tests(self, sys_argv): - """ - Run all unit tests inside the given package. - - Arguments: - - sys_argv: a reference to sys.argv. - - """ - if len(sys_argv) <= 1 or sys_argv[-1].startswith("-"): - # Then no explicit module or test names were provided, so - # auto-detect all unit tests. - module_names = _discover_test_modules(PACKAGE_DIR) - sys_argv.extend(module_names) - - # We pass None for the module because we do not want the unittest - # module to resolve module names relative to a given module. - # (This would require importing all of the unittest modules from - # this module.) See the loadTestsFromName() method of the - # unittest.TestLoader class for more details on this parameter. - _PystacheTestProgram(argv=sys_argv, module=None) - # No need to return since unitttest.main() exits. |