/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: 2017-05-22 00:56:52 UTC
  • mfrom: (6621.2.26 py3_pokes)
  • Revision ID: jelmer@jelmer.uk-20170522005652-yjahcr9hwmjkno7n
Merge Python3 porting work ('py3 pokes')

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for the test framework."""
18
18
 
19
 
from cStringIO import StringIO
20
19
import gc
21
20
import doctest
22
21
import os
40
39
import testtools.testresult.doubles
41
40
 
42
41
import breezy
43
 
from breezy import (
 
42
from .. import (
44
43
    branchbuilder,
45
44
    bzrdir,
46
45
    controldir,
58
57
    workingtree_3,
59
58
    workingtree_4,
60
59
    )
61
 
from breezy.repofmt import (
 
60
from ..repofmt import (
62
61
    groupcompress_repo,
63
62
    )
64
 
from breezy.symbol_versioning import (
 
63
from ..sixish import (
 
64
    BytesIO,
 
65
    )
 
66
from ..symbol_versioning import (
65
67
    deprecated_function,
66
68
    deprecated_in,
67
69
    deprecated_method,
68
70
    )
69
 
from breezy.tests import (
 
71
from . import (
70
72
    features,
71
73
    test_lsprof,
72
74
    test_server,
73
75
    TestUtil,
74
76
    )
75
 
from breezy.trace import note, mutter
76
 
from breezy.transport import memory
 
77
from ..trace import note, mutter
 
78
from ..transport import memory
77
79
 
78
80
 
79
81
def _test_ids(test_suite):
109
111
    """As a convenience we expose Test* classes from breezy.tests"""
110
112
 
111
113
    def test_test_case(self):
112
 
        from breezy.tests import TestCase
 
114
        from . import TestCase
113
115
 
114
116
    def test_test_loader(self):
115
 
        from breezy.tests import TestLoader
 
117
        from . import TestLoader
116
118
 
117
119
    def test_test_suite(self):
118
 
        from breezy.tests import TestSuite
 
120
        from . import TestSuite
119
121
 
120
122
 
121
123
class TestTransportScenarios(tests.TestCase):
135
137
            def get_test_permutations(self):
136
138
                return sample_permutation
137
139
        sample_permutation = [(1,2), (3,4)]
138
 
        from breezy.tests.per_transport import get_transport_test_permutations
 
140
        from .per_transport import get_transport_test_permutations
139
141
        self.assertEqual(sample_permutation,
140
142
                         get_transport_test_permutations(MockModule()))
141
143
 
144
146
        # as there are in all the registered transport modules - we assume if
145
147
        # this matches its probably doing the right thing especially in
146
148
        # combination with the tests for setting the right classes below.
147
 
        from breezy.tests.per_transport import transport_test_permutations
148
 
        from breezy.transport import _get_transport_modules
 
149
        from .per_transport import transport_test_permutations
 
150
        from ..transport import _get_transport_modules
149
151
        modules = _get_transport_modules()
150
152
        permutation_count = 0
151
153
        for module in modules:
162
164
        # This test used to know about all the possible transports and the
163
165
        # order they were returned but that seems overly brittle (mbp
164
166
        # 20060307)
165
 
        from breezy.tests.per_transport import transport_test_permutations
 
167
        from .per_transport import transport_test_permutations
166
168
        scenarios = transport_test_permutations()
167
169
        # there are at least that many builtin transports
168
170
        self.assertTrue(len(scenarios) > 6)
179
181
    def test_scenarios(self):
180
182
        # check that constructor parameters are passed through to the adapted
181
183
        # test.
182
 
        from breezy.tests.per_branch import make_scenarios
 
184
        from .per_branch import make_scenarios
183
185
        server1 = "a"
184
186
        server2 = "b"
185
187
        formats = [("c", "C"), ("d", "D")]
204
206
    def test_scenarios(self):
205
207
        # check that constructor parameters are passed through to the adapted
206
208
        # test.
207
 
        from breezy.tests.per_controldir import make_scenarios
 
209
        from .per_controldir import make_scenarios
208
210
        vfs_factory = "v"
209
211
        server1 = "a"
210
212
        server2 = "b"
227
229
class TestRepositoryScenarios(tests.TestCase):
228
230
 
229
231
    def test_formats_to_scenarios(self):
230
 
        from breezy.tests.per_repository import formats_to_scenarios
 
232
        from .per_repository import formats_to_scenarios
231
233
        formats = [("(c)", remote.RemoteRepositoryFormat()),
232
234
                   ("(d)", repository.format_registry.get(
233
235
                    'Bazaar repository format 2a (needs bzr 1.16 or later)\n'))]
305
307
    def test_scenarios(self):
306
308
        # check that constructor parameters are passed through to the adapted
307
309
        # test.
308
 
        from breezy.tests.per_interrepository import make_scenarios
 
310
        from .per_interrepository import make_scenarios
309
311
        server1 = "a"
310
312
        server2 = "b"
311
313
        formats = [("C0", "C1", "C2", "C3"), ("D0", "D1", "D2", "D3")]
331
333
    def test_scenarios(self):
332
334
        # check that constructor parameters are passed through to the adapted
333
335
        # test.
334
 
        from breezy.tests.per_workingtree import make_scenarios
 
336
        from .per_workingtree import make_scenarios
335
337
        server1 = "a"
336
338
        server2 = "b"
337
339
        formats = [workingtree_4.WorkingTreeFormat4(),
378
380
        # 'return_parameter' and the revision one set to
379
381
        # revision_tree_from_workingtree.
380
382
 
381
 
        from breezy.tests.per_tree import (
 
383
        from .per_tree import (
382
384
            _dirstate_tree_from_workingtree,
383
385
            make_scenarios,
384
386
            preview_tree_pre,
473
475
        # unlike the TestProviderAdapter we dont want to automatically add a
474
476
        # parameterized one for WorkingTree - the optimisers will tell us what
475
477
        # ones to add.
476
 
        from breezy.tests.per_tree import (
 
478
        from .per_tree import (
477
479
            return_parameter,
478
480
            )
479
 
        from breezy.tests.per_intertree import (
 
481
        from .per_intertree import (
480
482
            make_scenarios,
481
483
            )
482
 
        from breezy.workingtree_3 import WorkingTreeFormat3
483
 
        from breezy.workingtree_4 import WorkingTreeFormat4
 
484
        from ..workingtree_3 import WorkingTreeFormat3
 
485
        from ..workingtree_4 import WorkingTreeFormat4
484
486
        input_test = TestInterTreeScenarios(
485
487
            "test_scenarios")
486
488
        server1 = "a"
525
527
        self.assertIsSameRealPath(self.test_home_dir, os.environ['HOME'])
526
528
 
527
529
    def test_assertEqualStat_equal(self):
528
 
        from breezy.tests.test_dirstate import _FakeStat
 
530
        from .test_dirstate import _FakeStat
529
531
        self.build_tree(["foo"])
530
532
        real = os.lstat("foo")
531
533
        fake = _FakeStat(real.st_size, real.st_mtime, real.st_ctime,
669
671
    """Tests for the convenience functions TestCaseWithTransport introduces."""
670
672
 
671
673
    def test_get_readonly_url_none(self):
672
 
        from breezy.transport.readonly import ReadonlyTransportDecorator
 
674
        from ..transport.readonly import ReadonlyTransportDecorator
673
675
        self.vfs_transport_factory = memory.MemoryServer
674
676
        self.transport_readonly_server = None
675
677
        # calling get_readonly_transport() constructs a decorator on the url
683
685
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
684
686
 
685
687
    def test_get_readonly_url_http(self):
686
 
        from breezy.tests.http_server import HttpServer
687
 
        from breezy.transport.http import HttpTransportBase
 
688
        from ..http_server import HttpServer
 
689
        from ..transport.http import HttpTransportBase
688
690
        self.transport_server = test_server.LocalURLServer
689
691
        self.transport_readonly_server = HttpServer
690
692
        # calling get_readonly_transport() gives us a HTTP server instance.
806
808
    def test_lsprofiling(self):
807
809
        """Verbose test result prints lsprof statistics from test cases."""
808
810
        self.requireFeature(features.lsprof_feature)
809
 
        result_stream = StringIO()
 
811
        result_stream = BytesIO()
810
812
        result = breezy.tests.VerboseTestResult(
811
813
            result_stream,
812
814
            descriptions=0,
851
853
                self.time(datetime.datetime.utcfromtimestamp(51.147))
852
854
                super(TimeAddedVerboseTestResult, self).addSuccess(test)
853
855
            def report_tests_starting(self): pass
854
 
        sio = StringIO()
 
856
        sio = BytesIO()
855
857
        self.get_passing_test().run(TimeAddedVerboseTestResult(sio, 0, 2))
856
858
        self.assertEndsWith(sio.getvalue(), "OK    50002ms\n")
857
859
 
881
883
 
882
884
    def test_verbose_report_known_failure(self):
883
885
        # verbose test output formatting
884
 
        result_stream = StringIO()
 
886
        result_stream = BytesIO()
885
887
        result = breezy.tests.VerboseTestResult(
886
888
            result_stream,
887
889
            descriptions=0,
928
930
 
929
931
    def test_verbose_report_unsupported(self):
930
932
        # verbose test output formatting
931
 
        result_stream = StringIO()
 
933
        result_stream = BytesIO()
932
934
        result = breezy.tests.VerboseTestResult(
933
935
            result_stream,
934
936
            descriptions=0,
1051
1053
        def failing_test():
1052
1054
            raise AssertionError('foo')
1053
1055
        test.addTest(unittest.FunctionTestCase(failing_test))
1054
 
        stream = StringIO()
 
1056
        stream = BytesIO()
1055
1057
        runner = tests.TextTestRunner(stream=stream)
1056
1058
        result = self.run_test_runner(runner, test)
1057
1059
        lines = stream.getvalue().splitlines()
1077
1079
            def known_failure_test(self):
1078
1080
                self.knownFailure("Never works...")
1079
1081
        test = Test("known_failure_test")
1080
 
        stream = StringIO()
 
1082
        stream = BytesIO()
1081
1083
        runner = tests.TextTestRunner(stream=stream)
1082
1084
        result = self.run_test_runner(runner, test)
1083
1085
        self.assertContainsRe(stream.getvalue(),
1091
1093
        class Test(tests.TestCase):
1092
1094
            def test_truth(self):
1093
1095
                self.expectFailure("No absolute truth", self.assertTrue, True)
1094
 
        runner = tests.TextTestRunner(stream=StringIO())
 
1096
        runner = tests.TextTestRunner(stream=BytesIO())
1095
1097
        result = self.run_test_runner(runner, Test("test_truth"))
1096
1098
        self.assertContainsRe(runner.stream.getvalue(),
1097
1099
            "=+\n"
1116
1118
                ExtendedToOriginalDecorator.startTest(self, test)
1117
1119
                calls.append('start')
1118
1120
        test = unittest.FunctionTestCase(lambda:None)
1119
 
        stream = StringIO()
 
1121
        stream = BytesIO()
1120
1122
        runner = tests.TextTestRunner(stream=stream,
1121
1123
            result_decorators=[LoggingDecorator])
1122
1124
        result = self.run_test_runner(runner, test)
1183
1185
        class Test(tests.TestCase):
1184
1186
            def not_applicable_test(self):
1185
1187
                raise tests.TestNotApplicable('this test never runs')
1186
 
        out = StringIO()
 
1188
        out = BytesIO()
1187
1189
        runner = tests.TextTestRunner(stream=out, verbosity=2)
1188
1190
        test = Test("not_applicable_test")
1189
1191
        result = self.run_test_runner(runner, test)
1209
1211
        test = unittest.TestSuite()
1210
1212
        test.addTest(test1)
1211
1213
        test.addTest(test2)
1212
 
        stream = StringIO()
 
1214
        stream = BytesIO()
1213
1215
        runner = tests.TextTestRunner(stream=stream)
1214
1216
        result = self.run_test_runner(runner, test)
1215
1217
        lines = stream.getvalue().splitlines()
1226
1228
            unittest.FunctionTestCase(lambda:None),
1227
1229
            unittest.FunctionTestCase(lambda:None)])
1228
1230
        self.assertEqual(suite.countTestCases(), 2)
1229
 
        stream = StringIO()
 
1231
        stream = BytesIO()
1230
1232
        runner = tests.TextTestRunner(stream=stream, verbosity=2)
1231
1233
        # Need to use the CountingDecorator as that's what sets num_tests
1232
1234
        result = self.run_test_runner(runner, tests.CountingDecorator(suite))
1240
1242
                ExtendedToOriginalDecorator.startTestRun(self)
1241
1243
                calls.append('startTestRun')
1242
1244
        test = unittest.FunctionTestCase(lambda:None)
1243
 
        stream = StringIO()
 
1245
        stream = BytesIO()
1244
1246
        runner = tests.TextTestRunner(stream=stream,
1245
1247
            result_decorators=[LoggingDecorator])
1246
1248
        result = self.run_test_runner(runner, test)
1254
1256
                ExtendedToOriginalDecorator.stopTestRun(self)
1255
1257
                calls.append('stopTestRun')
1256
1258
        test = unittest.FunctionTestCase(lambda:None)
1257
 
        stream = StringIO()
 
1259
        stream = BytesIO()
1258
1260
        runner = tests.TextTestRunner(stream=stream,
1259
1261
            result_decorators=[LoggingDecorator])
1260
1262
        result = self.run_test_runner(runner, test)
1266
1268
            def test_log_unicode(self):
1267
1269
                self.log(u"\u2606")
1268
1270
                self.fail("Now print that log!")
1269
 
        out = StringIO()
 
1271
        out = BytesIO()
1270
1272
        self.overrideAttr(osutils, "get_terminal_encoding",
1271
1273
            lambda trace=False: "ascii")
1272
1274
        result = self.run_test_runner(tests.TextTestRunner(stream=out),
1353
1355
        """The -Eallow_debug flag prevents breezy.debug.debug_flags from being
1354
1356
        sanitised (i.e. cleared) before running a test.
1355
1357
        """
1356
 
        self.change_selftest_debug_flags(set(['allow_debug']))
1357
 
        breezy.debug.debug_flags = set(['a-flag'])
 
1358
        self.change_selftest_debug_flags({'allow_debug'})
 
1359
        breezy.debug.debug_flags = {'a-flag'}
1358
1360
        class TestThatRecordsFlags(tests.TestCase):
1359
1361
            def test_foo(nested_self):
1360
1362
                self.flags = set(breezy.debug.debug_flags)
1361
1363
        test = TestThatRecordsFlags('test_foo')
1362
1364
        test.run(self.make_test_result())
1363
 
        flags = set(['a-flag'])
 
1365
        flags = {'a-flag'}
1364
1366
        if 'disable_lock_checks' not in tests.selftest_debug_flags:
1365
1367
            flags.add('strict_locks')
1366
1368
        self.assertEqual(flags, self.flags)
1377
1379
        # By default we do strict lock checking and thorough lock/unlock
1378
1380
        # tracking.
1379
1381
        self.assertTrue(self.test_lock_check_thorough)
1380
 
        self.assertEqual(set(['strict_locks']), self.flags)
 
1382
        self.assertEqual({'strict_locks'}, self.flags)
1381
1383
        # Now set the disable_lock_checks flag, and show that this changed.
1382
 
        self.change_selftest_debug_flags(set(['disable_lock_checks']))
 
1384
        self.change_selftest_debug_flags({'disable_lock_checks'})
1383
1385
        test = TestThatRecordsFlags('test_foo')
1384
1386
        test.run(self.make_test_result())
1385
1387
        self.assertFalse(self.test_lock_check_thorough)
1395
1397
        self.change_selftest_debug_flags(set())
1396
1398
        test = TestThatRecordsFlags('test_foo')
1397
1399
        test.run(self.make_test_result())
1398
 
        self.assertEqual(set(['strict_locks']), self.flags1)
 
1400
        self.assertEqual({'strict_locks'}, self.flags1)
1399
1401
        self.assertEqual(set(), self.flags2)
1400
1402
 
1401
1403
    def test_debug_flags_restored(self):
1402
1404
        """The breezy debug flags should be restored to their original state
1403
1405
        after the test was run, even if allow_debug is set.
1404
1406
        """
1405
 
        self.change_selftest_debug_flags(set(['allow_debug']))
 
1407
        self.change_selftest_debug_flags({'allow_debug'})
1406
1408
        # Now run a test that modifies debug.debug_flags.
1407
 
        breezy.debug.debug_flags = set(['original-state'])
 
1409
        breezy.debug.debug_flags = {'original-state'}
1408
1410
        class TestThatModifiesFlags(tests.TestCase):
1409
1411
            def test_foo(self):
1410
 
                breezy.debug.debug_flags = set(['modified'])
 
1412
                breezy.debug.debug_flags = {'modified'}
1411
1413
        test = TestThatModifiesFlags('test_foo')
1412
1414
        test.run(self.make_test_result())
1413
 
        self.assertEqual(set(['original-state']), breezy.debug.debug_flags)
 
1415
        self.assertEqual({'original-state'}, breezy.debug.debug_flags)
1414
1416
 
1415
1417
    def make_test_result(self):
1416
1418
        """Get a test result that writes to the test log file."""
1455
1457
    def test_time_creates_benchmark_in_result(self):
1456
1458
        """Test that the TestCase.time() method accumulates a benchmark time."""
1457
1459
        sample_test = TestTestCase("method_that_times_a_bit_twice")
1458
 
        output_stream = StringIO()
 
1460
        output_stream = BytesIO()
1459
1461
        result = breezy.tests.VerboseTestResult(
1460
1462
            output_stream,
1461
1463
            descriptions=0,
2038
2040
 
2039
2041
    def run_selftest(self, **kwargs):
2040
2042
        """Run selftest returning its output."""
2041
 
        output = StringIO()
 
2043
        output = BytesIO()
2042
2044
        old_transport = breezy.tests.default_transport
2043
2045
        old_root = tests.TestCaseWithMemoryTransport.TEST_ROOT
2044
2046
        tests.TestCaseWithMemoryTransport.TEST_ROOT = None
2059
2061
        def factory():
2060
2062
            factory_called.append(True)
2061
2063
            return TestUtil.TestSuite()
2062
 
        out = StringIO()
2063
 
        err = StringIO()
 
2064
        out = BytesIO()
 
2065
        err = BytesIO()
2064
2066
        self.apply_redirected(out, err, None, breezy.tests.selftest,
2065
2067
            test_suite_factory=factory)
2066
2068
        self.assertEqual([True], factory_called)
2257
2259
        # GZ 2011-05-18: Old versions of subunit treat unexpected success as a
2258
2260
        #                success, if a min version check is added remove this
2259
2261
        from subunit import TestProtocolClient as _Client
2260
 
        if _Client.addUnexpectedSuccess.im_func is _Client.addSuccess.im_func:
 
2262
        if _Client.addUnexpectedSuccess.__func__ is _Client.addSuccess.__func__:
2261
2263
            self.expectFailure('subunit treats "unexpectedSuccess"'
2262
2264
                               ' as a plain success',
2263
2265
                self.assertEqual, 1, len(result.unexpectedSuccesses))
2384
2386
 
2385
2387
    def test_stdin(self):
2386
2388
        # test that the stdin keyword to _run_bzr_core is passed through to
2387
 
        # apply_redirected as a StringIO. We do this by overriding
 
2389
        # apply_redirected as a BytesIO. We do this by overriding
2388
2390
        # apply_redirected in this class, and then calling _run_bzr_core,
2389
2391
        # which calls apply_redirected.
2390
2392
        self.run_bzr(['foo', 'bar'], stdin='gam')
3052
3054
                'breezy.timestamp.format_highres_date',
3053
3055
                ])
3054
3056
        suite = tests.test_suite()
3055
 
        self.assertEqual(set(["testmod_names", "modules_to_doctest"]),
 
3057
        self.assertEqual({"testmod_names", "modules_to_doctest"},
3056
3058
            set(calls))
3057
3059
        self.assertSubset(expected_test_list, _test_ids(suite))
3058
3060
 
3200
3202
 
3201
3203
    class LeakRecordingResult(tests.ExtendedTestResult):
3202
3204
        def __init__(self):
3203
 
            tests.ExtendedTestResult.__init__(self, StringIO(), 0, 1)
 
3205
            tests.ExtendedTestResult.__init__(self, BytesIO(), 0, 1)
3204
3206
            self.leaks = []
3205
3207
        def _report_thread_leak(self, test, leaks, alive):
3206
3208
            self.leaks.append((test, leaks))
3240
3242
        result.stopTestRun()
3241
3243
        self.assertEqual(result._tests_leaking_threads_count, 1)
3242
3244
        self.assertEqual(result._first_thread_leaker_id, test.id())
3243
 
        self.assertEqual(result.leaks, [(test, set([thread]))])
 
3245
        self.assertEqual(result.leaks, [(test, {thread})])
3244
3246
        self.assertContainsString(result.stream.getvalue(), "leaking threads")
3245
3247
 
3246
3248
    def test_multiple_leaks(self):
3276
3278
        self.assertEqual(result._tests_leaking_threads_count, 2)
3277
3279
        self.assertEqual(result._first_thread_leaker_id, first_test.id())
3278
3280
        self.assertEqual(result.leaks, [
3279
 
            (first_test, set([thread_b])),
3280
 
            (third_test, set([thread_a, thread_c]))])
 
3281
            (first_test, {thread_b}),
 
3282
            (third_test, {thread_a, thread_c})])
3281
3283
        self.assertContainsString(result.stream.getvalue(), "leaking threads")
3282
3284
 
3283
3285
 
3286
3288
 
3287
3289
    class TracebackRecordingResult(tests.ExtendedTestResult):
3288
3290
        def __init__(self):
3289
 
            tests.ExtendedTestResult.__init__(self, StringIO(), 0, 1)
 
3291
            tests.ExtendedTestResult.__init__(self, BytesIO(), 0, 1)
3290
3292
            self.postcode = None
3291
3293
        def _post_mortem(self, tb=None):
3292
3294
            """Record the code object at the end of the current traceback"""
3309
3311
                raise RuntimeError
3310
3312
        result = self.TracebackRecordingResult()
3311
3313
        Test().run(result)
3312
 
        self.assertEqual(result.postcode, Test.runTest.func_code)
 
3314
        self.assertEqual(result.postcode, Test.runTest.__code__)
3313
3315
 
3314
3316
    def test_location_unittest_failure(self):
3315
3317
        """Needs right post mortem traceback with failing unittest case"""
3318
3320
                raise self.failureException
3319
3321
        result = self.TracebackRecordingResult()
3320
3322
        Test().run(result)
3321
 
        self.assertEqual(result.postcode, Test.runTest.func_code)
 
3323
        self.assertEqual(result.postcode, Test.runTest.__code__)
3322
3324
 
3323
3325
    def test_location_bt_error(self):
3324
3326
        """Needs right post mortem traceback with erroring breezy.tests case"""
3327
3329
                raise RuntimeError
3328
3330
        result = self.TracebackRecordingResult()
3329
3331
        Test("test_error").run(result)
3330
 
        self.assertEqual(result.postcode, Test.test_error.func_code)
 
3332
        self.assertEqual(result.postcode, Test.test_error.__code__)
3331
3333
 
3332
3334
    def test_location_bt_failure(self):
3333
3335
        """Needs right post mortem traceback with failing breezy.tests case"""
3336
3338
                raise self.failureException
3337
3339
        result = self.TracebackRecordingResult()
3338
3340
        Test("test_failure").run(result)
3339
 
        self.assertEqual(result.postcode, Test.test_failure.func_code)
 
3341
        self.assertEqual(result.postcode, Test.test_failure.__code__)
3340
3342
 
3341
3343
    def test_env_var_triggers_post_mortem(self):
3342
3344
        """Check pdb.post_mortem is called iff BRZ_TEST_PDB is set"""
3343
3345
        import pdb
3344
 
        result = tests.ExtendedTestResult(StringIO(), 0, 1)
 
3346
        result = tests.ExtendedTestResult(BytesIO(), 0, 1)
3345
3347
        post_mortem_calls = []
3346
3348
        self.overrideAttr(pdb, "post_mortem", post_mortem_calls.append)
3347
3349
        self.overrideEnv('BRZ_TEST_PDB', None)
3365
3367
                calls.append(test)
3366
3368
                return tests.ExtendedTestResult(self.stream, self.descriptions,
3367
3369
                                                self.verbosity)
3368
 
        tests.run_suite(suite, runner_class=MyRunner, stream=StringIO())
 
3370
        tests.run_suite(suite, runner_class=MyRunner, stream=BytesIO())
3369
3371
        self.assertLength(1, calls)
3370
3372
 
3371
3373
 
3376
3378
        """To be overridden by subclasses that run tests out of process"""
3377
3379
 
3378
3380
    def _run_selftest(self, **kwargs):
3379
 
        sio = StringIO()
 
3381
        sio = BytesIO()
3380
3382
        self._inject_stream_into_subunit(sio)
3381
3383
        tests.selftest(stream=sio, stop_on_failure=False, **kwargs)
3382
3384
        return sio.getvalue()
3443
3445
        def test_self_ref(self):
3444
3446
            self.also_self = self.test_self_ref
3445
3447
        def test_skip(self):
3446
 
            self.skip("Don't need")
 
3448
            self.skipTest("Don't need")
3447
3449
 
3448
3450
    def _get_suite(self):
3449
3451
        return TestUtil.TestSuite([
3525
3527
                # Make sure we can call it twice
3526
3528
                self.overrideEnv('MYVAR', None)
3527
3529
                self.assertEqual(None, os.environ.get('MYVAR'))
3528
 
        output = StringIO()
 
3530
        output = BytesIO()
3529
3531
        result = tests.TextTestResult(output, 0, 1)
3530
3532
        Test('test_me').run(result)
3531
3533
        if not result.wasStrictlySuccessful():
3613
3615
 
3614
3616
    def run_doctest_suite_for_string(self, klass, string):
3615
3617
        suite = self.get_doctest_suite_for_string(klass, string)
3616
 
        output = StringIO()
 
3618
        output = BytesIO()
3617
3619
        result = tests.TextTestResult(output, 0, 1)
3618
3620
        suite.run(result)
3619
3621
        return result, output
3717
3719
        result = unittest.TestResult()
3718
3720
        test.run(result)
3719
3721
        self.assertTrue(hasattr(test, '_counters'))
3720
 
        self.assertTrue(test._counters.has_key('myhook'))
 
3722
        self.assertTrue('myhook' in test._counters)
3721
3723
        self.assertEqual(expected_calls, test._counters['myhook'])
3722
3724
 
3723
3725
    def test_no_hook(self):