summaryrefslogtreecommitdiff
path: root/pystache
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2012-11-03 23:38:41 -0700
committerChris Jerdonek <chris.jerdonek@gmail.com>2012-11-03 23:38:41 -0700
commitde33ff316211ca35c87232cf594ef06a8daf0806 (patch)
tree56cfab7255b693b3f812771eaf5d8656e808820b /pystache
parent661a959bf3ecf9c6592d3047089c2b44cf1042e3 (diff)
downloadpystache-de33ff316211ca35c87232cf594ef06a8daf0806.tar.gz
Allow tox to run from a downloaded sdist (i.e. without spec tests).
Diffstat (limited to 'pystache')
-rw-r--r--pystache/tests/common.py5
-rw-r--r--pystache/tests/main.py37
2 files changed, 25 insertions, 17 deletions
diff --git a/pystache/tests/common.py b/pystache/tests/common.py
index 99be4c8..222e14f 100644
--- a/pystache/tests/common.py
+++ b/pystache/tests/common.py
@@ -19,7 +19,6 @@ DATA_DIR = os.path.join(_TESTS_DIR, 'data') # i.e. 'pystache/tests/data'.
EXAMPLES_DIR = os.path.dirname(examples.__file__)
PACKAGE_DIR = os.path.dirname(pystache.__file__)
PROJECT_DIR = os.path.join(PACKAGE_DIR, '..')
-SPEC_TEST_DIR = os.path.join(PROJECT_DIR, 'ext', 'spec', 'specs')
# TEXT_DOCTEST_PATHS: the paths to text files (i.e. non-module files)
# containing doctests. The paths should be relative to the project directory.
TEXT_DOCTEST_PATHS = ['README.md']
@@ -27,6 +26,10 @@ TEXT_DOCTEST_PATHS = ['README.md']
UNITTEST_FILE_PREFIX = "test_"
+def get_spec_test_dir(project_dir):
+ return os.path.join(project_dir, 'ext', 'spec', 'specs')
+
+
def html_escape(u):
"""
An html escape function that behaves the same in both Python 2 and 3.
diff --git a/pystache/tests/main.py b/pystache/tests/main.py
index 184122d..8af6b2e 100644
--- a/pystache/tests/main.py
+++ b/pystache/tests/main.py
@@ -13,8 +13,8 @@ import unittest
from unittest import TestCase, TestProgram
import pystache
-from pystache.tests.common import PACKAGE_DIR, PROJECT_DIR, SPEC_TEST_DIR, UNITTEST_FILE_PREFIX
-from pystache.tests.common import get_module_names
+from pystache.tests.common import PACKAGE_DIR, PROJECT_DIR, UNITTEST_FILE_PREFIX
+from pystache.tests.common import get_module_names, get_spec_test_dir
from pystache.tests.doctesting import get_doctests
from pystache.tests.spectesting import get_spec_tests
@@ -87,39 +87,43 @@ def main(sys_argv):
sys_argv: a reference to sys.argv.
"""
+ # TODO: use logging module
+ print "pystache: running tests: argv: %s" % repr(sys_argv)
+
should_source_exist = False
spec_test_dir = None
project_dir = None
if len(sys_argv) > 1 and sys_argv[1] == FROM_SOURCE_OPTION:
+ # This usually means the test_pystache.py convenience script
+ # in the source directory was run.
should_source_exist = True
sys_argv.pop(1)
- # TODO: use logging module
- print "pystache: running tests: expecting source: %s" % should_source_exist
+ try:
+ # TODO: use optparse command options instead.
+ project_dir = sys_argv[1]
+ sys_argv.pop(1)
+ except IndexError:
+ if should_source_exist:
+ project_dir = PROJECT_DIR
try:
# TODO: use optparse command options instead.
spec_test_dir = sys_argv[1]
sys_argv.pop(1)
except IndexError:
- if should_source_exist:
- if not os.path.exists(SPEC_TEST_DIR):
+ if project_dir is not None:
+ # Then auto-detect the spec test directory.
+ _spec_test_dir = get_spec_test_dir(project_dir)
+ if not os.path.exists(_spec_test_dir):
# Then the user is probably using a downloaded sdist rather
# than a repository clone (since the sdist does not include
# the spec test directory).
print("pystache: skipping spec tests: spec test directory "
"not found")
else:
- spec_test_dir = SPEC_TEST_DIR
-
- try:
- # TODO: use optparse command options instead.
- project_dir = sys_argv[1]
- sys_argv.pop(1)
- except IndexError:
- if should_source_exist:
- project_dir = PROJECT_DIR
+ spec_test_dir = _spec_test_dir
if len(sys_argv) <= 1 or sys_argv[-1].startswith("-"):
# Then no explicit module or test names were provided, so
@@ -127,7 +131,8 @@ def main(sys_argv):
module_names = _discover_test_modules(PACKAGE_DIR)
sys_argv.extend(module_names)
if project_dir is not None:
- # Add the current module for unit tests contained here.
+ # Add the current module for unit tests contained here (e.g.
+ # to include SetupTests).
sys_argv.append(__name__)
SetupTests.project_dir = project_dir