21
21
from functools import reduce
22
from io import BytesIO, TextIOWrapper
22
from io import BytesIO, StringIO, TextIOWrapper
546
541
self.assertIsSameRealPath(self.test_home_dir, os.environ['HOME'])
548
543
def test_assertEqualStat_equal(self):
549
from .test_dirstate import _FakeStat
544
from ..bzr.tests.test_dirstate import _FakeStat
550
545
self.build_tree(["foo"])
551
546
real = os.lstat("foo")
552
547
fake = _FakeStat(real.st_size, real.st_mtime, real.st_ctime,
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(
1603
1589
self.assertEqual([], result.failures)
1605
1591
def test_run_disabled_unittest_result(self):
1606
"""Test our compatability for disabled tests with unittest results."""
1592
"""Test our compatibility for disabled tests with unittest results."""
1607
1593
test = SampleTestCase('_test_pass')
1609
1595
class DisabledFeature(object):
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
2881
2857
def test_preserve_input(self):
2882
2858
# NB: Surely this is something in the stdlib to do this?
2883
self.assertTrue(self.suite is tests.preserve_input(self.suite))
2884
self.assertTrue("@#$" is tests.preserve_input("@#$"))
2859
self.assertIs(self.suite, tests.preserve_input(self.suite))
2860
self.assertEqual("@#$", tests.preserve_input("@#$"))
2886
2862
def test_randomize_suite(self):
2887
2863
randomized_suite = tests.randomize_suite(self.suite)
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):
3295
3262
def test_resolve_unknown_alias(self):
3296
3263
tpr = self._get_registry()
3297
self.assertRaises(errors.BzrCommandError,
3264
self.assertRaises(errors.CommandError,
3298
3265
tpr.resolve_alias, 'I am not a prefix')
3300
3267
def test_predefined_prefixes(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)