/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 breezy/tests/test_selftest.py

  • Committer: Jelmer Vernooij
  • Date: 2020-02-07 02:14:30 UTC
  • mto: This revision was merged to the branch mainline in revision 7492.
  • Revision ID: jelmer@jelmer.uk-20200207021430-m49iq3x4x8xlib6x
Drop python2 support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import gc
20
20
import doctest
21
21
from functools import reduce
22
 
from io import BytesIO, TextIOWrapper
 
22
from io import BytesIO, StringIO, TextIOWrapper
23
23
import os
24
24
import signal
25
25
import sys
67
67
from ..git import (
68
68
    workingtree as git_workingtree,
69
69
    )
70
 
from ..sixish import (
71
 
    PY3,
72
 
    StringIO,
73
 
    text_type,
74
 
    )
75
70
from ..symbol_versioning import (
76
71
    deprecated_function,
77
72
    deprecated_in,
809
804
 
810
805
        This is used to exercise the test framework.
811
806
        """
812
 
        self.time(text_type, b'hello', errors='replace')
813
 
        self.time(text_type, b'world', errors='replace')
 
807
        self.time(str, b'hello', errors='replace')
 
808
        self.time(str, b'world', errors='replace')
814
809
 
815
810
    def test_lsprofiling(self):
816
811
        """Verbose test result prints lsprof statistics from test cases."""
840
835
        # and then repeated but with 'world', rather than 'hello'.
841
836
        # this should appear in the output stream of our test result.
842
837
        output = result_stream.getvalue()
843
 
        if PY3:
844
 
            self.assertContainsRe(output,
845
 
                                  r"LSProf output for <class 'str'>\(\(b'hello',\), {'errors': 'replace'}\)")
846
 
            self.assertContainsRe(output,
847
 
                                  r"LSProf output for <class 'str'>\(\(b'world',\), {'errors': 'replace'}\)")
848
 
        else:
849
 
            self.assertContainsRe(output,
850
 
                                  r"LSProf output for <type 'unicode'>\(\('hello',\), {'errors': 'replace'}\)")
851
 
            self.assertContainsRe(output,
852
 
                                  r"LSProf output for <type 'unicode'>\(\('world',\), {'errors': 'replace'}\)\n")
 
838
        self.assertContainsRe(output,
 
839
                              r"LSProf output for <class 'str'>\(\(b'hello',\), {'errors': 'replace'}\)")
 
840
        self.assertContainsRe(output,
 
841
                              r"LSProf output for <class 'str'>\(\(b'world',\), {'errors': 'replace'}\)")
853
842
        self.assertContainsRe(output,
854
843
                              r" *CallCount *Recursive *Total\(ms\) *Inline\(ms\) *module:lineno\(function\)\n")
855
844
        self.assertContainsRe(output,
1305
1294
            def test_log_unicode(self):
1306
1295
                self.log(u"\u2606")
1307
1296
                self.fail("Now print that log!")
1308
 
        if PY3:
1309
 
            bio = BytesIO()
1310
 
            out = TextIOWrapper(bio, 'ascii', 'backslashreplace')
1311
 
        else:
1312
 
            bio = out = StringIO()
 
1297
        bio = BytesIO()
 
1298
        out = TextIOWrapper(bio, 'ascii', 'backslashreplace')
1313
1299
        self.overrideAttr(osutils, "get_terminal_encoding",
1314
1300
                          lambda trace=False: "ascii")
1315
1301
        self.run_test_runner(
1982
1968
 
1983
1969
    def test_assert_isinstance(self):
1984
1970
        self.assertIsInstance(2, int)
1985
 
        self.assertIsInstance(u'', (str, text_type))
 
1971
        self.assertIsInstance(u'', str)
1986
1972
        e = self.assertRaises(AssertionError, self.assertIsInstance, None, int)
1987
1973
        self.assertIn(
1988
1974
            str(e),
1994
1980
        e = self.assertRaises(AssertionError,
1995
1981
                              self.assertIsInstance, None, int,
1996
1982
                              "it's just not")
1997
 
        if PY3:
1998
 
            self.assertEqual(
1999
 
                str(e),
2000
 
                "None is an instance of <class 'NoneType'> rather "
2001
 
                "than <class 'int'>: it's just not")
2002
 
        else:
2003
 
            self.assertEqual(
2004
 
                str(e),
2005
 
                "None is an instance of <type 'NoneType'> "
2006
 
                "rather than <type 'int'>: it's just not")
 
1983
        self.assertEqual(
 
1984
            str(e),
 
1985
            "None is an instance of <class 'NoneType'> rather "
 
1986
            "than <class 'int'>: it's just not")
2007
1987
 
2008
1988
    def test_assertEndsWith(self):
2009
1989
        self.assertEndsWith('foo', 'oo')
2129
2109
 
2130
2110
    def run_selftest(self, **kwargs):
2131
2111
        """Run selftest returning its output."""
2132
 
        if PY3:
2133
 
            bio = BytesIO()
2134
 
            output = TextIOWrapper(bio, 'utf-8')
2135
 
        else:
2136
 
            bio = output = StringIO()
 
2112
        bio = BytesIO()
 
2113
        output = TextIOWrapper(bio, 'utf-8')
2137
2114
        old_transport = breezy.tests.default_transport
2138
2115
        old_root = tests.TestCaseWithMemoryTransport.TEST_ROOT
2139
2116
        tests.TestCaseWithMemoryTransport.TEST_ROOT = None
2142
2119
        finally:
2143
2120
            breezy.tests.default_transport = old_transport
2144
2121
            tests.TestCaseWithMemoryTransport.TEST_ROOT = old_root
2145
 
        if PY3:
2146
 
            output.flush()
2147
 
            output.detach()
 
2122
        output.flush()
 
2123
        output.detach()
2148
2124
        bio.seek(0)
2149
2125
        return bio
2150
2126
 
3155
3131
            # plugins can't be tested that way since selftest may be run with
3156
3132
            # --no-plugins
3157
3133
            ]
3158
 
        if __doc__ is not None and not PY3:
3159
 
            expected_test_list.extend([
3160
 
                # modules_to_doctest
3161
 
                'breezy.timestamp.format_highres_date',
3162
 
                ])
3163
3134
        suite = tests.test_suite()
3164
 
        if PY3:
3165
 
            self.assertEqual({"testmod_names"}, set(calls))
3166
 
        else:
3167
 
            self.assertEqual({"testmod_names", "modules_to_doctest"},
3168
 
                             set(calls))
 
3135
        self.assertEqual({"testmod_names", "modules_to_doctest"}, set(calls))
3169
3136
        self.assertSubset(expected_test_list, _test_ids(suite))
3170
3137
 
3171
3138
    def test_test_suite_list_and_start(self):
3497
3464
        """To be overridden by subclasses that run tests out of process"""
3498
3465
 
3499
3466
    def _run_selftest(self, **kwargs):
3500
 
        if PY3:
3501
 
            bio = BytesIO()
3502
 
            sio = TextIOWrapper(bio, 'utf-8')
3503
 
        else:
3504
 
            sio = bio = StringIO()
 
3467
        bio = BytesIO()
 
3468
        sio = TextIOWrapper(bio, 'utf-8')
3505
3469
        self._inject_stream_into_subunit(bio)
3506
3470
        tests.selftest(stream=sio, stop_on_failure=False, **kwargs)
3507
3471
        sio.flush()