~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: 2009-08-04 05:20:54 UTC
  • mfrom: (4580.3.11 selftest)
  • Revision ID: pqm@pqm.ubuntu.com-20090804052054-yd271soudff1dbgt
(mbp) fix selftest progress and error display problems

Show diffs side-by-side

added added

removed removed

Lines of Context:
681
681
        self.assertEqual(url, t.clone('..').base)
682
682
 
683
683
 
684
 
class MockProgress(progress._BaseProgressBar):
685
 
    """Progress-bar standin that records calls.
686
 
 
687
 
    Useful for testing pb using code.
688
 
    """
689
 
 
690
 
    def __init__(self):
691
 
        progress._BaseProgressBar.__init__(self)
692
 
        self.calls = []
693
 
 
694
 
    def tick(self):
695
 
        self.calls.append(('tick',))
696
 
 
697
 
    def update(self, msg=None, current=None, total=None):
698
 
        self.calls.append(('update', msg, current, total))
699
 
 
700
 
    def clear(self):
701
 
        self.calls.append(('clear',))
702
 
 
703
 
    def note(self, msg, *args):
704
 
        self.calls.append(('note', msg, args))
705
 
 
706
 
 
707
684
class TestTestResult(tests.TestCase):
708
685
 
709
686
    def check_timing(self, test_case, expected_re):
862
839
        self.assertEqual(lines[1], '    foo')
863
840
        self.assertEqual(2, len(lines))
864
841
 
865
 
    def test_text_report_known_failure(self):
866
 
        # text test output formatting
867
 
        pb = MockProgress()
868
 
        result = bzrlib.tests.TextTestResult(
869
 
            StringIO(),
870
 
            descriptions=0,
871
 
            verbosity=1,
872
 
            pb=pb,
873
 
            )
874
 
        test = self.get_passing_test()
875
 
        # this seeds the state to handle reporting the test.
876
 
        result.startTest(test)
877
 
        # the err parameter has the shape:
878
 
        # (class, exception object, traceback)
879
 
        # KnownFailures dont get their tracebacks shown though, so we
880
 
        # can skip that.
881
 
        err = (tests.KnownFailure, tests.KnownFailure('foo'), None)
882
 
        result.report_known_failure(test, err)
883
 
        self.assertEqual(
884
 
            [
885
 
            ('update', '[1 in 0s] passing_test', None, None),
886
 
            ('note', 'XFAIL: %s\n%s\n', ('passing_test', err[1]))
887
 
            ],
888
 
            pb.calls)
889
 
        # known_failures should be printed in the summary, so if we run a test
890
 
        # after there are some known failures, the update prefix should match
891
 
        # this.
892
 
        result.known_failure_count = 3
893
 
        test.run(result)
894
 
        self.assertEqual(
895
 
            [
896
 
            ('update', '[2 in 0s] passing_test', None, None),
897
 
            ],
898
 
            pb.calls[2:])
899
 
 
900
842
    def get_passing_test(self):
901
843
        """Return a test object that can't be run usefully."""
902
844
        def passing_test():
947
889
        self.assertEqual(lines, ['NODEP        0ms',
948
890
                                 "    The feature 'Feature' is not available."])
949
891
 
950
 
    def test_text_report_unsupported(self):
951
 
        # text test output formatting
952
 
        pb = MockProgress()
953
 
        result = bzrlib.tests.TextTestResult(
954
 
            StringIO(),
955
 
            descriptions=0,
956
 
            verbosity=1,
957
 
            pb=pb,
958
 
            )
959
 
        test = self.get_passing_test()
960
 
        feature = tests.Feature()
961
 
        # this seeds the state to handle reporting the test.
962
 
        result.startTest(test)
963
 
        result.report_unsupported(test, feature)
964
 
        # no output on unsupported features
965
 
        self.assertEqual(
966
 
            [('update', '[1 in 0s] passing_test', None, None)
967
 
            ],
968
 
            pb.calls)
969
 
        # the number of missing features should be printed in the progress
970
 
        # summary, so check for that.
971
 
        result.unsupported = {'foo':0, 'bar':0}
972
 
        test.run(result)
973
 
        self.assertEqual(
974
 
            [
975
 
            ('update', '[2 in 0s, 2 missing] passing_test', None, None),
976
 
            ],
977
 
            pb.calls[1:])
978
 
 
979
892
    def test_unavailable_exception(self):
980
893
        """An UnavailableFeature being raised should invoke addNotSupported."""
981
894
        class InstrumentedTestResult(tests.ExtendedTestResult):