/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 bzrlib/tests/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-07-19 14:26:11 UTC
  • mfrom: (5346.4.6 cleanup)
  • Revision ID: pqm@pqm.ubuntu.com-20100719142611-fbhst4ivcngc32d5
(mbp) tree_files and internal_tree files moved to WorkingTree (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
import atexit
31
31
import codecs
32
 
from copy import copy
 
32
import copy
33
33
from cStringIO import StringIO
34
34
import difflib
35
35
import doctest
37
37
import logging
38
38
import math
39
39
import os
40
 
from pprint import pformat
 
40
import pprint
41
41
import random
42
42
import re
43
43
import shlex
44
44
import stat
45
 
from subprocess import Popen, PIPE, STDOUT
 
45
import subprocess
46
46
import sys
47
47
import tempfile
48
48
import threading
74
74
    ui,
75
75
    urlutils,
76
76
    registry,
 
77
    transport as _mod_transport,
77
78
    workingtree,
78
79
    )
79
80
import bzrlib.branch
103
104
    )
104
105
import bzrlib.trace
105
106
from bzrlib.transport import (
106
 
    get_transport,
107
107
    memory,
108
108
    pathfilter,
109
109
    )
110
 
import bzrlib.transport
111
110
from bzrlib.trace import mutter, note
112
111
from bzrlib.tests import (
113
112
    test_server,
114
113
    TestUtil,
 
114
    treeshape,
115
115
    )
116
116
from bzrlib.tests.http_server import HttpServer
117
117
from bzrlib.tests.TestUtil import (
118
118
                          TestSuite,
119
119
                          TestLoader,
120
120
                          )
121
 
from bzrlib.tests.treeshape import build_tree_contents
122
121
from bzrlib.ui import NullProgressView
123
122
from bzrlib.ui.text import TextUIFactory
124
123
import bzrlib.version_info_formats.format_custom
749
748
    # XXX: Should probably unify more with CannedInputUIFactory or a
750
749
    # particular configuration of TextUIFactory, or otherwise have a clearer
751
750
    # idea of how they're supposed to be different.
752
 
    # See https://bugs.edge.launchpad.net/bzr/+bug/408213
 
751
    # See https://bugs.launchpad.net/bzr/+bug/408213
753
752
 
754
753
    def __init__(self, stdout=None, stderr=None, stdin=None):
755
754
        if stdin is not None:
943
942
 
944
943
    def permit_dir(self, name):
945
944
        """Permit a directory to be used by this test. See permit_url."""
946
 
        name_transport = get_transport(name)
 
945
        name_transport = _mod_transport.get_transport(name)
947
946
        self.permit_url(name)
948
947
        self.permit_url(name_transport.base)
949
948
 
1028
1027
        self.addCleanup(transport_server.stop_server)
1029
1028
        # Obtain a real transport because if the server supplies a password, it
1030
1029
        # will be hidden from the base on the client side.
1031
 
        t = get_transport(transport_server.get_url())
 
1030
        t = _mod_transport.get_transport(transport_server.get_url())
1032
1031
        # Some transport servers effectively chroot the backing transport;
1033
1032
        # others like SFTPServer don't - users of the transport can walk up the
1034
1033
        # transport to read the entire backing transport. This wouldn't matter
1095
1094
            message += '\n'
1096
1095
        raise AssertionError("%snot equal:\na = %s\nb = %s\n"
1097
1096
            % (message,
1098
 
               pformat(a), pformat(b)))
 
1097
               pprint.pformat(a), pprint.pformat(b)))
1099
1098
 
1100
1099
    assertEquals = assertEqual
1101
1100
 
1524
1523
            'EDITOR': None,
1525
1524
            'BZR_EMAIL': None,
1526
1525
            'BZREMAIL': None, # may still be present in the environment
1527
 
            'EMAIL': None,
 
1526
            'EMAIL': 'jrandom@example.com', # set EMAIL as bzr does not guess
1528
1527
            'BZR_PROGRESS_BAR': None,
1529
1528
            'BZR_LOG': None,
1530
1529
            'BZR_PLUGIN_PATH': None,
1986
1985
            if not allow_plugins:
1987
1986
                command.append('--no-plugins')
1988
1987
            command.extend(process_args)
1989
 
            process = self._popen(command, stdin=PIPE, stdout=PIPE, stderr=PIPE)
 
1988
            process = self._popen(command, stdin=subprocess.PIPE,
 
1989
                                  stdout=subprocess.PIPE,
 
1990
                                  stderr=subprocess.PIPE)
1990
1991
        finally:
1991
1992
            restore_environment()
1992
1993
            if cwd is not None:
2000
2001
        Allows tests to override this method to intercept the calls made to
2001
2002
        Popen for introspection.
2002
2003
        """
2003
 
        return Popen(*args, **kwargs)
 
2004
        return subprocess.Popen(*args, **kwargs)
2004
2005
 
2005
2006
    def get_source_path(self):
2006
2007
        """Return the path of the directory containing bzrlib."""
2186
2187
 
2187
2188
        :param relpath: a path relative to the base url.
2188
2189
        """
2189
 
        t = get_transport(self.get_url(relpath))
 
2190
        t = _mod_transport.get_transport(self.get_url(relpath))
2190
2191
        self.assertFalse(t.is_readonly())
2191
2192
        return t
2192
2193
 
2198
2199
 
2199
2200
        :param relpath: a path relative to the base url.
2200
2201
        """
2201
 
        t = get_transport(self.get_readonly_url(relpath))
 
2202
        t = _mod_transport.get_transport(self.get_readonly_url(relpath))
2202
2203
        self.assertTrue(t.is_readonly())
2203
2204
        return t
2204
2205
 
2334
2335
        propagating. This method ensures than a test did not leaked.
2335
2336
        """
2336
2337
        root = TestCaseWithMemoryTransport.TEST_ROOT
2337
 
        self.permit_url(get_transport(root).base)
 
2338
        self.permit_url(_mod_transport.get_transport(root).base)
2338
2339
        wt = workingtree.WorkingTree.open(root)
2339
2340
        last_rev = wt.last_revision()
2340
2341
        if last_rev != 'null:':
2385
2386
            # might be a relative or absolute path
2386
2387
            maybe_a_url = self.get_url(relpath)
2387
2388
            segments = maybe_a_url.rsplit('/', 1)
2388
 
            t = get_transport(maybe_a_url)
 
2389
            t = _mod_transport.get_transport(maybe_a_url)
2389
2390
            if len(segments) > 1 and segments[-1] not in ('', '.'):
2390
2391
                t.ensure_base()
2391
2392
            if format is None:
2408
2409
        made_control = self.make_bzrdir(relpath, format=format)
2409
2410
        return made_control.create_repository(shared=shared)
2410
2411
 
2411
 
    def make_smart_server(self, path):
 
2412
    def make_smart_server(self, path, backing_server=None):
 
2413
        if backing_server is None:
 
2414
            backing_server = self.get_server()
2412
2415
        smart_server = test_server.SmartTCPServer_for_testing()
2413
 
        self.start_server(smart_server, self.get_server())
2414
 
        remote_transport = get_transport(smart_server.get_url()).clone(path)
 
2416
        self.start_server(smart_server, backing_server)
 
2417
        remote_transport = _mod_transport.get_transport(smart_server.get_url()
 
2418
                                                   ).clone(path)
2415
2419
        return remote_transport
2416
2420
 
2417
2421
    def make_branch_and_memory_tree(self, relpath, format=None):
2482
2486
 
2483
2487
    def check_file_contents(self, filename, expect):
2484
2488
        self.log("check contents of file %s" % filename)
2485
 
        contents = file(filename, 'r').read()
 
2489
        f = file(filename)
 
2490
        try:
 
2491
            contents = f.read()
 
2492
        finally:
 
2493
            f.close()
2486
2494
        if contents != expect:
2487
2495
            self.log("expected: %r" % expect)
2488
2496
            self.log("actually: %r" % contents)
2562
2570
                "a list or a tuple. Got %r instead" % (shape,))
2563
2571
        # It's OK to just create them using forward slashes on windows.
2564
2572
        if transport is None or transport.is_readonly():
2565
 
            transport = get_transport(".")
 
2573
            transport = _mod_transport.get_transport(".")
2566
2574
        for name in shape:
2567
2575
            self.assertIsInstance(name, basestring)
2568
2576
            if name[-1] == '/':
2578
2586
                content = "contents of %s%s" % (name.encode('utf-8'), end)
2579
2587
                transport.put_bytes_non_atomic(urlutils.escape(name), content)
2580
2588
 
2581
 
    def build_tree_contents(self, shape):
2582
 
        build_tree_contents(shape)
 
2589
    build_tree_contents = staticmethod(treeshape.build_tree_contents)
2583
2590
 
2584
2591
    def assertInWorkingTree(self, path, root_path='.', tree=None):
2585
2592
        """Assert whether path or paths are in the WorkingTree"""
2737
2744
    :param pattern: A regular expression string.
2738
2745
    :return: A callable that returns True if the re matches.
2739
2746
    """
2740
 
    filter_re = osutils.re_compile_checked(pattern, 0,
2741
 
        'test filter')
 
2747
    filter_re = re.compile(pattern, 0)
2742
2748
    def condition(test):
2743
2749
        test_id = test.id()
2744
2750
        return filter_re.search(test_id)
3310
3316
                '--subunit']
3311
3317
            if '--no-plugins' in sys.argv:
3312
3318
                argv.append('--no-plugins')
3313
 
            # stderr=STDOUT would be ideal, but until we prevent noise on
3314
 
            # stderr it can interrupt the subunit protocol.
3315
 
            process = Popen(argv, stdin=PIPE, stdout=PIPE, stderr=PIPE,
3316
 
                bufsize=1)
 
3319
            # stderr=subprocess.STDOUT would be ideal, but until we prevent
 
3320
            # noise on stderr it can interrupt the subunit protocol.
 
3321
            process = subprocess.Popen(argv, stdin=subprocess.PIPE,
 
3322
                                      stdout=subprocess.PIPE,
 
3323
                                      stderr=subprocess.PIPE,
 
3324
                                      bufsize=1)
3317
3325
            test = TestInSubprocess(process, test_list_file_name)
3318
3326
            result.append(test)
3319
3327
        except:
3368
3376
 
3369
3377
    def startTest(self, test):
3370
3378
        self.profiler = bzrlib.lsprof.BzrProfiler()
 
3379
        # Prevent deadlocks in tests that use lsprof: those tests will
 
3380
        # unavoidably fail.
 
3381
        bzrlib.lsprof.BzrProfiler.profiler_block = 0
3371
3382
        self.profiler.start()
3372
3383
        ForwardingResult.startTest(self, test)
3373
3384
 
3701
3712
        'bzrlib.tests.test_export',
3702
3713
        'bzrlib.tests.test_extract',
3703
3714
        'bzrlib.tests.test_fetch',
 
3715
        'bzrlib.tests.test_fixtures',
3704
3716
        'bzrlib.tests.test_fifo_cache',
3705
3717
        'bzrlib.tests.test_filters',
3706
3718
        'bzrlib.tests.test_ftp_transport',
3727
3739
        'bzrlib.tests.test_knit',
3728
3740
        'bzrlib.tests.test_lazy_import',
3729
3741
        'bzrlib.tests.test_lazy_regex',
 
3742
        'bzrlib.tests.test_library_state',
3730
3743
        'bzrlib.tests.test_lock',
3731
3744
        'bzrlib.tests.test_lockable_files',
3732
3745
        'bzrlib.tests.test_lockdir',
3800
3813
        'bzrlib.tests.test_transport_log',
3801
3814
        'bzrlib.tests.test_tree',
3802
3815
        'bzrlib.tests.test_treebuilder',
 
3816
        'bzrlib.tests.test_treeshape',
3803
3817
        'bzrlib.tests.test_tsort',
3804
3818
        'bzrlib.tests.test_tuned_gzip',
3805
3819
        'bzrlib.tests.test_ui',
3836
3850
        'bzrlib.option',
3837
3851
        'bzrlib.symbol_versioning',
3838
3852
        'bzrlib.tests',
 
3853
        'bzrlib.tests.fixtures',
3839
3854
        'bzrlib.timestamp',
3840
3855
        'bzrlib.version_info_formats.format_custom',
3841
3856
        ]
4035
4050
    :param new_id: The id to assign to it.
4036
4051
    :return: The new test.
4037
4052
    """
4038
 
    new_test = copy(test)
 
4053
    new_test = copy.copy(test)
4039
4054
    new_test.id = lambda: new_id
4040
4055
    return new_test
4041
4056
 
4102
4117
        if test_id != None:
4103
4118
            ui.ui_factory.clear_term()
4104
4119
            sys.stderr.write('\nWhile running: %s\n' % (test_id,))
 
4120
        # Ugly, but the last thing we want here is fail, so bear with it.
 
4121
        printable_e = str(e).decode(osutils.get_user_encoding(), 'replace'
 
4122
                                    ).encode('ascii', 'replace')
4105
4123
        sys.stderr.write('Unable to remove testing dir %s\n%s'
4106
 
                         % (os.path.basename(dirname), e))
 
4124
                         % (os.path.basename(dirname), printable_e))
4107
4125
 
4108
4126
 
4109
4127
class Feature(object):
4339
4357
UnicodeFilename = _UnicodeFilename()
4340
4358
 
4341
4359
 
 
4360
class _ByteStringNamedFilesystem(Feature):
 
4361
    """Is the filesystem based on bytes?"""
 
4362
 
 
4363
    def _probe(self):
 
4364
        if os.name == "posix":
 
4365
            return True
 
4366
        return False
 
4367
 
 
4368
ByteStringNamedFilesystem = _ByteStringNamedFilesystem()
 
4369
 
 
4370
 
4342
4371
class _UTF8Filesystem(Feature):
4343
4372
    """Is the filesystem UTF-8?"""
4344
4373