Example #1
0
 def setUp(self):
     self.case_1 = _test_cases.TestCase(methodName='test_method')
     self.case_2 = _test_cases.TestCase(methodName='_private_method')
     self.case_3 = FilterTestCase(methodName='_private_method')
     self.suite = TestSuite([
         TestSuite([
             self.case_1,
             self.case_2,
         ], ),
         TestSuite([
             self.case_3,
         ], ),
     ], )
Example #2
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 \(')
Example #3
0
    def test_no_output_stop_test(self, stderr):
        # Given
        handler = TimingResultHandler(number_to_summarize=5)
        case = _test_cases.TestCase('test_method')

        # When
        handler.stop_test(case)

        # Then
        output = stderr.getvalue()
        self.assertEqual(output, '')
Example #4
0
class TestTimingResultHandler(ExcInfoFixture, unittest.TestCase):
    @patch('sys.stderr', new_callable=StringIO)
    def test_output_start_test_run(self, stderr):
        # Given
        handler = TimingResultHandler(number_to_summarize=5)

        # When
        handler.start_test_run()

        # Then
        output = stderr.getvalue()
        self.assertEqual(output, '')

    @patch('sys.stderr', new_callable=StringIO)
    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 \(')

    @patch('time.ctime')
    @patch('sys.stderr', new_callable=StringIO)
    def test_output_start_test(self, stderr, mock_ctime):
        # Given
        case = _test_cases.TestCase('test_method')
        handler = TimingResultHandler(number_to_summarize=5)

        # When
        handler.start_test(case)

        # Then
        output = stderr.getvalue()
        self.assertEqual(output, '')
Example #5
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, '')
Example #6
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, '')