diff options
author | Jason Pellerin <jpellerin@gmail.com> | 2007-04-10 02:14:09 +0000 |
---|---|---|
committer | Jason Pellerin <jpellerin@gmail.com> | 2007-04-10 02:14:09 +0000 |
commit | 00adb580f9801bf3b704f22cb72c98cbf438b42e (patch) | |
tree | db810fea225203cfaa3f526bf1c7af55814bb68b | |
parent | 0c12ebbed8bc4fea4951a16713ae09aa9c7819f1 (diff) | |
download | nose-00adb580f9801bf3b704f22cb72c98cbf438b42e.tar.gz |
Fixed some unit tests
-rw-r--r-- | nose/core.py | 26 | ||||
-rw-r--r-- | nose/plugins/capture.py | 3 | ||||
-rw-r--r-- | unit_tests/test_core.py | 31 | ||||
-rw-r--r-- | unit_tests/test_importer.py | 8 | ||||
-rw-r--r-- | unit_tests/test_lazy_suite.py | 31 |
5 files changed, 17 insertions, 82 deletions
diff --git a/nose/core.py b/nose/core.py index 3f06827..1394733 100644 --- a/nose/core.py +++ b/nose/core.py @@ -194,28 +194,6 @@ class TestProgram(unittest.TestProgram): self, module=module, defaultTest=defaultTest, argv=argv, testRunner=testRunner, testLoader=testLoader) -# def __init__(self, module=None, defaultTest=defaultTestCollector, -# argv=None, testRunner=None, testLoader=None, env=None, -# stream=sys.stderr): -# self.testRunner = testRunner -# self.testCollector = defaultTest -# self.testLoader = testLoader -# self.stream = stream -# self.success = False -# self.module = module - -# if not callable(self.testCollector): -# raise ValueError("TestProgram argument defaultTest must be " -# "a callable with the same signature as " -# "nose.TestCollector") - -# if argv is None: -# argv = sys.argv -# if env is None: -# env = os.environ -# self.parseArgs(argv, env) -# self.createTests() -# self.runTests() def parseArgs(self, argv): """Parse argv and env and configure running environment. @@ -353,9 +331,7 @@ run_exit = main def run(*arg, **kw): """Collect and run test, returning success or failure """ - result = TestProgram(*arg, **kw).success - end_capture() - return result + return TestProgram(*arg, **kw).success def runmodule(name='__main__'): """Collect and run tests in a single module only. Defaults to running diff --git a/nose/plugins/capture.py b/nose/plugins/capture.py index 679a4d3..e1b6cd0 100644 --- a/nose/plugins/capture.py +++ b/nose/plugins/capture.py @@ -76,3 +76,6 @@ class Capture(Plugin): buffer = property(_get_buffer, None, None, """Captured stdout output.""") + + def __del__(self): + self.end() diff --git a/unit_tests/test_core.py b/unit_tests/test_core.py index b25dbf2..610c5f3 100644 --- a/unit_tests/test_core.py +++ b/unit_tests/test_core.py @@ -1,30 +1,12 @@ import unittest import nose.core +from nose.config import Config from cStringIO import StringIO -def nullcollector(conf, loader): - def nulltest(result): - pass - return nulltest - -class TestTestProgram(unittest.TestCase): - - def test_init_arg_defaultTest(self): - try: - t = nose.core.TestProgram(defaultTest='something', argv=[], env={}) - except ValueError: - pass - else: - self.fail("TestProgram with non-callable defaultTest should " - "have thrown ValueError") - - def test_init_arg_module(self): - s = StringIO() - t = nose.core.TestProgram('__main__', defaultTest=nullcollector, - argv=[], env={}, stream=s) - assert '__main__' in t.conf.tests - +class nullLoader: + def loadTestsFromNames(self, names): + return unittest.TestSuite() class TestAPI_run(unittest.TestCase): @@ -32,8 +14,9 @@ class TestAPI_run(unittest.TestCase): import sys s = StringIO() stdout = sys.stdout - res = nose.core.run(defaultTest=nullcollector, argv=[], env={}, - stream=s) + conf = Config(stream=s, exit=False) + res = nose.core.run( + testLoader=nullLoader(), argv=['test_run'], env={}, config=conf) stdout_after = sys.stdout self.assertEqual(stdout, stdout_after) diff --git a/unit_tests/test_importer.py b/unit_tests/test_importer.py index d265393..74098b6 100644 --- a/unit_tests/test_importer.py +++ b/unit_tests/test_importer.py @@ -30,7 +30,8 @@ class TestImporter(unittest.TestCase): foo = os.path.join(where, 'foo') foobar = os.path.join(foo, 'bar') - mod = nose.importer._import('buz', [foobar], nose.config.Config()) + imp = nose.importer.Importer() + mod = imp.import_from_dir(foobar, 'buz') assert where in sys.path # buz has an intra-package import that sets boodle assert mod.boodle @@ -43,8 +44,9 @@ class TestImporter(unittest.TestCase): # something that's not a real module and has no __file__ sys.modules['buz'] = 'Whatever' - - mod = nose.importer._import('buz', [foobar], nose.config.Config()) + + imp = nose.importer.Importer() + mod = imp.import_from_dir(foobar, 'buz') assert where in sys.path # buz has an intra-package import that sets boodle assert mod.boodle diff --git a/unit_tests/test_lazy_suite.py b/unit_tests/test_lazy_suite.py index db1869f..79cdcf0 100644 --- a/unit_tests/test_lazy_suite.py +++ b/unit_tests/test_lazy_suite.py @@ -1,5 +1,5 @@ import unittest -from nose import LazySuite +from nose.suite import LazySuite from helpers import iter_compat def gen(): @@ -16,35 +16,6 @@ class TestLazySuite(unittest.TestCase): ls = LazySuite(gen) for t in iter_compat(ls): assert isinstance(t, unittest.TestCase) - - def test_setup_teardown(self): - class SetupTeardownLazySuite(LazySuite): - _setup = False - _teardown = False - - def setUp(self): - self._setup = True - - def tearDown(self): - if self._setup: - self._teardown = True - - class Result: - shouldStop = False - - def addSuccess(self, test): - pass - - def startTest(self, test): - pass - - def stopTest(self, test): - pass - - ls = SetupTeardownLazySuite(gen) - ls(Result()) - assert ls._setup - assert ls._teardown if __name__ == '__main__': unittest.main() |