summaryrefslogtreecommitdiff
path: root/pystache
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2012-04-20 20:56:54 -0700
committerChris Jerdonek <chris.jerdonek@gmail.com>2012-04-20 20:56:54 -0700
commit3e20e42308a4cfafd1190d843f7c5897245e7fe7 (patch)
tree864562812f3d97f7e99dc12f134c081a57a1e886 /pystache
parent60a6c396b55b986f823d34e67b25adc44791e684 (diff)
downloadpystache-3e20e42308a4cfafd1190d843f7c5897245e7fe7.tar.gz
Removed test_doctests.py (and use of the load_tests protocol).
Diffstat (limited to 'pystache')
-rw-r--r--pystache/commands/test.py7
-rw-r--r--pystache/tests/main.py19
-rw-r--r--pystache/tests/test_doctests.py35
3 files changed, 13 insertions, 48 deletions
diff --git a/pystache/commands/test.py b/pystache/commands/test.py
index 4bf0a4b..61b2a78 100644
--- a/pystache/commands/test.py
+++ b/pystache/commands/test.py
@@ -7,13 +7,12 @@ This module provides a command to test pystache (unit tests, doctests, etc).
import sys
-import pystache
-from pystache.tests.main import Tester
+from pystache.tests.main import TestHarness
def main(sys_argv=sys.argv):
- tester = Tester()
- tester.run_tests(package=pystache, sys_argv=sys_argv)
+ harness = TestHarness()
+ harness.run_tests(sys_argv=sys_argv)
if __name__=='__main__':
diff --git a/pystache/tests/main.py b/pystache/tests/main.py
index 0cd3e8e..e460a08 100644
--- a/pystache/tests/main.py
+++ b/pystache/tests/main.py
@@ -11,6 +11,9 @@ import os
import sys
from unittest import TestProgram
+from pystache.tests.common import PACKAGE_DIR
+from pystache.tests.doctesting import get_module_doctests
+
UNITTEST_FILE_PREFIX = "test_"
@@ -93,12 +96,11 @@ def _get_test_module_names(package_dir):
return modules
-def _discover_test_modules(package):
+def _discover_test_modules(package_dir):
"""
Discover and return a sorted list of the names of unit-test modules.
"""
- package_dir = os.path.dirname(package.__file__)
modules = _get_test_module_names(package_dir)
modules.sort()
@@ -119,33 +121,32 @@ class _PystacheTestProgram(TestProgram):
"""
def runTests(self):
- # TODO: add doctests, etc. to the self.test TestSuite.
+ doctest_suites = get_module_doctests()
+ self.test.addTests(doctest_suites)
+
TestProgram.runTests(self)
-class Tester(object):
+class TestHarness(object):
"""
Discovers and runs unit tests.
"""
- # TODO: consider replacing the package argument with a package_dir argument.
- def run_tests(self, package, sys_argv):
+ def run_tests(self, sys_argv):
"""
Run all unit tests inside the given package.
Arguments:
- package: a module instance corresponding to the package.
-
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)
+ 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
diff --git a/pystache/tests/test_doctests.py b/pystache/tests/test_doctests.py
deleted file mode 100644
index bdc3428..0000000
--- a/pystache/tests/test_doctests.py
+++ /dev/null
@@ -1,35 +0,0 @@
-# coding: utf-8
-
-"""
-Creates unittest.TestSuite instances for the doctests in the project.
-
-"""
-
-from pystache.tests.doctesting import get_module_doctests
-
-
-# The following load_tests() function implements unittests's load_tests
-# protocol added in Python 2.7:
-#
-# http://docs.python.org/library/unittest.html#load-tests-protocol
-#
-# Using this protocol lets us include the doctests in test runs without
-# using nose, for example when using Distribute's test as in the following:
-#
-# python setup.py test
-#
-# Normally, nosetests would interpret this function as a test case (because
-# its name matches the test regular expression) and call it with zero arguments
-# as opposed to the required three. However, we are able to exclude it with
-# an entry like the following in setup.cfg:
-#
-# exclude=load_tests
-#
-# TODO: find a substitute for the load_tests protocol for Python versions
-# before version 2.7.
-#
-def load_tests(loader, tests, ignore):
- suites = get_module_doctests()
- tests.addTests(suites)
-
- return tests