576
576
# cheat. Yes, wash thy mouth out with soap.
577
577
self._benchtime = None
579
def test_assigned_benchmark_file_stores_date(self):
581
result = bzrlib.tests._MyResult(self._log_file,
586
output_string = output.getvalue()
587
# if you are wondering about the regexp please read the comment in
588
# test_bench_history (bzrlib.tests.test_selftest.TestRunner)
589
self.assertContainsRe(output_string, "--date [0-9.]+ \S")
591
def test_benchhistory_records_test_times(self):
592
result_stream = StringIO()
593
result = bzrlib.tests._MyResult(
597
bench_history=result_stream
600
# we want profile a call and check that its test duration is recorded
601
# make a new test instance that when run will generate a benchmark
602
example_test_case = TestTestResult("_time_hello_world_encoding")
603
# execute the test, which should succeed and record times
604
example_test_case.run(result)
605
lines = result_stream.getvalue().splitlines()
606
self.assertEqual(2, len(lines))
607
self.assertContainsRe(lines[1],
608
" *[0-9]+ms bzrlib.tests.test_selftest.TestTestResult"
609
"._time_hello_world_encoding")
579
611
def _time_hello_world_encoding(self):
580
612
"""Profile two sleep calls
671
703
result = self.run_test_runner(runner, test)
672
704
self.assertTrue(result.wasSuccessful())
706
def test_bench_history(self):
708
import bzrlib.revisionspec
709
test = TestRunner('dummy_test')
711
runner = TextTestRunner(stream=self._log_file, bench_history=output)
712
result = self.run_test_runner(runner, test)
713
output_string = output.getvalue()
714
# does anyone know a good regexp for revision ids?
715
# here we are using \S instead and checking the revision id afterwards
716
self.assertContainsRe(output_string, "--date [0-9.]+ \S")
717
branch = bzrlib.branch.Branch.open_containing('.')[0]
718
revision_id = bzrlib.revisionspec.RevisionSpec(branch.revno()).in_history(branch).rev_id
719
self.assert_(output_string.rstrip().endswith(revision_id))
675
722
class TestTestCase(TestCase):
676
723
"""Tests that test the core bzrlib TestCase."""