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