~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

Merge updated set_parents api.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
                          )
37
37
from bzrlib.tests.TestUtil import _load_module_by_name
38
38
import bzrlib.errors as errors
 
39
from bzrlib import symbol_versioning
39
40
from bzrlib.trace import note
40
41
 
41
42
 
576
577
        # cheat. Yes, wash thy mouth out with soap.
577
578
        self._benchtime = None
578
579
 
 
580
    def test_assigned_benchmark_file_stores_date(self):
 
581
        output = StringIO()
 
582
        result = bzrlib.tests._MyResult(self._log_file,
 
583
                                        descriptions=0,
 
584
                                        verbosity=1,
 
585
                                        bench_history=output
 
586
                                        )
 
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")
 
591
 
 
592
    def test_benchhistory_records_test_times(self):
 
593
        result_stream = StringIO()
 
594
        result = bzrlib.tests._MyResult(
 
595
            self._log_file,
 
596
            descriptions=0,
 
597
            verbosity=1,
 
598
            bench_history=result_stream
 
599
            )
 
600
 
 
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")
 
611
 
579
612
    def _time_hello_world_encoding(self):
580
613
        """Profile two sleep calls
581
614
        
671
704
        result = self.run_test_runner(runner, test)
672
705
        self.assertTrue(result.wasSuccessful())
673
706
 
 
707
    def test_bench_history(self):
 
708
        import bzrlib.branch
 
709
        import bzrlib.revisionspec
 
710
        test = TestRunner('dummy_test')
 
711
        output = StringIO()
 
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))
 
721
 
674
722
 
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')
763
811
 
 
812
    def test_assertDeprecated(self):
 
813
        def testfunc(be_deprecated):
 
814
            if be_deprecated is True:
 
815
                symbol_versioning.warn('i am deprecated', DeprecationWarning, 
 
816
                                       stacklevel=1)
 
817
        self.assertDeprecated(['i am deprecated'], testfunc, True)
 
818
        self.assertDeprecated([], testfunc, False)
 
819
        self.assertDeprecated(['i am deprecated'], testfunc, 
 
820
                              be_deprecated=True)
 
821
        self.assertDeprecated([], testfunc, be_deprecated=False)
 
822
 
764
823
 
765
824
class TestConvenienceMakers(TestCaseWithTransport):
766
825
    """Test for the make_* convenience functions."""