21
21
from functools import reduce
22
from io import BytesIO, StringIO, TextIOWrapper
22
from io import BytesIO, TextIOWrapper
541
546
self.assertIsSameRealPath(self.test_home_dir, os.environ['HOME'])
543
548
def test_assertEqualStat_equal(self):
544
from ..bzr.tests.test_dirstate import _FakeStat
549
from .test_dirstate import _FakeStat
545
550
self.build_tree(["foo"])
546
551
real = os.lstat("foo")
547
552
fake = _FakeStat(real.st_size, real.st_mtime, real.st_ctime,
805
810
This is used to exercise the test framework.
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')
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'}\)")
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")
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!")
1298
out = TextIOWrapper(bio, 'ascii', 'backslashreplace')
1310
out = TextIOWrapper(bio, 'ascii', 'backslashreplace')
1312
bio = out = StringIO()
1299
1313
self.overrideAttr(osutils, "get_terminal_encoding",
1300
1314
lambda trace=False: "ascii")
1301
1315
self.run_test_runner(
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)
1980
1994
e = self.assertRaises(AssertionError,
1981
1995
self.assertIsInstance, None, int,
1982
1996
"it's just not")
1985
"None is an instance of <class 'NoneType'> rather "
1986
"than <class 'int'>: 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")
1988
2008
def test_assertEndsWith(self):
1989
2009
self.assertEndsWith('foo', 'oo')
2110
2130
def run_selftest(self, **kwargs):
2111
2131
"""Run selftest returning its output."""
2113
output = TextIOWrapper(bio, 'utf-8')
2134
output = TextIOWrapper(bio, 'utf-8')
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
3131
3155
# 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',
3134
3163
suite = tests.test_suite()
3135
self.assertEqual({"testmod_names", "modules_to_doctest"}, set(calls))
3165
self.assertEqual({"testmod_names"}, set(calls))
3167
self.assertEqual({"testmod_names", "modules_to_doctest"},
3136
3169
self.assertSubset(expected_test_list, _test_ids(suite))
3138
3171
def test_test_suite_list_and_start(self):
3262
3295
def test_resolve_unknown_alias(self):
3263
3296
tpr = self._get_registry()
3264
self.assertRaises(errors.CommandError,
3297
self.assertRaises(errors.BzrCommandError,
3265
3298
tpr.resolve_alias, 'I am not a prefix')
3267
3300
def test_predefined_prefixes(self):
3464
3497
"""To be overridden by subclasses that run tests out of process"""
3466
3499
def _run_selftest(self, **kwargs):
3468
sio = TextIOWrapper(bio, 'utf-8')
3502
sio = TextIOWrapper(bio, 'utf-8')
3504
sio = bio = StringIO()
3469
3505
self._inject_stream_into_subunit(bio)
3470
3506
tests.selftest(stream=sio, stop_on_failure=False, **kwargs)