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])
def test_run_call_order__failure_in_test(self): events = [] result = LoggingResult(events) def setUp(): events.append('setUp') def test(): events.append('test') self.fail('raised by test') def tearDown(): events.append('tearDown') expected = [ 'startTest', 'setUp', 'test', 'tearDown', 'addFailure', 'stopTest' ] unittest2.FunctionTestCase(test, setUp, tearDown).run(result) self.assertEqual(events, expected)
def test_case_script(path): """ Return a TestCase instance from a script in `path`. The script will be run in the directory it is in. :param path: The path to the script to test :type path: str """ dirname = os.path.dirname(os.path.realpath(path)) _dir = {} def setUp(): _dir["cwd"] = os.path.realpath(os.curdir) os.chdir(dirname) def tearDown(): os.chdir(_dir["cwd"]) def runScript(): execfile(path, {}) runScript.__name__ = "runScript %s" % os.path.basename(path) return unittest.FunctionTestCase(runScript, setUp=setUp, tearDown=tearDown)
def tests(): yield unittest2.FunctionTestCase(lambda: None) yield unittest2.FunctionTestCase(lambda: None)
def test_iter(self): test1 = unittest2.FunctionTestCase(lambda: None) test2 = unittest2.FunctionTestCase(lambda: None) suite = unittest2.TestSuite((test1, test2)) self.assertEqual(list(suite), [test1, test2])
def tests(): ftc = unittest2.FunctionTestCase(lambda: None) yield unittest2.TestSuite([ftc]) yield unittest2.FunctionTestCase(lambda: None)
def test_shortDescription__singleline_docstring(self): desc = "this tests foo" test = unittest2.FunctionTestCase(lambda: None, description=desc) self.assertEqual(test.shortDescription(), "this tests foo")
def test_shortDescription__no_docstring(self): test = unittest2.FunctionTestCase(lambda: None) self.assertEqual(test.shortDescription(), None)
def test_id(self): test = unittest2.FunctionTestCase(lambda: None) self.assertIsInstance(test.id(), six.string_types)
def test_countTestCases(self): test = unittest2.FunctionTestCase(lambda: None) self.assertEqual(test.countTestCases(), 1)
def test_countTestCases_simple(self): test1 = unittest2.FunctionTestCase(lambda: None) test2 = unittest2.FunctionTestCase(lambda: None) suite = unittest2.TestSuite((test1, test2)) self.assertEqual(suite.countTestCases(), 2)