From f30aad9ad2a3fd6be307d76c719d13f73d62734e Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Mon, 23 Apr 2012 17:45:04 -0700 Subject: Changes in preparation for 0.5.1. --- README.rst | 29 +++++++++++++++++------------ TODO.md | 1 - pystache/tests/main.py | 18 +++++++++++++++++- pystache/tests/spectesting.py | 12 ++++++++++-- setup.cfg | 5 ----- setup.py | 9 +++------ tox.ini | 11 ++++++++++- 7 files changed, 57 insertions(+), 28 deletions(-) delete mode 100644 setup.cfg diff --git a/README.rst b/README.rst index a42daa0..b10ff52 100644 --- a/README.rst +++ b/README.rst @@ -25,19 +25,20 @@ Requirements Pystache is tested with the following versions of Python: -* Python 2.4 (requires simplejson version 2.0.9 or earlier) -* Python 2.5 (requires simplejson) +* Python 2.4 (requires `simplejson version 2.0.9`_ or earlier) +* Python 2.5 (requires simplejson_) * Python 2.6 * Python 2.7 +* Python 3.1 * Python 3.2 JSON support is needed only for the command-line interface and to run the -spec tests. We require simplejson_ for earlier versions of Python since -Python's json_ module was added in Python 2.6. Moreover, we require an -earlier version of simplejson for Python 2.4 since simplejson stopped -officially supporting Python 2.4 with version 2.1.0. +spec tests. We require simplejson for earlier versions of Python since +Python's json_ module was added in Python 2.6. -An earlier version of simplejson can be installed manually, as follows: :: +For Python 2.4 we require an earlier version of simplejson since simplejson +stopped officially supporting Python 2.4 in simplejson version 2.1.0. +Earlier versions of simplejson can be installed manually, as follows: :: pip install 'simplejson<2.1.0' @@ -162,9 +163,11 @@ Mustache spec. To include tests from the Mustache spec in your test runs: :: git submodule init git submodule update +The test harness parses the spec's yaml files if PyYAML_ is present. +Otherwise, it parses the json files. + To test Pystache from a source distribution with Python 3.x, you must use tox. -This is because the raw source is not Python 3 compatible and must first be -run through 2to3_. +This is because the source code must first be run through 2to3_. Mailing List @@ -183,9 +186,9 @@ Author :: - >>> context = { 'author': 'Chris Wanstrath', 'email': 'chris@ozmm.org' } - >>> print pystache.render("{{author}} :: {{email}}", context) - Chris Wanstrath :: chris@ozmm.org + >>> context = { 'author': 'Chris Wanstrath', 'maintainer': 'Chris Jerdonek' } + >>> print pystache.render("{{author}} :: {{maintainer}}", context) + Chris Wanstrath :: Chris Jerdonek .. _2to3: http://docs.python.org/library/2to3.html @@ -202,8 +205,10 @@ Author .. _only unicode strings: http://docs.python.org/howto/unicode.html#tips-for-writing-unicode-aware-programs .. _PyPI: http://pypi.python.org/pypi/pystache .. _Pystache: https://github.com/defunkt/pystache +.. _PyYAML: http://pypi.python.org/pypi/PyYAML .. _semantically versioned: http://semver.org .. _simplejson: http://pypi.python.org/pypi/simplejson/ +.. _simplejson version 2.0.9: http://pypi.python.org/pypi/simplejson/2.0.9 .. _test: http://packages.python.org/distribute/setuptools.html#test .. _tox: http://pypi.python.org/pypi/tox .. _version 1.0.3: https://github.com/mustache/spec/tree/48c933b0bb780875acbfd15816297e263c53d6f7 diff --git a/TODO.md b/TODO.md index 3a8c8d9..a6eb1a9 100644 --- a/TODO.md +++ b/TODO.md @@ -7,4 +7,3 @@ TODO * Make sure doctest text files can be converted for Python 3 when using tox. * Make sure command parsing to pystache-test doesn't break with Python 2.4 and earlier. * Combine pystache-test with the main command. -* Add a unittest that pystache.__version__ matches the version in setup.py. diff --git a/pystache/tests/main.py b/pystache/tests/main.py index 9364f39..c75664e 100644 --- a/pystache/tests/main.py +++ b/pystache/tests/main.py @@ -9,15 +9,16 @@ This module is for our test console script. import os import sys +import unittest from unittest import 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.doctesting import get_doctests from pystache.tests.spectesting import get_spec_tests -# TODO: enhance this function to create spec-test tests. def run_tests(sys_argv): """ Run all tests in the project. @@ -46,6 +47,8 @@ def run_tests(sys_argv): # 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__) _PystacheTestProgram._text_doctest_dir = project_dir _PystacheTestProgram._spec_test_dir = spec_test_dir @@ -78,6 +81,19 @@ def _discover_test_modules(package_dir): return names +class SetupTests(unittest.TestCase): + + """Tests about setup.py.""" + + def test_version(self): + """ + Test that setup.py's version matches the package's version. + + """ + from setup import VERSION + self.assertEqual(VERSION, pystache.__version__) + + # The function unittest.main() is an alias for unittest.TestProgram's # constructor. TestProgram's constructor calls self.runTests() as its # final step, which expects self.test to be set. The constructor sets diff --git a/pystache/tests/spectesting.py b/pystache/tests/spectesting.py index cb9d316..d79d75c 100644 --- a/pystache/tests/spectesting.py +++ b/pystache/tests/spectesting.py @@ -61,6 +61,9 @@ def get_spec_tests(spec_test_dir): Return a list of unittest.TestCase instances. """ + # TODO: use logging module instead. + print "pystache: spec tests: using %s" % _get_parser_info() + cases = [] # Make this absolute for easier diagnosis in case of error. @@ -90,6 +93,10 @@ def get_spec_tests(spec_test_dir): return cases +def _get_parser_info(): + return "%s (version %s)" % (parser.__name__, parser.__version__) + + def _read_spec_tests(path): """ Return a list of unittest.TestCase instances. @@ -231,8 +238,9 @@ class SpecTestBase(unittest.TestCase, AssertStringMixin): def escape(s): return s.replace("%", "%%") + parser_info = _get_parser_info() subs = [repr(test_name), description, os.path.abspath(file_path), - template, repr(context), parser.__version__, str(parser)] + template, repr(context), parser_info] subs = tuple([escape(sub) for sub in subs]) # We include the parsing module version info to help with troubleshooting # yaml/json/simplejson issues. @@ -246,7 +254,7 @@ class SpecTestBase(unittest.TestCase, AssertStringMixin): %%s - (using version %s of %s) + [using %s] """ % subs self.assertString(actual, expected, format=message) diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 472b1ac..0000000 --- a/setup.cfg +++ /dev/null @@ -1,5 +0,0 @@ -[nosetests] -with-doctest=1 -doctest-extension=rst -# Prevent nose from interpreting the load_tests protocol function as a test. -exclude=load_tests diff --git a/setup.py b/setup.py index bb229f5..6051fba 100644 --- a/setup.py +++ b/setup.py @@ -52,10 +52,11 @@ else: setup = dist.setup # TODO: use the logging module instead of printing. -print("Using: version %s of %s" % (repr(dist.__version__), repr(dist))) +# TODO: include the following in a verbose mode. +# print("Using: version %s of %s" % (repr(dist.__version__), repr(dist))) -VERSION = '0.5.1-alpha' # Also change in pystache/init.py. +VERSION = '0.5.1-alpha' # Also change in pystache/__init__.py. HISTORY_PATH = 'HISTORY.rst' LICENSE_PATH = 'LICENSE' @@ -134,7 +135,6 @@ else: extra = { # Causes 2to3 to be run during the build step. 'use_2to3': True, - 'convert_2to3_doctests': [README_PATH], } # We use the package simplejson for older Python versions since Python @@ -151,8 +151,6 @@ if py_version < (2, 5): requires.append('simplejson<2.1') elif py_version < (2, 6): requires.append('simplejson') -else: - requires.append('pyyaml') INSTALL_REQUIRES = requires @@ -188,7 +186,6 @@ def main(sys_argv): 'pystache.tests.data.locator': template_files, 'pystache.tests.examples': template_files, }, - test_suite='pystache.tests', entry_points = { 'console_scripts': [ 'pystache=pystache.commands.render:main', diff --git a/tox.ini b/tox.ini index a6a20ed..72c5369 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ # http://pypi.python.org/pypi/tox # [tox] -envlist = py24,py25,py26,py27,py31,py32 +envlist = py24,py25,py26,py27,py27-yaml,py31,py32 [testenv] # Change the working directory so that we don't import the pystache located @@ -12,3 +12,12 @@ changedir = {envbindir} commands = pystache-test {toxinidir} {toxinidir}/ext/spec/specs + +# Check that the spec tests work with PyYAML. +[testenv:py27-yaml] +deps = + PyYAML +changedir = + {envbindir} +commands = + pystache-test {toxinidir} {toxinidir}/ext/spec/specs -- cgit v1.2.1