~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License version 2 as published by
5
 
# the Free Software Foundation.
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
6
7
#
7
8
# This program is distributed in the hope that it will be useful,
8
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
62
63
                          _load_module_by_name,
63
64
                          'bzrlib.no-name-yet')
64
65
 
65
 
 
66
66
class MetaTestLog(TestCase):
67
67
 
68
68
    def test_logging(self):
502
502
 
503
503
    def test_get_readonly_url_http(self):
504
504
        from bzrlib.transport import get_transport
505
 
        from bzrlib.transport.local import LocalRelpathServer
 
505
        from bzrlib.transport.local import LocalURLServer
506
506
        from bzrlib.transport.http import HttpServer, HttpTransportBase
507
 
        self.transport_server = LocalRelpathServer
 
507
        self.transport_server = LocalURLServer
508
508
        self.transport_readonly_server = HttpServer
509
509
        # calling get_readonly_transport() gives us a HTTP server instance.
510
510
        url = self.get_readonly_url()
574
574
 
575
575
class TestTestResult(TestCase):
576
576
 
577
 
    def test_progress_bar_style_quiet(self):
578
 
        # test using a progress bar.
579
 
        dummy_test = TestTestResult('test_progress_bar_style_quiet')
580
 
        dummy_error = (Exception, None, [])
581
 
        mypb = MockProgress()
582
 
        mypb.update('Running tests', 0, 4)
583
 
        last_calls = mypb.calls[:]
584
 
 
585
 
        result = bzrlib.tests._MyResult(self._log_file,
586
 
                                        descriptions=0,
587
 
                                        verbosity=1,
588
 
                                        pb=mypb)
589
 
        self.assertEqual(last_calls, mypb.calls)
590
 
 
591
 
        def shorten(s):
592
 
            """Shorten a string based on the terminal width"""
593
 
            return result._ellipsise_unimportant_words(s,
594
 
                                 osutils.terminal_width())
595
 
 
596
 
        # an error 
597
 
        result.startTest(dummy_test)
598
 
        # starting a test prints the test name
599
 
        last_calls += [('update', '...tyle_quiet', 0, None)]
600
 
        self.assertEqual(last_calls, mypb.calls)
601
 
        result.addError(dummy_test, dummy_error)
602
 
        last_calls += [('update', 'ERROR        ', 1, None),
603
 
                       ('note', shorten(dummy_test.id() + ': ERROR'), ())
604
 
                      ]
605
 
        self.assertEqual(last_calls, mypb.calls)
606
 
 
607
 
        # a failure
608
 
        result.startTest(dummy_test)
609
 
        last_calls += [('update', '...tyle_quiet', 1, None)]
610
 
        self.assertEqual(last_calls, mypb.calls)
611
 
        last_calls += [('update', 'FAIL         ', 2, None),
612
 
                       ('note', shorten(dummy_test.id() + ': FAIL'), ())
613
 
                      ]
614
 
        result.addFailure(dummy_test, dummy_error)
615
 
        self.assertEqual(last_calls, mypb.calls)
616
 
 
617
 
        # a success
618
 
        result.startTest(dummy_test)
619
 
        last_calls += [('update', '...tyle_quiet', 2, None)]
620
 
        self.assertEqual(last_calls, mypb.calls)
621
 
        result.addSuccess(dummy_test)
622
 
        last_calls += [('update', 'OK           ', 3, None)]
623
 
        self.assertEqual(last_calls, mypb.calls)
624
 
 
625
 
        # a skip
626
 
        result.startTest(dummy_test)
627
 
        last_calls += [('update', '...tyle_quiet', 3, None)]
628
 
        self.assertEqual(last_calls, mypb.calls)
629
 
        result.addSkipped(dummy_test, dummy_error)
630
 
        last_calls += [('update', 'SKIP         ', 4, None)]
631
 
        self.assertEqual(last_calls, mypb.calls)
632
 
 
633
577
    def test_elapsed_time_with_benchmarking(self):
634
 
        result = bzrlib.tests._MyResult(self._log_file,
 
578
        result = bzrlib.tests.TextTestResult(self._log_file,
635
579
                                        descriptions=0,
636
580
                                        verbosity=1,
637
581
                                        )
657
601
 
658
602
    def test_assigned_benchmark_file_stores_date(self):
659
603
        output = StringIO()
660
 
        result = bzrlib.tests._MyResult(self._log_file,
 
604
        result = bzrlib.tests.TextTestResult(self._log_file,
661
605
                                        descriptions=0,
662
606
                                        verbosity=1,
663
607
                                        bench_history=output
664
608
                                        )
665
609
        output_string = output.getvalue()
 
610
        
666
611
        # if you are wondering about the regexp please read the comment in
667
612
        # test_bench_history (bzrlib.tests.test_selftest.TestRunner)
668
613
        # XXX: what comment?  -- Andrew Bennetts
670
615
 
671
616
    def test_benchhistory_records_test_times(self):
672
617
        result_stream = StringIO()
673
 
        result = bzrlib.tests._MyResult(
 
618
        result = bzrlib.tests.TextTestResult(
674
619
            self._log_file,
675
620
            descriptions=0,
676
621
            verbosity=1,
703
648
        except ImportError:
704
649
            raise TestSkipped("lsprof not installed.")
705
650
        result_stream = StringIO()
706
 
        result = bzrlib.tests._MyResult(
 
651
        result = bzrlib.tests.VerboseTestResult(
707
652
            unittest._WritelnDecorator(result_stream),
708
653
            descriptions=0,
709
654
            verbosity=2,
758
703
        finally:
759
704
            TestCaseInTempDir.TEST_ROOT = old_root
760
705
 
761
 
    def test_accepts_and_uses_pb_parameter(self):
762
 
        test = TestRunner('dummy_test')
763
 
        mypb = MockProgress()
764
 
        self.assertEqual([], mypb.calls)
765
 
        runner = TextTestRunner(stream=self._log_file, pb=mypb)
766
 
        result = self.run_test_runner(runner, test)
767
 
        self.assertEqual(1, result.testsRun)
768
 
        self.assertEqual(('update', 'Running tests', 0, 1), mypb.calls[0])
769
 
        self.assertEqual(('update', '...dummy_test', 0, None), mypb.calls[1])
770
 
        self.assertEqual(('update', 'OK           ', 1, None), mypb.calls[2])
771
 
        self.assertEqual(('update', 'Cleaning up', 0, 1), mypb.calls[3])
772
 
        self.assertEqual(('clear',), mypb.calls[4])
773
 
        self.assertEqual(5, len(mypb.calls))
774
 
 
775
706
    def test_skipped_test(self):
776
707
        # run a test that is skipped, and check the suite as a whole still
777
708
        # succeeds.
872
803
        # the outer child test
873
804
        note("outer_start")
874
805
        self.inner_test = TestTestCase("inner_child")
875
 
        result = bzrlib.tests._MyResult(self._log_file,
 
806
        result = bzrlib.tests.TextTestResult(self._log_file,
876
807
                                        descriptions=0,
877
808
                                        verbosity=1)
878
809
        self.inner_test.run(result)
892
823
        # the outer child test
893
824
        original_trace = bzrlib.trace._trace_file
894
825
        outer_test = TestTestCase("outer_child")
895
 
        result = bzrlib.tests._MyResult(self._log_file,
 
826
        result = bzrlib.tests.TextTestResult(self._log_file,
896
827
                                        descriptions=0,
897
828
                                        verbosity=1)
898
829
        outer_test.run(result)
907
838
        """Test that the TestCase.time() method accumulates a benchmark time."""
908
839
        sample_test = TestTestCase("method_that_times_a_bit_twice")
909
840
        output_stream = StringIO()
910
 
        result = bzrlib.tests._MyResult(
 
841
        result = bzrlib.tests.VerboseTestResult(
911
842
            unittest._WritelnDecorator(output_stream),
912
843
            descriptions=0,
913
 
            verbosity=2)
 
844
            verbosity=2,
 
845
            num_tests=sample_test.countTestCases())
914
846
        sample_test.run(result)
915
847
        self.assertContainsRe(
916
848
            output_stream.getvalue(),
917
 
            "[1-9][0-9]ms/   [1-9][0-9]ms\n$")
 
849
            r"\d+ms/ +\d+ms\n$")
918
850
        
919
851
    def test__gather_lsprof_in_benchmarks(self):
920
852
        """When _gather_lsprof_in_benchmarks is on, accumulate profile data.