]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - third_party/Python/module/unittest2/unittest2/test/test_loader.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / third_party / Python / module / unittest2 / unittest2 / test / test_loader.py
1 import sys
2 import types
3
4 import unittest2
5
6
7 class Test_TestLoader(unittest2.TestCase):
8
9     # Tests for TestLoader.loadTestsFromTestCase
10     ################################################################
11
12     # "Return a suite of all tests cases contained in the TestCase-derived
13     # class testCaseClass"
14     def test_loadTestsFromTestCase(self):
15         class Foo(unittest2.TestCase):
16
17             def test_1(self): pass
18
19             def test_2(self): pass
20
21             def foo_bar(self): pass
22
23         tests = unittest2.TestSuite([Foo('test_1'), Foo('test_2')])
24
25         loader = unittest2.TestLoader()
26         self.assertEqual(loader.loadTestsFromTestCase(Foo), tests)
27
28     # "Return a suite of all tests cases contained in the TestCase-derived
29     # class testCaseClass"
30     #
31     # Make sure it does the right thing even if no tests were found
32     def test_loadTestsFromTestCase__no_matches(self):
33         class Foo(unittest2.TestCase):
34
35             def foo_bar(self): pass
36
37         empty_suite = unittest2.TestSuite()
38
39         loader = unittest2.TestLoader()
40         self.assertEqual(loader.loadTestsFromTestCase(Foo), empty_suite)
41
42     # "Return a suite of all tests cases contained in the TestCase-derived
43     # class testCaseClass"
44     #
45     # What happens if loadTestsFromTestCase() is given an object
46     # that isn't a subclass of TestCase? Specifically, what happens
47     # if testCaseClass is a subclass of TestSuite?
48     #
49     # This is checked for specifically in the code, so we better add a
50     # test for it.
51     def test_loadTestsFromTestCase__TestSuite_subclass(self):
52         class NotATestCase(unittest2.TestSuite):
53             pass
54
55         loader = unittest2.TestLoader()
56         try:
57             loader.loadTestsFromTestCase(NotATestCase)
58         except TypeError:
59             pass
60         else:
61             self.fail('Should raise TypeError')
62
63     # "Return a suite of all tests cases contained in the TestCase-derived
64     # class testCaseClass"
65     #
66     # Make sure loadTestsFromTestCase() picks up the default test method
67     # name (as specified by TestCase), even though the method name does
68     # not match the default TestLoader.testMethodPrefix string
69     def test_loadTestsFromTestCase__default_method_name(self):
70         class Foo(unittest2.TestCase):
71
72             def runTest(self):
73                 pass
74
75         loader = unittest2.TestLoader()
76         # This has to be false for the test to succeed
77         self.assertFalse('runTest'.startswith(loader.testMethodPrefix))
78
79         suite = loader.loadTestsFromTestCase(Foo)
80         self.assertIsInstance(suite, loader.suiteClass)
81         self.assertEqual(list(suite), [Foo('runTest')])
82
83     ################################################################
84     # /Tests for TestLoader.loadTestsFromTestCase
85
86     # Tests for TestLoader.loadTestsFromModule
87     ################################################################
88
89     # "This method searches `module` for classes derived from TestCase"
90     def test_loadTestsFromModule__TestCase_subclass(self):
91         m = types.ModuleType('m')
92
93         class MyTestCase(unittest2.TestCase):
94
95             def test(self):
96                 pass
97         m.testcase_1 = MyTestCase
98
99         loader = unittest2.TestLoader()
100         suite = loader.loadTestsFromModule(m)
101         self.assertIsInstance(suite, loader.suiteClass)
102
103         expected = [loader.suiteClass([MyTestCase('test')])]
104         self.assertEqual(list(suite), expected)
105
106     # "This method searches `module` for classes derived from TestCase"
107     #
108     # What happens if no tests are found (no TestCase instances)?
109     def test_loadTestsFromModule__no_TestCase_instances(self):
110         m = types.ModuleType('m')
111
112         loader = unittest2.TestLoader()
113         suite = loader.loadTestsFromModule(m)
114         self.assertIsInstance(suite, loader.suiteClass)
115         self.assertEqual(list(suite), [])
116
117     # "This method searches `module` for classes derived from TestCase"
118     #
119     # What happens if no tests are found (TestCases instances, but no tests)?
120     def test_loadTestsFromModule__no_TestCase_tests(self):
121         m = types.ModuleType('m')
122
123         class MyTestCase(unittest2.TestCase):
124             pass
125         m.testcase_1 = MyTestCase
126
127         loader = unittest2.TestLoader()
128         suite = loader.loadTestsFromModule(m)
129         self.assertIsInstance(suite, loader.suiteClass)
130
131         self.assertEqual(list(suite), [loader.suiteClass()])
132
133     # "This method searches `module` for classes derived from TestCase"s
134     #
135     # What happens if loadTestsFromModule() is given something other
136     # than a module?
137     #
138     # XXX Currently, it succeeds anyway. This flexibility
139     # should either be documented or loadTestsFromModule() should
140     # raise a TypeError
141     #
142     # XXX Certain people are using this behaviour. We'll add a test for it
143     def test_loadTestsFromModule__not_a_module(self):
144         class MyTestCase(unittest2.TestCase):
145
146             def test(self):
147                 pass
148
149         class NotAModule(object):
150             test_2 = MyTestCase
151
152         loader = unittest2.TestLoader()
153         suite = loader.loadTestsFromModule(NotAModule)
154
155         reference = [unittest2.TestSuite([MyTestCase('test')])]
156         self.assertEqual(list(suite), reference)
157
158     # Check that loadTestsFromModule honors (or not) a module
159     # with a load_tests function.
160     def test_loadTestsFromModule__load_tests(self):
161         m = types.ModuleType('m')
162
163         class MyTestCase(unittest2.TestCase):
164
165             def test(self):
166                 pass
167         m.testcase_1 = MyTestCase
168
169         load_tests_args = []
170
171         def load_tests(loader, tests, pattern):
172             self.assertIsInstance(tests, unittest2.TestSuite)
173             load_tests_args.extend((loader, tests, pattern))
174             return tests
175         m.load_tests = load_tests
176
177         loader = unittest2.TestLoader()
178         suite = loader.loadTestsFromModule(m)
179         self.assertIsInstance(suite, unittest2.TestSuite)
180         self.assertEquals(load_tests_args, [loader, suite, None])
181
182         load_tests_args = []
183         suite = loader.loadTestsFromModule(m, use_load_tests=False)
184         self.assertEquals(load_tests_args, [])
185
186     def test_loadTestsFromModule__faulty_load_tests(self):
187         m = types.ModuleType('m')
188
189         def load_tests(loader, tests, pattern):
190             raise TypeError('some failure')
191         m.load_tests = load_tests
192
193         loader = unittest2.TestLoader()
194         suite = loader.loadTestsFromModule(m)
195         self.assertIsInstance(suite, unittest2.TestSuite)
196         self.assertEqual(suite.countTestCases(), 1)
197         test = list(suite)[0]
198
199         self.assertRaisesRegexp(TypeError, "some failure", test.m)
200
201     ################################################################
202     # /Tests for TestLoader.loadTestsFromModule()
203
204     # Tests for TestLoader.loadTestsFromName()
205     ################################################################
206
207     # "The specifier name is a ``dotted name'' that may resolve either to
208     # a module, a test case class, a TestSuite instance, a test method
209     # within a test case class, or a callable object which returns a
210     # TestCase or TestSuite instance."
211     #
212     # Is ValueError raised in response to an empty name?
213     def test_loadTestsFromName__empty_name(self):
214         loader = unittest2.TestLoader()
215
216         try:
217             loader.loadTestsFromName('')
218         except ValueError as e:
219             self.assertEqual(str(e), "Empty module name")
220         else:
221             self.fail("TestLoader.loadTestsFromName failed to raise ValueError")
222
223     # "The specifier name is a ``dotted name'' that may resolve either to
224     # a module, a test case class, a TestSuite instance, a test method
225     # within a test case class, or a callable object which returns a
226     # TestCase or TestSuite instance."
227     #
228     # What happens when the name contains invalid characters?
229     def test_loadTestsFromName__malformed_name(self):
230         loader = unittest2.TestLoader()
231
232         # XXX Should this raise ValueError or ImportError?
233         try:
234             loader.loadTestsFromName('abc () //')
235         except ValueError:
236             pass
237         except ImportError:
238             pass
239         else:
240             self.fail("TestLoader.loadTestsFromName failed to raise ValueError")
241
242     # "The specifier name is a ``dotted name'' that may resolve ... to a
243     # module"
244     #
245     # What happens when a module by that name can't be found?
246     def test_loadTestsFromName__unknown_module_name(self):
247         loader = unittest2.TestLoader()
248
249         try:
250             loader.loadTestsFromName('sdasfasfasdf')
251         except ImportError as e:
252             self.assertEqual(str(e), "No module named sdasfasfasdf")
253         else:
254             self.fail("TestLoader.loadTestsFromName failed to raise ImportError")
255
256     # "The specifier name is a ``dotted name'' that may resolve either to
257     # a module, a test case class, a TestSuite instance, a test method
258     # within a test case class, or a callable object which returns a
259     # TestCase or TestSuite instance."
260     #
261     # What happens when the module is found, but the attribute can't?
262     def test_loadTestsFromName__unknown_attr_name(self):
263         loader = unittest2.TestLoader()
264
265         try:
266             loader.loadTestsFromName('unittest2.sdasfasfasdf')
267         except AttributeError as e:
268             self.assertEqual(
269                 str(e), "'module' object has no attribute 'sdasfasfasdf'")
270         else:
271             self.fail(
272                 "TestLoader.loadTestsFromName failed to raise AttributeError")
273
274     # "The specifier name is a ``dotted name'' that may resolve either to
275     # a module, a test case class, a TestSuite instance, a test method
276     # within a test case class, or a callable object which returns a
277     # TestCase or TestSuite instance."
278     #
279     # What happens when we provide the module, but the attribute can't be
280     # found?
281     def test_loadTestsFromName__relative_unknown_name(self):
282         loader = unittest2.TestLoader()
283
284         try:
285             loader.loadTestsFromName('sdasfasfasdf', unittest2)
286         except AttributeError as e:
287             self.assertEqual(
288                 str(e), "'module' object has no attribute 'sdasfasfasdf'")
289         else:
290             self.fail(
291                 "TestLoader.loadTestsFromName failed to raise AttributeError")
292
293     # "The specifier name is a ``dotted name'' that may resolve either to
294     # a module, a test case class, a TestSuite instance, a test method
295     # within a test case class, or a callable object which returns a
296     # TestCase or TestSuite instance."
297     # ...
298     # "The method optionally resolves name relative to the given module"
299     #
300     # Does loadTestsFromName raise ValueError when passed an empty
301     # name relative to a provided module?
302     #
303     # XXX Should probably raise a ValueError instead of an AttributeError
304     def test_loadTestsFromName__relative_empty_name(self):
305         loader = unittest2.TestLoader()
306
307         try:
308             loader.loadTestsFromName('', unittest2)
309         except AttributeError:
310             pass
311         else:
312             self.fail("Failed to raise AttributeError")
313
314     # "The specifier name is a ``dotted name'' that may resolve either to
315     # a module, a test case class, a TestSuite instance, a test method
316     # within a test case class, or a callable object which returns a
317     # TestCase or TestSuite instance."
318     # ...
319     # "The method optionally resolves name relative to the given module"
320     #
321     # What happens when an impossible name is given, relative to the provided
322     # `module`?
323     def test_loadTestsFromName__relative_malformed_name(self):
324         loader = unittest2.TestLoader()
325
326         # XXX Should this raise AttributeError or ValueError?
327         try:
328             loader.loadTestsFromName('abc () //', unittest2)
329         except ValueError:
330             pass
331         except AttributeError:
332             pass
333         else:
334             self.fail("TestLoader.loadTestsFromName failed to raise ValueError")
335
336     # "The method optionally resolves name relative to the given module"
337     #
338     # Does loadTestsFromName raise TypeError when the `module` argument
339     # isn't a module object?
340     #
341     # XXX Accepts the not-a-module object, ignorning the object's type
342     # This should raise an exception or the method name should be changed
343     #
344     # XXX Some people are relying on this, so keep it for now
345     def test_loadTestsFromName__relative_not_a_module(self):
346         class MyTestCase(unittest2.TestCase):
347
348             def test(self):
349                 pass
350
351         class NotAModule(object):
352             test_2 = MyTestCase
353
354         loader = unittest2.TestLoader()
355         suite = loader.loadTestsFromName('test_2', NotAModule)
356
357         reference = [MyTestCase('test')]
358         self.assertEqual(list(suite), reference)
359
360     # "The specifier name is a ``dotted name'' that may resolve either to
361     # a module, a test case class, a TestSuite instance, a test method
362     # within a test case class, or a callable object which returns a
363     # TestCase or TestSuite instance."
364     #
365     # Does it raise an exception if the name resolves to an invalid
366     # object?
367     def test_loadTestsFromName__relative_bad_object(self):
368         m = types.ModuleType('m')
369         m.testcase_1 = object()
370
371         loader = unittest2.TestLoader()
372         try:
373             loader.loadTestsFromName('testcase_1', m)
374         except TypeError:
375             pass
376         else:
377             self.fail("Should have raised TypeError")
378
379     # "The specifier name is a ``dotted name'' that may
380     # resolve either to ... a test case class"
381     def test_loadTestsFromName__relative_TestCase_subclass(self):
382         m = types.ModuleType('m')
383
384         class MyTestCase(unittest2.TestCase):
385
386             def test(self):
387                 pass
388         m.testcase_1 = MyTestCase
389
390         loader = unittest2.TestLoader()
391         suite = loader.loadTestsFromName('testcase_1', m)
392         self.assertIsInstance(suite, loader.suiteClass)
393         self.assertEqual(list(suite), [MyTestCase('test')])
394
395     # "The specifier name is a ``dotted name'' that may resolve either to
396     # a module, a test case class, a TestSuite instance, a test method
397     # within a test case class, or a callable object which returns a
398     # TestCase or TestSuite instance."
399     def test_loadTestsFromName__relative_TestSuite(self):
400         m = types.ModuleType('m')
401
402         class MyTestCase(unittest2.TestCase):
403
404             def test(self):
405                 pass
406         m.testsuite = unittest2.TestSuite([MyTestCase('test')])
407
408         loader = unittest2.TestLoader()
409         suite = loader.loadTestsFromName('testsuite', m)
410         self.assertIsInstance(suite, loader.suiteClass)
411
412         self.assertEqual(list(suite), [MyTestCase('test')])
413
414     # "The specifier name is a ``dotted name'' that may resolve ... to
415     # ... a test method within a test case class"
416     def test_loadTestsFromName__relative_testmethod(self):
417         m = types.ModuleType('m')
418
419         class MyTestCase(unittest2.TestCase):
420
421             def test(self):
422                 pass
423         m.testcase_1 = MyTestCase
424
425         loader = unittest2.TestLoader()
426         suite = loader.loadTestsFromName('testcase_1.test', m)
427         self.assertIsInstance(suite, loader.suiteClass)
428
429         self.assertEqual(list(suite), [MyTestCase('test')])
430
431     # "The specifier name is a ``dotted name'' that may resolve either to
432     # a module, a test case class, a TestSuite instance, a test method
433     # within a test case class, or a callable object which returns a
434     # TestCase or TestSuite instance."
435     #
436     # Does loadTestsFromName() raise the proper exception when trying to
437     # resolve "a test method within a test case class" that doesn't exist
438     # for the given name (relative to a provided module)?
439     def test_loadTestsFromName__relative_invalid_testmethod(self):
440         m = types.ModuleType('m')
441
442         class MyTestCase(unittest2.TestCase):
443
444             def test(self):
445                 pass
446         m.testcase_1 = MyTestCase
447
448         loader = unittest2.TestLoader()
449         try:
450             loader.loadTestsFromName('testcase_1.testfoo', m)
451         except AttributeError as e:
452             self.assertEqual(
453                 str(e), "type object 'MyTestCase' has no attribute 'testfoo'")
454         else:
455             self.fail("Failed to raise AttributeError")
456
457     # "The specifier name is a ``dotted name'' that may resolve ... to
458     # ... a callable object which returns a ... TestSuite instance"
459     def test_loadTestsFromName__callable__TestSuite(self):
460         m = types.ModuleType('m')
461         testcase_1 = unittest2.FunctionTestCase(lambda: None)
462         testcase_2 = unittest2.FunctionTestCase(lambda: None)
463
464         def return_TestSuite():
465             return unittest2.TestSuite([testcase_1, testcase_2])
466         m.return_TestSuite = return_TestSuite
467
468         loader = unittest2.TestLoader()
469         suite = loader.loadTestsFromName('return_TestSuite', m)
470         self.assertIsInstance(suite, loader.suiteClass)
471         self.assertEqual(list(suite), [testcase_1, testcase_2])
472
473     # "The specifier name is a ``dotted name'' that may resolve ... to
474     # ... a callable object which returns a TestCase ... instance"
475     def test_loadTestsFromName__callable__TestCase_instance(self):
476         m = types.ModuleType('m')
477         testcase_1 = unittest2.FunctionTestCase(lambda: None)
478
479         def return_TestCase():
480             return testcase_1
481         m.return_TestCase = return_TestCase
482
483         loader = unittest2.TestLoader()
484         suite = loader.loadTestsFromName('return_TestCase', m)
485         self.assertIsInstance(suite, loader.suiteClass)
486         self.assertEqual(list(suite), [testcase_1])
487
488     # "The specifier name is a ``dotted name'' that may resolve ... to
489     # ... a callable object which returns a TestCase ... instance"
490     #*****************************************************************
491     # Override the suiteClass attribute to ensure that the suiteClass
492     #attribute is used
493     def test_loadTestsFromName__callable__TestCase_instance_ProperSuiteClass(
494             self):
495         class SubTestSuite(unittest2.TestSuite):
496             pass
497         m = types.ModuleType('m')
498         testcase_1 = unittest2.FunctionTestCase(lambda: None)
499
500         def return_TestCase():
501             return testcase_1
502         m.return_TestCase = return_TestCase
503
504         loader = unittest2.TestLoader()
505         loader.suiteClass = SubTestSuite
506         suite = loader.loadTestsFromName('return_TestCase', m)
507         self.assertIsInstance(suite, loader.suiteClass)
508         self.assertEqual(list(suite), [testcase_1])
509
510     # "The specifier name is a ``dotted name'' that may resolve ... to
511     # ... a test method within a test case class"
512     #*****************************************************************
513     # Override the suiteClass attribute to ensure that the suiteClass
514     #attribute is used
515     def test_loadTestsFromName__relative_testmethod_ProperSuiteClass(self):
516         class SubTestSuite(unittest2.TestSuite):
517             pass
518         m = types.ModuleType('m')
519
520         class MyTestCase(unittest2.TestCase):
521
522             def test(self):
523                 pass
524         m.testcase_1 = MyTestCase
525
526         loader = unittest2.TestLoader()
527         loader.suiteClass = SubTestSuite
528         suite = loader.loadTestsFromName('testcase_1.test', m)
529         self.assertIsInstance(suite, loader.suiteClass)
530
531         self.assertEqual(list(suite), [MyTestCase('test')])
532
533     # "The specifier name is a ``dotted name'' that may resolve ... to
534     # ... a callable object which returns a TestCase or TestSuite instance"
535     #
536     # What happens if the callable returns something else?
537     def test_loadTestsFromName__callable__wrong_type(self):
538         m = types.ModuleType('m')
539
540         def return_wrong():
541             return 6
542         m.return_wrong = return_wrong
543
544         loader = unittest2.TestLoader()
545         try:
546             loader.loadTestsFromName('return_wrong', m)
547         except TypeError:
548             pass
549         else:
550             self.fail("TestLoader.loadTestsFromName failed to raise TypeError")
551
552     # "The specifier can refer to modules and packages which have not been
553     # imported; they will be imported as a side-effect"
554     def test_loadTestsFromName__module_not_loaded(self):
555         # We're going to try to load this module as a side-effect, so it
556         # better not be loaded before we try.
557         #
558         module_name = 'unittest2.test.dummy'
559         sys.modules.pop(module_name, None)
560
561         loader = unittest2.TestLoader()
562         try:
563             suite = loader.loadTestsFromName(module_name)
564
565             self.assertIsInstance(suite, loader.suiteClass)
566             self.assertEqual(list(suite), [])
567
568             # module should now be loaded, thanks to loadTestsFromName()
569             self.assertIn(module_name, sys.modules)
570         finally:
571             if module_name in sys.modules:
572                 del sys.modules[module_name]
573
574     ################################################################
575     # Tests for TestLoader.loadTestsFromName()
576
577     # Tests for TestLoader.loadTestsFromNames()
578     ################################################################
579
580     # "Similar to loadTestsFromName(), but takes a sequence of names rather
581     # than a single name."
582     #
583     # What happens if that sequence of names is empty?
584     def test_loadTestsFromNames__empty_name_list(self):
585         loader = unittest2.TestLoader()
586
587         suite = loader.loadTestsFromNames([])
588         self.assertIsInstance(suite, loader.suiteClass)
589         self.assertEqual(list(suite), [])
590
591     # "Similar to loadTestsFromName(), but takes a sequence of names rather
592     # than a single name."
593     # ...
594     # "The method optionally resolves name relative to the given module"
595     #
596     # What happens if that sequence of names is empty?
597     #
598     # XXX Should this raise a ValueError or just return an empty TestSuite?
599     def test_loadTestsFromNames__relative_empty_name_list(self):
600         loader = unittest2.TestLoader()
601
602         suite = loader.loadTestsFromNames([], unittest2)
603         self.assertIsInstance(suite, loader.suiteClass)
604         self.assertEqual(list(suite), [])
605
606     # "The specifier name is a ``dotted name'' that may resolve either to
607     # a module, a test case class, a TestSuite instance, a test method
608     # within a test case class, or a callable object which returns a
609     # TestCase or TestSuite instance."
610     #
611     # Is ValueError raised in response to an empty name?
612     def test_loadTestsFromNames__empty_name(self):
613         loader = unittest2.TestLoader()
614
615         try:
616             loader.loadTestsFromNames([''])
617         except ValueError as e:
618             self.assertEqual(str(e), "Empty module name")
619         else:
620             self.fail("TestLoader.loadTestsFromNames failed to raise ValueError")
621
622     # "The specifier name is a ``dotted name'' that may resolve either to
623     # a module, a test case class, a TestSuite instance, a test method
624     # within a test case class, or a callable object which returns a
625     # TestCase or TestSuite instance."
626     #
627     # What happens when presented with an impossible module name?
628     def test_loadTestsFromNames__malformed_name(self):
629         loader = unittest2.TestLoader()
630
631         # XXX Should this raise ValueError or ImportError?
632         try:
633             loader.loadTestsFromNames(['abc () //'])
634         except ValueError:
635             pass
636         except ImportError:
637             pass
638         else:
639             self.fail("TestLoader.loadTestsFromNames failed to raise ValueError")
640
641     # "The specifier name is a ``dotted name'' that may resolve either to
642     # a module, a test case class, a TestSuite instance, a test method
643     # within a test case class, or a callable object which returns a
644     # TestCase or TestSuite instance."
645     #
646     # What happens when no module can be found for the given name?
647     def test_loadTestsFromNames__unknown_module_name(self):
648         loader = unittest2.TestLoader()
649
650         try:
651             loader.loadTestsFromNames(['sdasfasfasdf'])
652         except ImportError as e:
653             self.assertEqual(str(e), "No module named sdasfasfasdf")
654         else:
655             self.fail("TestLoader.loadTestsFromNames failed to raise ImportError")
656
657     # "The specifier name is a ``dotted name'' that may resolve either to
658     # a module, a test case class, a TestSuite instance, a test method
659     # within a test case class, or a callable object which returns a
660     # TestCase or TestSuite instance."
661     #
662     # What happens when the module can be found, but not the attribute?
663     def test_loadTestsFromNames__unknown_attr_name(self):
664         loader = unittest2.TestLoader()
665
666         try:
667             loader.loadTestsFromNames(['unittest2.sdasfasfasdf', 'unittest2'])
668         except AttributeError as e:
669             self.assertEqual(
670                 str(e), "'module' object has no attribute 'sdasfasfasdf'")
671         else:
672             self.fail(
673                 "TestLoader.loadTestsFromNames failed to raise AttributeError")
674
675     # "The specifier name is a ``dotted name'' that may resolve either to
676     # a module, a test case class, a TestSuite instance, a test method
677     # within a test case class, or a callable object which returns a
678     # TestCase or TestSuite instance."
679     # ...
680     # "The method optionally resolves name relative to the given module"
681     #
682     # What happens when given an unknown attribute on a specified `module`
683     # argument?
684     def test_loadTestsFromNames__unknown_name_relative_1(self):
685         loader = unittest2.TestLoader()
686
687         try:
688             loader.loadTestsFromNames(['sdasfasfasdf'], unittest2)
689         except AttributeError as e:
690             self.assertEqual(
691                 str(e), "'module' object has no attribute 'sdasfasfasdf'")
692         else:
693             self.fail(
694                 "TestLoader.loadTestsFromName failed to raise AttributeError")
695
696     # "The specifier name is a ``dotted name'' that may resolve either to
697     # a module, a test case class, a TestSuite instance, a test method
698     # within a test case class, or a callable object which returns a
699     # TestCase or TestSuite instance."
700     # ...
701     # "The method optionally resolves name relative to the given module"
702     #
703     # Do unknown attributes (relative to a provided module) still raise an
704     # exception even in the presence of valid attribute names?
705     def test_loadTestsFromNames__unknown_name_relative_2(self):
706         loader = unittest2.TestLoader()
707
708         try:
709             loader.loadTestsFromNames(['TestCase', 'sdasfasfasdf'], unittest2)
710         except AttributeError as e:
711             self.assertEqual(
712                 str(e), "'module' object has no attribute 'sdasfasfasdf'")
713         else:
714             self.fail(
715                 "TestLoader.loadTestsFromName failed to raise AttributeError")
716
717     # "The specifier name is a ``dotted name'' that may resolve either to
718     # a module, a test case class, a TestSuite instance, a test method
719     # within a test case class, or a callable object which returns a
720     # TestCase or TestSuite instance."
721     # ...
722     # "The method optionally resolves name relative to the given module"
723     #
724     # What happens when faced with the empty string?
725     #
726     # XXX This currently raises AttributeError, though ValueError is probably
727     # more appropriate
728     def test_loadTestsFromNames__relative_empty_name(self):
729         loader = unittest2.TestLoader()
730
731         try:
732             loader.loadTestsFromNames([''], unittest2)
733         except AttributeError:
734             pass
735         else:
736             self.fail("Failed to raise ValueError")
737
738     # "The specifier name is a ``dotted name'' that may resolve either to
739     # a module, a test case class, a TestSuite instance, a test method
740     # within a test case class, or a callable object which returns a
741     # TestCase or TestSuite instance."
742     # ...
743     # "The method optionally resolves name relative to the given module"
744     #
745     # What happens when presented with an impossible attribute name?
746     def test_loadTestsFromNames__relative_malformed_name(self):
747         loader = unittest2.TestLoader()
748
749         # XXX Should this raise AttributeError or ValueError?
750         try:
751             loader.loadTestsFromNames(['abc () //'], unittest2)
752         except AttributeError:
753             pass
754         except ValueError:
755             pass
756         else:
757             self.fail("TestLoader.loadTestsFromNames failed to raise ValueError")
758
759     # "The method optionally resolves name relative to the given module"
760     #
761     # Does loadTestsFromNames() make sure the provided `module` is in fact
762     # a module?
763     #
764     # XXX This validation is currently not done. This flexibility should
765     # either be documented or a TypeError should be raised.
766     def test_loadTestsFromNames__relative_not_a_module(self):
767         class MyTestCase(unittest2.TestCase):
768
769             def test(self):
770                 pass
771
772         class NotAModule(object):
773             test_2 = MyTestCase
774
775         loader = unittest2.TestLoader()
776         suite = loader.loadTestsFromNames(['test_2'], NotAModule)
777
778         reference = [unittest2.TestSuite([MyTestCase('test')])]
779         self.assertEqual(list(suite), reference)
780
781     # "The specifier name is a ``dotted name'' that may resolve either to
782     # a module, a test case class, a TestSuite instance, a test method
783     # within a test case class, or a callable object which returns a
784     # TestCase or TestSuite instance."
785     #
786     # Does it raise an exception if the name resolves to an invalid
787     # object?
788     def test_loadTestsFromNames__relative_bad_object(self):
789         m = types.ModuleType('m')
790         m.testcase_1 = object()
791
792         loader = unittest2.TestLoader()
793         try:
794             loader.loadTestsFromNames(['testcase_1'], m)
795         except TypeError:
796             pass
797         else:
798             self.fail("Should have raised TypeError")
799
800     # "The specifier name is a ``dotted name'' that may resolve ... to
801     # ... a test case class"
802     def test_loadTestsFromNames__relative_TestCase_subclass(self):
803         m = types.ModuleType('m')
804
805         class MyTestCase(unittest2.TestCase):
806
807             def test(self):
808                 pass
809         m.testcase_1 = MyTestCase
810
811         loader = unittest2.TestLoader()
812         suite = loader.loadTestsFromNames(['testcase_1'], m)
813         self.assertIsInstance(suite, loader.suiteClass)
814
815         expected = loader.suiteClass([MyTestCase('test')])
816         self.assertEqual(list(suite), [expected])
817
818     # "The specifier name is a ``dotted name'' that may resolve ... to
819     # ... a TestSuite instance"
820     def test_loadTestsFromNames__relative_TestSuite(self):
821         m = types.ModuleType('m')
822
823         class MyTestCase(unittest2.TestCase):
824
825             def test(self):
826                 pass
827         m.testsuite = unittest2.TestSuite([MyTestCase('test')])
828
829         loader = unittest2.TestLoader()
830         suite = loader.loadTestsFromNames(['testsuite'], m)
831         self.assertIsInstance(suite, loader.suiteClass)
832
833         self.assertEqual(list(suite), [m.testsuite])
834
835     # "The specifier name is a ``dotted name'' that may resolve ... to ... a
836     # test method within a test case class"
837     def test_loadTestsFromNames__relative_testmethod(self):
838         m = types.ModuleType('m')
839
840         class MyTestCase(unittest2.TestCase):
841
842             def test(self):
843                 pass
844         m.testcase_1 = MyTestCase
845
846         loader = unittest2.TestLoader()
847         suite = loader.loadTestsFromNames(['testcase_1.test'], m)
848         self.assertIsInstance(suite, loader.suiteClass)
849
850         ref_suite = unittest2.TestSuite([MyTestCase('test')])
851         self.assertEqual(list(suite), [ref_suite])
852
853     # "The specifier name is a ``dotted name'' that may resolve ... to ... a
854     # test method within a test case class"
855     #
856     # Does the method gracefully handle names that initially look like they
857     # resolve to "a test method within a test case class" but don't?
858     def test_loadTestsFromNames__relative_invalid_testmethod(self):
859         m = types.ModuleType('m')
860
861         class MyTestCase(unittest2.TestCase):
862
863             def test(self):
864                 pass
865         m.testcase_1 = MyTestCase
866
867         loader = unittest2.TestLoader()
868         try:
869             loader.loadTestsFromNames(['testcase_1.testfoo'], m)
870         except AttributeError as e:
871             self.assertEqual(
872                 str(e), "type object 'MyTestCase' has no attribute 'testfoo'")
873         else:
874             self.fail("Failed to raise AttributeError")
875
876     # "The specifier name is a ``dotted name'' that may resolve ... to
877     # ... a callable object which returns a ... TestSuite instance"
878     def test_loadTestsFromNames__callable__TestSuite(self):
879         m = types.ModuleType('m')
880         testcase_1 = unittest2.FunctionTestCase(lambda: None)
881         testcase_2 = unittest2.FunctionTestCase(lambda: None)
882
883         def return_TestSuite():
884             return unittest2.TestSuite([testcase_1, testcase_2])
885         m.return_TestSuite = return_TestSuite
886
887         loader = unittest2.TestLoader()
888         suite = loader.loadTestsFromNames(['return_TestSuite'], m)
889         self.assertIsInstance(suite, loader.suiteClass)
890
891         expected = unittest2.TestSuite([testcase_1, testcase_2])
892         self.assertEqual(list(suite), [expected])
893
894     # "The specifier name is a ``dotted name'' that may resolve ... to
895     # ... a callable object which returns a TestCase ... instance"
896     def test_loadTestsFromNames__callable__TestCase_instance(self):
897         m = types.ModuleType('m')
898         testcase_1 = unittest2.FunctionTestCase(lambda: None)
899
900         def return_TestCase():
901             return testcase_1
902         m.return_TestCase = return_TestCase
903
904         loader = unittest2.TestLoader()
905         suite = loader.loadTestsFromNames(['return_TestCase'], m)
906         self.assertIsInstance(suite, loader.suiteClass)
907
908         ref_suite = unittest2.TestSuite([testcase_1])
909         self.assertEqual(list(suite), [ref_suite])
910
911     # "The specifier name is a ``dotted name'' that may resolve ... to
912     # ... a callable object which returns a TestCase or TestSuite instance"
913     #
914     # Are staticmethods handled correctly?
915     def test_loadTestsFromNames__callable__call_staticmethod(self):
916         m = types.ModuleType('m')
917
918         class Test1(unittest2.TestCase):
919
920             def test(self):
921                 pass
922
923         testcase_1 = Test1('test')
924
925         class Foo(unittest2.TestCase):
926
927             @staticmethod
928             def foo():
929                 return testcase_1
930         m.Foo = Foo
931
932         loader = unittest2.TestLoader()
933         suite = loader.loadTestsFromNames(['Foo.foo'], m)
934         self.assertIsInstance(suite, loader.suiteClass)
935
936         ref_suite = unittest2.TestSuite([testcase_1])
937         self.assertEqual(list(suite), [ref_suite])
938
939     # "The specifier name is a ``dotted name'' that may resolve ... to
940     # ... a callable object which returns a TestCase or TestSuite instance"
941     #
942     # What happens when the callable returns something else?
943     def test_loadTestsFromNames__callable__wrong_type(self):
944         m = types.ModuleType('m')
945
946         def return_wrong():
947             return 6
948         m.return_wrong = return_wrong
949
950         loader = unittest2.TestLoader()
951         try:
952             loader.loadTestsFromNames(['return_wrong'], m)
953         except TypeError:
954             pass
955         else:
956             self.fail("TestLoader.loadTestsFromNames failed to raise TypeError")
957
958     # "The specifier can refer to modules and packages which have not been
959     # imported; they will be imported as a side-effect"
960     def test_loadTestsFromNames__module_not_loaded(self):
961         # We're going to try to load this module as a side-effect, so it
962         # better not be loaded before we try.
963         #
964         module_name = 'unittest2.test.dummy'
965         sys.modules.pop(module_name, None)
966
967         loader = unittest2.TestLoader()
968         try:
969             suite = loader.loadTestsFromNames([module_name])
970
971             self.assertIsInstance(suite, loader.suiteClass)
972             self.assertEqual(list(suite), [unittest2.TestSuite()])
973
974             # module should now be loaded, thanks to loadTestsFromName()
975             self.assertIn(module_name, sys.modules)
976         finally:
977             if module_name in sys.modules:
978                 del sys.modules[module_name]
979
980     ################################################################
981     # /Tests for TestLoader.loadTestsFromNames()
982
983     # Tests for TestLoader.getTestCaseNames()
984     ################################################################
985
986     # "Return a sorted sequence of method names found within testCaseClass"
987     #
988     # Test.foobar is defined to make sure getTestCaseNames() respects
989     # loader.testMethodPrefix
990     def test_getTestCaseNames(self):
991         class Test(unittest2.TestCase):
992
993             def test_1(self): pass
994
995             def test_2(self): pass
996
997             def foobar(self): pass
998
999         loader = unittest2.TestLoader()
1000
1001         self.assertEqual(loader.getTestCaseNames(Test), ['test_1', 'test_2'])
1002
1003     # "Return a sorted sequence of method names found within testCaseClass"
1004     #
1005     # Does getTestCaseNames() behave appropriately if no tests are found?
1006     def test_getTestCaseNames__no_tests(self):
1007         class Test(unittest2.TestCase):
1008
1009             def foobar(self): pass
1010
1011         loader = unittest2.TestLoader()
1012
1013         self.assertEqual(loader.getTestCaseNames(Test), [])
1014
1015     # "Return a sorted sequence of method names found within testCaseClass"
1016     #
1017     # Are not-TestCases handled gracefully?
1018     #
1019     # XXX This should raise a TypeError, not return a list
1020     #
1021     # XXX It's too late in the 2.5 release cycle to fix this, but it should
1022     # probably be revisited for 2.6
1023     def test_getTestCaseNames__not_a_TestCase(self):
1024         class BadCase(int):
1025
1026             def test_foo(self):
1027                 pass
1028
1029         loader = unittest2.TestLoader()
1030         names = loader.getTestCaseNames(BadCase)
1031
1032         self.assertEqual(names, ['test_foo'])
1033
1034     # "Return a sorted sequence of method names found within testCaseClass"
1035     #
1036     # Make sure inherited names are handled.
1037     #
1038     # TestP.foobar is defined to make sure getTestCaseNames() respects
1039     # loader.testMethodPrefix
1040     def test_getTestCaseNames__inheritance(self):
1041         class TestP(unittest2.TestCase):
1042
1043             def test_1(self): pass
1044
1045             def test_2(self): pass
1046
1047             def foobar(self): pass
1048
1049         class TestC(TestP):
1050
1051             def test_1(self): pass
1052
1053             def test_3(self): pass
1054
1055         loader = unittest2.TestLoader()
1056
1057         names = ['test_1', 'test_2', 'test_3']
1058         self.assertEqual(loader.getTestCaseNames(TestC), names)
1059
1060     ################################################################
1061     # /Tests for TestLoader.getTestCaseNames()
1062
1063     # Tests for TestLoader.testMethodPrefix
1064     ################################################################
1065
1066     # "String giving the prefix of method names which will be interpreted as
1067     # test methods"
1068     #
1069     # Implicit in the documentation is that testMethodPrefix is respected by
1070     # all loadTestsFrom* methods.
1071     def test_testMethodPrefix__loadTestsFromTestCase(self):
1072         class Foo(unittest2.TestCase):
1073
1074             def test_1(self): pass
1075
1076             def test_2(self): pass
1077
1078             def foo_bar(self): pass
1079
1080         tests_1 = unittest2.TestSuite([Foo('foo_bar')])
1081         tests_2 = unittest2.TestSuite([Foo('test_1'), Foo('test_2')])
1082
1083         loader = unittest2.TestLoader()
1084         loader.testMethodPrefix = 'foo'
1085         self.assertEqual(loader.loadTestsFromTestCase(Foo), tests_1)
1086
1087         loader.testMethodPrefix = 'test'
1088         self.assertEqual(loader.loadTestsFromTestCase(Foo), tests_2)
1089
1090     # "String giving the prefix of method names which will be interpreted as
1091     # test methods"
1092     #
1093     # Implicit in the documentation is that testMethodPrefix is respected by
1094     # all loadTestsFrom* methods.
1095     def test_testMethodPrefix__loadTestsFromModule(self):
1096         m = types.ModuleType('m')
1097
1098         class Foo(unittest2.TestCase):
1099
1100             def test_1(self): pass
1101
1102             def test_2(self): pass
1103
1104             def foo_bar(self): pass
1105         m.Foo = Foo
1106
1107         tests_1 = [unittest2.TestSuite([Foo('foo_bar')])]
1108         tests_2 = [unittest2.TestSuite([Foo('test_1'), Foo('test_2')])]
1109
1110         loader = unittest2.TestLoader()
1111         loader.testMethodPrefix = 'foo'
1112         self.assertEqual(list(loader.loadTestsFromModule(m)), tests_1)
1113
1114         loader.testMethodPrefix = 'test'
1115         self.assertEqual(list(loader.loadTestsFromModule(m)), tests_2)
1116
1117     # "String giving the prefix of method names which will be interpreted as
1118     # test methods"
1119     #
1120     # Implicit in the documentation is that testMethodPrefix is respected by
1121     # all loadTestsFrom* methods.
1122     def test_testMethodPrefix__loadTestsFromName(self):
1123         m = types.ModuleType('m')
1124
1125         class Foo(unittest2.TestCase):
1126
1127             def test_1(self): pass
1128
1129             def test_2(self): pass
1130
1131             def foo_bar(self): pass
1132         m.Foo = Foo
1133
1134         tests_1 = unittest2.TestSuite([Foo('foo_bar')])
1135         tests_2 = unittest2.TestSuite([Foo('test_1'), Foo('test_2')])
1136
1137         loader = unittest2.TestLoader()
1138         loader.testMethodPrefix = 'foo'
1139         self.assertEqual(loader.loadTestsFromName('Foo', m), tests_1)
1140
1141         loader.testMethodPrefix = 'test'
1142         self.assertEqual(loader.loadTestsFromName('Foo', m), tests_2)
1143
1144     # "String giving the prefix of method names which will be interpreted as
1145     # test methods"
1146     #
1147     # Implicit in the documentation is that testMethodPrefix is respected by
1148     # all loadTestsFrom* methods.
1149     def test_testMethodPrefix__loadTestsFromNames(self):
1150         m = types.ModuleType('m')
1151
1152         class Foo(unittest2.TestCase):
1153
1154             def test_1(self): pass
1155
1156             def test_2(self): pass
1157
1158             def foo_bar(self): pass
1159         m.Foo = Foo
1160
1161         tests_1 = unittest2.TestSuite([unittest2.TestSuite([Foo('foo_bar')])])
1162         tests_2 = unittest2.TestSuite([Foo('test_1'), Foo('test_2')])
1163         tests_2 = unittest2.TestSuite([tests_2])
1164
1165         loader = unittest2.TestLoader()
1166         loader.testMethodPrefix = 'foo'
1167         self.assertEqual(loader.loadTestsFromNames(['Foo'], m), tests_1)
1168
1169         loader.testMethodPrefix = 'test'
1170         self.assertEqual(loader.loadTestsFromNames(['Foo'], m), tests_2)
1171
1172     # "The default value is 'test'"
1173     def test_testMethodPrefix__default_value(self):
1174         loader = unittest2.TestLoader()
1175         self.assertTrue(loader.testMethodPrefix == 'test')
1176
1177     ################################################################
1178     # /Tests for TestLoader.testMethodPrefix
1179
1180     # Tests for TestLoader.sortTestMethodsUsing
1181     ################################################################
1182
1183     # "Function to be used to compare method names when sorting them in
1184     # getTestCaseNames() and all the loadTestsFromX() methods"
1185     def test_sortTestMethodsUsing__loadTestsFromTestCase(self):
1186         class Foo(unittest2.TestCase):
1187
1188             def test_1(self): pass
1189
1190             def test_2(self): pass
1191
1192         loader = unittest2.TestLoader()
1193         loader.sortTestMethodsUsing = unittest2.reversed_cmp_
1194
1195         tests = loader.suiteClass([Foo('test_2'), Foo('test_1')])
1196         self.assertEqual(loader.loadTestsFromTestCase(Foo), tests)
1197
1198     # "Function to be used to compare method names when sorting them in
1199     # getTestCaseNames() and all the loadTestsFromX() methods"
1200     def test_sortTestMethodsUsing__loadTestsFromModule(self):
1201         m = types.ModuleType('m')
1202
1203         class Foo(unittest2.TestCase):
1204
1205             def test_1(self): pass
1206
1207             def test_2(self): pass
1208         m.Foo = Foo
1209
1210         loader = unittest2.TestLoader()
1211         loader.sortTestMethodsUsing = unittest2.reversed_cmp_
1212
1213         tests = [loader.suiteClass([Foo('test_2'), Foo('test_1')])]
1214         self.assertEqual(list(loader.loadTestsFromModule(m)), tests)
1215
1216     # "Function to be used to compare method names when sorting them in
1217     # getTestCaseNames() and all the loadTestsFromX() methods"
1218     def test_sortTestMethodsUsing__loadTestsFromName(self):
1219         m = types.ModuleType('m')
1220
1221         class Foo(unittest2.TestCase):
1222
1223             def test_1(self): pass
1224
1225             def test_2(self): pass
1226         m.Foo = Foo
1227
1228         loader = unittest2.TestLoader()
1229         loader.sortTestMethodsUsing = unittest2.reversed_cmp_
1230
1231         tests = loader.suiteClass([Foo('test_2'), Foo('test_1')])
1232         self.assertEqual(loader.loadTestsFromName('Foo', m), tests)
1233
1234     # "Function to be used to compare method names when sorting them in
1235     # getTestCaseNames() and all the loadTestsFromX() methods"
1236     def test_sortTestMethodsUsing__loadTestsFromNames(self):
1237         m = types.ModuleType('m')
1238
1239         class Foo(unittest2.TestCase):
1240
1241             def test_1(self): pass
1242
1243             def test_2(self): pass
1244         m.Foo = Foo
1245
1246         loader = unittest2.TestLoader()
1247         loader.sortTestMethodsUsing = unittest2.reversed_cmp_
1248
1249         tests = [loader.suiteClass([Foo('test_2'), Foo('test_1')])]
1250         self.assertEqual(list(loader.loadTestsFromNames(['Foo'], m)), tests)
1251
1252     # "Function to be used to compare method names when sorting them in
1253     # getTestCaseNames()"
1254     #
1255     # Does it actually affect getTestCaseNames()?
1256     def test_sortTestMethodsUsing__getTestCaseNames(self):
1257         class Foo(unittest2.TestCase):
1258
1259             def test_1(self): pass
1260
1261             def test_2(self): pass
1262
1263         loader = unittest2.TestLoader()
1264         loader.sortTestMethodsUsing = unittest2.reversed_cmp_
1265
1266         test_names = ['test_2', 'test_1']
1267         self.assertEqual(loader.getTestCaseNames(Foo), test_names)
1268
1269     # "The default value is the built-in cmp() function"
1270     def test_sortTestMethodsUsing__default_value(self):
1271         loader = unittest2.TestLoader()
1272         self.assertTrue(loader.sortTestMethodsUsing is unittest2.cmp_)
1273
1274     # "it can be set to None to disable the sort."
1275     #
1276     # XXX How is this different from reassigning cmp? Are the tests returned
1277     # in a random order or something? This behaviour should die
1278     def test_sortTestMethodsUsing__None(self):
1279         class Foo(unittest2.TestCase):
1280
1281             def test_1(self): pass
1282
1283             def test_2(self): pass
1284
1285         loader = unittest2.TestLoader()
1286         loader.sortTestMethodsUsing = None
1287
1288         test_names = ['test_2', 'test_1']
1289         self.assertEqual(set(loader.getTestCaseNames(Foo)), set(test_names))
1290
1291     ################################################################
1292     # /Tests for TestLoader.sortTestMethodsUsing
1293
1294     # Tests for TestLoader.suiteClass
1295     ################################################################
1296
1297     # "Callable object that constructs a test suite from a list of tests."
1298     def test_suiteClass__loadTestsFromTestCase(self):
1299         class Foo(unittest2.TestCase):
1300
1301             def test_1(self): pass
1302
1303             def test_2(self): pass
1304
1305             def foo_bar(self): pass
1306
1307         tests = [Foo('test_1'), Foo('test_2')]
1308
1309         loader = unittest2.TestLoader()
1310         loader.suiteClass = list
1311         self.assertEqual(loader.loadTestsFromTestCase(Foo), tests)
1312
1313     # It is implicit in the documentation for TestLoader.suiteClass that
1314     # all TestLoader.loadTestsFrom* methods respect it. Let's make sure
1315     def test_suiteClass__loadTestsFromModule(self):
1316         m = types.ModuleType('m')
1317
1318         class Foo(unittest2.TestCase):
1319
1320             def test_1(self): pass
1321
1322             def test_2(self): pass
1323
1324             def foo_bar(self): pass
1325         m.Foo = Foo
1326
1327         tests = [[Foo('test_1'), Foo('test_2')]]
1328
1329         loader = unittest2.TestLoader()
1330         loader.suiteClass = list
1331         self.assertEqual(loader.loadTestsFromModule(m), tests)
1332
1333     # It is implicit in the documentation for TestLoader.suiteClass that
1334     # all TestLoader.loadTestsFrom* methods respect it. Let's make sure
1335     def test_suiteClass__loadTestsFromName(self):
1336         m = types.ModuleType('m')
1337
1338         class Foo(unittest2.TestCase):
1339
1340             def test_1(self): pass
1341
1342             def test_2(self): pass
1343
1344             def foo_bar(self): pass
1345         m.Foo = Foo
1346
1347         tests = [Foo('test_1'), Foo('test_2')]
1348
1349         loader = unittest2.TestLoader()
1350         loader.suiteClass = list
1351         self.assertEqual(loader.loadTestsFromName('Foo', m), tests)
1352
1353     # It is implicit in the documentation for TestLoader.suiteClass that
1354     # all TestLoader.loadTestsFrom* methods respect it. Let's make sure
1355     def test_suiteClass__loadTestsFromNames(self):
1356         m = types.ModuleType('m')
1357
1358         class Foo(unittest2.TestCase):
1359
1360             def test_1(self): pass
1361
1362             def test_2(self): pass
1363
1364             def foo_bar(self): pass
1365         m.Foo = Foo
1366
1367         tests = [[Foo('test_1'), Foo('test_2')]]
1368
1369         loader = unittest2.TestLoader()
1370         loader.suiteClass = list
1371         self.assertEqual(loader.loadTestsFromNames(['Foo'], m), tests)
1372
1373     # "The default value is the TestSuite class"
1374     def test_suiteClass__default_value(self):
1375         loader = unittest2.TestLoader()
1376         self.assertTrue(loader.suiteClass is unittest2.TestSuite)
1377
1378
1379 if __name__ == '__main__':
1380     unittest2.main()