From de33ff316211ca35c87232cf594ef06a8daf0806 Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Sat, 3 Nov 2012 23:38:41 -0700 Subject: Allow tox to run from a downloaded sdist (i.e. without spec tests). --- HISTORY.md | 4 ++-- pystache/tests/common.py | 5 ++++- pystache/tests/main.py | 37 +++++++++++++++++++++---------------- setup_description.rst | 4 ++-- tox.ini | 4 ++-- 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index bcf5d7f..1cca5c8 100644 --- a/HISTORY.md +++ b/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. 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 diff --git a/setup_description.rst b/setup_description.rst index 6001c6b..1ca09e8 100644 --- a/setup_description.rst +++ b/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. diff --git a/tox.ini b/tox.ini index bef48f2..d1eaebf 100644 --- a/tox.ini +++ b/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] -- cgit v1.2.1