Python unittest2.TestSuite() Examples
The following are 30
code examples of unittest2.TestSuite().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
unittest2
, or try the search function
.
Example #1
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_loadTestsFromName__relative_testmethod_ProperSuiteClass(self): class SubTestSuite(unittest2.TestSuite): pass m = types.ModuleType('m') class MyTestCase(unittest2.TestCase): def test(self): pass m.testcase_1 = MyTestCase loader = unittest2.TestLoader() loader.suiteClass=SubTestSuite suite = loader.loadTestsFromName('testcase_1.test', m) self.assertIsInstance(suite, loader.suiteClass) self.assertEqual(list(suite), [MyTestCase('test')]) # "The specifier name is a ``dotted name'' that may resolve ... to # ... a callable object which returns a TestCase or TestSuite instance" # # What happens if the callable returns something else?
Example #2
Source File: support.py From verge3d-blender-addon with GNU General Public License v3.0 | 6 votes |
def _run_suite(suite): """Run tests from a unittest.TestSuite-derived class.""" if verbose: runner = unittest.TextTestRunner(sys.stdout, verbosity=2, failfast=failfast) else: runner = BasicTestRunner() result = runner.run(suite) if not result.wasSuccessful(): if len(result.errors) == 1 and not result.failures: err = result.errors[0][1] elif len(result.failures) == 1 and not result.errors: err = result.failures[0][1] else: err = "multiple errors occurred" if not verbose: err += "; run in verbose mode for details" raise TestFailed(err)
Example #3
Source File: support.py From telegram-robot-rss with Mozilla Public License 2.0 | 6 votes |
def _run_suite(suite): """Run tests from a unittest.TestSuite-derived class.""" if verbose: runner = unittest.TextTestRunner(sys.stdout, verbosity=2, failfast=failfast) else: runner = BasicTestRunner() result = runner.run(suite) if not result.wasSuccessful(): if len(result.errors) == 1 and not result.failures: err = result.errors[0][1] elif len(result.failures) == 1 and not result.errors: err = result.failures[0][1] else: err = "multiple errors occurred" if not verbose: err += "; run in verbose mode for details" raise TestFailed(err)
Example #4
Source File: support.py From blackmamba with MIT License | 6 votes |
def _run_suite(suite): """Run tests from a unittest.TestSuite-derived class.""" if verbose: runner = unittest.TextTestRunner(sys.stdout, verbosity=2, failfast=failfast) else: runner = BasicTestRunner() result = runner.run(suite) if not result.wasSuccessful(): if len(result.errors) == 1 and not result.failures: err = result.errors[0][1] elif len(result.failures) == 1 and not result.errors: err = result.failures[0][1] else: err = "multiple errors occurred" if not verbose: err += "; run in verbose mode for details" raise TestFailed(err)
Example #5
Source File: support.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 6 votes |
def _run_suite(suite): """Run tests from a unittest.TestSuite-derived class.""" if verbose: runner = unittest.TextTestRunner(sys.stdout, verbosity=2, failfast=failfast) else: runner = BasicTestRunner() result = runner.run(suite) if not result.wasSuccessful(): if len(result.errors) == 1 and not result.failures: err = result.errors[0][1] elif len(result.failures) == 1 and not result.errors: err = result.failures[0][1] else: err = "multiple errors occurred" if not verbose: err += "; run in verbose mode for details" raise TestFailed(err)
Example #6
Source File: support.py From deepWordBug with Apache License 2.0 | 6 votes |
def _run_suite(suite): """Run tests from a unittest.TestSuite-derived class.""" if verbose: runner = unittest.TextTestRunner(sys.stdout, verbosity=2, failfast=failfast) else: runner = BasicTestRunner() result = runner.run(suite) if not result.wasSuccessful(): if len(result.errors) == 1 and not result.failures: err = result.errors[0][1] elif len(result.failures) == 1 and not result.errors: err = result.failures[0][1] else: err = "multiple errors occurred" if not verbose: err += "; run in verbose mode for details" raise TestFailed(err)
Example #7
Source File: test_runner.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_startTestRun_stopTestRun_called(self): class LoggingTextResult(LoggingResult): separator2 = '' def printErrors(self): pass class LoggingRunner(unittest2.TextTestRunner): def __init__(self, events): super(LoggingRunner, self).__init__(StringIO()) self._events = events def _makeResult(self): return LoggingTextResult(self._events) events = [] runner = LoggingRunner(events) runner.run(unittest2.TestSuite()) expected = ['startTestRun', 'stopTestRun'] self.assertEqual(events, expected)
Example #8
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_loadTestsFromTestCase__no_matches(self): class Foo(unittest2.TestCase): def foo_bar(self): pass empty_suite = unittest2.TestSuite() loader = unittest2.TestLoader() self.assertEqual(loader.loadTestsFromTestCase(Foo), empty_suite) # "Return a suite of all tests cases contained in the TestCase-derived # class testCaseClass" # # What happens if loadTestsFromTestCase() is given an object # that isn't a subclass of TestCase? Specifically, what happens # if testCaseClass is a subclass of TestSuite? # # This is checked for specifically in the code, so we better add a # test for it.
Example #9
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_loadTestsFromTestCase__TestSuite_subclass(self): class NotATestCase(unittest2.TestSuite): pass loader = unittest2.TestLoader() try: loader.loadTestsFromTestCase(NotATestCase) except TypeError: pass else: self.fail('Should raise TypeError') # "Return a suite of all tests cases contained in the TestCase-derived # class testCaseClass" # # Make sure loadTestsFromTestCase() picks up the default test method # name (as specified by TestCase), even though the method name does # not match the default TestLoader.testMethodPrefix string
Example #10
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_loadTestsFromModule__not_a_module(self): class MyTestCase(unittest2.TestCase): def test(self): pass class NotAModule(object): test_2 = MyTestCase loader = unittest2.TestLoader() suite = loader.loadTestsFromModule(NotAModule) reference = [unittest2.TestSuite([MyTestCase('test')])] self.assertEqual(list(suite), reference) # Check that loadTestsFromModule honors (or not) a module # with a load_tests function.
Example #11
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_loadTestsFromModule__load_tests(self): m = types.ModuleType('m') class MyTestCase(unittest2.TestCase): def test(self): pass m.testcase_1 = MyTestCase load_tests_args = [] def load_tests(loader, tests, pattern): self.assertIsInstance(tests, unittest2.TestSuite) load_tests_args.extend((loader, tests, pattern)) return tests m.load_tests = load_tests loader = unittest2.TestLoader() suite = loader.loadTestsFromModule(m) self.assertIsInstance(suite, unittest2.TestSuite) self.assertEquals(load_tests_args, [loader, suite, None]) load_tests_args = [] suite = loader.loadTestsFromModule(m, use_load_tests=False) self.assertEquals(load_tests_args, [])
Example #12
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_loadTestsFromName__relative_empty_name(self): loader = unittest2.TestLoader() try: loader.loadTestsFromName('', unittest2) except AttributeError: pass else: self.fail("Failed to raise AttributeError") # "The specifier name is a ``dotted name'' that may resolve either to # a module, a test case class, a TestSuite instance, a test method # within a test case class, or a callable object which returns a # TestCase or TestSuite instance." # ... # "The method optionally resolves name relative to the given module" # # What happens when an impossible name is given, relative to the provided # `module`?
Example #13
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_loadTestsFromName__relative_not_a_module(self): class MyTestCase(unittest2.TestCase): def test(self): pass class NotAModule(object): test_2 = MyTestCase loader = unittest2.TestLoader() suite = loader.loadTestsFromName('test_2', NotAModule) reference = [MyTestCase('test')] self.assertEqual(list(suite), reference) # "The specifier name is a ``dotted name'' that may resolve either to # a module, a test case class, a TestSuite instance, a test method # within a test case class, or a callable object which returns a # TestCase or TestSuite instance." # # Does it raise an exception if the name resolves to an invalid # object?
Example #14
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_loadTestsFromName__relative_TestCase_subclass(self): m = types.ModuleType('m') class MyTestCase(unittest2.TestCase): def test(self): pass m.testcase_1 = MyTestCase loader = unittest2.TestLoader() suite = loader.loadTestsFromName('testcase_1', m) self.assertIsInstance(suite, loader.suiteClass) self.assertEqual(list(suite), [MyTestCase('test')]) # "The specifier name is a ``dotted name'' that may resolve either to # a module, a test case class, a TestSuite instance, a test method # within a test case class, or a callable object which returns a # TestCase or TestSuite instance."
Example #15
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_loadTestsFromName__relative_testmethod(self): m = types.ModuleType('m') class MyTestCase(unittest2.TestCase): def test(self): pass m.testcase_1 = MyTestCase loader = unittest2.TestLoader() suite = loader.loadTestsFromName('testcase_1.test', m) self.assertIsInstance(suite, loader.suiteClass) self.assertEqual(list(suite), [MyTestCase('test')]) # "The specifier name is a ``dotted name'' that may resolve either to # a module, a test case class, a TestSuite instance, a test method # within a test case class, or a callable object which returns a # TestCase or TestSuite instance." # # Does loadTestsFromName() raise the proper exception when trying to # resolve "a test method within a test case class" that doesn't exist # for the given name (relative to a provided module)?
Example #16
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_loadTestsFromName__callable__TestCase_instance_ProperSuiteClass(self): class SubTestSuite(unittest2.TestSuite): pass m = types.ModuleType('m') testcase_1 = unittest2.FunctionTestCase(lambda: None) def return_TestCase(): return testcase_1 m.return_TestCase = return_TestCase loader = unittest2.TestLoader() loader.suiteClass = SubTestSuite suite = loader.loadTestsFromName('return_TestCase', m) self.assertIsInstance(suite, loader.suiteClass) self.assertEqual(list(suite), [testcase_1]) # "The specifier name is a ``dotted name'' that may resolve ... to # ... a test method within a test case class" #***************************************************************** #Override the suiteClass attribute to ensure that the suiteClass #attribute is used
Example #17
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_loadTestsFromNames__malformed_name(self): loader = unittest2.TestLoader() # XXX Should this raise ValueError or ImportError? try: loader.loadTestsFromNames(['abc () //']) except ValueError: pass except ImportError: pass else: self.fail("TestLoader.loadTestsFromNames failed to raise ValueError") # "The specifier name is a ``dotted name'' that may resolve either to # a module, a test case class, a TestSuite instance, a test method # within a test case class, or a callable object which returns a # TestCase or TestSuite instance." # # What happens when no module can be found for the given name?
Example #18
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_loadTestsFromNames__relative_not_a_module(self): class MyTestCase(unittest2.TestCase): def test(self): pass class NotAModule(object): test_2 = MyTestCase loader = unittest2.TestLoader() suite = loader.loadTestsFromNames(['test_2'], NotAModule) reference = [unittest2.TestSuite([MyTestCase('test')])] self.assertEqual(list(suite), reference) # "The specifier name is a ``dotted name'' that may resolve either to # a module, a test case class, a TestSuite instance, a test method # within a test case class, or a callable object which returns a # TestCase or TestSuite instance." # # Does it raise an exception if the name resolves to an invalid # object?
Example #19
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_loadTestsFromNames__relative_TestCase_subclass(self): m = types.ModuleType('m') class MyTestCase(unittest2.TestCase): def test(self): pass m.testcase_1 = MyTestCase loader = unittest2.TestLoader() suite = loader.loadTestsFromNames(['testcase_1'], m) self.assertIsInstance(suite, loader.suiteClass) expected = loader.suiteClass([MyTestCase('test')]) self.assertEqual(list(suite), [expected]) # "The specifier name is a ``dotted name'' that may resolve ... to # ... a TestSuite instance"
Example #20
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_loadTestsFromNames__relative_testmethod(self): m = types.ModuleType('m') class MyTestCase(unittest2.TestCase): def test(self): pass m.testcase_1 = MyTestCase loader = unittest2.TestLoader() suite = loader.loadTestsFromNames(['testcase_1.test'], m) self.assertIsInstance(suite, loader.suiteClass) ref_suite = unittest2.TestSuite([MyTestCase('test')]) self.assertEqual(list(suite), [ref_suite]) # "The specifier name is a ``dotted name'' that may resolve ... to ... a # test method within a test case class" # # Does the method gracefully handle names that initially look like they # resolve to "a test method within a test case class" but don't?
Example #21
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_loadTestsFromNames__callable__TestSuite(self): m = types.ModuleType('m') testcase_1 = unittest2.FunctionTestCase(lambda: None) testcase_2 = unittest2.FunctionTestCase(lambda: None) def return_TestSuite(): return unittest2.TestSuite([testcase_1, testcase_2]) m.return_TestSuite = return_TestSuite loader = unittest2.TestLoader() suite = loader.loadTestsFromNames(['return_TestSuite'], m) self.assertIsInstance(suite, loader.suiteClass) expected = unittest2.TestSuite([testcase_1, testcase_2]) self.assertEqual(list(suite), [expected]) # "The specifier name is a ``dotted name'' that may resolve ... to # ... a callable object which returns a TestCase ... instance"
Example #22
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_loadTestsFromNames__callable__call_staticmethod(self): m = types.ModuleType('m') class Test1(unittest2.TestCase): def test(self): pass testcase_1 = Test1('test') class Foo(unittest2.TestCase): def foo(): return testcase_1 foo = staticmethod(foo) m.Foo = Foo loader = unittest2.TestLoader() suite = loader.loadTestsFromNames(['Foo.foo'], m) self.assertIsInstance(suite, loader.suiteClass) ref_suite = unittest2.TestSuite([testcase_1]) self.assertEqual(list(suite), [ref_suite]) # "The specifier name is a ``dotted name'' that may resolve ... to # ... a callable object which returns a TestCase or TestSuite instance" # # What happens when the callable returns something else?
Example #23
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_testMethodPrefix__loadTestsFromTestCase(self): class Foo(unittest2.TestCase): def test_1(self): pass def test_2(self): pass def foo_bar(self): pass tests_1 = unittest2.TestSuite([Foo('foo_bar')]) tests_2 = unittest2.TestSuite([Foo('test_1'), Foo('test_2')]) loader = unittest2.TestLoader() loader.testMethodPrefix = 'foo' self.assertEqual(loader.loadTestsFromTestCase(Foo), tests_1) loader.testMethodPrefix = 'test' self.assertEqual(loader.loadTestsFromTestCase(Foo), tests_2) # "String giving the prefix of method names which will be interpreted as # test methods" # # Implicit in the documentation is that testMethodPrefix is respected by # all loadTestsFrom* methods.
Example #24
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_testMethodPrefix__loadTestsFromModule(self): m = types.ModuleType('m') class Foo(unittest2.TestCase): def test_1(self): pass def test_2(self): pass def foo_bar(self): pass m.Foo = Foo tests_1 = [unittest2.TestSuite([Foo('foo_bar')])] tests_2 = [unittest2.TestSuite([Foo('test_1'), Foo('test_2')])] loader = unittest2.TestLoader() loader.testMethodPrefix = 'foo' self.assertEqual(list(loader.loadTestsFromModule(m)), tests_1) loader.testMethodPrefix = 'test' self.assertEqual(list(loader.loadTestsFromModule(m)), tests_2) # "String giving the prefix of method names which will be interpreted as # test methods" # # Implicit in the documentation is that testMethodPrefix is respected by # all loadTestsFrom* methods.
Example #25
Source File: test_loader.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_testMethodPrefix__loadTestsFromName(self): m = types.ModuleType('m') class Foo(unittest2.TestCase): def test_1(self): pass def test_2(self): pass def foo_bar(self): pass m.Foo = Foo tests_1 = unittest2.TestSuite([Foo('foo_bar')]) tests_2 = unittest2.TestSuite([Foo('test_1'), Foo('test_2')]) loader = unittest2.TestLoader() loader.testMethodPrefix = 'foo' self.assertEqual(loader.loadTestsFromName('Foo', m), tests_1) loader.testMethodPrefix = 'test' self.assertEqual(loader.loadTestsFromName('Foo', m), tests_2) # "String giving the prefix of method names which will be interpreted as # test methods" # # Implicit in the documentation is that testMethodPrefix is respected by # all loadTestsFrom* methods.
Example #26
Source File: test_suite.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_init__tests_from_any_iterable(self): def tests(): yield unittest2.FunctionTestCase(lambda: None) yield unittest2.FunctionTestCase(lambda: None) suite_1 = unittest2.TestSuite(tests()) self.assertEqual(suite_1.countTestCases(), 2) suite_2 = unittest2.TestSuite(suite_1) self.assertEqual(suite_2.countTestCases(), 2) suite_3 = unittest2.TestSuite(set(suite_1)) self.assertEqual(suite_3.countTestCases(), 2) # "class TestSuite([tests])" # ... # "If tests is given, it must be an iterable of individual test cases # or other test suites that will be used to build the suite initially" # # Does TestSuite() also allow other TestSuite() instances to be present # in the tests iterable?
Example #27
Source File: test_suite.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_countTestCases_nested(self): class Test1(unittest2.TestCase): def test1(self): pass def test2(self): pass test2 = unittest2.FunctionTestCase(lambda: None) test3 = unittest2.FunctionTestCase(lambda: None) child = unittest2.TestSuite((Test1('test2'), test2)) parent = unittest2.TestSuite((test3, child, Test1('test1'))) self.assertEqual(parent.countTestCases(), 4) # "Run the tests associated with this suite, collecting the result into # the test result object passed as result." # # And if there are no tests? What then?
Example #28
Source File: test_suite.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_run(self): events = [] result = LoggingResult(events) class LoggingCase(unittest2.TestCase): def run(self, result): events.append('run %s' % self._testMethodName) def test1(self): pass def test2(self): pass tests = [LoggingCase('test1'), LoggingCase('test2')] unittest2.TestSuite(tests).run(result) self.assertEqual(events, ['run test1', 'run test2']) # "Add a TestCase ... to the suite"
Example #29
Source File: test_suite.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_addTest__TestSuite(self): class Foo(unittest2.TestCase): def test(self): pass suite_2 = unittest2.TestSuite([Foo('test')]) suite = unittest2.TestSuite() suite.addTest(suite_2) self.assertEqual(suite.countTestCases(), 1) self.assertEqual(list(suite), [suite_2]) # "Add all the tests from an iterable of TestCase and TestSuite # instances to this test suite." # # "This is equivalent to iterating over tests, calling addTest() for # each element"
Example #30
Source File: test_skipping.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_skip_doesnt_run_setup(self): class Foo(unittest2.TestCase): wasSetUp = False wasTornDown = False def setUp(self): Foo.wasSetUp = True def tornDown(self): Foo.wasTornDown = True def test_1(self): pass test_1 = unittest2.skip('testing')(test_1) result = unittest2.TestResult() test = Foo("test_1") suite = unittest2.TestSuite([test]) suite.run(result) self.assertEqual(result.skipped, [(test, "testing")]) self.assertFalse(Foo.wasSetUp) self.assertFalse(Foo.wasTornDown)