~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Martin Pool
  • Date: 2010-04-01 04:41:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5128.
  • Revision ID: mbp@sourcefrog.net-20100401044118-shyctqc02ob08ngz
ignore .testrepository

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Testing framework extensions"""
18
17
 
19
18
# TODO: Perhaps there should be an API to find out if bzr running under the
20
19
# test suite -- some plugins might want to avoid making intrusive changes if
29
28
 
30
29
import atexit
31
30
import codecs
32
 
import copy
 
31
from copy import copy
33
32
from cStringIO import StringIO
34
33
import difflib
35
34
import doctest
36
35
import errno
37
 
import itertools
38
36
import logging
39
37
import math
40
38
import os
41
 
import pprint
 
39
from pprint import pformat
42
40
import random
43
41
import re
44
42
import shlex
45
43
import stat
46
 
import subprocess
 
44
from subprocess import Popen, PIPE, STDOUT
47
45
import sys
48
46
import tempfile
49
47
import threading
75
73
    ui,
76
74
    urlutils,
77
75
    registry,
78
 
    transport as _mod_transport,
79
76
    workingtree,
80
77
    )
81
78
import bzrlib.branch
105
102
    )
106
103
import bzrlib.trace
107
104
from bzrlib.transport import (
 
105
    get_transport,
108
106
    memory,
109
107
    pathfilter,
110
108
    )
 
109
import bzrlib.transport
111
110
from bzrlib.trace import mutter, note
112
111
from bzrlib.tests import (
113
112
    test_server,
114
113
    TestUtil,
115
 
    treeshape,
116
114
    )
 
115
from bzrlib.tests.http_server import HttpServer
 
116
from bzrlib.tests.TestUtil import (
 
117
                          TestSuite,
 
118
                          TestLoader,
 
119
                          )
 
120
from bzrlib.tests.treeshape import build_tree_contents
117
121
from bzrlib.ui import NullProgressView
118
122
from bzrlib.ui.text import TextUIFactory
119
123
import bzrlib.version_info_formats.format_custom
136
140
SUBUNIT_SEEK_CUR = 1
137
141
 
138
142
 
139
 
class ExtendedTestResult(testtools.TextTestResult):
 
143
class ExtendedTestResult(unittest._TextTestResult):
140
144
    """Accepts, reports and accumulates the results of running tests.
141
145
 
142
146
    Compared to the unittest version this class adds support for
163
167
        :param bench_history: Optionally, a writable file object to accumulate
164
168
            benchmark results.
165
169
        """
166
 
        testtools.TextTestResult.__init__(self, stream)
 
170
        unittest._TextTestResult.__init__(self, stream, descriptions, verbosity)
167
171
        if bench_history is not None:
168
172
            from bzrlib.version import _get_bzr_source_tree
169
173
            src_tree = _get_bzr_source_tree()
196
200
        actionTaken = "Ran"
197
201
        stopTime = time.time()
198
202
        timeTaken = stopTime - self.startTime
199
 
        # GZ 2010-07-19: Seems testtools has no printErrors method, and though
200
 
        #                the parent class method is similar have to duplicate
201
 
        self._show_list('ERROR', self.errors)
202
 
        self._show_list('FAIL', self.failures)
203
 
        self.stream.write(self.sep2)
204
 
        self.stream.write("%s %d test%s in %.3fs\n\n" % (actionTaken,
 
203
        self.printErrors()
 
204
        self.stream.writeln(self.separator2)
 
205
        self.stream.writeln("%s %d test%s in %.3fs" % (actionTaken,
205
206
                            run, run != 1 and "s" or "", timeTaken))
 
207
        self.stream.writeln()
206
208
        if not self.wasSuccessful():
207
209
            self.stream.write("FAILED (")
208
210
            failed, errored = map(len, (self.failures, self.errors))
215
217
                if failed or errored: self.stream.write(", ")
216
218
                self.stream.write("known_failure_count=%d" %
217
219
                    self.known_failure_count)
218
 
            self.stream.write(")\n")
 
220
            self.stream.writeln(")")
219
221
        else:
220
222
            if self.known_failure_count:
221
 
                self.stream.write("OK (known_failures=%d)\n" %
 
223
                self.stream.writeln("OK (known_failures=%d)" %
222
224
                    self.known_failure_count)
223
225
            else:
224
 
                self.stream.write("OK\n")
 
226
                self.stream.writeln("OK")
225
227
        if self.skip_count > 0:
226
228
            skipped = self.skip_count
227
 
            self.stream.write('%d test%s skipped\n' %
 
229
            self.stream.writeln('%d test%s skipped' %
228
230
                                (skipped, skipped != 1 and "s" or ""))
229
231
        if self.unsupported:
230
232
            for feature, count in sorted(self.unsupported.items()):
231
 
                self.stream.write("Missing feature '%s' skipped %d tests.\n" %
 
233
                self.stream.writeln("Missing feature '%s' skipped %d tests." %
232
234
                    (feature, count))
233
235
        if self._strict:
234
236
            ok = self.wasStrictlySuccessful()
272
274
 
273
275
    def _shortened_test_description(self, test):
274
276
        what = test.id()
275
 
        what = re.sub(r'^bzrlib\.tests\.', '', what)
 
277
        what = re.sub(r'^bzrlib\.(tests|benchmarks)\.', '', what)
276
278
        return what
277
279
 
278
280
    def startTest(self, test):
279
 
        super(ExtendedTestResult, self).startTest(test)
 
281
        unittest.TestResult.startTest(self, test)
280
282
        if self.count == 0:
281
283
            self.startTests()
282
284
        self.report_test_start(test)
320
322
        fails with an unexpected error.
321
323
        """
322
324
        self._post_mortem()
323
 
        super(ExtendedTestResult, self).addError(test, err)
 
325
        unittest.TestResult.addError(self, test, err)
324
326
        self.error_count += 1
325
327
        self.report_error(test, err)
326
328
        if self.stop_early:
334
336
        fails because e.g. an assert() method failed.
335
337
        """
336
338
        self._post_mortem()
337
 
        super(ExtendedTestResult, self).addFailure(test, err)
 
339
        unittest.TestResult.addFailure(self, test, err)
338
340
        self.failure_count += 1
339
341
        self.report_failure(test, err)
340
342
        if self.stop_early:
354
356
                    test.id()))
355
357
        self.report_success(test)
356
358
        self._cleanupLogFile(test)
357
 
        super(ExtendedTestResult, self).addSuccess(test)
 
359
        unittest.TestResult.addSuccess(self, test)
358
360
        test._log_contents = ''
359
361
 
360
362
    def addExpectedFailure(self, test, err):
487
489
        return self._shortened_test_description(test)
488
490
 
489
491
    def report_error(self, test, err):
490
 
        self.stream.write('ERROR: %s\n    %s\n' % (
 
492
        self.ui.note('ERROR: %s\n    %s\n' % (
491
493
            self._test_description(test),
492
494
            err[1],
493
495
            ))
494
496
 
495
497
    def report_failure(self, test, err):
496
 
        self.stream.write('FAIL: %s\n    %s\n' % (
 
498
        self.ui.note('FAIL: %s\n    %s\n' % (
497
499
            self._test_description(test),
498
500
            err[1],
499
501
            ))
548
550
        return '%s%s' % (indent, err[1])
549
551
 
550
552
    def report_error(self, test, err):
551
 
        self.stream.write('ERROR %s\n%s\n'
 
553
        self.stream.writeln('ERROR %s\n%s'
552
554
                % (self._testTimeString(test),
553
555
                   self._error_summary(err)))
554
556
 
555
557
    def report_failure(self, test, err):
556
 
        self.stream.write(' FAIL %s\n%s\n'
 
558
        self.stream.writeln(' FAIL %s\n%s'
557
559
                % (self._testTimeString(test),
558
560
                   self._error_summary(err)))
559
561
 
560
562
    def report_known_failure(self, test, err):
561
 
        self.stream.write('XFAIL %s\n%s\n'
 
563
        self.stream.writeln('XFAIL %s\n%s'
562
564
                % (self._testTimeString(test),
563
565
                   self._error_summary(err)))
564
566
 
565
567
    def report_success(self, test):
566
 
        self.stream.write('   OK %s\n' % self._testTimeString(test))
 
568
        self.stream.writeln('   OK %s' % self._testTimeString(test))
567
569
        for bench_called, stats in getattr(test, '_benchcalls', []):
568
 
            self.stream.write('LSProf output for %s(%s, %s)\n' % bench_called)
 
570
            self.stream.writeln('LSProf output for %s(%s, %s)' % bench_called)
569
571
            stats.pprint(file=self.stream)
570
572
        # flush the stream so that we get smooth output. This verbose mode is
571
573
        # used to show the output in PQM.
572
574
        self.stream.flush()
573
575
 
574
576
    def report_skip(self, test, reason):
575
 
        self.stream.write(' SKIP %s\n%s\n'
 
577
        self.stream.writeln(' SKIP %s\n%s'
576
578
                % (self._testTimeString(test), reason))
577
579
 
578
580
    def report_not_applicable(self, test, reason):
579
 
        self.stream.write('  N/A %s\n    %s\n'
 
581
        self.stream.writeln('  N/A %s\n    %s'
580
582
                % (self._testTimeString(test), reason))
581
583
 
582
584
    def report_unsupported(self, test, feature):
583
585
        """test cannot be run because feature is missing."""
584
 
        self.stream.write("NODEP %s\n    The feature '%s' is not available.\n"
 
586
        self.stream.writeln("NODEP %s\n    The feature '%s' is not available."
585
587
                %(self._testTimeString(test), feature))
586
588
 
587
589
 
616
618
            encode = codec.encode
617
619
        stream = osutils.UnicodeOrBytesToBytesWriter(encode, stream)
618
620
        stream.encoding = new_encoding
619
 
        self.stream = stream
 
621
        self.stream = unittest._WritelnDecorator(stream)
620
622
        self.descriptions = descriptions
621
623
        self.verbosity = verbosity
622
624
        self._bench_history = bench_history
746
748
    # XXX: Should probably unify more with CannedInputUIFactory or a
747
749
    # particular configuration of TextUIFactory, or otherwise have a clearer
748
750
    # idea of how they're supposed to be different.
749
 
    # See https://bugs.launchpad.net/bzr/+bug/408213
 
751
    # See https://bugs.edge.launchpad.net/bzr/+bug/408213
750
752
 
751
753
    def __init__(self, stdout=None, stderr=None, stdin=None):
752
754
        if stdin is not None:
843
845
        # going away but leak one) but it seems less likely than the actual
844
846
        # false positives (the test see threads going away and does not leak).
845
847
        if leaked_threads > 0:
846
 
            if 'threads' in selftest_debug_flags:
847
 
                print '%s is leaking, active is now %d' % (self.id(), active)
848
848
            TestCase._leaking_threads_tests += 1
849
849
            if TestCase._first_thread_leaker_id is None:
850
850
                TestCase._first_thread_leaker_id = self.id()
942
942
 
943
943
    def permit_dir(self, name):
944
944
        """Permit a directory to be used by this test. See permit_url."""
945
 
        name_transport = _mod_transport.get_transport(name)
 
945
        name_transport = get_transport(name)
946
946
        self.permit_url(name)
947
947
        self.permit_url(name_transport.base)
948
948
 
1027
1027
        self.addCleanup(transport_server.stop_server)
1028
1028
        # Obtain a real transport because if the server supplies a password, it
1029
1029
        # will be hidden from the base on the client side.
1030
 
        t = _mod_transport.get_transport(transport_server.get_url())
 
1030
        t = get_transport(transport_server.get_url())
1031
1031
        # Some transport servers effectively chroot the backing transport;
1032
1032
        # others like SFTPServer don't - users of the transport can walk up the
1033
1033
        # transport to read the entire backing transport. This wouldn't matter
1094
1094
            message += '\n'
1095
1095
        raise AssertionError("%snot equal:\na = %s\nb = %s\n"
1096
1096
            % (message,
1097
 
               pprint.pformat(a), pprint.pformat(b)))
 
1097
               pformat(a), pformat(b)))
1098
1098
 
1099
1099
    assertEquals = assertEqual
1100
1100
 
1312
1312
            f.close()
1313
1313
        self.assertEqualDiff(content, s)
1314
1314
 
1315
 
    def assertDocstring(self, expected_docstring, obj):
1316
 
        """Fail if obj does not have expected_docstring"""
1317
 
        if __doc__ is None:
1318
 
            # With -OO the docstring should be None instead
1319
 
            self.assertIs(obj.__doc__, None)
1320
 
        else:
1321
 
            self.assertEqual(expected_docstring, obj.__doc__)
1322
 
 
1323
1315
    def failUnlessExists(self, path):
1324
1316
        """Fail unless path or paths, which may be abs or relative, exist."""
1325
1317
        if not isinstance(path, basestring):
1523
1515
            'EDITOR': None,
1524
1516
            'BZR_EMAIL': None,
1525
1517
            'BZREMAIL': None, # may still be present in the environment
1526
 
            'EMAIL': 'jrandom@example.com', # set EMAIL as bzr does not guess
 
1518
            'EMAIL': None,
1527
1519
            'BZR_PROGRESS_BAR': None,
1528
1520
            'BZR_LOG': None,
1529
1521
            'BZR_PLUGIN_PATH': None,
1985
1977
            if not allow_plugins:
1986
1978
                command.append('--no-plugins')
1987
1979
            command.extend(process_args)
1988
 
            process = self._popen(command, stdin=subprocess.PIPE,
1989
 
                                  stdout=subprocess.PIPE,
1990
 
                                  stderr=subprocess.PIPE)
 
1980
            process = self._popen(command, stdin=PIPE, stdout=PIPE, stderr=PIPE)
1991
1981
        finally:
1992
1982
            restore_environment()
1993
1983
            if cwd is not None:
2001
1991
        Allows tests to override this method to intercept the calls made to
2002
1992
        Popen for introspection.
2003
1993
        """
2004
 
        return subprocess.Popen(*args, **kwargs)
 
1994
        return Popen(*args, **kwargs)
2005
1995
 
2006
1996
    def get_source_path(self):
2007
1997
        """Return the path of the directory containing bzrlib."""
2009
1999
 
2010
2000
    def get_bzr_path(self):
2011
2001
        """Return the path of the 'bzr' executable for this test suite."""
2012
 
        bzr_path = os.path.join(self.get_source_path(), "bzr")
 
2002
        bzr_path = self.get_source_path()+'/bzr'
2013
2003
        if not os.path.isfile(bzr_path):
2014
2004
            # We are probably installed. Assume sys.argv is the right file
2015
2005
            bzr_path = sys.argv[0]
2187
2177
 
2188
2178
        :param relpath: a path relative to the base url.
2189
2179
        """
2190
 
        t = _mod_transport.get_transport(self.get_url(relpath))
 
2180
        t = get_transport(self.get_url(relpath))
2191
2181
        self.assertFalse(t.is_readonly())
2192
2182
        return t
2193
2183
 
2199
2189
 
2200
2190
        :param relpath: a path relative to the base url.
2201
2191
        """
2202
 
        t = _mod_transport.get_transport(self.get_readonly_url(relpath))
 
2192
        t = get_transport(self.get_readonly_url(relpath))
2203
2193
        self.assertTrue(t.is_readonly())
2204
2194
        return t
2205
2195
 
2335
2325
        propagating. This method ensures than a test did not leaked.
2336
2326
        """
2337
2327
        root = TestCaseWithMemoryTransport.TEST_ROOT
2338
 
        self.permit_url(_mod_transport.get_transport(root).base)
 
2328
        self.permit_url(get_transport(root).base)
2339
2329
        wt = workingtree.WorkingTree.open(root)
2340
2330
        last_rev = wt.last_revision()
2341
2331
        if last_rev != 'null:':
2386
2376
            # might be a relative or absolute path
2387
2377
            maybe_a_url = self.get_url(relpath)
2388
2378
            segments = maybe_a_url.rsplit('/', 1)
2389
 
            t = _mod_transport.get_transport(maybe_a_url)
 
2379
            t = get_transport(maybe_a_url)
2390
2380
            if len(segments) > 1 and segments[-1] not in ('', '.'):
2391
2381
                t.ensure_base()
2392
2382
            if format is None:
2409
2399
        made_control = self.make_bzrdir(relpath, format=format)
2410
2400
        return made_control.create_repository(shared=shared)
2411
2401
 
2412
 
    def make_smart_server(self, path, backing_server=None):
2413
 
        if backing_server is None:
2414
 
            backing_server = self.get_server()
 
2402
    def make_smart_server(self, path):
2415
2403
        smart_server = test_server.SmartTCPServer_for_testing()
2416
 
        self.start_server(smart_server, backing_server)
2417
 
        remote_transport = _mod_transport.get_transport(smart_server.get_url()
2418
 
                                                   ).clone(path)
 
2404
        self.start_server(smart_server, self.get_server())
 
2405
        remote_transport = get_transport(smart_server.get_url()).clone(path)
2419
2406
        return remote_transport
2420
2407
 
2421
2408
    def make_branch_and_memory_tree(self, relpath, format=None):
2436
2423
 
2437
2424
    def setUp(self):
2438
2425
        super(TestCaseWithMemoryTransport, self).setUp()
2439
 
        # Ensure that ConnectedTransport doesn't leak sockets
2440
 
        def get_transport_with_cleanup(*args, **kwargs):
2441
 
            t = orig_get_transport(*args, **kwargs)
2442
 
            if isinstance(t, _mod_transport.ConnectedTransport):
2443
 
                self.addCleanup(t.disconnect)
2444
 
            return t
2445
 
 
2446
 
        orig_get_transport = self.overrideAttr(_mod_transport, 'get_transport',
2447
 
                                               get_transport_with_cleanup)
2448
2426
        self._make_test_root()
2449
2427
        self.addCleanup(os.chdir, os.getcwdu())
2450
2428
        self.makeAndChdirToTestDir()
2495
2473
 
2496
2474
    def check_file_contents(self, filename, expect):
2497
2475
        self.log("check contents of file %s" % filename)
2498
 
        f = file(filename)
2499
 
        try:
2500
 
            contents = f.read()
2501
 
        finally:
2502
 
            f.close()
 
2476
        contents = file(filename, 'r').read()
2503
2477
        if contents != expect:
2504
2478
            self.log("expected: %r" % expect)
2505
2479
            self.log("actually: %r" % contents)
2579
2553
                "a list or a tuple. Got %r instead" % (shape,))
2580
2554
        # It's OK to just create them using forward slashes on windows.
2581
2555
        if transport is None or transport.is_readonly():
2582
 
            transport = _mod_transport.get_transport(".")
 
2556
            transport = get_transport(".")
2583
2557
        for name in shape:
2584
2558
            self.assertIsInstance(name, basestring)
2585
2559
            if name[-1] == '/':
2595
2569
                content = "contents of %s%s" % (name.encode('utf-8'), end)
2596
2570
                transport.put_bytes_non_atomic(urlutils.escape(name), content)
2597
2571
 
2598
 
    build_tree_contents = staticmethod(treeshape.build_tree_contents)
 
2572
    def build_tree_contents(self, shape):
 
2573
        build_tree_contents(shape)
2599
2574
 
2600
2575
    def assertInWorkingTree(self, path, root_path='.', tree=None):
2601
2576
        """Assert whether path or paths are in the WorkingTree"""
2742
2717
    """
2743
2718
 
2744
2719
    def setUp(self):
2745
 
        from bzrlib.tests import http_server
2746
2720
        super(ChrootedTestCase, self).setUp()
2747
2721
        if not self.vfs_transport_factory == memory.MemoryServer:
2748
 
            self.transport_readonly_server = http_server.HttpServer
 
2722
            self.transport_readonly_server = HttpServer
2749
2723
 
2750
2724
 
2751
2725
def condition_id_re(pattern):
2754
2728
    :param pattern: A regular expression string.
2755
2729
    :return: A callable that returns True if the re matches.
2756
2730
    """
2757
 
    filter_re = re.compile(pattern, 0)
 
2731
    filter_re = osutils.re_compile_checked(pattern, 0,
 
2732
        'test filter')
2758
2733
    def condition(test):
2759
2734
        test_id = test.id()
2760
2735
        return filter_re.search(test_id)
3072
3047
    return suite
3073
3048
 
3074
3049
 
3075
 
class TestDecorator(TestUtil.TestSuite):
 
3050
class TestDecorator(TestSuite):
3076
3051
    """A decorator for TestCase/TestSuite objects.
3077
3052
    
3078
3053
    Usually, subclasses should override __iter__(used when flattening test
3081
3056
    """
3082
3057
 
3083
3058
    def __init__(self, suite):
3084
 
        TestUtil.TestSuite.__init__(self)
 
3059
        TestSuite.__init__(self)
3085
3060
        self.addTest(suite)
3086
3061
 
3087
3062
    def countTestCases(self):
3206
3181
 
3207
3182
def partition_tests(suite, count):
3208
3183
    """Partition suite into count lists of tests."""
3209
 
    # This just assigns tests in a round-robin fashion.  On one hand this
3210
 
    # splits up blocks of related tests that might run faster if they shared
3211
 
    # resources, but on the other it avoids assigning blocks of slow tests to
3212
 
    # just one partition.  So the slowest partition shouldn't be much slower
3213
 
    # than the fastest.
3214
 
    partitions = [list() for i in range(count)]
3215
 
    tests = iter_suite_tests(suite)
3216
 
    for partition, test in itertools.izip(itertools.cycle(partitions), tests):
3217
 
        partition.append(test)
3218
 
    return partitions
3219
 
 
3220
 
 
3221
 
def workaround_zealous_crypto_random():
3222
 
    """Crypto.Random want to help us being secure, but we don't care here.
3223
 
 
3224
 
    This workaround some test failure related to the sftp server. Once paramiko
3225
 
    stop using the controversial API in Crypto.Random, we may get rid of it.
3226
 
    """
3227
 
    try:
3228
 
        from Crypto.Random import atfork
3229
 
        atfork()
3230
 
    except ImportError:
3231
 
        pass
 
3184
    result = []
 
3185
    tests = list(iter_suite_tests(suite))
 
3186
    tests_per_process = int(math.ceil(float(len(tests)) / count))
 
3187
    for block in range(count):
 
3188
        low_test = block * tests_per_process
 
3189
        high_test = low_test + tests_per_process
 
3190
        process_tests = tests[low_test:high_test]
 
3191
        result.append(process_tests)
 
3192
    return result
3232
3193
 
3233
3194
 
3234
3195
def fork_for_tests(suite):
3251
3212
            try:
3252
3213
                ProtocolTestCase.run(self, result)
3253
3214
            finally:
3254
 
                os.waitpid(self.pid, 0)
 
3215
                os.waitpid(self.pid, os.WNOHANG)
3255
3216
 
3256
3217
    test_blocks = partition_tests(suite, concurrency)
3257
3218
    for process_tests in test_blocks:
3258
 
        process_suite = TestUtil.TestSuite()
 
3219
        process_suite = TestSuite()
3259
3220
        process_suite.addTests(process_tests)
3260
3221
        c2pread, c2pwrite = os.pipe()
3261
3222
        pid = os.fork()
3262
3223
        if pid == 0:
3263
 
            workaround_zealous_crypto_random()
3264
3224
            try:
3265
3225
                os.close(c2pread)
3266
3226
                # Leave stderr and stdout open so we can see test noise
3327
3287
                '--subunit']
3328
3288
            if '--no-plugins' in sys.argv:
3329
3289
                argv.append('--no-plugins')
3330
 
            # stderr=subprocess.STDOUT would be ideal, but until we prevent
3331
 
            # noise on stderr it can interrupt the subunit protocol.
3332
 
            process = subprocess.Popen(argv, stdin=subprocess.PIPE,
3333
 
                                      stdout=subprocess.PIPE,
3334
 
                                      stderr=subprocess.PIPE,
3335
 
                                      bufsize=1)
 
3290
            # stderr=STDOUT would be ideal, but until we prevent noise on
 
3291
            # stderr it can interrupt the subunit protocol.
 
3292
            process = Popen(argv, stdin=PIPE, stdout=PIPE, stderr=PIPE,
 
3293
                bufsize=1)
3336
3294
            test = TestInSubprocess(process, test_list_file_name)
3337
3295
            result.append(test)
3338
3296
        except:
3387
3345
 
3388
3346
    def startTest(self, test):
3389
3347
        self.profiler = bzrlib.lsprof.BzrProfiler()
3390
 
        # Prevent deadlocks in tests that use lsprof: those tests will
3391
 
        # unavoidably fail.
3392
 
        bzrlib.lsprof.BzrProfiler.profiler_block = 0
3393
3348
        self.profiler.start()
3394
3349
        ForwardingResult.startTest(self, test)
3395
3350
 
3416
3371
#                           rather than failing tests. And no longer raise
3417
3372
#                           LockContention when fctnl locks are not being used
3418
3373
#                           with proper exclusion rules.
3419
 
#   -Ethreads               Will display thread ident at creation/join time to
3420
 
#                           help track thread leaks
3421
3374
selftest_debug_flags = set()
3422
3375
 
3423
3376
 
3656
3609
        'bzrlib.doc',
3657
3610
        'bzrlib.tests.blackbox',
3658
3611
        'bzrlib.tests.commands',
3659
 
        'bzrlib.tests.doc_generate',
3660
3612
        'bzrlib.tests.per_branch',
3661
 
        'bzrlib.tests.per_controldir',
3662
 
        'bzrlib.tests.per_controldir_colo',
 
3613
        'bzrlib.tests.per_bzrdir',
3663
3614
        'bzrlib.tests.per_foreign_vcs',
3664
3615
        'bzrlib.tests.per_interrepository',
3665
3616
        'bzrlib.tests.per_intertree',
3678
3629
        'bzrlib.tests.per_workingtree',
3679
3630
        'bzrlib.tests.test__annotator',
3680
3631
        'bzrlib.tests.test__bencode',
3681
 
        'bzrlib.tests.test__btree_serializer',
3682
3632
        'bzrlib.tests.test__chk_map',
3683
3633
        'bzrlib.tests.test__dirstate_helpers',
3684
3634
        'bzrlib.tests.test__groupcompress',
3727
3677
        'bzrlib.tests.test_export',
3728
3678
        'bzrlib.tests.test_extract',
3729
3679
        'bzrlib.tests.test_fetch',
3730
 
        'bzrlib.tests.test_fixtures',
3731
3680
        'bzrlib.tests.test_fifo_cache',
3732
3681
        'bzrlib.tests.test_filters',
3733
3682
        'bzrlib.tests.test_ftp_transport',
3754
3703
        'bzrlib.tests.test_knit',
3755
3704
        'bzrlib.tests.test_lazy_import',
3756
3705
        'bzrlib.tests.test_lazy_regex',
3757
 
        'bzrlib.tests.test_library_state',
3758
3706
        'bzrlib.tests.test_lock',
3759
3707
        'bzrlib.tests.test_lockable_files',
3760
3708
        'bzrlib.tests.test_lockdir',
3762
3710
        'bzrlib.tests.test_lru_cache',
3763
3711
        'bzrlib.tests.test_lsprof',
3764
3712
        'bzrlib.tests.test_mail_client',
3765
 
        'bzrlib.tests.test_matchers',
3766
3713
        'bzrlib.tests.test_memorytree',
3767
3714
        'bzrlib.tests.test_merge',
3768
3715
        'bzrlib.tests.test_merge3',
3817
3764
        'bzrlib.tests.test_switch',
3818
3765
        'bzrlib.tests.test_symbol_versioning',
3819
3766
        'bzrlib.tests.test_tag',
3820
 
        'bzrlib.tests.test_test_server',
3821
3767
        'bzrlib.tests.test_testament',
3822
3768
        'bzrlib.tests.test_textfile',
3823
3769
        'bzrlib.tests.test_textmerge',
3829
3775
        'bzrlib.tests.test_transport_log',
3830
3776
        'bzrlib.tests.test_tree',
3831
3777
        'bzrlib.tests.test_treebuilder',
3832
 
        'bzrlib.tests.test_treeshape',
3833
3778
        'bzrlib.tests.test_tsort',
3834
3779
        'bzrlib.tests.test_tuned_gzip',
3835
3780
        'bzrlib.tests.test_ui',
3839
3784
        'bzrlib.tests.test_urlutils',
3840
3785
        'bzrlib.tests.test_version',
3841
3786
        'bzrlib.tests.test_version_info',
3842
 
        'bzrlib.tests.test_versionedfile',
3843
3787
        'bzrlib.tests.test_weave',
3844
3788
        'bzrlib.tests.test_whitebox',
3845
3789
        'bzrlib.tests.test_win32utils',
3851
3795
 
3852
3796
 
3853
3797
def _test_suite_modules_to_doctest():
3854
 
    """Return the list of modules to doctest."""
3855
 
    if __doc__ is None:
3856
 
        # GZ 2009-03-31: No docstrings with -OO so there's nothing to doctest
3857
 
        return []
 
3798
    """Return the list of modules to doctest."""   
3858
3799
    return [
3859
3800
        'bzrlib',
3860
3801
        'bzrlib.branchbuilder',
3867
3808
        'bzrlib.option',
3868
3809
        'bzrlib.symbol_versioning',
3869
3810
        'bzrlib.tests',
3870
 
        'bzrlib.tests.fixtures',
3871
3811
        'bzrlib.timestamp',
3872
3812
        'bzrlib.version_info_formats.format_custom',
3873
3813
        ]
4014
3954
    ...     bzrlib.tests.test_sampler.DemoTest('test_nothing'),
4015
3955
    ...     [('one', dict(param=1)),
4016
3956
    ...      ('two', dict(param=2))],
4017
 
    ...     TestUtil.TestSuite())
 
3957
    ...     TestSuite())
4018
3958
    >>> tests = list(iter_suite_tests(r))
4019
3959
    >>> len(tests)
4020
3960
    2
4067
4007
    :param new_id: The id to assign to it.
4068
4008
    :return: The new test.
4069
4009
    """
4070
 
    new_test = copy.copy(test)
 
4010
    new_test = copy(test)
4071
4011
    new_test.id = lambda: new_id
4072
4012
    return new_test
4073
4013
 
4134
4074
        if test_id != None:
4135
4075
            ui.ui_factory.clear_term()
4136
4076
            sys.stderr.write('\nWhile running: %s\n' % (test_id,))
4137
 
        # Ugly, but the last thing we want here is fail, so bear with it.
4138
 
        printable_e = str(e).decode(osutils.get_user_encoding(), 'replace'
4139
 
                                    ).encode('ascii', 'replace')
4140
4077
        sys.stderr.write('Unable to remove testing dir %s\n%s'
4141
 
                         % (os.path.basename(dirname), printable_e))
 
4078
                         % (os.path.basename(dirname), e))
4142
4079
 
4143
4080
 
4144
4081
class Feature(object):
4374
4311
UnicodeFilename = _UnicodeFilename()
4375
4312
 
4376
4313
 
4377
 
class _ByteStringNamedFilesystem(Feature):
4378
 
    """Is the filesystem based on bytes?"""
4379
 
 
4380
 
    def _probe(self):
4381
 
        if os.name == "posix":
4382
 
            return True
4383
 
        return False
4384
 
 
4385
 
ByteStringNamedFilesystem = _ByteStringNamedFilesystem()
4386
 
 
4387
 
 
4388
4314
class _UTF8Filesystem(Feature):
4389
4315
    """Is the filesystem UTF-8?"""
4390
4316
 
4508
4434
            return result
4509
4435
except ImportError:
4510
4436
    pass
4511
 
 
4512
 
class _PosixPermissionsFeature(Feature):
4513
 
 
4514
 
    def _probe(self):
4515
 
        def has_perms():
4516
 
            # create temporary file and check if specified perms are maintained.
4517
 
            import tempfile
4518
 
 
4519
 
            write_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
4520
 
            f = tempfile.mkstemp(prefix='bzr_perms_chk_')
4521
 
            fd, name = f
4522
 
            os.close(fd)
4523
 
            os.chmod(name, write_perms)
4524
 
 
4525
 
            read_perms = os.stat(name).st_mode & 0777
4526
 
            os.unlink(name)
4527
 
            return (write_perms == read_perms)
4528
 
 
4529
 
        return (os.name == 'posix') and has_perms()
4530
 
 
4531
 
    def feature_name(self):
4532
 
        return 'POSIX permissions support'
4533
 
 
4534
 
posix_permissions_feature = _PosixPermissionsFeature()