def test_iterateIsLeftToRightDepthFirst(self): """ L{_iterateTests} returns tests in left-to-right, depth-first order. """ test = unittest.TestCase() suite = runner.TestSuite([runner.TestSuite([test]), self]) self.assertEqual([test, self], list(unittest._iterateTests(suite)))
def test_iterateNestedTestSuite(self): """ L{_iterateTests} returns tests that are in nested test suites. """ test = unittest.TestCase() suite = runner.TestSuite([runner.TestSuite([test])]) self.assertEqual([test], list(unittest._iterateTests(suite)))
def test_iterateTestCase(self): """ L{_iterateTests} on a single test case returns a list containing that test case. """ test = unittest.TestCase() self.assertEqual([test], list(unittest._iterateTests(test)))
def test_iterateSingletonTestSuite(self): """ L{_iterateTests} on a test suite that contains a single test case returns a list containing that test case. """ test = unittest.TestCase() suite = runner.TestSuite([test]) self.assertEqual([test], list(unittest._iterateTests(suite)))
def test_defaultIsSuccessful(self): """ Test that L{unittest.TestCase} itself can be instantiated, run, and reported as being successful. """ test = unittest.TestCase() test.run(self.result) self.assertSuccessful(test, self.result)
def test_decorateSingleTest(self): """ Calling L{decorate} on a single test case returns the test case decorated with the provided decorator. """ test = unittest.TestCase() decoratedTest = unittest.decorate(test, unittest.TestDecorator) self.assertTestsEqual(unittest.TestDecorator(test), decoratedTest)
def test_decorateTestSuite(self): """ Calling L{decorate} on a test suite will return a test suite with each test decorated with the provided decorator. """ test = unittest.TestCase() suite = unittest.TestSuite([test]) decoratedTest = unittest.decorate(suite, unittest.TestDecorator) self.assertSuitesEqual( decoratedTest, unittest.TestSuite([unittest.TestDecorator(test)]))
def test_decoratePreservesSuite(self): """ Tests can be in non-standard suites. L{decorate} preserves the non-standard suites when it decorates the tests. """ test = unittest.TestCase() suite = runner.DestructiveTestSuite([test]) decorated = unittest.decorate(suite, unittest.TestDecorator) self.assertSuitesEqual( decorated, runner.DestructiveTestSuite([unittest.TestDecorator(test)]))
def _bail(self): from twisted.internet import reactor d = defer.Deferred() reactor.addSystemEventTrigger('after', 'shutdown', lambda: d.callback(None)) reactor.fireSystemEvent('shutdown') # radix's suggestion # As long as TestCase does crap stuff with the reactor we need to # manually shutdown the reactor here, and that requires util.wait # :( # so that the shutdown event completes unittest.TestCase('mktemp')._wait(d)
def test_decorateInPlaceMutatesOriginal(self): """ Calling L{decorate} on a test suite will mutate the original suite. """ test = unittest.TestCase() suite = unittest.TestSuite([test]) decoratedTest = unittest.decorate(suite, unittest.TestDecorator) self.assertSuitesEqual( decoratedTest, unittest.TestSuite([unittest.TestDecorator(test)])) self.assertSuitesEqual( suite, unittest.TestSuite([unittest.TestDecorator(test)]))
def test_decorateDecoratedSuite(self): """ Calling L{decorate} on a test suite with already-decorated tests decorates all of the tests in the suite again. """ test = unittest.TestCase() decoratedTest = unittest.decorate(test, unittest.TestDecorator) redecoratedTest = unittest.decorate(decoratedTest, unittest.TestDecorator) self.assertTestsEqual(redecoratedTest, unittest.TestDecorator(decoratedTest))
def test_clearSuite(self): """ Calling L{unittest._clearSuite} on a populated L{TestSuite} removes all tests. """ suite = unittest.TestSuite() suite.addTest(unittest.TestCase()) # Double check that the test suite actually has something in it. self.assertEqual(1, suite.countTestCases()) unittest._clearSuite(suite) self.assertEqual(0, suite.countTestCases())
def test_decorateNestedTestSuite(self): """ Calling L{decorate} on a test suite with nested suites will return a test suite that maintains the same structure, but with all tests decorated. """ test = unittest.TestCase() suite = unittest.TestSuite([unittest.TestSuite([test])]) decoratedTest = unittest.decorate(suite, unittest.TestDecorator) expected = unittest.TestSuite( [unittest.TestSuite([unittest.TestDecorator(test)])]) self.assertSuitesEqual(decoratedTest, expected)
def test_usesAdaptedReporterWithRun(self): """ For decorated tests, C{run} uses a result adapter that preserves the test decoration for calls to C{addError}, C{startTest} and the like. See L{reporter._AdaptedReporter}. """ test = unittest.TestCase() decoratedTest = unittest.TestDecorator(test) result = LoggingReporter() decoratedTest.run(result) self.assertTestsEqual(result.test, decoratedTest)
def test_clearPyunitSuite(self): """ Calling L{unittest._clearSuite} on a populated standard library L{TestSuite} removes all tests. This test is important since C{_clearSuite} operates by mutating internal variables. """ pyunit = __import__('unittest') suite = pyunit.TestSuite() suite.addTest(unittest.TestCase()) # Double check that the test suite actually has something in it. self.assertEqual(1, suite.countTestCases()) unittest._clearSuite(suite) self.assertEqual(0, suite.countTestCases())
def test_decorateTestSuiteReferences(self): """ When decorating a test suite in-place, the number of references to the test objects in that test suite should stay the same. Previously, L{unittest.decorate} recreated a test suite, so the original suite kept references to the test objects. This test is here to ensure the problem doesn't reappear again. """ getrefcount = getattr(sys, 'getrefcount', None) if getrefcount is None: raise unittest.SkipTest( "getrefcount not supported on this platform") test = unittest.TestCase() suite = unittest.TestSuite([test]) count1 = getrefcount(test) decoratedTest = unittest.decorate(suite, unittest.TestDecorator) count2 = getrefcount(test) self.assertEquals(count1, count2)
def render_element(self, element, args=None): d = flattenString(TestRequest(args), element) return unittest.TestCase().successResultOf(d)
def setUp(self): self.originalValue = 'original' self.patchedValue = 'patched' self.objectToPatch = self.originalValue self.test = unittest.TestCase()