21
21
from functools import reduce
22
from io import BytesIO, TextIOWrapper
22
from io import BytesIO, StringIO, TextIOWrapper
810
805
This is used to exercise the test framework.
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')
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()
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'}\)")
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!")
1310
out = TextIOWrapper(bio, 'ascii', 'backslashreplace')
1312
bio = out = StringIO()
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(
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)
1994
1980
e = self.assertRaises(AssertionError,
1995
1981
self.assertIsInstance, None, int,
1996
1982
"it's just not")
2000
"None is an instance of <class 'NoneType'> rather "
2001
"than <class 'int'>: it's just not")
2005
"None is an instance of <type 'NoneType'> "
2006
"rather than <type 'int'>: it's just not")
1985
"None is an instance of <class 'NoneType'> rather "
1986
"than <class 'int'>: it's just not")
2008
1988
def test_assertEndsWith(self):
2009
1989
self.assertEndsWith('foo', 'oo')
2130
2110
def run_selftest(self, **kwargs):
2131
2111
"""Run selftest returning its output."""
2134
output = TextIOWrapper(bio, 'utf-8')
2136
bio = output = StringIO()
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
3155
3131
# plugins can't be tested that way since selftest may be run with
3158
if __doc__ is not None and not PY3:
3159
expected_test_list.extend([
3160
# modules_to_doctest
3161
'breezy.timestamp.format_highres_date',
3163
3134
suite = tests.test_suite()
3165
self.assertEqual({"testmod_names"}, set(calls))
3167
self.assertEqual({"testmod_names", "modules_to_doctest"},
3135
self.assertEqual({"testmod_names", "modules_to_doctest"}, set(calls))
3169
3136
self.assertSubset(expected_test_list, _test_ids(suite))
3171
3138
def test_test_suite_list_and_start(self):
3497
3464
"""To be overridden by subclasses that run tests out of process"""
3499
3466
def _run_selftest(self, **kwargs):
3502
sio = TextIOWrapper(bio, 'utf-8')
3504
sio = bio = StringIO()
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)