~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-08-16 04:31:16 UTC
  • mfrom: (1819.1.9 bzr.mbp.perf-history)
  • Revision ID: pqm@pqm.ubuntu.com-20060816043116-0e82b6cea99bffd4
(mbp) performance-history tracking

Show diffs side-by-side

added added

removed removed

Lines of Context:
576
576
        # cheat. Yes, wash thy mouth out with soap.
577
577
        self._benchtime = None
578
578
 
 
579
    def test_assigned_benchmark_file_stores_date(self):
 
580
        output = StringIO()
 
581
        result = bzrlib.tests._MyResult(self._log_file,
 
582
                                        descriptions=0,
 
583
                                        verbosity=1,
 
584
                                        bench_history=output
 
585
                                        )
 
586
        output_string = output.getvalue()
 
587
        # if you are wondering about the regexp please read the comment in
 
588
        # test_bench_history (bzrlib.tests.test_selftest.TestRunner)
 
589
        self.assertContainsRe(output_string, "--date [0-9.]+ \S")
 
590
 
 
591
    def test_benchhistory_records_test_times(self):
 
592
        result_stream = StringIO()
 
593
        result = bzrlib.tests._MyResult(
 
594
            self._log_file,
 
595
            descriptions=0,
 
596
            verbosity=1,
 
597
            bench_history=result_stream
 
598
            )
 
599
 
 
600
        # we want profile a call and check that its test duration is recorded
 
601
        # make a new test instance that when run will generate a benchmark
 
602
        example_test_case = TestTestResult("_time_hello_world_encoding")
 
603
        # execute the test, which should succeed and record times
 
604
        example_test_case.run(result)
 
605
        lines = result_stream.getvalue().splitlines()
 
606
        self.assertEqual(2, len(lines))
 
607
        self.assertContainsRe(lines[1],
 
608
            " *[0-9]+ms bzrlib.tests.test_selftest.TestTestResult"
 
609
            "._time_hello_world_encoding")
 
610
 
579
611
    def _time_hello_world_encoding(self):
580
612
        """Profile two sleep calls
581
613
        
671
703
        result = self.run_test_runner(runner, test)
672
704
        self.assertTrue(result.wasSuccessful())
673
705
 
 
706
    def test_bench_history(self):
 
707
        import bzrlib.branch
 
708
        import bzrlib.revisionspec
 
709
        test = TestRunner('dummy_test')
 
710
        output = StringIO()
 
711
        runner = TextTestRunner(stream=self._log_file, bench_history=output)
 
712
        result = self.run_test_runner(runner, test)
 
713
        output_string = output.getvalue()
 
714
        # does anyone know a good regexp for revision ids?
 
715
        # here we are using \S instead and checking the revision id afterwards
 
716
        self.assertContainsRe(output_string, "--date [0-9.]+ \S")
 
717
        branch = bzrlib.branch.Branch.open_containing('.')[0]
 
718
        revision_id = bzrlib.revisionspec.RevisionSpec(branch.revno()).in_history(branch).rev_id
 
719
        self.assert_(output_string.rstrip().endswith(revision_id))
 
720
 
674
721
 
675
722
class TestTestCase(TestCase):
676
723
    """Tests that test the core bzrlib TestCase."""