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):
588
589
output_string = output.getvalue()
589
590
# if you are wondering about the regexp please read the comment in
590
591
# test_bench_history (bzrlib.tests.test_selftest.TestRunner)
591
self.assertContainsRe(output_string, "--date [0-9.]+ \S")
592
# XXX: what comment? -- Andrew Bennetts
593
self.assertContainsRe(output_string, "--date [0-9.]+")
593
595
def test_benchhistory_records_test_times(self):
594
596
result_stream = StringIO()
706
708
self.assertTrue(result.wasSuccessful())
708
710
def test_bench_history(self):
710
import bzrlib.revisionspec
711
# tests that the running the benchmark produces a history file
712
# containing a timestamp and the revision id of the bzrlib source which
714
workingtree = _get_bzr_source_tree()
711
715
test = TestRunner('dummy_test')
712
716
output = StringIO()
713
717
runner = TextTestRunner(stream=self._log_file, bench_history=output)
714
718
result = self.run_test_runner(runner, test)
715
719
output_string = output.getvalue()
716
# does anyone know a good regexp for revision ids?
717
# here we are using \S instead and checking the revision id afterwards
718
self.assertContainsRe(output_string, "--date [0-9.]+ \S")
719
branch = bzrlib.branch.Branch.open_containing('.')[0]
720
revision_id = bzrlib.revisionspec.RevisionSpec(branch.revno()).in_history(branch).rev_id
721
self.assert_(output_string.rstrip().endswith(revision_id))
720
self.assertContainsRe(output_string, "--date [0-9.]+")
721
if workingtree is not None:
722
revision_id = workingtree.last_revision()
723
self.assertEndsWith(output_string.rstrip(), revision_id)
724
726
class TestTestCase(TestCase):
810
812
self.assertEndsWith('foo', 'oo')
811
813
self.assertRaises(AssertionError, self.assertEndsWith, 'o', 'oo')
813
def test_assertDeprecated(self):
814
def testfunc(be_deprecated):
815
def test_callDeprecated(self):
816
def testfunc(be_deprecated, result=None):
815
817
if be_deprecated is True:
816
818
symbol_versioning.warn('i am deprecated', DeprecationWarning,
818
self.assertDeprecated(['i am deprecated'], testfunc, True)
819
self.assertDeprecated([], testfunc, False)
820
self.assertDeprecated(['i am deprecated'], testfunc,
821
result = self.callDeprecated(['i am deprecated'], testfunc, True)
822
self.assertIs(None, result)
823
result = self.callDeprecated([], testfunc, False, 'result')
824
self.assertEqual('result', result)
825
self.callDeprecated(['i am deprecated'], testfunc,
821
826
be_deprecated=True)
822
self.assertDeprecated([], testfunc, be_deprecated=False)
827
self.callDeprecated([], testfunc, be_deprecated=False)
825
830
class TestConvenienceMakers(TestCaseWithTransport):