summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test/test_program.py
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2010-03-27 12:34:21 (GMT)
committerMichael Foord <fuzzyman@voidspace.org.uk>2010-03-27 12:34:21 (GMT)
commit2560e5cf5335011a3cb81562fe4028a0fb8c35da (patch)
tree42c2935dbd2388f142fff184457d548a1d073140 /Lib/unittest/test/test_program.py
parentab4d63b7f7f79d9cb5780b0666923aa05513b3bf (diff)
downloadcpython-2560e5cf5335011a3cb81562fe4028a0fb8c35da.zip
cpython-2560e5cf5335011a3cb81562fe4028a0fb8c35da.tar.gz
cpython-2560e5cf5335011a3cb81562fe4028a0fb8c35da.tar.bz2
Breaking test_unittest.py into a package. Manual merge of revision 79432.
Diffstat (limited to 'Lib/unittest/test/test_program.py')
-rw-r--r--Lib/unittest/test/test_program.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_program.py b/Lib/unittest/test/test_program.py
new file mode 100644
index 0000000..b6a69dc
--- /dev/null
+++ b/Lib/unittest/test/test_program.py
@@ -0,0 +1,74 @@
+import io
+
+import unittest
+
+
+class Test_TestProgram(unittest.TestCase):
+
+ # Horrible white box test
+ def testNoExit(self):
+ result = object()
+ test = object()
+
+ class FakeRunner(object):
+ def run(self, test):
+ self.test = test
+ return result
+
+ runner = FakeRunner()
+
+ oldParseArgs = unittest.TestProgram.parseArgs
+ def restoreParseArgs():
+ unittest.TestProgram.parseArgs = oldParseArgs
+ unittest.TestProgram.parseArgs = lambda *args: None
+ self.addCleanup(restoreParseArgs)
+
+ def removeTest():
+ del unittest.TestProgram.test
+ unittest.TestProgram.test = test
+ self.addCleanup(removeTest)
+
+ program = unittest.TestProgram(testRunner=runner, exit=False, verbosity=2)
+
+ self.assertEqual(program.result, result)
+ self.assertEqual(runner.test, test)
+ self.assertEqual(program.verbosity, 2)
+
+ class FooBar(unittest.TestCase):
+ def testPass(self):
+ assert True
+ def testFail(self):
+ assert False
+
+ class FooBarLoader(unittest.TestLoader):
+ """Test loader that returns a suite containing FooBar."""
+ def loadTestsFromModule(self, module):
+ return self.suiteClass(
+ [self.loadTestsFromTestCase(Test_TestProgram.FooBar)])
+
+
+ def test_NonExit(self):
+ program = unittest.main(exit=False,
+ argv=["foobar"],
+ testRunner=unittest.TextTestRunner(stream=io.StringIO()),
+ testLoader=self.FooBarLoader())
+ self.assertTrue(hasattr(program, 'result'))
+
+
+ def test_Exit(self):
+ self.assertRaises(
+ SystemExit,
+ unittest.main,
+ argv=["foobar"],
+ testRunner=unittest.TextTestRunner(stream=io.StringIO()),
+ exit=True,
+ testLoader=self.FooBarLoader())
+
+
+ def test_ExitAsDefault(self):
+ self.assertRaises(
+ SystemExit,
+ unittest.main,
+ argv=["foobar"],
+ testRunner=unittest.TextTestRunner(stream=io.StringIO()),
+ testLoader=self.FooBarLoader())