def test_traceback_size_limit(self): """Insert a failure with a long exception and make sure it gets truncated.""" conn = self.reporter.conn test_case = DummyTestCase() result = TestResult(test_case.test_fail) result.start() result.end_in_failure( (type(AssertionError), AssertionError('A' * 200), None)) with patch.object(self.reporter.options, 'sql_traceback_size', 50): with patch.object( result, 'format_exception_info') as mock_format_exception_info: mock_format_exception_info.return_value = "AssertionError: %s\n%s\n" % ( 'A' * 200, 'A' * 200) self.reporter.test_complete(result.to_dict()) assert self.reporter.report() failure = conn.execute(self.reporter.Failures.select()).fetchone() assert_equal(len(failure.traceback), 50) assert_equal(len(failure.error), 50) assert_in('Exception truncated.', failure.traceback) assert_in('Exception truncated.', failure.error)
def test_test_complete(self): assert_equal(self.reporter.result_queue.qsize(), 0) test_case = DummyTestCase() fake_test_result = TestResult(test_case.run) self.reporter.test_complete(fake_test_result.to_dict()) assert_equal(self.reporter.result_queue.qsize(), 0)
def test_json_reporter_reports(self): self.set_options() with mock_conf_files(): self.reporter = TestCaseJSONReporter(self.options) test_case = TestCase() fake_test_result = TestResult(test_case.run) with mock.patch.object(datetime, 'datetime', **{'now.return_value': start_time}): fake_test_result.start() with mock.patch.object(datetime, 'datetime', **{'now.return_value': end_time}): fake_test_result._complete() self.reporter.test_case_complete(fake_test_result.to_dict()) assert_equal( json.loads(self.reporter.log_file.getvalue()), json.loads(output_str), )
def test_json_reporter_reports(self): self.set_options() with mock_conf_files(): self.reporter = TestCaseJSONReporter(self.options) test_case = TestCase() fake_test_result = TestResult(test_case.run) with mock.patch.object( datetime, 'datetime', **{'now.return_value': start_time} ): fake_test_result.start() with mock.patch.object(datetime, 'datetime', **{'now.return_value': end_time}): fake_test_result._complete() self.reporter.test_case_complete(fake_test_result.to_dict()) assert_equal( json.loads(self.reporter.log_file.getvalue()), json.loads(output_str), )
def test_traceback_size_limit(self): """Insert a failure with a long exception and make sure it gets truncated.""" conn = self.reporter.conn test_case = DummyTestCase() result = TestResult(test_case.test_fail) result.start() result.end_in_failure((type(AssertionError), AssertionError('A' * 200), None)) with patch.object(self.reporter.options, 'sql_traceback_size', 50): with patch.object(result, 'format_exception_info') as mock_format_exception_info: mock_format_exception_info.return_value = ["AssertionError: %s" % ('A' * 200), 'A' * 200] self.reporter.test_complete(result.to_dict()) assert self.reporter.report() failure = conn.execute(Failures.select()).fetchone() assert_equal(len(failure.traceback), 50) assert_equal(len(failure.error), 50) assert_in('Exception truncated.', failure.traceback) assert_in('Exception truncated.', failure.error)