/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

Support user.signingkey configuration variable in .git/config.

Merged from https://code.launchpad.net/~jelmer/brz/local-git-key/+merge/381000

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