/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

Merge bzr.dev

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):
502
501
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
503
502
 
504
503
    def test_get_readonly_url_http(self):
 
504
        from bzrlib.tests.HttpServer import HttpServer
505
505
        from bzrlib.transport import get_transport
506
506
        from bzrlib.transport.local import LocalURLServer
507
 
        from bzrlib.transport.http import HttpServer, HttpTransportBase
 
507
        from bzrlib.transport.http import HttpTransportBase
508
508
        self.transport_server = LocalURLServer
509
509
        self.transport_readonly_server = HttpServer
510
510
        # calling get_readonly_transport() gives us a HTTP server instance.
575
575
 
576
576
class TestTestResult(TestCase):
577
577
 
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
578
    def test_elapsed_time_with_benchmarking(self):
635
 
        result = bzrlib.tests._MyResult(self._log_file,
 
579
        result = bzrlib.tests.TextTestResult(self._log_file,
636
580
                                        descriptions=0,
637
581
                                        verbosity=1,
638
582
                                        )
658
602
 
659
603
    def test_assigned_benchmark_file_stores_date(self):
660
604
        output = StringIO()
661
 
        result = bzrlib.tests._MyResult(self._log_file,
 
605
        result = bzrlib.tests.TextTestResult(self._log_file,
662
606
                                        descriptions=0,
663
607
                                        verbosity=1,
664
608
                                        bench_history=output
665
609
                                        )
666
610
        output_string = output.getvalue()
 
611
        
667
612
        # if you are wondering about the regexp please read the comment in
668
613
        # test_bench_history (bzrlib.tests.test_selftest.TestRunner)
669
614
        # XXX: what comment?  -- Andrew Bennetts
671
616
 
672
617
    def test_benchhistory_records_test_times(self):
673
618
        result_stream = StringIO()
674
 
        result = bzrlib.tests._MyResult(
 
619
        result = bzrlib.tests.TextTestResult(
675
620
            self._log_file,
676
621
            descriptions=0,
677
622
            verbosity=1,
704
649
        except ImportError:
705
650
            raise TestSkipped("lsprof not installed.")
706
651
        result_stream = StringIO()
707
 
        result = bzrlib.tests._MyResult(
 
652
        result = bzrlib.tests.VerboseTestResult(
708
653
            unittest._WritelnDecorator(result_stream),
709
654
            descriptions=0,
710
655
            verbosity=2,
759
704
        finally:
760
705
            TestCaseInTempDir.TEST_ROOT = old_root
761
706
 
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
707
    def test_skipped_test(self):
777
708
        # run a test that is skipped, and check the suite as a whole still
778
709
        # succeeds.
873
804
        # the outer child test
874
805
        note("outer_start")
875
806
        self.inner_test = TestTestCase("inner_child")
876
 
        result = bzrlib.tests._MyResult(self._log_file,
 
807
        result = bzrlib.tests.TextTestResult(self._log_file,
877
808
                                        descriptions=0,
878
809
                                        verbosity=1)
879
810
        self.inner_test.run(result)
893
824
        # the outer child test
894
825
        original_trace = bzrlib.trace._trace_file
895
826
        outer_test = TestTestCase("outer_child")
896
 
        result = bzrlib.tests._MyResult(self._log_file,
 
827
        result = bzrlib.tests.TextTestResult(self._log_file,
897
828
                                        descriptions=0,
898
829
                                        verbosity=1)
899
830
        outer_test.run(result)
908
839
        """Test that the TestCase.time() method accumulates a benchmark time."""
909
840
        sample_test = TestTestCase("method_that_times_a_bit_twice")
910
841
        output_stream = StringIO()
911
 
        result = bzrlib.tests._MyResult(
 
842
        result = bzrlib.tests.VerboseTestResult(
912
843
            unittest._WritelnDecorator(output_stream),
913
844
            descriptions=0,
914
 
            verbosity=2)
 
845
            verbosity=2,
 
846
            num_tests=sample_test.countTestCases())
915
847
        sample_test.run(result)
916
848
        self.assertContainsRe(
917
849
            output_stream.getvalue(),
918
 
            "[1-9][0-9]ms/   [1-9][0-9]ms\n$")
 
850
            r"\d+ms/ +\d+ms\n$")
919
851
        
920
852
    def test__gather_lsprof_in_benchmarks(self):
921
853
        """When _gather_lsprof_in_benchmarks is on, accumulate profile data.