576
577
# cheat. Yes, wash thy mouth out with soap.
577
578
self._benchtime = None
580
def test_assigned_benchmark_file_stores_date(self):
582
result = bzrlib.tests._MyResult(self._log_file,
587
output_string = output.getvalue()
588
# if you are wondering about the regexp please read the comment in
589
# test_bench_history (bzrlib.tests.test_selftest.TestRunner)
590
self.assertContainsRe(output_string, "--date [0-9.]+ \S")
592
def test_benchhistory_records_test_times(self):
593
result_stream = StringIO()
594
result = bzrlib.tests._MyResult(
598
bench_history=result_stream
601
# we want profile a call and check that its test duration is recorded
602
# make a new test instance that when run will generate a benchmark
603
example_test_case = TestTestResult("_time_hello_world_encoding")
604
# execute the test, which should succeed and record times
605
example_test_case.run(result)
606
lines = result_stream.getvalue().splitlines()
607
self.assertEqual(2, len(lines))
608
self.assertContainsRe(lines[1],
609
" *[0-9]+ms bzrlib.tests.test_selftest.TestTestResult"
610
"._time_hello_world_encoding")
579
612
def _time_hello_world_encoding(self):
580
613
"""Profile two sleep calls
671
704
result = self.run_test_runner(runner, test)
672
705
self.assertTrue(result.wasSuccessful())
707
def test_bench_history(self):
709
import bzrlib.revisionspec
710
test = TestRunner('dummy_test')
712
runner = TextTestRunner(stream=self._log_file, bench_history=output)
713
result = self.run_test_runner(runner, test)
714
output_string = output.getvalue()
715
# does anyone know a good regexp for revision ids?
716
# here we are using \S instead and checking the revision id afterwards
717
self.assertContainsRe(output_string, "--date [0-9.]+ \S")
718
branch = bzrlib.branch.Branch.open_containing('.')[0]
719
revision_id = bzrlib.revisionspec.RevisionSpec(branch.revno()).in_history(branch).rev_id
720
self.assert_(output_string.rstrip().endswith(revision_id))
675
723
class TestTestCase(TestCase):
676
724
"""Tests that test the core bzrlib TestCase."""
761
809
self.assertEndsWith('foo', 'oo')
762
810
self.assertRaises(AssertionError, self.assertEndsWith, 'o', 'oo')
812
def test_assertDeprecated(self):
813
def testfunc(be_deprecated):
814
if be_deprecated is True:
815
symbol_versioning.warn('i am deprecated', DeprecationWarning,
817
self.assertDeprecated(['i am deprecated'], testfunc, True)
818
self.assertDeprecated([], testfunc, False)
819
self.assertDeprecated(['i am deprecated'], testfunc,
821
self.assertDeprecated([], testfunc, be_deprecated=False)
765
824
class TestConvenienceMakers(TestCaseWithTransport):
766
825
"""Test for the make_* convenience functions."""