Commit d9e84960 by Chris Jerdonek

Started refactoring pystache/tests/main.py and stubbed out _PystacheTestProgram.

parent 5a47ea6d
......@@ -10,6 +10,7 @@ This module is for our test console script.
import os
import sys
import unittest
from unittest import TestProgram
UNITTEST_FILE_PREFIX = "test_"
......@@ -31,19 +32,12 @@ UNITTEST_FILE_PREFIX = "test_"
# TestCase or TestSuite instances (e.g. doctests and spec tests), and then
# call the base class's runTests().
class Tester(object):
"""
Discovers and runs unit tests.
"""
def _find_unittest_files(self, package_dir):
def _find_unittest_files(package_dir):
"""
Return a list of paths to all unit-test files in the given package directory.
"""
unittest_paths = [] # Return value.
paths = [] # Return value.
def is_unittest(file_name):
return file_name.startswith(UNITTEST_FILE_PREFIX) and file_name.endswith('.py')
......@@ -54,14 +48,15 @@ class Tester(object):
file_names = filter(is_unittest, file_names)
for file_name in file_names:
unittest_path = os.path.join(dir_path, file_name)
unittest_paths.append(unittest_path)
path = os.path.join(dir_path, file_name)
paths.append(path)
return unittest_paths
return paths
def _modules_from_paths(self, package_dir, paths):
def _get_module_names(package_dir, paths):
"""
Return a list of fully-qualified module names given paths.
Return a list of fully-qualified test module names given a list of module paths.
"""
package_dir = os.path.abspath(package_dir)
......@@ -88,6 +83,29 @@ class Tester(object):
return module_names
def _get_test_module_names(package_dir):
"""
Return a list of fully-qualified module names given a list of module paths.
"""
paths = _find_unittest_files(package_dir)
modules = _get_module_names(package_dir, paths)
return modules
class _PystacheTestProgram(TestProgram):
pass
class Tester(object):
"""
Discovers and runs unit tests.
"""
# TODO: consider replacing the package argument with a package_dir argument.
def run_tests(self, package, sys_argv):
"""
......@@ -105,13 +123,10 @@ class Tester(object):
# the unittest module is equipped to handle.
unittest.main(argv=sys_argv, module=None)
# No need to return since unitttest.main() exits.
# Otherwise, auto-detect all unit tests.
package_dir = os.path.dirname(package.__file__)
unittest_paths = self._find_unittest_files(package_dir)
modules = self._modules_from_paths(package_dir, unittest_paths)
modules = _get_test_module_names(package_dir)
modules.sort()
# This is a sanity check to ensure that the unit-test discovery
......
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