Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
unittest.test.test_suite.Test_TestSuite Class Reference

List of all members.

Public Member Functions

def test_init__tests_optional
 /Set up attributes needed by inherited tests
def test_init__empty_tests
def test_init__tests_from_any_iterable
def test_init__TestSuite_instances_in_tests
def test_iter
 /Tests for TestSuite.__init__
def test_countTestCases_zero_simple
def test_countTestCases_zero_nested
def test_countTestCases_simple
def test_countTestCases_nested
def test_run__empty_suite
def test_run__requires_result
def test_run
def test_addTest__TestCase
def test_addTest__TestSuite
def test_addTests
def test_addTest__noniterable
def test_addTest__noncallable
def test_addTest__casesuiteclass
def test_addTests__string
def test_function_in_suite
def test_basetestsuite
def test_overriding_call

Public Attributes

 called

Static Public Attributes

list eq_pairs
 Set up attributes needed by inherited tests.
list ne_pairs

Detailed Description

Definition at line 23 of file test_suite.py.


Member Function Documentation

Definition at line 285 of file test_suite.py.

00285 
00286     def test_addTest__casesuiteclass(self):
00287         suite = unittest.TestSuite()
00288         self.assertRaises(TypeError, suite.addTest, Test_TestSuite)
00289         self.assertRaises(TypeError, suite.addTest, unittest.TestSuite)

Here is the call graph for this function:

Definition at line 281 of file test_suite.py.

00281 
00282     def test_addTest__noncallable(self):
00283         suite = unittest.TestSuite()
00284         self.assertRaises(TypeError, suite.addTest, 5)

Here is the call graph for this function:

Definition at line 271 of file test_suite.py.

00271 
00272     def test_addTest__noniterable(self):
00273         suite = unittest.TestSuite()
00274 
00275         try:
00276             suite.addTests(5)
00277         except TypeError:
00278             pass
00279         else:
00280             self.fail("Failed to raise TypeError")

Here is the call graph for this function:

Definition at line 210 of file test_suite.py.

00210 
00211     def test_addTest__TestCase(self):
00212         class Foo(unittest.TestCase):
00213             def test(self): pass
00214 
00215         test = Foo('test')
00216         suite = unittest.TestSuite()
00217 
00218         suite.addTest(test)
00219 
00220         self.assertEqual(suite.countTestCases(), 1)
00221         self.assertEqual(list(suite), [test])

Here is the call graph for this function:

Definition at line 223 of file test_suite.py.

00223 
00224     def test_addTest__TestSuite(self):
00225         class Foo(unittest.TestCase):
00226             def test(self): pass
00227 
00228         suite_2 = unittest.TestSuite([Foo('test')])
00229 
00230         suite = unittest.TestSuite()
00231         suite.addTest(suite_2)
00232 
00233         self.assertEqual(suite.countTestCases(), 1)
00234         self.assertEqual(list(suite), [suite_2])

Here is the call graph for this function:

Definition at line 240 of file test_suite.py.

00240 
00241     def test_addTests(self):
00242         class Foo(unittest.TestCase):
00243             def test_1(self): pass
00244             def test_2(self): pass
00245 
00246         test_1 = Foo('test_1')
00247         test_2 = Foo('test_2')
00248         inner_suite = unittest.TestSuite([test_2])
00249 
00250         def gen():
00251             yield test_1
00252             yield test_2
00253             yield inner_suite
00254 
00255         suite_1 = unittest.TestSuite()
00256         suite_1.addTests(gen())
00257 
00258         self.assertEqual(list(suite_1), list(gen()))
00259 
00260         # "This is equivalent to iterating over tests, calling addTest() for
00261         # each element"
00262         suite_2 = unittest.TestSuite()
00263         for t in gen():
00264             suite_2.addTest(t)
00265 
00266         self.assertEqual(suite_1, suite_2)

Here is the call graph for this function:

Definition at line 290 of file test_suite.py.

00290 
00291     def test_addTests__string(self):
00292         suite = unittest.TestSuite()
00293         self.assertRaises(TypeError, suite.addTests, "foo")

Here is the call graph for this function:

Definition at line 305 of file test_suite.py.

00305 
00306     def test_basetestsuite(self):
00307         class Test(unittest.TestCase):
00308             wasSetUp = False
00309             wasTornDown = False
00310             @classmethod
00311             def setUpClass(cls):
00312                 cls.wasSetUp = True
00313             @classmethod
00314             def tearDownClass(cls):
00315                 cls.wasTornDown = True
00316             def testPass(self):
00317                 pass
00318             def testFail(self):
00319                 fail
00320         class Module(object):
00321             wasSetUp = False
00322             wasTornDown = False
00323             @staticmethod
00324             def setUpModule():
00325                 Module.wasSetUp = True
00326             @staticmethod
00327             def tearDownModule():
00328                 Module.wasTornDown = True
00329 
00330         Test.__module__ = 'Module'
00331         sys.modules['Module'] = Module
00332         self.addCleanup(sys.modules.pop, 'Module')
00333 
00334         suite = unittest.BaseTestSuite()
00335         suite.addTests([Test('testPass'), Test('testFail')])
00336         self.assertEqual(suite.countTestCases(), 2)
00337 
00338         result = unittest.TestResult()
00339         suite.run(result)
00340         self.assertFalse(Module.wasSetUp)
00341         self.assertFalse(Module.wasTornDown)
00342         self.assertFalse(Test.wasSetUp)
00343         self.assertFalse(Test.wasTornDown)
00344         self.assertEqual(len(result.errors), 1)
00345         self.assertEqual(len(result.failures), 0)
00346         self.assertEqual(result.testsRun, 2)
00347 

Definition at line 152 of file test_suite.py.

00152 
00153     def test_countTestCases_nested(self):
00154         class Test1(unittest.TestCase):
00155             def test1(self): pass
00156             def test2(self): pass
00157 
00158         test2 = unittest.FunctionTestCase(lambda: None)
00159         test3 = unittest.FunctionTestCase(lambda: None)
00160         child = unittest.TestSuite((Test1('test2'), test2))
00161         parent = unittest.TestSuite((test3, child, Test1('test1')))
00162 
00163         self.assertEqual(parent.countTestCases(), 4)

Here is the call graph for this function:

Definition at line 140 of file test_suite.py.

00140 
00141     def test_countTestCases_simple(self):
00142         test1 = unittest.FunctionTestCase(lambda: None)
00143         test2 = unittest.FunctionTestCase(lambda: None)
00144         suite = unittest.TestSuite((test1, test2))
00145 
00146         self.assertEqual(suite.countTestCases(), 2)

Here is the call graph for this function:

Definition at line 128 of file test_suite.py.

00128 
00129     def test_countTestCases_zero_nested(self):
00130         class Test1(unittest.TestCase):
00131             def test(self):
00132                 pass
00133 
00134         suite = unittest.TestSuite([unittest.TestSuite()])
00135 
00136         self.assertEqual(suite.countTestCases(), 0)

Definition at line 117 of file test_suite.py.

00117 
00118     def test_countTestCases_zero_simple(self):
00119         suite = unittest.TestSuite()
00120 
00121         self.assertEqual(suite.countTestCases(), 0)

Here is the call graph for this function:

Definition at line 294 of file test_suite.py.

00294 
00295     def test_function_in_suite(self):
00296         def f(_):
00297             pass
00298         suite = unittest.TestSuite()
00299         suite.addTest(f)
00300 
00301         # when the bug is fixed this line will not crash
00302         suite.run(unittest.TestResult())
00303 
00304 

Definition at line 60 of file test_suite.py.

00060 
00061     def test_init__empty_tests(self):
00062         suite = unittest.TestSuite([])
00063 
00064         self.assertEqual(suite.countTestCases(), 0)

Here is the call graph for this function:

Definition at line 71 of file test_suite.py.

00071 
00072     def test_init__tests_from_any_iterable(self):
00073         def tests():
00074             yield unittest.FunctionTestCase(lambda: None)
00075             yield unittest.FunctionTestCase(lambda: None)
00076 
00077         suite_1 = unittest.TestSuite(tests())
00078         self.assertEqual(suite_1.countTestCases(), 2)
00079 
00080         suite_2 = unittest.TestSuite(suite_1)
00081         self.assertEqual(suite_2.countTestCases(), 2)
00082 
00083         suite_3 = unittest.TestSuite(set(suite_1))
00084         self.assertEqual(suite_3.countTestCases(), 2)

Here is the call graph for this function:

/Set up attributes needed by inherited tests

Tests for TestSuite.__init__

Definition at line 48 of file test_suite.py.

00048 
00049     def test_init__tests_optional(self):
00050         suite = unittest.TestSuite()
00051 
00052         self.assertEqual(suite.countTestCases(), 0)

Here is the call graph for this function:

Definition at line 92 of file test_suite.py.

00092 
00093     def test_init__TestSuite_instances_in_tests(self):
00094         def tests():
00095             ftc = unittest.FunctionTestCase(lambda: None)
00096             yield unittest.TestSuite([ftc])
00097             yield unittest.FunctionTestCase(lambda: None)
00098 
00099         suite = unittest.TestSuite(tests())
00100         self.assertEqual(suite.countTestCases(), 2)

Here is the call graph for this function:

/Tests for TestSuite.__init__

Definition at line 105 of file test_suite.py.

00105 
00106     def test_iter(self):
00107         test1 = unittest.FunctionTestCase(lambda: None)
00108         test2 = unittest.FunctionTestCase(lambda: None)
00109         suite = unittest.TestSuite((test1, test2))
00110 
00111         self.assertEqual(list(suite), [test1, test2])

Here is the call graph for this function:

Definition at line 348 of file test_suite.py.

00348 
00349     def test_overriding_call(self):
00350         class MySuite(unittest.TestSuite):
00351             called = False
00352             def __call__(self, *args, **kw):
00353                 self.called = True
00354                 unittest.TestSuite.__call__(self, *args, **kw)
00355 
00356         suite = MySuite()
00357         result = unittest.TestResult()
00358         wrapper = unittest.TestSuite()
00359         wrapper.addTest(suite)
00360         wrapper(result)
00361         self.assertTrue(suite.called)
00362 
00363         # reusing results should be permitted even if abominable
00364         self.assertFalse(result._testRunEntered)
00365 
00366 

Definition at line 192 of file test_suite.py.

00192 
00193     def test_run(self):
00194         events = []
00195         result = LoggingResult(events)
00196 
00197         class LoggingCase(unittest.TestCase):
00198             def run(self, result):
00199                 events.append('run %s' % self._testMethodName)
00200 
00201             def test1(self): pass
00202             def test2(self): pass
00203 
00204         tests = [LoggingCase('test1'), LoggingCase('test2')]
00205 
00206         unittest.TestSuite(tests).run(result)
00207 
00208         self.assertEqual(events, ['run test1', 'run test2'])

Here is the call graph for this function:

Definition at line 168 of file test_suite.py.

00168 
00169     def test_run__empty_suite(self):
00170         events = []
00171         result = LoggingResult(events)
00172 
00173         suite = unittest.TestSuite()
00174 
00175         suite.run(result)
00176 
00177         self.assertEqual(events, [])

Here is the call graph for this function:

Definition at line 180 of file test_suite.py.

00180 
00181     def test_run__requires_result(self):
00182         suite = unittest.TestSuite()
00183 
00184         try:
00185             suite.run()
00186         except TypeError:
00187             pass
00188         else:
00189             self.fail("Failed to raise TypeError")

Here is the call graph for this function:


Member Data Documentation

Definition at line 352 of file test_suite.py.

Initial value:
[(unittest.TestSuite(), unittest.TestSuite())
               ,(unittest.TestSuite(), unittest.TestSuite([]))
               ,(_mk_TestSuite('test_1'), _mk_TestSuite('test_1'))]

Set up attributes needed by inherited tests.

Definition at line 29 of file test_suite.py.

Initial value:
[(unittest.TestSuite(), _mk_TestSuite('test_1'))
               ,(unittest.TestSuite([]), _mk_TestSuite('test_1'))
               ,(_mk_TestSuite('test_1', 'test_2'), _mk_TestSuite('test_1', 'test_3'))
               ,(_mk_TestSuite('test_1'), _mk_TestSuite('test_2'))]

Definition at line 34 of file test_suite.py.


The documentation for this class was generated from the following file: