~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport.py

  • Committer: wang
  • Date: 2006-10-29 13:41:32 UTC
  • mto: (2104.4.1 wang_65714)
  • mto: This revision was merged to the branch mainline in revision 2109.
  • Revision ID: wang@ubuntu-20061029134132-3d7f4216f20c4aef
Replace python's difflib by patiencediff because the worst case 
performance is cubic for difflib and people commiting large data 
files are often hurt by this. The worst case performance of patience is 
quadratic. Fix bug 65714.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
21
21
from cStringIO import StringIO
22
22
 
23
23
import bzrlib
 
24
from bzrlib import urlutils
24
25
from bzrlib.errors import (NoSuchFile, FileExists,
25
26
                           TransportNotPossible,
26
27
                           ConnectionError,
40
41
from bzrlib.transport.local import LocalTransport
41
42
 
42
43
 
 
44
# TODO: Should possibly split transport-specific tests into their own files.
 
45
 
 
46
 
43
47
class TestTransport(TestCase):
44
48
    """Test the non transport-concrete class functionality."""
45
49
 
100
104
        finally:
101
105
            _set_protocol_handlers(saved_handlers)
102
106
 
 
107
    def test__combine_paths(self):
 
108
        t = Transport('/')
 
109
        self.assertEqual('/home/sarah/project/foo',
 
110
                         t._combine_paths('/home/sarah', 'project/foo'))
 
111
        self.assertEqual('/etc',
 
112
                         t._combine_paths('/home/sarah', '../../etc'))
 
113
        self.assertEqual('/etc',
 
114
                         t._combine_paths('/home/sarah', '../../../etc'))
 
115
        self.assertEqual('/etc',
 
116
                         t._combine_paths('/home/sarah', '/etc'))
 
117
 
103
118
 
104
119
class TestCoalesceOffsets(TestCase):
105
120
    
168
183
    def test_clone(self):
169
184
        transport = MemoryTransport()
170
185
        self.assertTrue(isinstance(transport, MemoryTransport))
 
186
        self.assertEqual("memory:///", transport.clone("/").base)
171
187
 
172
188
    def test_abspath(self):
173
189
        transport = MemoryTransport()
174
190
        self.assertEqual("memory:///relpath", transport.abspath('relpath'))
175
191
 
176
 
    def test_relpath(self):
177
 
        transport = MemoryTransport()
 
192
    def test_abspath_of_root(self):
 
193
        transport = MemoryTransport()
 
194
        self.assertEqual("memory:///", transport.base)
 
195
        self.assertEqual("memory:///", transport.abspath('/'))
 
196
 
 
197
    def test_abspath_of_relpath_starting_at_root(self):
 
198
        transport = MemoryTransport()
 
199
        self.assertEqual("memory:///foo", transport.abspath('/foo'))
178
200
 
179
201
    def test_append_and_get(self):
180
202
        transport = MemoryTransport()
181
 
        transport.append('path', StringIO('content'))
 
203
        transport.append_bytes('path', 'content')
182
204
        self.assertEqual(transport.get('path').read(), 'content')
183
 
        transport.append('path', StringIO('content'))
 
205
        transport.append_file('path', StringIO('content'))
184
206
        self.assertEqual(transport.get('path').read(), 'contentcontent')
185
207
 
186
208
    def test_put_and_get(self):
187
209
        transport = MemoryTransport()
188
 
        transport.put('path', StringIO('content'))
 
210
        transport.put_file('path', StringIO('content'))
189
211
        self.assertEqual(transport.get('path').read(), 'content')
190
 
        transport.put('path', StringIO('content'))
 
212
        transport.put_bytes('path', 'content')
191
213
        self.assertEqual(transport.get('path').read(), 'content')
192
214
 
193
215
    def test_append_without_dir_fails(self):
194
216
        transport = MemoryTransport()
195
217
        self.assertRaises(NoSuchFile,
196
 
                          transport.append, 'dir/path', StringIO('content'))
 
218
                          transport.append_bytes, 'dir/path', 'content')
197
219
 
198
220
    def test_put_without_dir_fails(self):
199
221
        transport = MemoryTransport()
200
222
        self.assertRaises(NoSuchFile,
201
 
                          transport.put, 'dir/path', StringIO('content'))
 
223
                          transport.put_file, 'dir/path', StringIO('content'))
202
224
 
203
225
    def test_get_missing(self):
204
226
        transport = MemoryTransport()
210
232
 
211
233
    def test_has_present(self):
212
234
        transport = MemoryTransport()
213
 
        transport.append('foo', StringIO('content'))
 
235
        transport.append_bytes('foo', 'content')
214
236
        self.assertEquals(True, transport.has('foo'))
215
237
 
216
238
    def test_mkdir(self):
217
239
        transport = MemoryTransport()
218
240
        transport.mkdir('dir')
219
 
        transport.append('dir/path', StringIO('content'))
 
241
        transport.append_bytes('dir/path', 'content')
220
242
        self.assertEqual(transport.get('dir/path').read(), 'content')
221
243
 
222
244
    def test_mkdir_missing_parent(self):
238
260
    def test_iter_files_recursive(self):
239
261
        transport = MemoryTransport()
240
262
        transport.mkdir('dir')
241
 
        transport.put('dir/foo', StringIO('content'))
242
 
        transport.put('dir/bar', StringIO('content'))
243
 
        transport.put('bar', StringIO('content'))
 
263
        transport.put_bytes('dir/foo', 'content')
 
264
        transport.put_bytes('dir/bar', 'content')
 
265
        transport.put_bytes('bar', 'content')
244
266
        paths = set(transport.iter_files_recursive())
245
267
        self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths)
246
268
 
247
269
    def test_stat(self):
248
270
        transport = MemoryTransport()
249
 
        transport.put('foo', StringIO('content'))
250
 
        transport.put('bar', StringIO('phowar'))
 
271
        transport.put_bytes('foo', 'content')
 
272
        transport.put_bytes('bar', 'phowar')
251
273
        self.assertEqual(7, transport.stat('foo').st_size)
252
274
        self.assertEqual(6, transport.stat('bar').st_size)
253
275
 
319
341
        server = fakenfs.FakeNFSServer()
320
342
        server.setUp()
321
343
        try:
322
 
            # the server should be a relpath localhost server
323
 
            self.assertEqual(server.get_url(), 'fakenfs+.')
 
344
            # the url should be decorated appropriately
 
345
            self.assertStartsWith(server.get_url(), 'fakenfs+')
324
346
            # and we should be able to get a transport for it
325
347
            transport = get_transport(server.get_url())
326
348
            # which must be a FakeNFSTransportDecorator instance.
409
431
        base_url = self._server.get_url()
410
432
        # try getting the transport via the regular interface:
411
433
        t = get_transport(base_url)
412
 
        if not isinstance(t, self.transport_class): 
 
434
        if not isinstance(t, self.transport_class):
413
435
            # we did not get the correct transport class type. Override the
414
436
            # regular connection behaviour by direct construction.
415
437
            t = self.transport_class(base_url)
416
438
        return t
 
439
 
 
440
 
 
441
class TestLocalTransports(TestCase):
 
442
 
 
443
    def test_get_transport_from_abspath(self):
 
444
        here = os.path.abspath('.')
 
445
        t = get_transport(here)
 
446
        self.assertIsInstance(t, LocalTransport)
 
447
        self.assertEquals(t.base, urlutils.local_path_to_url(here) + '/')
 
448
 
 
449
    def test_get_transport_from_relpath(self):
 
450
        here = os.path.abspath('.')
 
451
        t = get_transport('.')
 
452
        self.assertIsInstance(t, LocalTransport)
 
453
        self.assertEquals(t.base, urlutils.local_path_to_url('.') + '/')
 
454
 
 
455
    def test_get_transport_from_local_url(self):
 
456
        here = os.path.abspath('.')
 
457
        here_url = urlutils.local_path_to_url(here) + '/'
 
458
        t = get_transport(here_url)
 
459
        self.assertIsInstance(t, LocalTransport)
 
460
        self.assertEquals(t.base, here_url)