summaryrefslogtreecommitdiff
path: root/setuptools
diff options
context:
space:
mode:
authorPJ Eby <distutils-sig@python.org>2006-03-28 22:40:57 +0000
committerPJ Eby <distutils-sig@python.org>2006-03-28 22:40:57 +0000
commitfb76e7210334ecbadcabfb1549e9df40c138b746 (patch)
tree1f3e6cd64a6063145a55a56415756b01c6190c1e /setuptools
parentc1294e1d0218322a1e3457897198837a071f2271 (diff)
downloadpython-setuptools-git-fb76e7210334ecbadcabfb1549e9df40c138b746.tar.gz
Enhanced test loader to scan packages as well as modules, and call
``additional_tests()`` if present to get non-unittest tests. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4043412
Diffstat (limited to 'setuptools')
-rw-r--r--setuptools/command/test.py49
-rw-r--r--setuptools/tests/__init__.py53
2 files changed, 51 insertions, 51 deletions
diff --git a/setuptools/command/test.py b/setuptools/command/test.py
index 31f1ae40..30226866 100644
--- a/setuptools/command/test.py
+++ b/setuptools/command/test.py
@@ -2,6 +2,42 @@ from setuptools import Command
from distutils.errors import DistutilsOptionError
import sys
from pkg_resources import *
+from unittest import TestLoader, main
+
+class ScanningLoader(TestLoader):
+
+ def loadTestsFromModule(self, module):
+ """Return a suite of all tests cases contained in the given module
+
+ If the module is a package, load tests from all the modules in it.
+ If the module has an ``additional_tests`` function, call it and add
+ the return value to the tests.
+ """
+
+ tests = [TestLoader.loadTestsFromModule(self,module)]
+
+ if hasattr(module, "additional_tests"):
+ tests.append(module.additional_tests())
+
+ if hasattr(module, '__path__'):
+ for file in resource_listdir(module.__name__, ''):
+ if file.endswith('.py') and file!='__init__.py':
+ submodule = module.__name__+'.'+file[:-3]
+ else:
+ if resource_exists(
+ module.__name__, file+'/__init__.py'
+ ):
+ submodule = module.__name__+'.'+file
+ else:
+ continue
+ tests.append(self.loadTestsFromName(submodule))
+
+ if len(tests)>1:
+ return self.suiteClass(tests)
+ else:
+ return tests[0] # don't create a nested suite for only one return
+
+
class test(Command):
@@ -39,6 +75,11 @@ class test(Command):
if self.verbose:
self.test_args.insert(0,'--verbose')
+
+
+
+
+
def run(self):
# Ensure metadata is up-to-date
self.run_command('egg_info')
@@ -70,10 +111,10 @@ class test(Command):
dist = Distribution(path_item, metadata, project_name=ei_cmd.egg_name)
working_set.add(dist)
require(str(dist.as_requirement()))
- unittest.main(None, None, [unittest.__file__]+self.test_args)
-
-
-
+ unittest.main(
+ None, None, [unittest.__file__]+self.test_args,
+ testLoader = ScanningLoader()
+ )
diff --git a/setuptools/tests/__init__.py b/setuptools/tests/__init__.py
index 7009b321..ea469446 100644
--- a/setuptools/tests/__init__.py
+++ b/setuptools/tests/__init__.py
@@ -13,6 +13,12 @@ from distutils.version import StrictVersion, LooseVersion
from distutils.util import convert_path
import sys, os.path
+def additional_tests():
+ import doctest
+ return doctest.DocFileSuite(
+ 'api_tests.txt', optionflags=doctest.ELLIPSIS, package='pkg_resources',
+ )
+
def makeSetup(**args):
"""Return distribution from 'setup(**args)', without executing commands"""
@@ -33,12 +39,6 @@ def makeSetup(**args):
-
-
-
-
-
-
class DependsTests(TestCase):
def testExtractConst(self):
@@ -367,44 +367,3 @@ class TestCommandTests(TestCase):
-def test_api():
- import doctest
- return doctest.DocFileSuite(
- 'api_tests.txt', optionflags=doctest.ELLIPSIS, package='pkg_resources',
- )
-
-
-testClasses = (DependsTests, DistroTests, FeatureTests, TestCommandTests)
-testNames = ["setuptools.tests.test_resources", "setuptools.tests.test_api"]
-
-def test_suite():
- return TestSuite(
- [makeSuite(t,'test') for t in testClasses]+
- [defaultTestLoader.loadTestsFromName(n) for n in testNames]
- )
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-