Python unittest2.TestResult() Examples
The following are 30
code examples of unittest2.TestResult().
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_result.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_startTestRun_stopTestRun(self): result = unittest2.TestResult() result.startTestRun() result.stopTestRun() # "addSuccess(test)" # ... # "Called when the test case test succeeds" # ... # "wasSuccessful() - Returns True if all tests run so far have passed, # otherwise returns False" # ... # "testsRun - The total number of tests run so far." # ... # "errors - A list containing 2-tuples of TestCase instances and # formatted tracebacks. Each tuple represents a test which raised an # unexpected exception. Contains formatted # tracebacks instead of sys.exc_info() results." # ... # "failures - A list containing 2-tuples of TestCase instances and # formatted tracebacks. Each tuple represents a test where a failure was # explicitly signalled using the TestCase.fail*() or TestCase.assert*() # methods. Contains formatted tracebacks instead # of sys.exc_info() results."
Example #2
Source File: test_skipping.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_decorated_skip(self): def decorator(func): def inner(*a): return func(*a) return inner class Foo(unittest2.TestCase): def test_1(self): pass test_1 = decorator(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")])
Example #3
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)
Example #4
Source File: test_break.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def testRemoveResult(self): result = unittest2.TestResult() unittest2.registerResult(result) unittest2.installHandler() self.assertTrue(unittest2.removeResult(result)) # Should this raise an error instead? self.assertFalse(unittest2.removeResult(unittest2.TestResult())) try: pid = os.getpid() os.kill(pid, signal.SIGINT) except KeyboardInterrupt: pass self.assertFalse(result.shouldStop)
Example #5
Source File: test_runner.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def testRunnerRegistersResult(self): class Test(unittest2.TestCase): def testFoo(self): pass originalRegisterResult = unittest2.runner.registerResult def cleanup(): unittest2.runner.registerResult = originalRegisterResult self.addCleanup(cleanup) result = unittest2.TestResult() runner = unittest2.TextTestRunner(stream=StringIO()) # Use our result object runner._makeResult = lambda: result self.wasRegistered = 0 def fakeRegisterResult(thisResult): self.wasRegistered += 1 self.assertEqual(thisResult, result) unittest2.runner.registerResult = fakeRegisterResult runner.run(unittest2.TestSuite()) self.assertEqual(self.wasRegistered, 1)
Example #6
Source File: test_result.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_startTest(self): class Foo(unittest2.TestCase): def test_1(self): pass test = Foo('test_1') result = unittest2.TestResult() result.startTest(test) self.assertTrue(result.wasSuccessful()) self.assertEqual(len(result.errors), 0) self.assertEqual(len(result.failures), 0) self.assertEqual(result.testsRun, 1) self.assertEqual(result.shouldStop, False) result.stopTest(test) # "Called after the test case test has been executed, regardless of # the outcome. The default implementation does nothing."
Example #7
Source File: test_break.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def testTwoResults(self): unittest2.installHandler() result = unittest2.TestResult() unittest2.registerResult(result) new_handler = signal.getsignal(signal.SIGINT) result2 = unittest2.TestResult() unittest2.registerResult(result2) self.assertEqual(signal.getsignal(signal.SIGINT), new_handler) result3 = unittest2.TestResult() def test(result): pid = os.getpid() os.kill(pid, signal.SIGINT) try: test(result) except KeyboardInterrupt: self.fail("KeyboardInterrupt not handled") self.assertTrue(result.shouldStop) self.assertTrue(result2.shouldStop) self.assertFalse(result3.shouldStop)
Example #8
Source File: test_break.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def testSecondInterrupt(self): result = unittest2.TestResult() unittest2.installHandler() unittest2.registerResult(result) def test(result): pid = os.getpid() os.kill(pid, signal.SIGINT) result.breakCaught = True self.assertTrue(result.shouldStop) os.kill(pid, signal.SIGINT) self.fail("Second KeyboardInterrupt not raised") try: test(result) except KeyboardInterrupt: pass else: self.fail("Second KeyboardInterrupt not raised") self.assertTrue(result.breakCaught)
Example #9
Source File: test_case.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def test_run_call_order__error_in_tearDown_default_result(self): class Foo(Test.LoggingTestCase): def defaultTestResult(self): return LoggingResult(self.events) def tearDown(self): super(Foo, self).tearDown() raise RuntimeError('raised by Foo.tearDown') events = [] Foo(events).run() expected = ['startTestRun', 'startTest', 'setUp', 'test', 'tearDown', 'addError', 'stopTest', 'stopTestRun'] self.assertEqual(events, expected) # "TestCase.run() still works when the defaultTestResult is a TestResult # that does not support startTestRun and stopTestRun.
Example #10
Source File: test_break.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 6 votes |
def testInterruptCaught(self): default_handler = signal.getsignal(signal.SIGINT) result = unittest2.TestResult() unittest2.installHandler() unittest2.registerResult(result) self.assertNotEqual(signal.getsignal(signal.SIGINT), default_handler) def test(result): pid = os.getpid() os.kill(pid, signal.SIGINT) result.breakCaught = True self.assertTrue(result.shouldStop) try: test(result) except KeyboardInterrupt: self.fail("KeyboardInterrupt not handled") self.assertTrue(result.breakCaught)
Example #11
Source File: test_result.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def testStackFrameTrimming(self): class Frame(object): class tb_frame(object): f_globals = {} result = unittest2.TestResult() self.assertFalse(result._is_relevant_tb_level(Frame)) Frame.tb_frame.f_globals['__unittest'] = True self.assertTrue(result._is_relevant_tb_level(Frame))
Example #12
Source File: support.py From deepWordBug with Apache License 2.0 | 5 votes |
def run(self, test): result = unittest.TestResult() test(result) return result
Example #13
Source File: test_result.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def testBufferOutputOff(self): real_out = self._real_out real_err = self._real_err result = unittest2.TestResult() self.assertFalse(result.buffer) self.assertIs(real_out, sys.stdout) self.assertIs(real_err, sys.stderr) result.startTest(self) self.assertIs(real_out, sys.stdout) self.assertIs(real_err, sys.stderr)
Example #14
Source File: test_result.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def getStartedResult(self): result = unittest2.TestResult() result.buffer = True result.startTest(self) return result
Example #15
Source File: test_suite.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def test_function_in_suite(self): def f(_): pass suite = unittest2.TestSuite() suite.addTest(f) # when the bug is fixed this line will not crash suite.run(unittest2.TestResult())
Example #16
Source File: test_suite.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def test_basetestsuite(self): class Test(unittest2.TestCase): wasSetUp = False wasTornDown = False def setUpClass(cls): cls.wasSetUp = True setUpClass = classmethod(setUpClass) def tearDownClass(cls): cls.wasTornDown = True tearDownClass = classmethod(tearDownClass) def testPass(self): pass def testFail(self): fail class Module(object): wasSetUp = False wasTornDown = False def setUpModule(): Module.wasSetUp = True setUpModule = classmethod(setUpModule) def tearDownModule(): Module.wasTornDown = True setUpModule = classmethod(tearDownModule) Test.__module__ = 'Module' sys.modules['Module'] = Module self.addCleanup(sys.modules.pop, 'Module') suite = unittest2.BaseTestSuite() suite.addTests([Test('testPass'), Test('testFail')]) self.assertEqual(suite.countTestCases(), 2) result = unittest2.TestResult() suite.run(result) self.assertFalse(Module.wasSetUp) self.assertFalse(Module.wasTornDown) self.assertFalse(Test.wasSetUp) self.assertFalse(Test.wasTornDown) self.assertEqual(len(result.errors), 1) self.assertEqual(len(result.failures), 0) self.assertEqual(result.testsRun, 2)
Example #17
Source File: test_break.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def testWeakReferences(self): # Calling registerResult on a result should not keep it alive result = unittest2.TestResult() unittest2.registerResult(result) ref = weakref.ref(result) del result # For non-reference counting implementations gc.collect();gc.collect() self.assertIsNone(ref())
Example #18
Source File: support.py From gimp-plugin-export-layers with GNU General Public License v3.0 | 5 votes |
def run(self, test): result = unittest.TestResult() test(result) return result
Example #19
Source File: support.py From arissploit with GNU General Public License v3.0 | 5 votes |
def run(self, test): result = unittest.TestResult() test(result) return result
Example #20
Source File: support.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def run(self, test): result = unittest.TestResult() test(result) return result
Example #21
Source File: support.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def run(self, test): result = unittest.TestResult() test(result) return result
Example #22
Source File: support.py From verge3d-blender-addon with GNU General Public License v3.0 | 5 votes |
def run(self, test): result = unittest.TestResult() test(result) return result
Example #23
Source File: support.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 5 votes |
def run(self, test): result = unittest.TestResult() test(result) return result
Example #24
Source File: test_result.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def test_addSuccess(self): class Foo(unittest2.TestCase): def test_1(self): pass test = Foo('test_1') result = unittest2.TestResult() result.startTest(test) result.addSuccess(test) result.stopTest(test) self.assertTrue(result.wasSuccessful()) self.assertEqual(len(result.errors), 0) self.assertEqual(len(result.failures), 0) self.assertEqual(result.testsRun, 1) self.assertEqual(result.shouldStop, False) # "addFailure(test, err)" # ... # "Called when the test case test signals a failure. err is a tuple of # the form returned by sys.exc_info(): (type, value, traceback)" # ... # "wasSuccessful() - Returns True if all tests run so far have passed, # otherwise returns False" # ... # "testsRun - The total number of tests run so far." # ... # "errors - A list containing 2-tuples of TestCase instances and # formatted tracebacks. Each tuple represents a test which raised an # unexpected exception. Contains formatted # tracebacks instead of sys.exc_info() results." # ... # "failures - A list containing 2-tuples of TestCase instances and # formatted tracebacks. Each tuple represents a test where a failure was # explicitly signalled using the TestCase.fail*() or TestCase.assert*() # methods. Contains formatted tracebacks instead # of sys.exc_info() results."
Example #25
Source File: test_result.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def test_stop(self): result = unittest2.TestResult() result.stop() self.assertEqual(result.shouldStop, True) # "Called when the test case test is about to be run. The default # implementation simply increments the instance's testsRun counter."
Example #26
Source File: test_result.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def test_init(self): result = unittest2.TestResult() self.assertTrue(result.wasSuccessful()) self.assertEqual(len(result.errors), 0) self.assertEqual(len(result.failures), 0) self.assertEqual(result.testsRun, 0) self.assertEqual(result.shouldStop, False) self.assertIsNone(result._stdout_buffer) self.assertIsNone(result._stderr_buffer) # "This method can be called to signal that the set of tests being # run should be aborted by setting the TestResult's shouldStop # attribute to True."
Example #27
Source File: support.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def resultFactory(*_): return unittest2.TestResult()
Example #28
Source File: test_case.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def test_countTestCases(self): class Foo(unittest2.TestCase): def test(self): pass self.assertEqual(Foo('test').countTestCases(), 1) # "Return the default type of test result object to be used to run this # test. For TestCase instances, this will always be # unittest2.TestResult; subclasses of TestCase should # override this as necessary."
Example #29
Source File: test_result.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def test_addError(self): class Foo(unittest2.TestCase): def test_1(self): pass test = Foo('test_1') try: raise TypeError() except: exc_info_tuple = sys.exc_info() result = unittest2.TestResult() result.startTest(test) result.addError(test, exc_info_tuple) result.stopTest(test) self.assertFalse(result.wasSuccessful()) self.assertEqual(len(result.errors), 1) self.assertEqual(len(result.failures), 0) self.assertEqual(result.testsRun, 1) self.assertEqual(result.shouldStop, False) test_case, formatted_exc = result.errors[0] self.assertTrue(test_case is test) self.assertIsInstance(formatted_exc, str)
Example #30
Source File: test_new_tests.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def testInheritance(self): self.assertIsSubclass(unittest2.TestCase, unittest.TestCase) self.assertIsSubclass(unittest2.TestResult, unittest.TestResult) self.assertIsSubclass(unittest2.TestSuite, unittest.TestSuite) self.assertIsSubclass(unittest2.TextTestRunner, unittest.TextTestRunner) self.assertIsSubclass(unittest2.TestLoader, unittest.TestLoader) self.assertIsSubclass(unittest2.TextTestResult, unittest.TestResult)