Permalink
Browse files

Test scripts now work with and without source.

  • Loading branch information...
1 parent 9447214 commit ff36b627772bc37263093f2d01fb08e699472c75 @cjerdonek cjerdonek committed Apr 24, 2012
Showing with 57 additions and 15 deletions.
  1. +1 −0 MANIFEST.in
  2. +31 −10 pystache/tests/main.py
  3. +1 −1 setup.py
  4. +10 −1 test_pystache.py
  5. +14 −3 tox.ini
View
@@ -2,6 +2,7 @@ include LICENSE
include HISTORY.rst
include README.rst
include tox.ini
+include test_pystache.py
# You cannot use package_data, for example, to include data files in a
# source distribution when using Distribute.
recursive-include pystache/tests *.mustache *.txt
@@ -19,6 +19,11 @@
from pystache.tests.spectesting import get_spec_tests
+# If this command option is present, then the spec test and doctest directories
+# will be inserted if not provided.
+FROM_SOURCE_OPTION = "--from-source"
+
+
def run_tests(sys_argv):
"""
Run all tests in the project.
@@ -28,27 +33,41 @@ def run_tests(sys_argv):
sys_argv: a reference to 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:
+ 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]
+ spec_test_dir = sys_argv[1]
sys_argv.pop(1)
except IndexError:
- project_dir = PROJECT_DIR
+ if should_source_exist:
+ spec_test_dir = SPEC_TEST_DIR
try:
# TODO: use optparse command options instead.
- spec_test_dir = sys_argv[1]
+ project_dir = sys_argv[1]
sys_argv.pop(1)
except IndexError:
- spec_test_dir = SPEC_TEST_DIR
+ if should_source_exist:
+ 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)
- # Add the current module for unit tests contained here.
- sys_argv.append(__name__)
+ if project_dir is not None:
+ # Add the current module for unit tests contained here.
+ sys_argv.append(__name__)
_PystacheTestProgram._text_doctest_dir = project_dir
_PystacheTestProgram._spec_test_dir = spec_test_dir
@@ -123,10 +142,12 @@ def runTests(self):
# http://docs.python.org/library/unittest.html#unittest.TestSuite
tests = self.test
- doctest_suites = get_doctests(self._text_doctest_dir)
- tests.addTests(doctest_suites)
+ if self._text_doctest_dir is not None:
+ doctest_suites = get_doctests(self._text_doctest_dir)
+ tests.addTests(doctest_suites)
- spec_testcases = get_spec_tests(self._spec_test_dir)
- tests.addTests(spec_testcases)
+ if self._spec_test_dir is not None:
+ spec_testcases = get_spec_tests(self._spec_test_dir)
+ tests.addTests(spec_testcases)
TestProgram.runTests(self)
View
@@ -2,7 +2,7 @@
# coding: utf-8
"""
-This script supports distributing Pystache and testing it from a source distribution.
+This script supports publishing Pystache to PyPI.
Below are instructions to pystache maintainers on how to push a new
version of pystache to PyPI--
View
@@ -15,7 +15,16 @@
"""
-from pystache.commands.test import main
+import sys
+
+from pystache.commands import test
+from pystache.tests.main import FROM_SOURCE_OPTION
+
+
+def main(sys_argv=sys.argv):
+ sys.argv.insert(1, FROM_SOURCE_OPTION)
+ test.main()
+
if __name__=='__main__':
main()
View
@@ -3,21 +3,32 @@
# http://pypi.python.org/pypi/tox
#
[tox]
-envlist = py24,py25,py26,py27,py27-yaml,py31,py32
+envlist = py24,py25,py26,py27,py27-yaml,py27-noargs,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} {toxinidir}/ext/spec/specs
+ pystache-test {toxinidir}/ext/spec/specs {toxinidir}
# Check that the spec tests work with PyYAML.
[testenv:py27-yaml]
+basepython =
+ python2.7
deps =
PyYAML
changedir =
{envbindir}
commands =
- pystache-test {toxinidir} {toxinidir}/ext/spec/specs
+ pystache-test {toxinidir}/ext/spec/specs {toxinidir}
+
+# Check that pystache-test works from an install with no arguments.
+[testenv:py27-noargs]
+basepython =
+ python2.7
+changedir =
+ {envbindir}
+commands =
+ pystache-test

0 comments on commit ff36b62

Please sign in to comment.