38
38
import bzrlib.errors as errors
39
39
from bzrlib import symbol_versioning
40
40
from bzrlib.trace import note
41
from bzrlib.version import _get_bzr_source_tree
43
44
class SelftestTests(TestCase):
587
588
output_string = output.getvalue()
588
589
# if you are wondering about the regexp please read the comment in
589
590
# test_bench_history (bzrlib.tests.test_selftest.TestRunner)
590
self.assertContainsRe(output_string, "--date [0-9.]+ \S")
591
# XXX: what comment? -- Andrew Bennetts
592
self.assertContainsRe(output_string, "--date [0-9.]+")
592
594
def test_benchhistory_records_test_times(self):
593
595
result_stream = StringIO()
705
707
self.assertTrue(result.wasSuccessful())
707
709
def test_bench_history(self):
709
import bzrlib.revisionspec
710
# tests that the running the benchmark produces a history file
711
# containing a timestamp and the revision id of the bzrlib source which
713
workingtree = _get_bzr_source_tree()
710
714
test = TestRunner('dummy_test')
711
715
output = StringIO()
712
716
runner = TextTestRunner(stream=self._log_file, bench_history=output)
713
717
result = self.run_test_runner(runner, test)
714
718
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))
719
self.assertContainsRe(output_string, "--date [0-9.]+")
720
if workingtree is not None:
721
revision_id = workingtree.last_revision()
722
self.assertEndsWith(output_string.rstrip(), revision_id)
723
725
class TestTestCase(TestCase):
809
811
self.assertEndsWith('foo', 'oo')
810
812
self.assertRaises(AssertionError, self.assertEndsWith, 'o', 'oo')
812
def test_assertDeprecated(self):
813
def testfunc(be_deprecated):
814
def test_callDeprecated(self):
815
def testfunc(be_deprecated, result=None):
814
816
if be_deprecated is True:
815
817
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,
820
result = self.callDeprecated(['i am deprecated'], testfunc, True)
821
self.assertIs(None, result)
822
result = self.callDeprecated([], testfunc, False, 'result')
823
self.assertEqual('result', result)
824
self.callDeprecated(['i am deprecated'], testfunc,
820
825
be_deprecated=True)
821
self.assertDeprecated([], testfunc, be_deprecated=False)
826
self.callDeprecated([], testfunc, be_deprecated=False)
824
829
class TestConvenienceMakers(TestCaseWithTransport):