Commit fb12f8a6 by Chris Jerdonek

The project directory can now be passed to pystache-test (for doctest purposes).

parent 728f6262
...@@ -10,14 +10,14 @@ import pkgutil ...@@ -10,14 +10,14 @@ import pkgutil
import doctest import doctest
import traceback import traceback
from pystache.tests.common import PACKAGE_DIR, PROJECT_DIR, TEXT_DOCTEST_PATHS from pystache.tests.common import PACKAGE_DIR, TEXT_DOCTEST_PATHS
# This module follows the guidance documented here: # This module follows the guidance documented here:
# #
# http://docs.python.org/library/doctest.html#unittest-api # http://docs.python.org/library/doctest.html#unittest-api
# #
def get_module_doctests(): def get_module_doctests(project_dir):
""" """
Return a list of TestSuite instances for all doctests in the pacakqge. Return a list of TestSuite instances for all doctests in the pacakqge.
...@@ -25,13 +25,11 @@ def get_module_doctests(): ...@@ -25,13 +25,11 @@ def get_module_doctests():
suites = [] suites = []
# Since module_relative is False in our calls to DocFileSuite below, # Since module_relative is False in our calls to DocFileSuite below,
# paths should be OS-specific. Moreover, we choose absolute paths # paths should be OS-specific. See the following for more info--
# so that the current working directory does not come into play.
# See the following for more info--
# #
# http://docs.python.org/library/doctest.html#doctest.DocFileSuite # http://docs.python.org/library/doctest.html#doctest.DocFileSuite
# #
paths = [os.path.join(PROJECT_DIR, path) for path in TEXT_DOCTEST_PATHS] paths = [os.path.normpath(os.path.join(project_dir, path)) for path in TEXT_DOCTEST_PATHS]
for path in paths: for path in paths:
suite = doctest.DocFileSuite(path, module_relative=False) suite = doctest.DocFileSuite(path, module_relative=False)
suites.append(suite) suites.append(suite)
......
...@@ -11,7 +11,7 @@ import os ...@@ -11,7 +11,7 @@ import os
import sys import sys
from unittest import TestProgram from unittest import TestProgram
from pystache.tests.common import PACKAGE_DIR from pystache.tests.common import PACKAGE_DIR, PROJECT_DIR
from pystache.tests.doctesting import get_module_doctests from pystache.tests.doctesting import get_module_doctests
...@@ -27,12 +27,21 @@ def run_tests(sys_argv): ...@@ -27,12 +27,21 @@ def run_tests(sys_argv):
sys_argv: a reference to sys.argv. sys_argv: a reference to sys.argv.
""" """
try:
# TODO: use optparse command options instead.
project_dir = sys_argv[1]
sys_argv.pop()
except IndexError:
project_dir = PROJECT_DIR
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_DIR) module_names = _discover_test_modules(PACKAGE_DIR)
sys_argv.extend(module_names) sys_argv.extend(module_names)
_PystacheTestProgram._project_dir = project_dir
# 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
# module to resolve module names relative to a given module. # module to resolve module names relative to a given module.
# (This would require importing all of the unittest modules from # (This would require importing all of the unittest modules from
...@@ -136,7 +145,7 @@ class _PystacheTestProgram(TestProgram): ...@@ -136,7 +145,7 @@ class _PystacheTestProgram(TestProgram):
""" """
def runTests(self): def runTests(self):
doctest_suites = get_module_doctests() doctest_suites = get_module_doctests(self._project_dir)
# self.test is a unittest.TestSuite instance: # self.test is a unittest.TestSuite instance:
# http://docs.python.org/library/unittest.html#unittest.TestSuite # http://docs.python.org/library/unittest.html#unittest.TestSuite
self.test.addTests(doctest_suites) self.test.addTests(doctest_suites)
......
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