Back to index

python3.2  3.2.2
Public Member Functions
unittest.test.test_loader.Test_TestLoader Class Reference

List of all members.

Public Member Functions

def test_loadTestsFromTestCase
 Tests for TestLoader.loadTestsFromTestCase.
def test_loadTestsFromTestCase__no_matches
def test_loadTestsFromTestCase__TestSuite_subclass
def test_loadTestsFromTestCase__default_method_name
def test_loadTestsFromModule__TestCase_subclass
 /Tests for TestLoader.loadTestsFromTestCase
def test_loadTestsFromModule__no_TestCase_instances
def test_loadTestsFromModule__no_TestCase_tests
def test_loadTestsFromModule__not_a_module
def test_loadTestsFromModule__load_tests
def test_loadTestsFromModule__faulty_load_tests
def test_loadTestsFromName__empty_name
 /Tests for TestLoader.loadTestsFromModule()
def test_loadTestsFromName__malformed_name
def test_loadTestsFromName__unknown_module_name
def test_loadTestsFromName__unknown_attr_name
def test_loadTestsFromName__relative_unknown_name
def test_loadTestsFromName__relative_empty_name
def test_loadTestsFromName__relative_malformed_name
def test_loadTestsFromName__relative_not_a_module
def test_loadTestsFromName__relative_bad_object
def test_loadTestsFromName__relative_TestCase_subclass
def test_loadTestsFromName__relative_TestSuite
def test_loadTestsFromName__relative_testmethod
def test_loadTestsFromName__relative_invalid_testmethod
def test_loadTestsFromName__callable__TestSuite
def test_loadTestsFromName__callable__TestCase_instance
def test_loadTestsFromName__callable__TestCase_instance_ProperSuiteClass
def test_loadTestsFromName__relative_testmethod_ProperSuiteClass
def test_loadTestsFromName__callable__wrong_type
def test_loadTestsFromName__module_not_loaded
def test_loadTestsFromNames__empty_name_list
 Tests for TestLoader.loadTestsFromName()
def test_loadTestsFromNames__relative_empty_name_list
def test_loadTestsFromNames__empty_name
def test_loadTestsFromNames__malformed_name
def test_loadTestsFromNames__unknown_module_name
def test_loadTestsFromNames__unknown_attr_name
def test_loadTestsFromNames__unknown_name_relative_1
def test_loadTestsFromNames__unknown_name_relative_2
def test_loadTestsFromNames__relative_empty_name
def test_loadTestsFromNames__relative_malformed_name
def test_loadTestsFromNames__relative_not_a_module
def test_loadTestsFromNames__relative_bad_object
def test_loadTestsFromNames__relative_TestCase_subclass
def test_loadTestsFromNames__relative_TestSuite
def test_loadTestsFromNames__relative_testmethod
def test_loadTestsFromNames__relative_invalid_testmethod
def test_loadTestsFromNames__callable__TestSuite
def test_loadTestsFromNames__callable__TestCase_instance
def test_loadTestsFromNames__callable__call_staticmethod
def test_loadTestsFromNames__callable__wrong_type
def test_loadTestsFromNames__module_not_loaded
def test_getTestCaseNames
 /Tests for TestLoader.loadTestsFromNames()
def test_getTestCaseNames__no_tests
def test_getTestCaseNames__not_a_TestCase
def test_getTestCaseNames__inheritance
def test_testMethodPrefix__loadTestsFromTestCase
 /Tests for TestLoader.getTestCaseNames()
def test_testMethodPrefix__loadTestsFromModule
def test_testMethodPrefix__loadTestsFromName
def test_testMethodPrefix__loadTestsFromNames
def test_testMethodPrefix__default_value
def test_sortTestMethodsUsing__loadTestsFromTestCase
 /Tests for TestLoader.testMethodPrefix
def test_sortTestMethodsUsing__loadTestsFromModule
def test_sortTestMethodsUsing__loadTestsFromName
def test_sortTestMethodsUsing__loadTestsFromNames
def test_sortTestMethodsUsing__getTestCaseNames
def test_sortTestMethodsUsing__default_value
def test_sortTestMethodsUsing__None
def test_suiteClass__loadTestsFromTestCase
 /Tests for TestLoader.sortTestMethodsUsing
def test_suiteClass__loadTestsFromModule
def test_suiteClass__loadTestsFromName
def test_suiteClass__loadTestsFromNames
def test_suiteClass__default_value

Detailed Description

Definition at line 8 of file test_loader.py.


Member Function Documentation

/Tests for TestLoader.loadTestsFromNames()

Tests for TestLoader.getTestCaseNames()

Definition at line 936 of file test_loader.py.

00936 
00937     def test_getTestCaseNames(self):
00938         class Test(unittest.TestCase):
00939             def test_1(self): pass
00940             def test_2(self): pass
00941             def foobar(self): pass
00942 
00943         loader = unittest.TestLoader()
00944 
00945         self.assertEqual(loader.getTestCaseNames(Test), ['test_1', 'test_2'])

Here is the call graph for this function:

Definition at line 981 of file test_loader.py.

00981 
00982     def test_getTestCaseNames__inheritance(self):
00983         class TestP(unittest.TestCase):
00984             def test_1(self): pass
00985             def test_2(self): pass
00986             def foobar(self): pass
00987 
00988         class TestC(TestP):
00989             def test_1(self): pass
00990             def test_3(self): pass
00991 
00992         loader = unittest.TestLoader()
00993 
00994         names = ['test_1', 'test_2', 'test_3']
00995         self.assertEqual(loader.getTestCaseNames(TestC), names)

Here is the call graph for this function:

Definition at line 949 of file test_loader.py.

00949 
00950     def test_getTestCaseNames__no_tests(self):
00951         class Test(unittest.TestCase):
00952             def foobar(self): pass
00953 
00954         loader = unittest.TestLoader()
00955 
00956         self.assertEqual(loader.getTestCaseNames(Test), [])

Here is the call graph for this function:

Definition at line 965 of file test_loader.py.

00965 
00966     def test_getTestCaseNames__not_a_TestCase(self):
00967         class BadCase(int):
00968             def test_foo(self):
00969                 pass
00970 
00971         loader = unittest.TestLoader()
00972         names = loader.getTestCaseNames(BadCase)
00973 
00974         self.assertEqual(names, ['test_foo'])

Definition at line 176 of file test_loader.py.

00176 
00177     def test_loadTestsFromModule__faulty_load_tests(self):
00178         m = types.ModuleType('m')
00179 
00180         def load_tests(loader, tests, pattern):
00181             raise TypeError('some failure')
00182         m.load_tests = load_tests
00183 
00184         loader = unittest.TestLoader()
00185         suite = loader.loadTestsFromModule(m)
00186         self.assertIsInstance(suite, unittest.TestSuite)
00187         self.assertEqual(suite.countTestCases(), 1)
00188         test = list(suite)[0]
00189 
00190         self.assertRaisesRegex(TypeError, "some failure", test.m)

Here is the call graph for this function:

Definition at line 153 of file test_loader.py.

00153 
00154     def test_loadTestsFromModule__load_tests(self):
00155         m = types.ModuleType('m')
00156         class MyTestCase(unittest.TestCase):
00157             def test(self):
00158                 pass
00159         m.testcase_1 = MyTestCase
00160 
00161         load_tests_args = []
00162         def load_tests(loader, tests, pattern):
00163             self.assertIsInstance(tests, unittest.TestSuite)
00164             load_tests_args.extend((loader, tests, pattern))
00165             return tests
00166         m.load_tests = load_tests
00167 
00168         loader = unittest.TestLoader()
00169         suite = loader.loadTestsFromModule(m)
00170         self.assertIsInstance(suite, unittest.TestSuite)
00171         self.assertEqual(load_tests_args, [loader, suite, None])
00172 
00173         load_tests_args = []
00174         suite = loader.loadTestsFromModule(m, use_load_tests=False)
00175         self.assertEqual(load_tests_args, [])

Definition at line 103 of file test_loader.py.

00103 
00104     def test_loadTestsFromModule__no_TestCase_instances(self):
00105         m = types.ModuleType('m')
00106 
00107         loader = unittest.TestLoader()
00108         suite = loader.loadTestsFromModule(m)
00109         self.assertIsInstance(suite, loader.suiteClass)
00110         self.assertEqual(list(suite), [])

Here is the call graph for this function:

Definition at line 114 of file test_loader.py.

00114 
00115     def test_loadTestsFromModule__no_TestCase_tests(self):
00116         m = types.ModuleType('m')
00117         class MyTestCase(unittest.TestCase):
00118             pass
00119         m.testcase_1 = MyTestCase
00120 
00121         loader = unittest.TestLoader()
00122         suite = loader.loadTestsFromModule(m)
00123         self.assertIsInstance(suite, loader.suiteClass)
00124 
00125         self.assertEqual(list(suite), [loader.suiteClass()])

Definition at line 136 of file test_loader.py.

00136 
00137     def test_loadTestsFromModule__not_a_module(self):
00138         class MyTestCase(unittest.TestCase):
00139             def test(self):
00140                 pass
00141 
00142         class NotAModule(object):
00143             test_2 = MyTestCase
00144 
00145         loader = unittest.TestLoader()
00146         suite = loader.loadTestsFromModule(NotAModule)
00147 
00148         reference = [unittest.TestSuite([MyTestCase('test')])]
00149         self.assertEqual(list(suite), reference)
00150 

/Tests for TestLoader.loadTestsFromTestCase

Tests for TestLoader.loadTestsFromModule

Definition at line 86 of file test_loader.py.

00086 
00087     def test_loadTestsFromModule__TestCase_subclass(self):
00088         m = types.ModuleType('m')
00089         class MyTestCase(unittest.TestCase):
00090             def test(self):
00091                 pass
00092         m.testcase_1 = MyTestCase
00093 
00094         loader = unittest.TestLoader()
00095         suite = loader.loadTestsFromModule(m)
00096         self.assertIsInstance(suite, loader.suiteClass)
00097 
00098         expected = [loader.suiteClass([MyTestCase('test')])]
00099         self.assertEqual(list(suite), expected)

Definition at line 450 of file test_loader.py.

00450 
00451     def test_loadTestsFromName__callable__TestCase_instance(self):
00452         m = types.ModuleType('m')
00453         testcase_1 = unittest.FunctionTestCase(lambda: None)
00454         def return_TestCase():
00455             return testcase_1
00456         m.return_TestCase = return_TestCase
00457 
00458         loader = unittest.TestLoader()
00459         suite = loader.loadTestsFromName('return_TestCase', m)
00460         self.assertIsInstance(suite, loader.suiteClass)
00461         self.assertEqual(list(suite), [testcase_1])

Here is the call graph for this function:

Definition at line 467 of file test_loader.py.

00467 
00468     def test_loadTestsFromName__callable__TestCase_instance_ProperSuiteClass(self):
00469         class SubTestSuite(unittest.TestSuite):
00470             pass
00471         m = types.ModuleType('m')
00472         testcase_1 = unittest.FunctionTestCase(lambda: None)
00473         def return_TestCase():
00474             return testcase_1
00475         m.return_TestCase = return_TestCase
00476 
00477         loader = unittest.TestLoader()
00478         loader.suiteClass = SubTestSuite
00479         suite = loader.loadTestsFromName('return_TestCase', m)
00480         self.assertIsInstance(suite, loader.suiteClass)
00481         self.assertEqual(list(suite), [testcase_1])

Definition at line 435 of file test_loader.py.

00435 
00436     def test_loadTestsFromName__callable__TestSuite(self):
00437         m = types.ModuleType('m')
00438         testcase_1 = unittest.FunctionTestCase(lambda: None)
00439         testcase_2 = unittest.FunctionTestCase(lambda: None)
00440         def return_TestSuite():
00441             return unittest.TestSuite([testcase_1, testcase_2])
00442         m.return_TestSuite = return_TestSuite
00443 
00444         loader = unittest.TestLoader()
00445         suite = loader.loadTestsFromName('return_TestSuite', m)
00446         self.assertIsInstance(suite, loader.suiteClass)
00447         self.assertEqual(list(suite), [testcase_1, testcase_2])

Here is the call graph for this function:

Definition at line 507 of file test_loader.py.

00507 
00508     def test_loadTestsFromName__callable__wrong_type(self):
00509         m = types.ModuleType('m')
00510         def return_wrong():
00511             return 6
00512         m.return_wrong = return_wrong
00513 
00514         loader = unittest.TestLoader()
00515         try:
00516             suite = loader.loadTestsFromName('return_wrong', m)
00517         except TypeError:
00518             pass
00519         else:
00520             self.fail("TestLoader.loadTestsFromName failed to raise TypeError")

Here is the call graph for this function:

/Tests for TestLoader.loadTestsFromModule()

Tests for TestLoader.loadTestsFromName()

Definition at line 203 of file test_loader.py.

00203 
00204     def test_loadTestsFromName__empty_name(self):
00205         loader = unittest.TestLoader()
00206 
00207         try:
00208             loader.loadTestsFromName('')
00209         except ValueError as e:
00210             self.assertEqual(str(e), "Empty module name")
00211         else:
00212             self.fail("TestLoader.loadTestsFromName failed to raise ValueError")

Here is the call graph for this function:

Definition at line 219 of file test_loader.py.

00219 
00220     def test_loadTestsFromName__malformed_name(self):
00221         loader = unittest.TestLoader()
00222 
00223         # XXX Should this raise ValueError or ImportError?
00224         try:
00225             loader.loadTestsFromName('abc () //')
00226         except ValueError:
00227             pass
00228         except ImportError:
00229             pass
00230         else:
00231             self.fail("TestLoader.loadTestsFromName failed to raise ValueError")

Here is the call graph for this function:

Definition at line 523 of file test_loader.py.

00523 
00524     def test_loadTestsFromName__module_not_loaded(self):
00525         # We're going to try to load this module as a side-effect, so it
00526         # better not be loaded before we try.
00527         #
00528         module_name = 'unittest.test.dummy'
00529         sys.modules.pop(module_name, None)
00530 
00531         loader = unittest.TestLoader()
00532         try:
00533             suite = loader.loadTestsFromName(module_name)
00534 
00535             self.assertIsInstance(suite, loader.suiteClass)
00536             self.assertEqual(list(suite), [])
00537 
00538             # module should now be loaded, thanks to loadTestsFromName()
00539             self.assertIn(module_name, sys.modules)
00540         finally:
00541             if module_name in sys.modules:
00542                 del sys.modules[module_name]

Here is the call graph for this function:

Definition at line 352 of file test_loader.py.

00352 
00353     def test_loadTestsFromName__relative_bad_object(self):
00354         m = types.ModuleType('m')
00355         m.testcase_1 = object()
00356 
00357         loader = unittest.TestLoader()
00358         try:
00359             loader.loadTestsFromName('testcase_1', m)
00360         except TypeError:
00361             pass
00362         else:
00363             self.fail("Should have raised TypeError")

Here is the call graph for this function:

Definition at line 290 of file test_loader.py.

00290 
00291     def test_loadTestsFromName__relative_empty_name(self):
00292         loader = unittest.TestLoader()
00293 
00294         try:
00295             loader.loadTestsFromName('', unittest)
00296         except AttributeError as e:
00297             pass
00298         else:
00299             self.fail("Failed to raise AttributeError")

Here is the call graph for this function:

Definition at line 418 of file test_loader.py.

00418 
00419     def test_loadTestsFromName__relative_invalid_testmethod(self):
00420         m = types.ModuleType('m')
00421         class MyTestCase(unittest.TestCase):
00422             def test(self):
00423                 pass
00424         m.testcase_1 = MyTestCase
00425 
00426         loader = unittest.TestLoader()
00427         try:
00428             loader.loadTestsFromName('testcase_1.testfoo', m)
00429         except AttributeError as e:
00430             self.assertEqual(str(e), "type object 'MyTestCase' has no attribute 'testfoo'")
00431         else:
00432             self.fail("Failed to raise AttributeError")

Definition at line 309 of file test_loader.py.

00309 
00310     def test_loadTestsFromName__relative_malformed_name(self):
00311         loader = unittest.TestLoader()
00312 
00313         # XXX Should this raise AttributeError or ValueError?
00314         try:
00315             loader.loadTestsFromName('abc () //', unittest)
00316         except ValueError:
00317             pass
00318         except AttributeError:
00319             pass
00320         else:
00321             self.fail("TestLoader.loadTestsFromName failed to raise ValueError")

Here is the call graph for this function:

Definition at line 331 of file test_loader.py.

00331 
00332     def test_loadTestsFromName__relative_not_a_module(self):
00333         class MyTestCase(unittest.TestCase):
00334             def test(self):
00335                 pass
00336 
00337         class NotAModule(object):
00338             test_2 = MyTestCase
00339 
00340         loader = unittest.TestLoader()
00341         suite = loader.loadTestsFromName('test_2', NotAModule)
00342 
00343         reference = [MyTestCase('test')]
00344         self.assertEqual(list(suite), reference)

Definition at line 366 of file test_loader.py.

00366 
00367     def test_loadTestsFromName__relative_TestCase_subclass(self):
00368         m = types.ModuleType('m')
00369         class MyTestCase(unittest.TestCase):
00370             def test(self):
00371                 pass
00372         m.testcase_1 = MyTestCase
00373 
00374         loader = unittest.TestLoader()
00375         suite = loader.loadTestsFromName('testcase_1', m)
00376         self.assertIsInstance(suite, loader.suiteClass)
00377         self.assertEqual(list(suite), [MyTestCase('test')])

Definition at line 397 of file test_loader.py.

00397 
00398     def test_loadTestsFromName__relative_testmethod(self):
00399         m = types.ModuleType('m')
00400         class MyTestCase(unittest.TestCase):
00401             def test(self):
00402                 pass
00403         m.testcase_1 = MyTestCase
00404 
00405         loader = unittest.TestLoader()
00406         suite = loader.loadTestsFromName('testcase_1.test', m)
00407         self.assertIsInstance(suite, loader.suiteClass)
00408 
00409         self.assertEqual(list(suite), [MyTestCase('test')])

Definition at line 487 of file test_loader.py.

00487 
00488     def test_loadTestsFromName__relative_testmethod_ProperSuiteClass(self):
00489         class SubTestSuite(unittest.TestSuite):
00490             pass
00491         m = types.ModuleType('m')
00492         class MyTestCase(unittest.TestCase):
00493             def test(self):
00494                 pass
00495         m.testcase_1 = MyTestCase
00496 
00497         loader = unittest.TestLoader()
00498         loader.suiteClass=SubTestSuite
00499         suite = loader.loadTestsFromName('testcase_1.test', m)
00500         self.assertIsInstance(suite, loader.suiteClass)
00501 
00502         self.assertEqual(list(suite), [MyTestCase('test')])

Definition at line 382 of file test_loader.py.

00382 
00383     def test_loadTestsFromName__relative_TestSuite(self):
00384         m = types.ModuleType('m')
00385         class MyTestCase(unittest.TestCase):
00386             def test(self):
00387                 pass
00388         m.testsuite = unittest.TestSuite([MyTestCase('test')])
00389 
00390         loader = unittest.TestLoader()
00391         suite = loader.loadTestsFromName('testsuite', m)
00392         self.assertIsInstance(suite, loader.suiteClass)
00393 
00394         self.assertEqual(list(suite), [MyTestCase('test')])

Definition at line 269 of file test_loader.py.

00269 
00270     def test_loadTestsFromName__relative_unknown_name(self):
00271         loader = unittest.TestLoader()
00272 
00273         try:
00274             loader.loadTestsFromName('sdasfasfasdf', unittest)
00275         except AttributeError as e:
00276             self.assertEqual(str(e), "'module' object has no attribute 'sdasfasfasdf'")
00277         else:
00278             self.fail("TestLoader.loadTestsFromName failed to raise AttributeError")

Here is the call graph for this function:

Definition at line 252 of file test_loader.py.

00252 
00253     def test_loadTestsFromName__unknown_attr_name(self):
00254         loader = unittest.TestLoader()
00255 
00256         try:
00257             loader.loadTestsFromName('unittest.sdasfasfasdf')
00258         except AttributeError as e:
00259             self.assertEqual(str(e), "'module' object has no attribute 'sdasfasfasdf'")
00260         else:
00261             self.fail("TestLoader.loadTestsFromName failed to raise AttributeError")

Here is the call graph for this function:

Definition at line 236 of file test_loader.py.

00236 
00237     def test_loadTestsFromName__unknown_module_name(self):
00238         loader = unittest.TestLoader()
00239 
00240         try:
00241             loader.loadTestsFromName('sdasfasfasdf')
00242         except ImportError as e:
00243             self.assertEqual(str(e), "No module named sdasfasfasdf")
00244         else:
00245             self.fail("TestLoader.loadTestsFromName failed to raise ImportError")

Here is the call graph for this function:

Definition at line 866 of file test_loader.py.

00866 
00867     def test_loadTestsFromNames__callable__call_staticmethod(self):
00868         m = types.ModuleType('m')
00869         class Test1(unittest.TestCase):
00870             def test(self):
00871                 pass
00872 
00873         testcase_1 = Test1('test')
00874         class Foo(unittest.TestCase):
00875             @staticmethod
00876             def foo():
00877                 return testcase_1
00878         m.Foo = Foo
00879 
00880         loader = unittest.TestLoader()
00881         suite = loader.loadTestsFromNames(['Foo.foo'], m)
00882         self.assertIsInstance(suite, loader.suiteClass)
00883 
00884         ref_suite = unittest.TestSuite([testcase_1])
00885         self.assertEqual(list(suite), [ref_suite])

Definition at line 848 of file test_loader.py.

00848 
00849     def test_loadTestsFromNames__callable__TestCase_instance(self):
00850         m = types.ModuleType('m')
00851         testcase_1 = unittest.FunctionTestCase(lambda: None)
00852         def return_TestCase():
00853             return testcase_1
00854         m.return_TestCase = return_TestCase
00855 
00856         loader = unittest.TestLoader()
00857         suite = loader.loadTestsFromNames(['return_TestCase'], m)
00858         self.assertIsInstance(suite, loader.suiteClass)
00859 
00860         ref_suite = unittest.TestSuite([testcase_1])
00861         self.assertEqual(list(suite), [ref_suite])

Here is the call graph for this function:

Definition at line 831 of file test_loader.py.

00831 
00832     def test_loadTestsFromNames__callable__TestSuite(self):
00833         m = types.ModuleType('m')
00834         testcase_1 = unittest.FunctionTestCase(lambda: None)
00835         testcase_2 = unittest.FunctionTestCase(lambda: None)
00836         def return_TestSuite():
00837             return unittest.TestSuite([testcase_1, testcase_2])
00838         m.return_TestSuite = return_TestSuite
00839 
00840         loader = unittest.TestLoader()
00841         suite = loader.loadTestsFromNames(['return_TestSuite'], m)
00842         self.assertIsInstance(suite, loader.suiteClass)
00843 
00844         expected = unittest.TestSuite([testcase_1, testcase_2])
00845         self.assertEqual(list(suite), [expected])

Here is the call graph for this function:

Definition at line 890 of file test_loader.py.

00890 
00891     def test_loadTestsFromNames__callable__wrong_type(self):
00892         m = types.ModuleType('m')
00893         def return_wrong():
00894             return 6
00895         m.return_wrong = return_wrong
00896 
00897         loader = unittest.TestLoader()
00898         try:
00899             suite = loader.loadTestsFromNames(['return_wrong'], m)
00900         except TypeError:
00901             pass
00902         else:
00903             self.fail("TestLoader.loadTestsFromNames failed to raise TypeError")

Here is the call graph for this function:

Definition at line 581 of file test_loader.py.

00581 
00582     def test_loadTestsFromNames__empty_name(self):
00583         loader = unittest.TestLoader()
00584 
00585         try:
00586             loader.loadTestsFromNames([''])
00587         except ValueError as e:
00588             self.assertEqual(str(e), "Empty module name")
00589         else:
00590             self.fail("TestLoader.loadTestsFromNames failed to raise ValueError")

Here is the call graph for this function:

Tests for TestLoader.loadTestsFromName()

Tests for TestLoader.loadTestsFromNames()

Definition at line 553 of file test_loader.py.

00553 
00554     def test_loadTestsFromNames__empty_name_list(self):
00555         loader = unittest.TestLoader()
00556 
00557         suite = loader.loadTestsFromNames([])
00558         self.assertIsInstance(suite, loader.suiteClass)
00559         self.assertEqual(list(suite), [])

Here is the call graph for this function:

Definition at line 597 of file test_loader.py.

00597 
00598     def test_loadTestsFromNames__malformed_name(self):
00599         loader = unittest.TestLoader()
00600 
00601         # XXX Should this raise ValueError or ImportError?
00602         try:
00603             loader.loadTestsFromNames(['abc () //'])
00604         except ValueError:
00605             pass
00606         except ImportError:
00607             pass
00608         else:
00609             self.fail("TestLoader.loadTestsFromNames failed to raise ValueError")

Here is the call graph for this function:

Definition at line 906 of file test_loader.py.

00906 
00907     def test_loadTestsFromNames__module_not_loaded(self):
00908         # We're going to try to load this module as a side-effect, so it
00909         # better not be loaded before we try.
00910         #
00911         module_name = 'unittest.test.dummy'
00912         sys.modules.pop(module_name, None)
00913 
00914         loader = unittest.TestLoader()
00915         try:
00916             suite = loader.loadTestsFromNames([module_name])
00917 
00918             self.assertIsInstance(suite, loader.suiteClass)
00919             self.assertEqual(list(suite), [unittest.TestSuite()])
00920 
00921             # module should now be loaded, thanks to loadTestsFromName()
00922             self.assertIn(module_name, sys.modules)
00923         finally:
00924             if module_name in sys.modules:
00925                 del sys.modules[module_name]

Here is the call graph for this function:

Definition at line 750 of file test_loader.py.

00750 
00751     def test_loadTestsFromNames__relative_bad_object(self):
00752         m = types.ModuleType('m')
00753         m.testcase_1 = object()
00754 
00755         loader = unittest.TestLoader()
00756         try:
00757             loader.loadTestsFromNames(['testcase_1'], m)
00758         except TypeError:
00759             pass
00760         else:
00761             self.fail("Should have raised TypeError")

Here is the call graph for this function:

Definition at line 691 of file test_loader.py.

00691 
00692     def test_loadTestsFromNames__relative_empty_name(self):
00693         loader = unittest.TestLoader()
00694 
00695         try:
00696             loader.loadTestsFromNames([''], unittest)
00697         except AttributeError:
00698             pass
00699         else:
00700             self.fail("Failed to raise ValueError")

Here is the call graph for this function:

Definition at line 568 of file test_loader.py.

00568 
00569     def test_loadTestsFromNames__relative_empty_name_list(self):
00570         loader = unittest.TestLoader()
00571 
00572         suite = loader.loadTestsFromNames([], unittest)
00573         self.assertIsInstance(suite, loader.suiteClass)
00574         self.assertEqual(list(suite), [])

Here is the call graph for this function:

Definition at line 814 of file test_loader.py.

00814 
00815     def test_loadTestsFromNames__relative_invalid_testmethod(self):
00816         m = types.ModuleType('m')
00817         class MyTestCase(unittest.TestCase):
00818             def test(self):
00819                 pass
00820         m.testcase_1 = MyTestCase
00821 
00822         loader = unittest.TestLoader()
00823         try:
00824             loader.loadTestsFromNames(['testcase_1.testfoo'], m)
00825         except AttributeError as e:
00826             self.assertEqual(str(e), "type object 'MyTestCase' has no attribute 'testfoo'")
00827         else:
00828             self.fail("Failed to raise AttributeError")

Definition at line 709 of file test_loader.py.

00709 
00710     def test_loadTestsFromNames__relative_malformed_name(self):
00711         loader = unittest.TestLoader()
00712 
00713         # XXX Should this raise AttributeError or ValueError?
00714         try:
00715             loader.loadTestsFromNames(['abc () //'], unittest)
00716         except AttributeError:
00717             pass
00718         except ValueError:
00719             pass
00720         else:
00721             self.fail("TestLoader.loadTestsFromNames failed to raise ValueError")

Here is the call graph for this function:

Definition at line 729 of file test_loader.py.

00729 
00730     def test_loadTestsFromNames__relative_not_a_module(self):
00731         class MyTestCase(unittest.TestCase):
00732             def test(self):
00733                 pass
00734 
00735         class NotAModule(object):
00736             test_2 = MyTestCase
00737 
00738         loader = unittest.TestLoader()
00739         suite = loader.loadTestsFromNames(['test_2'], NotAModule)
00740 
00741         reference = [unittest.TestSuite([MyTestCase('test')])]
00742         self.assertEqual(list(suite), reference)

Definition at line 764 of file test_loader.py.

00764 
00765     def test_loadTestsFromNames__relative_TestCase_subclass(self):
00766         m = types.ModuleType('m')
00767         class MyTestCase(unittest.TestCase):
00768             def test(self):
00769                 pass
00770         m.testcase_1 = MyTestCase
00771 
00772         loader = unittest.TestLoader()
00773         suite = loader.loadTestsFromNames(['testcase_1'], m)
00774         self.assertIsInstance(suite, loader.suiteClass)
00775 
00776         expected = loader.suiteClass([MyTestCase('test')])
00777         self.assertEqual(list(suite), [expected])

Definition at line 795 of file test_loader.py.

00795 
00796     def test_loadTestsFromNames__relative_testmethod(self):
00797         m = types.ModuleType('m')
00798         class MyTestCase(unittest.TestCase):
00799             def test(self):
00800                 pass
00801         m.testcase_1 = MyTestCase
00802 
00803         loader = unittest.TestLoader()
00804         suite = loader.loadTestsFromNames(['testcase_1.test'], m)
00805         self.assertIsInstance(suite, loader.suiteClass)
00806 
00807         ref_suite = unittest.TestSuite([MyTestCase('test')])
00808         self.assertEqual(list(suite), [ref_suite])

Definition at line 780 of file test_loader.py.

00780 
00781     def test_loadTestsFromNames__relative_TestSuite(self):
00782         m = types.ModuleType('m')
00783         class MyTestCase(unittest.TestCase):
00784             def test(self):
00785                 pass
00786         m.testsuite = unittest.TestSuite([MyTestCase('test')])
00787 
00788         loader = unittest.TestLoader()
00789         suite = loader.loadTestsFromNames(['testsuite'], m)
00790         self.assertIsInstance(suite, loader.suiteClass)
00791 
00792         self.assertEqual(list(suite), [m.testsuite])

Definition at line 632 of file test_loader.py.

00632 
00633     def test_loadTestsFromNames__unknown_attr_name(self):
00634         loader = unittest.TestLoader()
00635 
00636         try:
00637             loader.loadTestsFromNames(['unittest.sdasfasfasdf', 'unittest'])
00638         except AttributeError as e:
00639             self.assertEqual(str(e), "'module' object has no attribute 'sdasfasfasdf'")
00640         else:
00641             self.fail("TestLoader.loadTestsFromNames failed to raise AttributeError")

Here is the call graph for this function:

Definition at line 616 of file test_loader.py.

00616 
00617     def test_loadTestsFromNames__unknown_module_name(self):
00618         loader = unittest.TestLoader()
00619 
00620         try:
00621             loader.loadTestsFromNames(['sdasfasfasdf'])
00622         except ImportError as e:
00623             self.assertEqual(str(e), "No module named sdasfasfasdf")
00624         else:
00625             self.fail("TestLoader.loadTestsFromNames failed to raise ImportError")

Here is the call graph for this function:

Definition at line 651 of file test_loader.py.

00651 
00652     def test_loadTestsFromNames__unknown_name_relative_1(self):
00653         loader = unittest.TestLoader()
00654 
00655         try:
00656             loader.loadTestsFromNames(['sdasfasfasdf'], unittest)
00657         except AttributeError as e:
00658             self.assertEqual(str(e), "'module' object has no attribute 'sdasfasfasdf'")
00659         else:
00660             self.fail("TestLoader.loadTestsFromName failed to raise AttributeError")

Here is the call graph for this function:

Definition at line 670 of file test_loader.py.

00670 
00671     def test_loadTestsFromNames__unknown_name_relative_2(self):
00672         loader = unittest.TestLoader()
00673 
00674         try:
00675             loader.loadTestsFromNames(['TestCase', 'sdasfasfasdf'], unittest)
00676         except AttributeError as e:
00677             self.assertEqual(str(e), "'module' object has no attribute 'sdasfasfasdf'")
00678         else:
00679             self.fail("TestLoader.loadTestsFromName failed to raise AttributeError")

Here is the call graph for this function:

Tests for TestLoader.loadTestsFromTestCase.

Definition at line 15 of file test_loader.py.

00015 
00016     def test_loadTestsFromTestCase(self):
00017         class Foo(unittest.TestCase):
00018             def test_1(self): pass
00019             def test_2(self): pass
00020             def foo_bar(self): pass
00021 
00022         tests = unittest.TestSuite([Foo('test_1'), Foo('test_2')])
00023 
00024         loader = unittest.TestLoader()
00025         self.assertEqual(loader.loadTestsFromTestCase(Foo), tests)

Here is the call graph for this function:

Definition at line 66 of file test_loader.py.

00066 
00067     def test_loadTestsFromTestCase__default_method_name(self):
00068         class Foo(unittest.TestCase):
00069             def runTest(self):
00070                 pass
00071 
00072         loader = unittest.TestLoader()
00073         # This has to be false for the test to succeed
00074         self.assertFalse('runTest'.startswith(loader.testMethodPrefix))
00075 
00076         suite = loader.loadTestsFromTestCase(Foo)
00077         self.assertIsInstance(suite, loader.suiteClass)
00078         self.assertEqual(list(suite), [Foo('runTest')])

Definition at line 30 of file test_loader.py.

00030 
00031     def test_loadTestsFromTestCase__no_matches(self):
00032         class Foo(unittest.TestCase):
00033             def foo_bar(self): pass
00034 
00035         empty_suite = unittest.TestSuite()
00036 
00037         loader = unittest.TestLoader()
00038         self.assertEqual(loader.loadTestsFromTestCase(Foo), empty_suite)

Here is the call graph for this function:

Definition at line 48 of file test_loader.py.

00048 
00049     def test_loadTestsFromTestCase__TestSuite_subclass(self):
00050         class NotATestCase(unittest.TestSuite):
00051             pass
00052 
00053         loader = unittest.TestLoader()
00054         try:
00055             loader.loadTestsFromTestCase(NotATestCase)
00056         except TypeError:
00057             pass
00058         else:
00059             self.fail('Should raise TypeError')

Definition at line 1195 of file test_loader.py.

01195 
01196     def test_sortTestMethodsUsing__default_value(self):
01197         loader = unittest.TestLoader()
01198 
01199         class Foo(unittest.TestCase):
01200             def test_2(self): pass
01201             def test_3(self): pass
01202             def test_1(self): pass
01203 
01204         test_names = ['test_2', 'test_3', 'test_1']
01205         self.assertEqual(loader.getTestCaseNames(Foo), sorted(test_names))
01206 

Here is the call graph for this function:

Definition at line 1178 of file test_loader.py.

01178 
01179     def test_sortTestMethodsUsing__getTestCaseNames(self):
01180         def reversed_cmp(x, y):
01181             return -((x > y) - (x < y))
01182 
01183         class Foo(unittest.TestCase):
01184             def test_1(self): pass
01185             def test_2(self): pass
01186 
01187         loader = unittest.TestLoader()
01188         loader.sortTestMethodsUsing = reversed_cmp
01189 
01190         test_names = ['test_2', 'test_1']
01191         self.assertEqual(loader.getTestCaseNames(Foo), test_names)

Here is the call graph for this function:

Definition at line 1122 of file test_loader.py.

01122 
01123     def test_sortTestMethodsUsing__loadTestsFromModule(self):
01124         def reversed_cmp(x, y):
01125             return -((x > y) - (x < y))
01126 
01127         m = types.ModuleType('m')
01128         class Foo(unittest.TestCase):
01129             def test_1(self): pass
01130             def test_2(self): pass
01131         m.Foo = Foo
01132 
01133         loader = unittest.TestLoader()
01134         loader.sortTestMethodsUsing = reversed_cmp
01135 
01136         tests = [loader.suiteClass([Foo('test_2'), Foo('test_1')])]
01137         self.assertEqual(list(loader.loadTestsFromModule(m)), tests)

Here is the call graph for this function:

Definition at line 1140 of file test_loader.py.

01140 
01141     def test_sortTestMethodsUsing__loadTestsFromName(self):
01142         def reversed_cmp(x, y):
01143             return -((x > y) - (x < y))
01144 
01145         m = types.ModuleType('m')
01146         class Foo(unittest.TestCase):
01147             def test_1(self): pass
01148             def test_2(self): pass
01149         m.Foo = Foo
01150 
01151         loader = unittest.TestLoader()
01152         loader.sortTestMethodsUsing = reversed_cmp
01153 
01154         tests = loader.suiteClass([Foo('test_2'), Foo('test_1')])
01155         self.assertEqual(loader.loadTestsFromName('Foo', m), tests)

Here is the call graph for this function:

Definition at line 1158 of file test_loader.py.

01158 
01159     def test_sortTestMethodsUsing__loadTestsFromNames(self):
01160         def reversed_cmp(x, y):
01161             return -((x > y) - (x < y))
01162 
01163         m = types.ModuleType('m')
01164         class Foo(unittest.TestCase):
01165             def test_1(self): pass
01166             def test_2(self): pass
01167         m.Foo = Foo
01168 
01169         loader = unittest.TestLoader()
01170         loader.sortTestMethodsUsing = reversed_cmp
01171 
01172         tests = [loader.suiteClass([Foo('test_2'), Foo('test_1')])]
01173         self.assertEqual(list(loader.loadTestsFromNames(['Foo'], m)), tests)

Here is the call graph for this function:

/Tests for TestLoader.testMethodPrefix

Tests for TestLoader.sortTestMethodsUsing

Definition at line 1106 of file test_loader.py.

01106 
01107     def test_sortTestMethodsUsing__loadTestsFromTestCase(self):
01108         def reversed_cmp(x, y):
01109             return -((x > y) - (x < y))
01110 
01111         class Foo(unittest.TestCase):
01112             def test_1(self): pass
01113             def test_2(self): pass
01114 
01115         loader = unittest.TestLoader()
01116         loader.sortTestMethodsUsing = reversed_cmp
01117 
01118         tests = loader.suiteClass([Foo('test_2'), Foo('test_1')])
01119         self.assertEqual(loader.loadTestsFromTestCase(Foo), tests)

Here is the call graph for this function:

Definition at line 1211 of file test_loader.py.

01211 
01212     def test_sortTestMethodsUsing__None(self):
01213         class Foo(unittest.TestCase):
01214             def test_1(self): pass
01215             def test_2(self): pass
01216 
01217         loader = unittest.TestLoader()
01218         loader.sortTestMethodsUsing = None
01219 
01220         test_names = ['test_2', 'test_1']
01221         self.assertEqual(set(loader.getTestCaseNames(Foo)), set(test_names))

Here is the call graph for this function:

Definition at line 1290 of file test_loader.py.

01290 
01291     def test_suiteClass__default_value(self):
01292         loader = unittest.TestLoader()
01293         self.assertTrue(loader.suiteClass is unittest.TestSuite)

Here is the call graph for this function:

Definition at line 1243 of file test_loader.py.

01243 
01244     def test_suiteClass__loadTestsFromModule(self):
01245         m = types.ModuleType('m')
01246         class Foo(unittest.TestCase):
01247             def test_1(self): pass
01248             def test_2(self): pass
01249             def foo_bar(self): pass
01250         m.Foo = Foo
01251 
01252         tests = [[Foo('test_1'), Foo('test_2')]]
01253 
01254         loader = unittest.TestLoader()
01255         loader.suiteClass = list
01256         self.assertEqual(loader.loadTestsFromModule(m), tests)

Here is the call graph for this function:

Definition at line 1259 of file test_loader.py.

01259 
01260     def test_suiteClass__loadTestsFromName(self):
01261         m = types.ModuleType('m')
01262         class Foo(unittest.TestCase):
01263             def test_1(self): pass
01264             def test_2(self): pass
01265             def foo_bar(self): pass
01266         m.Foo = Foo
01267 
01268         tests = [Foo('test_1'), Foo('test_2')]
01269 
01270         loader = unittest.TestLoader()
01271         loader.suiteClass = list
01272         self.assertEqual(loader.loadTestsFromName('Foo', m), tests)

Here is the call graph for this function:

Definition at line 1275 of file test_loader.py.

01275 
01276     def test_suiteClass__loadTestsFromNames(self):
01277         m = types.ModuleType('m')
01278         class Foo(unittest.TestCase):
01279             def test_1(self): pass
01280             def test_2(self): pass
01281             def foo_bar(self): pass
01282         m.Foo = Foo
01283 
01284         tests = [[Foo('test_1'), Foo('test_2')]]
01285 
01286         loader = unittest.TestLoader()
01287         loader.suiteClass = list
01288         self.assertEqual(loader.loadTestsFromNames(['Foo'], m), tests)

Here is the call graph for this function:

/Tests for TestLoader.sortTestMethodsUsing

Tests for TestLoader.suiteClass

Definition at line 1229 of file test_loader.py.

01229 
01230     def test_suiteClass__loadTestsFromTestCase(self):
01231         class Foo(unittest.TestCase):
01232             def test_1(self): pass
01233             def test_2(self): pass
01234             def foo_bar(self): pass
01235 
01236         tests = [Foo('test_1'), Foo('test_2')]
01237 
01238         loader = unittest.TestLoader()
01239         loader.suiteClass = list
01240         self.assertEqual(loader.loadTestsFromTestCase(Foo), tests)

Here is the call graph for this function:

Definition at line 1094 of file test_loader.py.

01094 
01095     def test_testMethodPrefix__default_value(self):
01096         loader = unittest.TestLoader()
01097         self.assertEqual(loader.testMethodPrefix, 'test')

Here is the call graph for this function:

Definition at line 1028 of file test_loader.py.

01028 
01029     def test_testMethodPrefix__loadTestsFromModule(self):
01030         m = types.ModuleType('m')
01031         class Foo(unittest.TestCase):
01032             def test_1(self): pass
01033             def test_2(self): pass
01034             def foo_bar(self): pass
01035         m.Foo = Foo
01036 
01037         tests_1 = [unittest.TestSuite([Foo('foo_bar')])]
01038         tests_2 = [unittest.TestSuite([Foo('test_1'), Foo('test_2')])]
01039 
01040         loader = unittest.TestLoader()
01041         loader.testMethodPrefix = 'foo'
01042         self.assertEqual(list(loader.loadTestsFromModule(m)), tests_1)
01043 
01044         loader.testMethodPrefix = 'test'
01045         self.assertEqual(list(loader.loadTestsFromModule(m)), tests_2)

Here is the call graph for this function:

Definition at line 1051 of file test_loader.py.

01051 
01052     def test_testMethodPrefix__loadTestsFromName(self):
01053         m = types.ModuleType('m')
01054         class Foo(unittest.TestCase):
01055             def test_1(self): pass
01056             def test_2(self): pass
01057             def foo_bar(self): pass
01058         m.Foo = Foo
01059 
01060         tests_1 = unittest.TestSuite([Foo('foo_bar')])
01061         tests_2 = unittest.TestSuite([Foo('test_1'), Foo('test_2')])
01062 
01063         loader = unittest.TestLoader()
01064         loader.testMethodPrefix = 'foo'
01065         self.assertEqual(loader.loadTestsFromName('Foo', m), tests_1)
01066 
01067         loader.testMethodPrefix = 'test'
01068         self.assertEqual(loader.loadTestsFromName('Foo', m), tests_2)

Here is the call graph for this function:

Definition at line 1074 of file test_loader.py.

01074 
01075     def test_testMethodPrefix__loadTestsFromNames(self):
01076         m = types.ModuleType('m')
01077         class Foo(unittest.TestCase):
01078             def test_1(self): pass
01079             def test_2(self): pass
01080             def foo_bar(self): pass
01081         m.Foo = Foo
01082 
01083         tests_1 = unittest.TestSuite([unittest.TestSuite([Foo('foo_bar')])])
01084         tests_2 = unittest.TestSuite([Foo('test_1'), Foo('test_2')])
01085         tests_2 = unittest.TestSuite([tests_2])
01086 
01087         loader = unittest.TestLoader()
01088         loader.testMethodPrefix = 'foo'
01089         self.assertEqual(loader.loadTestsFromNames(['Foo'], m), tests_1)
01090 
01091         loader.testMethodPrefix = 'test'
01092         self.assertEqual(loader.loadTestsFromNames(['Foo'], m), tests_2)

Here is the call graph for this function:

/Tests for TestLoader.getTestCaseNames()

Tests for TestLoader.testMethodPrefix

Definition at line 1007 of file test_loader.py.

01007 
01008     def test_testMethodPrefix__loadTestsFromTestCase(self):
01009         class Foo(unittest.TestCase):
01010             def test_1(self): pass
01011             def test_2(self): pass
01012             def foo_bar(self): pass
01013 
01014         tests_1 = unittest.TestSuite([Foo('foo_bar')])
01015         tests_2 = unittest.TestSuite([Foo('test_1'), Foo('test_2')])
01016 
01017         loader = unittest.TestLoader()
01018         loader.testMethodPrefix = 'foo'
01019         self.assertEqual(loader.loadTestsFromTestCase(Foo), tests_1)
01020 
01021         loader.testMethodPrefix = 'test'
01022         self.assertEqual(loader.loadTestsFromTestCase(Foo), tests_2)

Here is the call graph for this function:


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