示例#1
0
 def test_testBrokenTearDownClass(self):
     """FixtureTest.testBrokenTearDownClass succeeds when run twice
     """
     test = FixtureTest('testBrokenTearDownClass')
     result = reporter.TestResult()
     test(result)
     self.failUnless(result.wasSuccessful())
     result2 = reporter.TestResult()
     test(result2)
     self.failUnless(result2.wasSuccessful())
 def test_failingException_fails(self):
     test = runner.TestLoader().loadClass(TestAssertions.FailingTest)
     result = reporter.TestResult()
     test.run(result)
     self.failIf(result.wasSuccessful())
     self.failUnlessEqual(result.errors, [])
     self.failUnlessEqual(len(result.failures), 1)
示例#3
0
 def test_classTimeout(self):
     loader = runner.TestLoader()
     suite = loader.loadClass(detests.TestClassTimeoutAttribute)
     result = reporter.TestResult()
     suite.run(result)
     self.failUnlessEqual(len(result.errors), 1)
     self._wasTimeout(result.errors[0][1])
示例#4
0
 def test_classTimeout(self):
     loader = pyunit.TestLoader()
     suite = loader.loadTestsFromTestCase(detests.TestClassTimeoutAttribute)
     result = reporter.TestResult()
     suite.run(result)
     self.assertEqual(len(result.errors), 1)
     self._wasTimeout(result.errors[0][1])
 def setUp(self):
     """
     Setup our test case
     """
     super(AddCleanupMixin, self).setUp()
     self.result = reporter.TestResult()
     self.test = self.AddCleanup()
示例#6
0
    def test_errorOnGeneratorFunction(self):
        """
        In a TestCase, a test method which is a generator function is reported
        as an error, as such a method will never run assertions.
        """
        class GeneratorTestCase(unittest.TestCase):
            """
            A fake TestCase for testing purposes.
            """
            def test_generator(self):
                """
                A method which is also a generator function, for testing
                purposes.
                """
                self.fail('this should never be reached')
                yield

        testCase = GeneratorTestCase('test_generator')
        result = reporter.TestResult()
        testCase.run(result)
        self.assertEqual(len(result.failures), 0)
        self.assertEqual(len(result.errors), 1)
        self.assertEqual(
            result.errors[0][1].value.args[0],
            '<bound method GeneratorTestCase.test_generator of <twisted.trial.'
            'test.test_tests.GeneratorTestCase testMethod=test_generator>> is '
            'a generator function and therefore will never run')
示例#7
0
 def test_expectedResults(self):
     suite = runner.DocTestSuite(mockdoctest)
     result = reporter.TestResult()
     suite.run(result)
     self.assertEqual(5, len(result.successes))
     # doctest reports failures as errors in 2.3
     self.assertEqual(2, len(result.errors) + len(result.failures))
示例#8
0
 def test_createAndRun(self):
     test = self.factory('test_1')
     self.failUnlessEqual(test._isFirst(), True)
     result = reporter.TestResult()
     test(result)
     self.failUnlessEqual(self.factory._setUpClassRun, 1)
     self.failUnlessEqual(self.factory._tearDownClassRun, 1)
    def test_synchronousTestCaseErrorOnGeneratorFunction(self):
        """
        In a SynchronousTestCase, a test method which is a generator function
        is reported as an error, as such a method will never run assertions.
        """
        class GeneratorSynchronousTestCase(unittest.SynchronousTestCase):
            """
            A fake SynchronousTestCase for testing purposes.
            """
            def test_generator(self):
                """
                A method which is also a generator function, for testing
                purposes.
                """
                self.fail('this should never be reached')
                yield

        testCase = GeneratorSynchronousTestCase('test_generator')
        result = reporter.TestResult()
        testCase.run(result)
        self.assertEqual(len(result.failures), 0)
        self.assertEqual(len(result.errors), 1)
        self.assertIn("GeneratorSynchronousTestCase.test_generator",
                      result.errors[0][1].value.args[0])
        self.assertIn("GeneratorSynchronousTestCase testMethod=test_generator",
                      result.errors[0][1].value.args[0])
        self.assertIn("is a generator function and therefore will never run",
                      result.errors[0][1].value.args[0])
示例#10
0
    def test_shouldStop(self):
        """
        Test the C{shouldStop} management: raising a C{KeyboardInterrupt} must
        interrupt the suite.
        """
        called = []

        class MockTest(unittest.TestCase):
            def test_foo1(test):
                called.append(1)

            def test_foo2(test):
                raise KeyboardInterrupt()

            def test_foo3(test):
                called.append(2)

        result = reporter.TestResult()
        loader = runner.TestLoader()
        loader.suiteFactory = runner.DestructiveTestSuite
        suite = loader.loadClass(MockTest)
        self.assertEquals(called, [])
        suite.run(result)
        self.assertEquals(called, [1])
        # The last test shouldn't have been run
        self.assertEquals(suite.countTestCases(), 1)
示例#11
0
 def test_shared(self):
     result = reporter.TestResult()
     suite = self.loader.loadClass(AttributeSharing.ClassAttributeSharer)
     suite.run(result)
     self.failUnlessEqual(result.errors, [])
     self.failUnlessEqual(len(result.failures), 1)  # from test_2
     self.failUnlessEqual(result.failures[0][0].shortDescription(),
                          'test_2')
示例#12
0
 def test_loadFailingMethod(self):
     # test added for issue1353
     import erroneous
     suite = self.loader.loadMethod(erroneous.TestRegularFail.test_fail)
     result = reporter.TestResult()
     suite.run(result)
     self.failUnlessEqual(result.testsRun, 1)
     self.failUnlessEqual(len(result.failures), 1)
 def loadSuite(self, suite):
     """
     Load tests from the given test case class and create a new reporter to
     use for running it.
     """
     self.loader = pyunit.TestLoader()
     self.suite = self.loader.loadTestsFromTestCase(suite)
     self.reporter = reporter.TestResult()
示例#14
0
 def _testRun(self, suite):
     """
     Run C{suite} and check the result.
     """
     result = reporter.TestResult()
     suite.run(result)
     self.assertEqual(5, result.successes)
     self.assertEqual(2, len(result.failures))
 def test_collectNotDefault(self):
     """
     By default, tests should not force garbage collection.
     """
     test = self.BasicTest('test_foo')
     result = reporter.TestResult()
     test.run(result)
     self.assertEqual(self._collectCalled, ['setUp', 'test', 'tearDown'])
示例#16
0
 def test_loadFailingMethod(self):
     # test added for issue1353
     from twisted.trial.test import erroneous
     suite = self.loader.loadMethod(erroneous.TestRegularFail.test_fail)
     result = reporter.TestResult()
     suite.run(result)
     self.assertEqual(result.testsRun, 1)
     self.assertEqual(len(result.failures), 1)
示例#17
0
 def test_skippingSetUpClass(self):
     tests = map(self.subFactory, ['test_1', 'test_2'])
     result = reporter.TestResult()
     tests[0](result)
     self.failUnlessEqual(self.subFactory._setUpClassRun, 1)
     self.failUnlessEqual(self.subFactory._tearDownClassRun, 0)
     tests[1](result)
     self.failUnlessEqual(self.subFactory._setUpClassRun, 2)
     self.failUnlessEqual(self.subFactory._tearDownClassRun, 0)
示例#18
0
 def _testRun(self, suite):
     """
     Run C{suite} and check the result.
     """
     result = reporter.TestResult()
     suite.run(result)
     self.assertEqual(5, result.successes)
     # doctest reports failures as errors in 2.3
     self.assertEqual(2, len(result.errors) + len(result.failures))
示例#19
0
 def test_runTwice(self):
     test = self.factory('test_1')
     result = reporter.TestResult()
     test(result)
     self.failUnlessEqual(self.factory._setUpClassRun, 1)
     self.failUnlessEqual(self.factory._tearDownClassRun, 1)
     test(result)
     self.failUnlessEqual(self.factory._setUpClassRun, 2)
     self.failUnlessEqual(self.factory._tearDownClassRun, 2)
 def test_isReported(self):
     """
     Forcing garbage collection should cause unhandled Deferreds to be
     reported as errors.
     """
     result = reporter.TestResult()
     self.test1(result)
     self.assertEqual(len(result.errors), 1,
                      'Unhandled deferred passed without notice')
示例#21
0
 def test_runMultipleCopies(self):
     tests = map(self.factory, ['test_1', 'test_1'])
     result = reporter.TestResult()
     tests[0](result)
     self.failUnlessEqual(self.factory._setUpClassRun, 1)
     self.failUnlessEqual(self.factory._tearDownClassRun, 0)
     tests[1](result)
     self.failUnlessEqual(self.factory._setUpClassRun, 1)
     self.failUnlessEqual(self.factory._tearDownClassRun, 1)
示例#22
0
 def test_collectCalled(self):
     """test gc.collect is called before and after each test
     """
     test = TestGarbageCollection.BasicTest('test_foo')
     test.forceGarbageCollection = True
     result = reporter.TestResult()
     test.run(result)
     self.failUnlessEqual(
         self._collectCalled,
         ['collect', 'setUp', 'test', 'tearDown', 'collect'])
 def test_collectCalled(self):
     """
     test gc.collect is called before and after each test.
     """
     test = GarbageCollectionTests.BasicTest('test_foo')
     test = _ForceGarbageCollectionDecorator(test)
     result = reporter.TestResult()
     test.run(result)
     self.assertEqual(self._collectCalled,
                      ['collect', 'setUp', 'test', 'tearDown', 'collect'])
示例#24
0
 def runTestMethod(self, method):
     class TestCase(GetProcessOutputMixin, unittest.TestCase):
         def setUp(self):
             self.setUpGetProcessOutput()
         def runTest(self):
             return method(self)
     self.testcase = TestCase()
     result = reporter.TestResult()
     self.testcase.run(result) # This blocks
     return result
示例#25
0
 def test_expectedResults(self):
     """
     Trial can correctly run doctests with its xUnit test APIs.
     """
     suite = self.makeDocSuite(mockdoctest)
     result = reporter.TestResult()
     suite.run(result)
     self.assertEqual(5, result.successes)
     # doctest reports failures as errors in 2.3
     self.assertEqual(2, len(result.errors) + len(result.failures))
示例#26
0
 def test_capturesError(self):
     """
     Chek that a L{LoggedSuite} reports any logged errors to its result.
     """
     result = reporter.TestResult()
     suite = runner.LoggedSuite([BreakingSuite()])
     suite.run(result)
     self.assertEqual(len(result.errors), 1)
     self.assertEqual(result.errors[0][0].id(), runner.NOT_IN_TEST)
     self.failUnless(result.errors[0][1].check(RuntimeError))
示例#27
0
 def test_collectCalled(self):
     """
     test gc.collect is called before and after each test.
     """
     test = GarbageCollectionTests.BasicTest("test_foo")
     test = _ForceGarbageCollectionDecorator(test)
     result = reporter.TestResult()
     test.run(result)
     self.assertEqual(self._collectCalled,
                      ["collect", "setUp", "test", "tearDown", "collect"])
示例#28
0
 def test_createTwoAndRun(self):
     tests = map(self.factory, ['test_1', 'test_2'])
     self.failUnlessEqual(tests[0]._isFirst(), True)
     self.failUnlessEqual(tests[1]._isFirst(), True)
     result = reporter.TestResult()
     tests[0](result)
     self.failUnlessEqual(self.factory._setUpClassRun, 1)
     self.failUnlessEqual(self.factory._tearDownClassRun, 0)
     tests[1](result)
     self.failUnlessEqual(self.factory._setUpClassRun, 1)
     self.failUnlessEqual(self.factory._tearDownClassRun, 1)
示例#29
0
 def test_loadFailure(self):
     """
     Loading a test that fails and getting the result of it ends up with one
     test ran and one failure.
     """
     suite = self.loader.loadByName(
         "twisted.trial.test.erroneous.TestRegularFail.test_fail")
     result = reporter.TestResult()
     suite.run(result)
     self.assertEqual(result.testsRun, 1)
     self.assertEqual(len(result.failures), 1)
示例#30
0
    def run_test_method(self, method):
        class TestCase(MasterRunProcessMixin, unittest.TestCase):
            def setUp(self):
                self.setup_master_run_process()

            def runTest(self):
                return method(self)

        self.testcase = TestCase()
        result = reporter.TestResult()
        self.testcase.run(result)  # This blocks
        return result