Commit f267ff77 by Chris Jerdonek

Doctests now included when running `python setup.py test`.

parent 9b00a932
......@@ -15,7 +15,8 @@ _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__)
PROJECT_DIR = os.path.join(os.path.dirname(pystache.__file__), '..')
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')
......
......@@ -12,10 +12,11 @@ Creates unittest.TestSuite instances for the doctests in the project.
import os
import doctest
import pkgutil
import unittest
import pystache
from pystache.tests.common import PROJECT_DIR
from pystache.tests.common import PROJECT_DIR, SOURCE_DIR
# The paths to text files (i.e. non-module files) containing doctests.
......@@ -34,4 +35,31 @@ def load_tests(loader, tests, ignore):
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
......@@ -35,7 +35,7 @@ spec_paths = glob.glob(os.path.join(SPEC_TEST_DIR, '*.json'))
# This test case lets us alert the user that spec tests are missing.
class CheckSpecTestsFound(unittest.TestCase):
def test_spec_tests_exist(self):
def test_spec_tests_found(self):
if len(spec_paths) > 0:
return
raise Exception("Spec tests not found in: %s\n "
......
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