Example #1
0
 def test_call_is_run(self):
     # A PlaceHolder can be called, in which case it behaves like run.
     test = self.makePlaceHolder()
     run_log = []
     test.run(LoggingResult(run_log))
     call_log = []
     test(LoggingResult(call_log))
     self.assertEqual(run_log, call_log)
Example #2
0
 def test_with_one_scenario_one_run(self):
     class ReferenceTest(self.Implementation):
         scenarios = [('demo', {})]
         def test_pass(self):
             pass
     test = ReferenceTest("test_pass")
     log = []
     result = LoggingResult(log)
     test.run(result)
     self.assertTrue(result.wasSuccessful())
     self.assertEqual(1, result.testsRun)
     self.expectThat(
         log[0][1].id(), EndsWith('ReferenceTest.test_pass(demo)'))
 def test_attributes_set(self):
     class ReferenceTest(testscenarios.TestWithScenarios):
         scenarios = [
             ('1', {'foo': 1, 'bar': 2}),
             ('2', {'foo': 2, 'bar': 4})]
         def test_check_foo(self):
             self.assertEqual(self.foo * 2, self.bar)
     test = ReferenceTest("test_check_foo")
     log = []
     result = LoggingResult(log)
     test.run(result)
     self.assertTrue(result.wasSuccessful())
     self.assertEqual(2, result.testsRun)
 def test_with_one_scenario_one_run(self):
     class ReferenceTest(testscenarios.TestWithScenarios):
         scenarios = [('demo', {})]
         def test_pass(self):
             pass
     test = ReferenceTest("test_pass")
     log = []
     result = LoggingResult(log)
     test.run(result)
     self.assertTrue(result.wasSuccessful())
     self.assertEqual(1, result.testsRun)
     self.assertEqual(
         'testscenarios.tests.test_testcase.ReferenceTest.test_pass(demo)',
         log[0][1].id())
Example #5
0
    def test_with_two_scenarios_two_run(self):
        class ReferenceTest(self.Implementation):
            scenarios = [('1', {}), ('2', {})]

            def test_pass(self):
                pass

        test = ReferenceTest("test_pass")
        log = []
        result = LoggingResult(log)
        test.run(result)
        self.assertTrue(result.wasSuccessful())
        self.assertEqual(2, result.testsRun)
        self.expectThat(log[0][1].id(), EndsWith('ReferenceTest.test_pass(1)'))
        self.expectThat(log[4][1].id(), EndsWith('ReferenceTest.test_pass(2)'))
Example #6
0
 def test_scenarios_attribute_cleared(self):
     class ReferenceTest(self.Implementation):
         scenarios = [
             ('1', {'foo': 1, 'bar': 2}),
             ('2', {'foo': 2, 'bar': 4})]
         def test_check_foo(self):
             self.assertEqual(self.foo * 2, self.bar)
     test = ReferenceTest("test_check_foo")
     log = []
     result = LoggingResult(log)
     test.run(result)
     self.assertTrue(result.wasSuccessful())
     self.assertEqual(2, result.testsRun)
     self.assertNotEqual(None, test.scenarios)
     self.assertEqual(None, log[0][1].scenarios)
     self.assertEqual(None, log[4][1].scenarios)
Example #7
0
    def test_with_one_scenario_one_run(self):
        class ReferenceTest(self.Implementation):
            scenarios = [('demo', {})]

            def test_pass(self):
                pass

        test = ReferenceTest("test_pass")
        log = []
        result = LoggingResult(log)
        test.run(result)
        self.assertTrue(result.wasSuccessful())
        self.assertEqual(1, result.testsRun)
        self.assertEqual(
            'testscenarios.tests.test_testcase.ReferenceTest.test_pass(demo)',
            log[0][1].id())
Example #8
0
 def test_runs_as_success(self):
     # When run, a PlaceHolder test records a success.
     test = self.makePlaceHolder()
     log = []
     test.run(LoggingResult(log))
     self.assertEqual([('startTest', test), ('addSuccess', test),
                       ('stopTest', test)], log)
Example #9
0
    def test_trivial(self):
        log = []
        result = LoggingResult(log)

        class Sample(TestCase):
            def __hash__(self):
                return id(self)

            def test_method1(self):
                pass

            def test_method2(self):
                pass

        test1 = Sample('test_method1')
        test2 = Sample('test_method2')
        original_suite = unittest.TestSuite([test1, test2])
        suite = ConcurrentTestSuite(original_suite, self.split_suite)
        suite.run(result)
        # 0 is the timestamp for the first test starting.
        test1 = log[1][1]
        test2 = log[-1][1]
        self.assertIsInstance(test1, Sample)
        self.assertIsInstance(test2, Sample)
        self.assertNotEqual(test1.id(), test2.id())
Example #10
0
 def test_runs_as_error(self):
     # When run, a PlaceHolder test records a success.
     error = self.makeException()
     test = self.makePlaceHolder(error=error)
     log = []
     test.run(LoggingResult(log))
     self.assertEqual([('startTest', test), ('addError', test, error),
                       ('stopTest', test)], log)
 def test_with_two_scenarios_two_run(self):
     class ReferenceTest(testscenarios.TestWithScenarios):
         scenarios = [('1', {}), ('2', {})]
         def test_pass(self):
             pass
     test = ReferenceTest("test_pass")
     log = []
     result = LoggingResult(log)
     test.run(result)
     self.assertTrue(result.wasSuccessful())
     self.assertEqual(2, result.testsRun)
     self.assertEqual(
         'testscenarios.tests.test_testcase.ReferenceTest.test_pass(1)',
         log[0][1].id())
     self.assertEqual(
         'testscenarios.tests.test_testcase.ReferenceTest.test_pass(2)',
         log[4][1].id())
Example #12
0
    def test_attributes_set(self):
        class ReferenceTest(self.Implementation):
            scenarios = [('1', {
                'foo': 1,
                'bar': 2
            }), ('2', {
                'foo': 2,
                'bar': 4
            })]

            def test_check_foo(self):
                self.assertEqual(self.foo * 2, self.bar)

        test = ReferenceTest("test_check_foo")
        log = []
        result = LoggingResult(log)
        test.run(result)
        self.assertTrue(result.wasSuccessful())
        self.assertEqual(2, result.testsRun)
Example #13
0
 def test_fixture_suite(self):
     log = []
     class Sample(TestCase):
         def test_one(self):
             log.append(1)
         def test_two(self):
             log.append(2)
     fixture = FunctionFixture(
         lambda: log.append('setUp'),
         lambda fixture: log.append('tearDown'))
     suite = FixtureSuite(fixture, [Sample('test_one'), Sample('test_two')])
     suite.run(LoggingResult([]))
     self.assertEqual(['setUp', 1, 2, 'tearDown'], log)
Example #14
0
 def test_skipException_in_setup_calls_result_addSkip(self):
     class TestThatRaisesInSetUp(TestCase):
         def setUp(self):
             TestCase.setUp(self)
             self.skip("skipping this test")
         def test_that_passes(self):
             pass
     calls = []
     result = LoggingResult(calls)
     test = TestThatRaisesInSetUp("test_that_passes")
     test.run(result)
     case = result._events[0][1]
     self.assertEqual([('startTest', case),
         ('addSkip', case, "skipping this test"), ('stopTest', case)],
         calls)
Example #15
0
 def test_setupclass_skip(self):
     # We should support setupclass skipping using cls.skipException.
     # Because folk have used that.
     class Skips(TestCase):
         @classmethod
         def setUpClass(cls):
             raise cls.skipException('foo')
         def test_notrun(self):
             pass
     # Test discovery uses the default suite from unittest2 (unless users
     # deliberately change things, in which case they keep both pieces).
     suite = unittest2.TestSuite([Skips("test_notrun")])
     log = []
     result = LoggingResult(log)
     suite.run(result)
     self.assertEqual(['addSkip'], [item[0] for item in log])
Example #16
0
 def test_setupclass_upcall(self):
     # Note that this is kindof-a-case-test, kindof-suite, because
     # setUpClass is linked between them.
     class Simples(TestCase):
         @classmethod
         def setUpClass(cls):
             super(Simples, cls).setUpClass()
         def test_simple(self):
             pass
     # Test discovery uses the default suite from unittest2 (unless users
     # deliberately change things, in which case they keep both pieces).
     suite = unittest2.TestSuite([Simples("test_simple")])
     log = []
     result = LoggingResult(log)
     suite.run(result)
     self.assertEqual(
         ['startTest', 'addSuccess', 'stopTest'],
         [item[0] for item in log])
Example #17
0
    def test_wrap_result(self):
        # ConcurrentTestSuite has a hook for wrapping the per-thread result.
        wrap_log = []

        def wrap_result(thread_safe_result, thread_number):
            wrap_log.append(
                (thread_safe_result.result.decorated, thread_number))
            return thread_safe_result

        result_log = []
        result = LoggingResult(result_log)
        test1 = Sample('test_method1')
        test2 = Sample('test_method2')
        original_suite = unittest.TestSuite([test1, test2])
        suite = ConcurrentTestSuite(
            original_suite, self.split_suite, wrap_result=wrap_result)
        suite.run(result)
        self.assertEqual(
            [(result, 0),
             (result, 1),
             ], wrap_log)
        # Smoke test to make sure everything ran OK.
        self.assertNotEqual([], result_log)
Example #18
0
 def setUp(self):
     TestCase.setUp(self)
     self._result_calls = []
     self.test = TestAddCleanup.LoggingTest('runTest')
     self.logging_result = LoggingResult(self._result_calls)
 def setUp(self):
     TestWithFakeExceptions.setUp(self)
     self.result_semaphore = threading.Semaphore(1)
     self.target = LoggingResult([])
     self.result1 = ThreadsafeForwardingResult(self.target,
         self.result_semaphore)
 def setUp(self):
     TestWithFakeExceptions.setUp(self)
     self.result1 = LoggingResult([])
     self.result2 = LoggingResult([])
     self.multiResult = MultiTestResult(self.result1, self.result2)