From 150d4c45563015b60afe79f6b011c0b21f6594b7 Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Sat, 21 Apr 2012 11:03:09 -0700 Subject: The pystache-tests script now accepts a spec test directory argument. --- pystache/tests/main.py | 11 +++++++++-- pystache/tests/test_mustachespec.py | 10 +++++++--- tox.ini | 4 +++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/pystache/tests/main.py b/pystache/tests/main.py index 7cfcfeb..5b08471 100644 --- a/pystache/tests/main.py +++ b/pystache/tests/main.py @@ -32,10 +32,17 @@ def run_tests(sys_argv): try: # TODO: use optparse command options instead. project_dir = sys_argv[1] - sys_argv.pop() + sys_argv.pop(1) except IndexError: project_dir = PROJECT_DIR + try: + # TODO: use optparse command options instead. + spec_test_dir = sys_argv[1] + sys_argv.pop(1) + except IndexError: + 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. @@ -43,7 +50,7 @@ def run_tests(sys_argv): sys_argv.extend(module_names) _PystacheTestProgram._text_doctest_dir = project_dir - _PystacheTestProgram._spec_test_dir = SPEC_TEST_DIR + _PystacheTestProgram._spec_test_dir = spec_test_dir # We pass None for the module because we do not want the unittest # module to resolve module names relative to a given module. diff --git a/pystache/tests/test_mustachespec.py b/pystache/tests/test_mustachespec.py index 273beed..453c5ea 100644 --- a/pystache/tests/test_mustachespec.py +++ b/pystache/tests/test_mustachespec.py @@ -77,14 +77,18 @@ def get_spec_tests(spec_test_dir): case = _deserialize_spec_test(data, path) cases.append(case) + # Store this as a value so that CheckSpecTestsFound is not checking + # a reference to cases that contains itself. + spec_test_count = len(cases) + # This test case lets us alert the user that spec tests are missing. class CheckSpecTestsFound(unittest.TestCase): def runTest(self): - if len(cases) > 0: + if spec_test_count > 0: return - raise Exception("Spec tests not found in: %s\n " - "Consult the README file on how to add the Mustache spec tests." % repr(spec_test_dir)) + raise Exception("Spec tests not found--\n in %s\n" + " Consult the README file on how to add the Mustache spec tests." % repr(spec_test_dir)) case = CheckSpecTestsFound() cases.append(case) diff --git a/tox.ini b/tox.ini index 6336889..a6a20ed 100644 --- a/tox.ini +++ b/tox.ini @@ -6,7 +6,9 @@ envlist = py24,py25,py26,py27,py31,py32 [testenv] +# Change the working directory so that we don't import the pystache located +# in the original location. changedir = {envbindir} commands = - pystache-test {toxinidir} + pystache-test {toxinidir} {toxinidir}/ext/spec/specs -- cgit v1.2.1