~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-14 16:16:53 UTC
  • mto: (1946.2.6 reduce-knit-churn)
  • mto: This revision was merged to the branch mainline in revision 1919.
  • Revision ID: john@arbash-meinel.com-20060814161653-54cdcdadcd4e9003
Remove bogus entry from BRANCH.TODO

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
40
39
from bzrlib.trace import note
41
40
 
42
41
 
577
576
        # cheat. Yes, wash thy mouth out with soap.
578
577
        self._benchtime = None
579
578
 
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
 
 
612
579
    def _time_hello_world_encoding(self):
613
580
        """Profile two sleep calls
614
581
        
704
671
        result = self.run_test_runner(runner, test)
705
672
        self.assertTrue(result.wasSuccessful())
706
673
 
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
 
 
722
674
 
723
675
class TestTestCase(TestCase):
724
676
    """Tests that test the core bzrlib TestCase."""
809
761
        self.assertEndsWith('foo', 'oo')
810
762
        self.assertRaises(AssertionError, self.assertEndsWith, 'o', 'oo')
811
763
 
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
 
 
823
764
 
824
765
class TestConvenienceMakers(TestCaseWithTransport):
825
766
    """Test for the make_* convenience functions."""