Skip to content
Browse files

Allow tox to run from a downloaded sdist (i.e. without spec tests).

  • Loading branch information...
1 parent 661a959 commit de33ff316211ca35c87232cf594ef06a8daf0806 @cjerdonek cjerdonek committed Nov 3, 2012
Showing with 31 additions and 23 deletions.
  1. +2 −2 HISTORY.md
  2. +4 −1 pystache/tests/common.py
  3. +21 −16 pystache/tests/main.py
  4. +2 −2 setup_description.rst
  5. +2 −2 tox.ini
View
4 HISTORY.md
@@ -28,8 +28,8 @@ History
when getting a key from a context stack (issue \#110).
- Bugfix: lambda section values can now return non-ascii, non-unicode
strings (issue \#118).
-- Bugfix: running `test_pystache.py` from a downloaded sdist no longer
- requires a spec test directory to pass.
+- Bugfix: allow `test_pystache.py` and `tox` to pass when run from a
+ downloaded sdist (i.e. without the spec test directory).
- Convert HISTORY and README files from reST to Markdown.
- More robust handling of byte strings in Python 3.
- Added Creative Commons license for David Phillips's logo.
View
5 pystache/tests/common.py
@@ -19,14 +19,17 @@
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']
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.
View
37 pystache/tests/main.py
@@ -13,8 +13,8 @@
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,47 +87,52 @@ 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
# auto-detect all unit tests.
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
View
4 setup_description.rst
@@ -346,8 +346,8 @@ History
when getting a key from a context stack (issue #110).
- Bugfix: lambda section values can now return non-ascii, non-unicode
strings (issue #118).
-- Bugfix: running ``test_pystache.py`` from a downloaded sdist no
- longer requires a spec test directory to pass.
+- Bugfix: allow ``test_pystache.py`` and ``tox`` to pass when run from
+ a downloaded sdist (i.e. without the spec test directory).
- Convert HISTORY and README files from reST to Markdown.
- More robust handling of byte strings in Python 3.
- Added Creative Commons license for David Phillips's logo.
View
4 tox.ini
@@ -13,7 +13,7 @@ envlist = py24,py25,py26,py27,py27-yaml,py27-noargs,py31,py32,pypy
changedir =
{envbindir}
commands =
- pystache-test {toxinidir}/ext/spec/specs {toxinidir}
+ pystache-test {toxinidir}
# Check that the spec tests work with PyYAML.
[testenv:py27-yaml]
@@ -24,7 +24,7 @@ deps =
changedir =
{envbindir}
commands =
- pystache-test {toxinidir}/ext/spec/specs {toxinidir}
+ pystache-test {toxinidir}
# Check that pystache-test works from an install with no arguments.
[testenv:py27-noargs]

0 comments on commit de33ff3

Please sign in to comment.
Something went wrong with that request. Please try again.