/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

  • Committer: John Arbash Meinel
  • Date: 2009-08-04 14:10:09 UTC
  • mfrom: (4585 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4588.
  • Revision ID: john@arbash-meinel.com-20090804141009-uety2n17v1atk5ok
Merge bzr.dev 4585, resolve NEWS

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):
723
700
                self.time(time.sleep, 0.003)
724
701
        self.check_timing(ShortDelayTestCase('test_short_delay'),
725
702
                          r"^ +[0-9]+ms$")
726
 
        # if a benchmark time is given, we want a x of y style result.
 
703
        # if a benchmark time is given, we now show just that time followed by
 
704
        # a star
727
705
        self.check_timing(ShortDelayTestCase('test_short_benchmark'),
728
 
                          r"^ +[0-9]+ms/ +[0-9]+ms$")
 
706
                          r"^ +[0-9]+ms\*$")
729
707
 
730
708
    def test_unittest_reporting_unittest_class(self):
731
709
        # getting the time from a non-bzrlib test works ok
861
839
        self.assertEqual(lines[1], '    foo')
862
840
        self.assertEqual(2, len(lines))
863
841
 
864
 
    def test_text_report_known_failure(self):
865
 
        # text test output formatting
866
 
        pb = MockProgress()
867
 
        result = bzrlib.tests.TextTestResult(
868
 
            StringIO(),
869
 
            descriptions=0,
870
 
            verbosity=1,
871
 
            pb=pb,
872
 
            )
873
 
        test = self.get_passing_test()
874
 
        # this seeds the state to handle reporting the test.
875
 
        result.startTest(test)
876
 
        # the err parameter has the shape:
877
 
        # (class, exception object, traceback)
878
 
        # KnownFailures dont get their tracebacks shown though, so we
879
 
        # can skip that.
880
 
        err = (tests.KnownFailure, tests.KnownFailure('foo'), None)
881
 
        result.report_known_failure(test, err)
882
 
        self.assertEqual(
883
 
            [
884
 
            ('update', '[1 in 0s] passing_test', None, None),
885
 
            ('note', 'XFAIL: %s\n%s\n', ('passing_test', err[1]))
886
 
            ],
887
 
            pb.calls)
888
 
        # known_failures should be printed in the summary, so if we run a test
889
 
        # after there are some known failures, the update prefix should match
890
 
        # this.
891
 
        result.known_failure_count = 3
892
 
        test.run(result)
893
 
        self.assertEqual(
894
 
            [
895
 
            ('update', '[2 in 0s] passing_test', None, None),
896
 
            ],
897
 
            pb.calls[2:])
898
 
 
899
842
    def get_passing_test(self):
900
843
        """Return a test object that can't be run usefully."""
901
844
        def passing_test():
943
886
        result.report_unsupported(test, feature)
944
887
        output = result_stream.getvalue()[prefix:]
945
888
        lines = output.splitlines()
946
 
        self.assertEqual(lines, ['NODEP                   0ms',
 
889
        self.assertEqual(lines, ['NODEP        0ms',
947
890
                                 "    The feature 'Feature' is not available."])
948
891
 
949
 
    def test_text_report_unsupported(self):
950
 
        # text test output formatting
951
 
        pb = MockProgress()
952
 
        result = bzrlib.tests.TextTestResult(
953
 
            StringIO(),
954
 
            descriptions=0,
955
 
            verbosity=1,
956
 
            pb=pb,
957
 
            )
958
 
        test = self.get_passing_test()
959
 
        feature = tests.Feature()
960
 
        # this seeds the state to handle reporting the test.
961
 
        result.startTest(test)
962
 
        result.report_unsupported(test, feature)
963
 
        # no output on unsupported features
964
 
        self.assertEqual(
965
 
            [('update', '[1 in 0s] passing_test', None, None)
966
 
            ],
967
 
            pb.calls)
968
 
        # the number of missing features should be printed in the progress
969
 
        # summary, so check for that.
970
 
        result.unsupported = {'foo':0, 'bar':0}
971
 
        test.run(result)
972
 
        self.assertEqual(
973
 
            [
974
 
            ('update', '[2 in 0s, 2 missing] passing_test', None, None),
975
 
            ],
976
 
            pb.calls[1:])
977
 
 
978
892
    def test_unavailable_exception(self):
979
893
        """An UnavailableFeature being raised should invoke addNotSupported."""
980
894
        class InstrumentedTestResult(tests.ExtendedTestResult):
1485
1399
        result = bzrlib.tests.VerboseTestResult(
1486
1400
            unittest._WritelnDecorator(output_stream),
1487
1401
            descriptions=0,
1488
 
            verbosity=2,
1489
 
            num_tests=sample_test.countTestCases())
 
1402
            verbosity=2)
1490
1403
        sample_test.run(result)
1491
1404
        self.assertContainsRe(
1492
1405
            output_stream.getvalue(),
1493
 
            r"\d+ms/ +\d+ms\n$")
 
1406
            r"\d+ms\*\n$")
1494
1407
 
1495
1408
    def test_hooks_sanitised(self):
1496
1409
        """The bzrlib hooks should be sanitised by setUp."""
1686
1599
    def test_assert_isinstance(self):
1687
1600
        self.assertIsInstance(2, int)
1688
1601
        self.assertIsInstance(u'', basestring)
1689
 
        self.assertRaises(AssertionError, self.assertIsInstance, None, int)
 
1602
        e = self.assertRaises(AssertionError, self.assertIsInstance, None, int)
 
1603
        self.assertEquals(str(e),
 
1604
            "None is an instance of <type 'NoneType'> rather than <type 'int'>")
1690
1605
        self.assertRaises(AssertionError, self.assertIsInstance, 23.3, int)
 
1606
        e = self.assertRaises(AssertionError,
 
1607
            self.assertIsInstance, None, int, "it's just not")
 
1608
        self.assertEquals(str(e),
 
1609
            "None is an instance of <type 'NoneType'> rather than <type 'int'>"
 
1610
            ": it's just not")
1691
1611
 
1692
1612
    def test_assertEndsWith(self):
1693
1613
        self.assertEndsWith('foo', 'oo')
2360
2280
                return tests.ExtendedTestResult(self.stream, self.descriptions,
2361
2281
                                                self.verbosity)
2362
2282
        tests.run_suite(suite, runner_class=MyRunner, stream=StringIO())
2363
 
        self.assertEqual(calls, [suite])
 
2283
        self.assertLength(1, calls)
2364
2284
 
2365
2285
    def test_done(self):
2366
2286
        """run_suite should call result.done()"""