~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

Merge bzr.dev (via NO_SMART_VFS branch).

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
                          _load_module_by_name,
64
64
                          'bzrlib.no-name-yet')
65
65
 
66
 
 
67
66
class MetaTestLog(TestCase):
68
67
 
69
68
    def test_logging(self):
575
574
 
576
575
class TestTestResult(TestCase):
577
576
 
578
 
    def test_progress_bar_style_quiet(self):
579
 
        # test using a progress bar.
580
 
        dummy_test = TestTestResult('test_progress_bar_style_quiet')
581
 
        dummy_error = (Exception, None, [])
582
 
        mypb = MockProgress()
583
 
        mypb.update('Running tests', 0, 4)
584
 
        last_calls = mypb.calls[:]
585
 
 
586
 
        result = bzrlib.tests._MyResult(self._log_file,
587
 
                                        descriptions=0,
588
 
                                        verbosity=1,
589
 
                                        pb=mypb)
590
 
        self.assertEqual(last_calls, mypb.calls)
591
 
 
592
 
        def shorten(s):
593
 
            """Shorten a string based on the terminal width"""
594
 
            return result._ellipsise_unimportant_words(s,
595
 
                                 osutils.terminal_width())
596
 
 
597
 
        # an error 
598
 
        result.startTest(dummy_test)
599
 
        # starting a test prints the test name
600
 
        last_calls += [('update', '...tyle_quiet', 0, None)]
601
 
        self.assertEqual(last_calls, mypb.calls)
602
 
        result.addError(dummy_test, dummy_error)
603
 
        last_calls += [('update', 'ERROR        ', 1, None),
604
 
                       ('note', shorten(dummy_test.id() + ': ERROR'), ())
605
 
                      ]
606
 
        self.assertEqual(last_calls, mypb.calls)
607
 
 
608
 
        # a failure
609
 
        result.startTest(dummy_test)
610
 
        last_calls += [('update', '...tyle_quiet', 1, None)]
611
 
        self.assertEqual(last_calls, mypb.calls)
612
 
        last_calls += [('update', 'FAIL         ', 2, None),
613
 
                       ('note', shorten(dummy_test.id() + ': FAIL'), ())
614
 
                      ]
615
 
        result.addFailure(dummy_test, dummy_error)
616
 
        self.assertEqual(last_calls, mypb.calls)
617
 
 
618
 
        # a success
619
 
        result.startTest(dummy_test)
620
 
        last_calls += [('update', '...tyle_quiet', 2, None)]
621
 
        self.assertEqual(last_calls, mypb.calls)
622
 
        result.addSuccess(dummy_test)
623
 
        last_calls += [('update', 'OK           ', 3, None)]
624
 
        self.assertEqual(last_calls, mypb.calls)
625
 
 
626
 
        # a skip
627
 
        result.startTest(dummy_test)
628
 
        last_calls += [('update', '...tyle_quiet', 3, None)]
629
 
        self.assertEqual(last_calls, mypb.calls)
630
 
        result.addSkipped(dummy_test, dummy_error)
631
 
        last_calls += [('update', 'SKIP         ', 4, None)]
632
 
        self.assertEqual(last_calls, mypb.calls)
633
 
 
634
577
    def test_elapsed_time_with_benchmarking(self):
635
 
        result = bzrlib.tests._MyResult(self._log_file,
 
578
        result = bzrlib.tests.TextTestResult(self._log_file,
636
579
                                        descriptions=0,
637
580
                                        verbosity=1,
638
581
                                        )
658
601
 
659
602
    def test_assigned_benchmark_file_stores_date(self):
660
603
        output = StringIO()
661
 
        result = bzrlib.tests._MyResult(self._log_file,
 
604
        result = bzrlib.tests.TextTestResult(self._log_file,
662
605
                                        descriptions=0,
663
606
                                        verbosity=1,
664
607
                                        bench_history=output
665
608
                                        )
666
609
        output_string = output.getvalue()
 
610
        
667
611
        # if you are wondering about the regexp please read the comment in
668
612
        # test_bench_history (bzrlib.tests.test_selftest.TestRunner)
669
613
        # XXX: what comment?  -- Andrew Bennetts
671
615
 
672
616
    def test_benchhistory_records_test_times(self):
673
617
        result_stream = StringIO()
674
 
        result = bzrlib.tests._MyResult(
 
618
        result = bzrlib.tests.TextTestResult(
675
619
            self._log_file,
676
620
            descriptions=0,
677
621
            verbosity=1,
704
648
        except ImportError:
705
649
            raise TestSkipped("lsprof not installed.")
706
650
        result_stream = StringIO()
707
 
        result = bzrlib.tests._MyResult(
 
651
        result = bzrlib.tests.VerboseTestResult(
708
652
            unittest._WritelnDecorator(result_stream),
709
653
            descriptions=0,
710
654
            verbosity=2,
759
703
        finally:
760
704
            TestCaseInTempDir.TEST_ROOT = old_root
761
705
 
762
 
    def test_accepts_and_uses_pb_parameter(self):
763
 
        test = TestRunner('dummy_test')
764
 
        mypb = MockProgress()
765
 
        self.assertEqual([], mypb.calls)
766
 
        runner = TextTestRunner(stream=self._log_file, pb=mypb)
767
 
        result = self.run_test_runner(runner, test)
768
 
        self.assertEqual(1, result.testsRun)
769
 
        self.assertEqual(('update', 'Running tests', 0, 1), mypb.calls[0])
770
 
        self.assertEqual(('update', '...dummy_test', 0, None), mypb.calls[1])
771
 
        self.assertEqual(('update', 'OK           ', 1, None), mypb.calls[2])
772
 
        self.assertEqual(('update', 'Cleaning up', 0, 1), mypb.calls[3])
773
 
        self.assertEqual(('clear',), mypb.calls[4])
774
 
        self.assertEqual(5, len(mypb.calls))
775
 
 
776
706
    def test_skipped_test(self):
777
707
        # run a test that is skipped, and check the suite as a whole still
778
708
        # succeeds.
873
803
        # the outer child test
874
804
        note("outer_start")
875
805
        self.inner_test = TestTestCase("inner_child")
876
 
        result = bzrlib.tests._MyResult(self._log_file,
 
806
        result = bzrlib.tests.TextTestResult(self._log_file,
877
807
                                        descriptions=0,
878
808
                                        verbosity=1)
879
809
        self.inner_test.run(result)
893
823
        # the outer child test
894
824
        original_trace = bzrlib.trace._trace_file
895
825
        outer_test = TestTestCase("outer_child")
896
 
        result = bzrlib.tests._MyResult(self._log_file,
 
826
        result = bzrlib.tests.TextTestResult(self._log_file,
897
827
                                        descriptions=0,
898
828
                                        verbosity=1)
899
829
        outer_test.run(result)
908
838
        """Test that the TestCase.time() method accumulates a benchmark time."""
909
839
        sample_test = TestTestCase("method_that_times_a_bit_twice")
910
840
        output_stream = StringIO()
911
 
        result = bzrlib.tests._MyResult(
 
841
        result = bzrlib.tests.VerboseTestResult(
912
842
            unittest._WritelnDecorator(output_stream),
913
843
            descriptions=0,
914
 
            verbosity=2)
 
844
            verbosity=2,
 
845
            num_tests=sample_test.countTestCases())
915
846
        sample_test.run(result)
916
847
        self.assertContainsRe(
917
848
            output_stream.getvalue(),
918
 
            "[1-9][0-9]ms/   [1-9][0-9]ms\n$")
 
849
            r"\d+ms/ +\d+ms\n$")
919
850
        
920
851
    def test__gather_lsprof_in_benchmarks(self):
921
852
        """When _gather_lsprof_in_benchmarks is on, accumulate profile data.