summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpje <pje@571e12c6-e1fa-0310-aee7-ff1267fa46bd>2004-03-06 18:54:32 +0000
committerpje <pje@571e12c6-e1fa-0310-aee7-ff1267fa46bd>2004-03-06 18:54:32 +0000
commitda3d6a1248fdf536a620cfd6ef3a15e99919c0be (patch)
tree5359d66bc9ef611388d01168aa7a145a6d199ae1
parent630ec4c2df41016589d45303a0bd7e05c7661dff (diff)
downloadwsgiref-da3d6a1248fdf536a620cfd6ef3a15e99919c0be.tar.gz
Added various tests for 'test' command option processing. Fixed missing
install of 'command' subpackage. Changed setup() arg to 'test_suite' instead of 'test_module'. Added '--test-suite' option to 'test' command, usable in place of '--test-module'. git-svn-id: svn://svn.eby-sarna.com/svnroot/wsgiref@234 571e12c6-e1fa-0310-aee7-ff1267fa46bd
-rw-r--r--setuptools/command/test.py50
-rw-r--r--setuptools/dist.py2
-rw-r--r--setuptools/tests/__init__.py123
3 files changed, 166 insertions, 9 deletions
diff --git a/setuptools/command/test.py b/setuptools/command/test.py
index 62be491..2509554 100644
--- a/setuptools/command/test.py
+++ b/setuptools/command/test.py
@@ -1,4 +1,5 @@
from distutils.cmd import Command
+from distutils.errors import DistutilsOptionError
import sys
class test(Command):
@@ -8,28 +9,42 @@ class test(Command):
description = "Run unit tests after installation"
user_options = [
- ('test-module=','m','Module to run tests from'),
+ ('test-module=','m', "Run 'test_suite' in specified module"),
+ ('test-suite=','s',
+ "Test suite to run (e.g. 'some_module.test_suite')"),
]
+ test_suite = None
+ test_module = None
+
def initialize_options(self):
- self.test_module = None
+ pass
+
def finalize_options(self):
- if self.test_module is None:
- self.test_module = self.distribution.test_module
+ if self.test_suite is None:
+ if self.test_module is None:
+ self.test_suite = self.distribution.test_suite
+ else:
+ self.test_suite = self.test_module+".test_suite"
+ elif self.test_module:
+ raise DistutilsOptionError(
+ "You may specify a module or a suite, but not both"
+ )
- self.test_args = [self.test_module+'.test_suite']
+ self.test_args = [self.test_suite]
if self.verbose:
self.test_args.insert(0,'--verbose')
+
def run(self):
# Install before testing
self.run_command('install')
- if not self.dry_run:
+ if self.test_suite and not self.dry_run:
import unittest
unittest.main(None, None, [unittest.__file__]+self.test_args)
@@ -42,3 +57,26 @@ class test(Command):
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/setuptools/dist.py b/setuptools/dist.py
index 9977214..e742780 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -8,7 +8,7 @@ class Distribution(_Distribution):
requires = ()
# 'test' command
- test_module = None
+ test_suite = None
def __init__ (self, attrs=None):
self.package_data = {}
diff --git a/setuptools/tests/__init__.py b/setuptools/tests/__init__.py
index f63a85e..40c5b18 100644
--- a/setuptools/tests/__init__.py
+++ b/setuptools/tests/__init__.py
@@ -1,4 +1,123 @@
-from unittest import TestSuite
+from unittest import TestSuite, TestCase, makeSuite
+import distutils.core, distutils.cmd
+from distutils.errors import DistutilsOptionError
+import setuptools, setuptools.dist
+
+def makeSetup(**args):
+ """Return distribution from 'setup(**args)', without executing commands"""
+ distutils.core._setup_stop_after = "commandline"
+ try:
+ return setuptools.setup(**args)
+ finally:
+ distutils.core_setup_stop_after = None
+
+
+class DistroTests(TestCase):
+
+ def testDistro(self):
+ self.failUnless(isinstance(makeSetup(),setuptools.dist.Distribution))
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+class TestCommandTests(TestCase):
+
+ def testTestIsCommand(self):
+ test_cmd = makeSetup().get_command_obj('test')
+ self.failUnless(isinstance(test_cmd, distutils.cmd.Command))
+
+ def testLongOptSuiteWNoDefault(self):
+ ts1 = makeSetup(script_args=['test','--test-suite=foo.tests.suite'])
+ ts1 = ts1.get_command_obj('test')
+ ts1.ensure_finalized()
+ self.assertEqual(ts1.test_suite, 'foo.tests.suite')
+
+ def testDefaultSuite(self):
+ ts2 = makeSetup(test_suite='bar.tests.suite').get_command_obj('test')
+ ts2.ensure_finalized()
+ self.assertEqual(ts2.test_suite, 'bar.tests.suite')
+
+ def testDefaultWModuleOnCmdLine(self):
+ ts3 = makeSetup(
+ test_suite='bar.tests',
+ script_args=['test','-m','foo.tests']
+ ).get_command_obj('test')
+ ts3.ensure_finalized()
+ self.assertEqual(ts3.test_module, 'foo.tests')
+ self.assertEqual(ts3.test_suite, 'foo.tests.test_suite')
+
+ def testConflictingOptions(self):
+ ts4 = makeSetup(
+ script_args=['test','-m','bar.tests', '-s','foo.tests.suite']
+ ).get_command_obj('test')
+ self.assertRaises(DistutilsOptionError, ts4.ensure_finalized)
+
+ def testNoSuite(self):
+ ts5 = makeSetup().get_command_obj('test')
+ ts5.ensure_finalized()
+ self.assertEqual(ts5.test_suite, None)
+
+
+
+
+
+testClasses = (DistroTests, TestCommandTests)
def test_suite():
- return TestSuite([])
+ return TestSuite([makeSuite(t,'test') for t in testClasses])
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+