~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/local.py

 * Test sftp with relative, absolute-in-homedir and absolute-not-in-homedir
   paths for the transport tests. Introduce blackbox remote sftp tests that
   test the same permutations. (Robert Collins, Robey Pointer)

 * Transport implementation tests are now independent of the local file
   system, which allows tests for esoteric transports, and for features
   not available in the local file system. They also repeat for variations
   on the URL scheme that can introduce issues in the transport code,
   see bzrlib.transport.TransportTestProviderAdapter() for this.
   (Robert Collins).

 * TestCase.build_tree uses the transport interface to build trees, pass
   in a transport parameter to give it an existing connection.
   (Robert Collins).

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import urllib
26
26
 
27
27
from bzrlib.trace import mutter
28
 
from bzrlib.transport import Transport
 
28
from bzrlib.transport import Transport, Server
29
29
from bzrlib.osutils import abspath, realpath, normpath, pathjoin, rename
30
30
 
31
31
 
38
38
            base = base[7:]
39
39
        # realpath is incompatible with symlinks. When we traverse
40
40
        # up we might be able to normpath stuff. RBC 20051003
41
 
        super(LocalTransport, self).__init__(normpath(abspath(base)))
 
41
        base = normpath(abspath(base))
 
42
        if base[-1] != '/':
 
43
            base = base + '/'
 
44
        super(LocalTransport, self).__init__(base)
42
45
 
43
46
    def should_cache(self):
44
47
        return False
66
69
        from bzrlib.osutils import relpath
67
70
        if abspath is None:
68
71
            abspath = u'.'
69
 
        return relpath(self.base, abspath)
 
72
        if abspath.endswith('/'):
 
73
            abspath = abspath[:-1]
 
74
        return relpath(self.base[:-1], abspath)
70
75
 
71
76
    def has(self, relpath):
72
77
        return os.access(self.abspath(relpath), os.F_OK)
129
134
        """Append the text in the file-like object into the final
130
135
        location.
131
136
        """
132
 
        fp = open(self.abspath(relpath), 'ab')
 
137
        try:
 
138
            fp = open(self.abspath(relpath), 'ab')
 
139
        except (IOError, OSError),e:
 
140
            self._translate_error(e, relpath)
133
141
        self._pump(f, fp)
134
142
 
135
143
    def copy(self, rel_from, rel_to):
250
258
    def __del__(self):
251
259
        shutil.rmtree(self.base, ignore_errors=True)
252
260
        mutter("%r destroyed" % self)
 
261
 
 
262
 
 
263
class LocalRelpathServer(Server):
 
264
    """A pretend server for local transports, using relpaths."""
 
265
 
 
266
    def get_url(self):
 
267
        """See Transport.Server.get_url."""
 
268
        return "."
 
269
 
 
270
 
 
271
class LocalAbspathServer(Server):
 
272
    """A pretend server for local transports, using absolute paths."""
 
273
 
 
274
    def get_url(self):
 
275
        """See Transport.Server.get_url."""
 
276
        return os.path.abspath("")
 
277
 
 
278
 
 
279
class LocalURLServer(Server):
 
280
    """A pretend server for local transports, using file:// urls."""
 
281
 
 
282
    def get_url(self):
 
283
        """See Transport.Server.get_url."""
 
284
        # FIXME: \ to / on windows
 
285
        return "file://%s" % os.path.abspath("")
 
286
 
 
287
 
 
288
def get_test_permutations():
 
289
    """Return the permutations to be used in testing."""
 
290
    return [(LocalTransport, LocalRelpathServer),
 
291
            (LocalTransport, LocalAbspathServer),
 
292
            (LocalTransport, LocalURLServer),
 
293
            ]