Commit 5b428cd7 by Chris Jerdonek

Merge branch 'issue-105-remove-nose' into 'development'

This addresses issue #105 by letting all tests be run using
Distribute's test, and in particular without using nose.
This paves the way for automatically running 2to3 when running
unit tests from Python 3, as described in issue #104.
parents c46fcb1f 98a5baa0
......@@ -15,7 +15,9 @@ _TESTS_DIR = os.path.dirname(pystache.tests.__file__)
DATA_DIR = os.path.join(_TESTS_DIR, 'data') # i.e. 'pystache/tests/data'.
EXAMPLES_DIR = os.path.dirname(examples.__file__)
SPEC_TEST_DIR = os.path.join(os.path.dirname(pystache.__file__), '..', 'ext', 'spec', 'specs')
SOURCE_DIR = os.path.dirname(pystache.__file__)
PROJECT_DIR = os.path.join(SOURCE_DIR, '..')
SPEC_TEST_DIR = os.path.join(PROJECT_DIR, 'ext', 'spec', 'specs')
def get_data_path(file_name):
......
# coding: utf-8
"""
Creates unittest.TestSuite instances for the doctests in the project.
"""
# This module follows the guidance documented here:
#
# http://docs.python.org/library/doctest.html#unittest-api
#
import os
import doctest
import pkgutil
import unittest
import pystache
from pystache.tests.common import PROJECT_DIR, SOURCE_DIR
# The paths to text files (i.e. non-module files) containing doctests.
# Paths should be OS-specific and relative to the project directory.
text_file_paths = ['README.rst']
# The following load_tests() function implements unittests's load_tests
# protocol added in Python 2.7. Using this protocol allows us to
# include the doctests in test runs without the use of nose, for example
# when using Distribute's test as in the following:
#
# python setup.py test
#
# TODO: find a substitute for the load_tests protocol for Python versions
# before version 2.7.
#
# HACK: Allowing load_tests() to be called without arguments is a hack
# to allow unit tests to be run with nose's nosetests without error.
# Otherwise, nose interprets the following function as a test case,
# raising the following error:
#
# TypeError: load_tests() takes exactly 3 arguments (0 given)
#
def load_tests(loader=None, tests=None, ignore=None):
if loader is None:
return
# Since module_relative is False in our calls to DocFileSuite below,
# paths should be OS-specific. Moreover, we choose absolute paths
# so that the current working directory does not come into play.
# See the following for more info--
#
# http://docs.python.org/library/doctest.html#doctest.DocFileSuite
#
paths = [os.path.join(PROJECT_DIR, path) for path in text_file_paths]
tests.addTests(doctest.DocFileSuite(*paths, module_relative=False))
modules = get_module_doctests()
for module in modules:
suite = doctest.DocTestSuite(module)
tests.addTests(suite)
return tests
def get_module_doctests():
modules = []
for pkg in pkgutil.walk_packages([SOURCE_DIR]):
# The importer is a pkgutil.ImpImporter instance:
#
# http://docs.python.org/library/pkgutil.html#pkgutil.ImpImporter
#
importer, module_name, is_package = pkg
if is_package:
# Otherwise, we will get the following error when adding tests:
#
# ValueError: (<module 'tests' from '.../pystache/tests/__init__.pyc'>, 'has no tests')
#
continue
# The loader is a pkgutil.ImpLoader instance.
loader = importer.find_module(module_name)
module = loader.load_module(module_name)
modules.append(module)
return modules
......@@ -31,15 +31,22 @@ from pystache.tests.common import AssertStringMixin, SPEC_TEST_DIR
spec_paths = glob.glob(os.path.join(SPEC_TEST_DIR, '*.json'))
if len(spec_paths) == 0:
raise Exception("""Spec tests not found in: %s
Consult the README file on how to add the spec tests.""" % repr(SPEC_TEST_DIR))
# This test case lets us alert the user that spec tests are missing.
class CheckSpecTestsFound(unittest.TestCase):
def test_spec_tests_found(self):
if len(spec_paths) > 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))
# TODO: give this a name better than MustacheSpec.
class MustacheSpec(unittest.TestCase, AssertStringMixin):
pass
def buildTest(testData, spec_filename):
name = testData['name']
......
......@@ -79,6 +79,7 @@ setup(name='pystache',
url='http://github.com/defunkt/pystache',
packages=['pystache'],
license='MIT',
test_suite='pystache.tests',
entry_points = {
'console_scripts': ['pystache=pystache.commands:main'],
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment