summaryrefslogtreecommitdiff
path: root/pystache
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2012-04-21 08:29:12 -0700
committerChris Jerdonek <chris.jerdonek@gmail.com>2012-04-21 08:29:12 -0700
commitfb12f8a6528357e6a1be7fd550040c2f9b213b2c (patch)
tree2f56be01e291e4b10923eb29dc495811a06339b5 /pystache
parent728f62621f068f6dd202f3ebcf7c3f7a761c9777 (diff)
downloadpystache-fb12f8a6528357e6a1be7fd550040c2f9b213b2c.tar.gz
The project directory can now be passed to pystache-test (for doctest purposes).
Diffstat (limited to 'pystache')
-rw-r--r--pystache/tests/doctesting.py10
-rw-r--r--pystache/tests/main.py13
2 files changed, 15 insertions, 8 deletions
diff --git a/pystache/tests/doctesting.py b/pystache/tests/doctesting.py
index 4a5f9f5..04f1c87 100644
--- a/pystache/tests/doctesting.py
+++ b/pystache/tests/doctesting.py
@@ -10,14 +10,14 @@ import pkgutil
import doctest
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:
#
# 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.
@@ -25,13 +25,11 @@ def get_module_doctests():
suites = []
# Since module_relative is False in our calls to DocFileSuite below,
- # paths should be OS-specific. Moreover, we choose absolute paths
- # so that the current working directory does not come into play.
- # See the following for more info--
+ # paths should be OS-specific. See the following for more info--
#
# 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:
suite = doctest.DocFileSuite(path, module_relative=False)
suites.append(suite)
diff --git a/pystache/tests/main.py b/pystache/tests/main.py
index 5db267a..799b7a6 100644
--- a/pystache/tests/main.py
+++ b/pystache/tests/main.py
@@ -11,7 +11,7 @@ import os
import sys
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
@@ -27,12 +27,21 @@ def run_tests(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("-"):
# 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)
+ _PystacheTestProgram._project_dir = project_dir
+
# 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
@@ -136,7 +145,7 @@ class _PystacheTestProgram(TestProgram):
"""
def runTests(self):
- doctest_suites = get_module_doctests()
+ doctest_suites = get_module_doctests(self._project_dir)
# self.test is a unittest.TestSuite instance:
# http://docs.python.org/library/unittest.html#unittest.TestSuite
self.test.addTests(doctest_suites)