예제 #1
0
    def test_output_with_failure_on_stop_test_run(self, stderr):
        # Given
        start_time = datetime(2015, 12, 23, 8, 14, 12)
        duration = timedelta(hours=1, minutes=1, seconds=14, milliseconds=567)
        end_time = start_time + duration
        expected_duration = TestDuration(start_time, end_time)
        case = _test_cases.TestCase('test_method')

        handler = TimingResultHandler(number_to_summarize=5)
        handler.start_test_run()
        with self.failure_exc_info() as exc_info:
            result = TestResult.from_test_case(
                case, TestCompletionStatus.failure, expected_duration,
                exception=exc_info)

        # When
        handler(result)
        handler.stop_test_run()

        # Then
        output = stderr.getvalue()
        output_start = '\n\nTest timing report\n' + handler.separator2
        self.assertTrue(output.startswith(output_start))
        self.assertRegexpMatches(
            output.replace('\n', ''), r'--+.*?1:01:14\.567 test_method \(')
예제 #2
0
    def test_output_multiple_tests(self, stderr):
        # Given
        tests_start_time = datetime(2015, 12, 23, 8, 14, 12)
        test_durations = [
            dict(seconds=9, milliseconds=123),
            dict(seconds=2, milliseconds=50),
            dict(seconds=1, milliseconds=100),
            dict(seconds=6, milliseconds=0),
            dict(seconds=3, milliseconds=542),
        ]

        expected_stats = self._calculate_statistics(test_durations)

        test_start_time = None
        expected_durations = []
        for kwargs in test_durations:
            duration = timedelta(**kwargs)
            if test_start_time is None:
                test_start_time = tests_start_time
            end_time = test_start_time + duration
            expected_durations.append(TestDuration(test_start_time, end_time))
            test_start_time = end_time

        handler = TimingResultHandler(number_to_summarize=5)
        handler.start_test_run()

        def make_case():
            class Case(_test_cases.TestCase):
                pass

            return Case('test_method')

        for duration in expected_durations:
            result = TestResult.from_test_case(make_case(),
                                               TestCompletionStatus.success,
                                               duration)
            handler(result)

        # When
        handler.stop_test_run()

        # Then
        output = stderr.getvalue()
        output_start = '\n\nTest timing report\n' + handler.separator2
        self.assertTrue(output.startswith(output_start))
        self.assertRegexpMatches(output.replace('\n', ''),
                                 r'--+.*?00:09\.123 test_method \(')
        self.assertIn(expected_stats, output)
예제 #3
0
    def test_output_multiple_tests(self, stderr):
        # Given
        tests_start_time = datetime(2015, 12, 23, 8, 14, 12)
        test_durations = [
            dict(seconds=9, milliseconds=123),
            dict(seconds=2, milliseconds=50),
            dict(seconds=1, milliseconds=100),
            dict(seconds=6, milliseconds=0),
            dict(seconds=3, milliseconds=542),
        ]

        expected_stats = self._calculate_statistics(test_durations)

        test_start_time = None
        expected_durations = []
        for kwargs in test_durations:
            duration = timedelta(**kwargs)
            if test_start_time is None:
                test_start_time = tests_start_time
            end_time = test_start_time + duration
            expected_durations.append(TestDuration(test_start_time, end_time))
            test_start_time = end_time

        handler = TimingResultHandler(number_to_summarize=5)
        handler.start_test_run()

        def make_case():
            class Case(_test_cases.TestCase):
                pass
            return Case('test_method')

        for duration in expected_durations:
            result = TestResult.from_test_case(
                make_case(), TestCompletionStatus.success, duration)
            handler(result)

        # When
        handler.stop_test_run()

        # Then
        output = stderr.getvalue()
        output_start = '\n\nTest timing report\n' + handler.separator2
        self.assertTrue(output.startswith(output_start))
        self.assertRegexpMatches(
            output.replace('\n', ''), r'--+.*?00:09\.123 test_method \(')
        self.assertIn(expected_stats, output)
예제 #4
0
    def test_output_on_unexpected_success(self, stderr):
        # Given
        start_time = datetime(2015, 12, 23, 8, 14, 12)
        duration = timedelta(seconds=10)
        end_time = start_time + duration
        expected_duration = TestDuration(start_time, end_time)
        case = _test_cases.TestCase('test_method')

        handler = TimingResultHandler(number_to_summarize=5)
        result = TestResult.from_test_case(
            case, TestCompletionStatus.unexpected_success, expected_duration)

        # When
        handler(result)

        # Then
        output = stderr.getvalue()
        self.assertEqual(output, '')
예제 #5
0
    def test_output_on_expected_fail(self, stderr):
        # Given
        start_time = datetime(2015, 12, 23, 8, 14, 12)
        duration = timedelta(seconds=10)
        end_time = start_time + duration
        expected_duration = TestDuration(start_time, end_time)
        case = _test_cases.TestCase('test_method')

        handler = TimingResultHandler(number_to_summarize=5)
        with self.exc_info(RuntimeError) as exc_info:
            result = TestResult.from_test_case(
                case, TestCompletionStatus.expected_failure, expected_duration,
                exception=exc_info)

        # When
        handler(result)

        # Then
        output = stderr.getvalue()
        self.assertEqual(output, '')
예제 #6
0
    def test_output_stop_test_run_success(self, stderr):
        # Given
        start_time = datetime(2015, 12, 23, 8, 14, 12)
        duration = timedelta(seconds=10, milliseconds=123)
        end_time = start_time + duration
        expected_duration = TestDuration(start_time, end_time)
        case = _test_cases.TestCase('test_method')
        handler = TimingResultHandler(number_to_summarize=5)
        handler.start_test_run()

        result = TestResult.from_test_case(
            case, TestCompletionStatus.success, expected_duration)
        handler(result)

        # When
        handler.stop_test_run()

        # Then
        output = stderr.getvalue()
        output_start = '\n\nTest timing report\n' + handler.separator2
        self.assertTrue(output.startswith(output_start))
        self.assertRegexpMatches(
            output.replace('\n', ''), r'--+.*?00:10\.123 test_method \(')