Commit 3e20e423 by Chris Jerdonek

Removed test_doctests.py (and use of the load_tests protocol).

parent 60a6c396
...@@ -7,13 +7,12 @@ This module provides a command to test pystache (unit tests, doctests, etc). ...@@ -7,13 +7,12 @@ This module provides a command to test pystache (unit tests, doctests, etc).
import sys import sys
import pystache from pystache.tests.main import TestHarness
from pystache.tests.main import Tester
def main(sys_argv=sys.argv): def main(sys_argv=sys.argv):
tester = Tester() harness = TestHarness()
tester.run_tests(package=pystache, sys_argv=sys_argv) harness.run_tests(sys_argv=sys_argv)
if __name__=='__main__': if __name__=='__main__':
......
...@@ -11,6 +11,9 @@ import os ...@@ -11,6 +11,9 @@ import os
import sys import sys
from unittest import TestProgram from unittest import TestProgram
from pystache.tests.common import PACKAGE_DIR
from pystache.tests.doctesting import get_module_doctests
UNITTEST_FILE_PREFIX = "test_" UNITTEST_FILE_PREFIX = "test_"
...@@ -93,12 +96,11 @@ def _get_test_module_names(package_dir): ...@@ -93,12 +96,11 @@ def _get_test_module_names(package_dir):
return modules 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. 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 = _get_test_module_names(package_dir)
modules.sort() modules.sort()
...@@ -119,33 +121,32 @@ class _PystacheTestProgram(TestProgram): ...@@ -119,33 +121,32 @@ class _PystacheTestProgram(TestProgram):
""" """
def runTests(self): 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) TestProgram.runTests(self)
class Tester(object): class TestHarness(object):
""" """
Discovers and runs unit tests. Discovers and runs unit tests.
""" """
# TODO: consider replacing the package argument with a package_dir argument. def run_tests(self, sys_argv):
def run_tests(self, package, sys_argv):
""" """
Run all unit tests inside the given package. Run all unit tests inside the given package.
Arguments: Arguments:
package: a module instance corresponding to the package.
sys_argv: a reference to sys.argv. sys_argv: a reference to sys.argv.
""" """
if len(sys_argv) <= 1 or sys_argv[-1].startswith("-"): if len(sys_argv) <= 1 or sys_argv[-1].startswith("-"):
# Then no explicit module or test names were provided, so # Then no explicit module or test names were provided, so
# auto-detect all unit tests. # auto-detect all unit tests.
module_names = _discover_test_modules(package) module_names = _discover_test_modules(PACKAGE_DIR)
sys_argv.extend(module_names) sys_argv.extend(module_names)
# We pass None for the module because we do not want the unittest # We pass None for the module because we do not want the unittest
......
# 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment