~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-06-30 10:12:41 UTC
  • mfrom: (5273.1.11 cleanup)
  • Revision ID: pqm@pqm.ubuntu.com-20100630101241-gj9gnm31gj0ptaj7
(vila) Cleanup tests importing get_transport. (Vincent Ladeuil)

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,
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
 
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:
2413
2414
            backing_server = self.get_server()
2414
2415
        smart_server = test_server.SmartTCPServer_for_testing()
2415
2416
        self.start_server(smart_server, backing_server)
2416
 
        remote_transport = get_transport(smart_server.get_url()).clone(path)
 
2417
        remote_transport = _mod_transport.get_transport(smart_server.get_url()
 
2418
                                                   ).clone(path)
2417
2419
        return remote_transport
2418
2420
 
2419
2421
    def make_branch_and_memory_tree(self, relpath, format=None):
2568
2570
                "a list or a tuple. Got %r instead" % (shape,))
2569
2571
        # It's OK to just create them using forward slashes on windows.
2570
2572
        if transport is None or transport.is_readonly():
2571
 
            transport = get_transport(".")
 
2573
            transport = _mod_transport.get_transport(".")
2572
2574
        for name in shape:
2573
2575
            self.assertIsInstance(name, basestring)
2574
2576
            if name[-1] == '/':
3315
3317
                '--subunit']
3316
3318
            if '--no-plugins' in sys.argv:
3317
3319
                argv.append('--no-plugins')
3318
 
            # stderr=STDOUT would be ideal, but until we prevent noise on
3319
 
            # stderr it can interrupt the subunit protocol.
3320
 
            process = Popen(argv, stdin=PIPE, stdout=PIPE, stderr=PIPE,
3321
 
                bufsize=1)
 
3320
            # stderr=subprocess.STDOUT would be ideal, but until we prevent
 
3321
            # noise on stderr it can interrupt the subunit protocol.
 
3322
            process = subprocess.Popen(argv, stdin=subprocess.PIPE,
 
3323
                                      stdout=subprocess.PIPE,
 
3324
                                      stderr=subprocess.PIPE,
 
3325
                                      bufsize=1)
3322
3326
            test = TestInSubprocess(process, test_list_file_name)
3323
3327
            result.append(test)
3324
3328
        except:
4043
4047
    :param new_id: The id to assign to it.
4044
4048
    :return: The new test.
4045
4049
    """
4046
 
    new_test = copy(test)
 
4050
    new_test = copy.copy(test)
4047
4051
    new_test.id = lambda: new_id
4048
4052
    return new_test
4049
4053