~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-30 13:54:37 UTC
  • mto: (1946.2.6 reduce-knit-churn)
  • mto: This revision was merged to the branch mainline in revision 1898.
  • Revision ID: john@arbash-meinel.com-20060730135437-1d722abdb14bff76
(jelmer) Install new intertree tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006 by 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
25
24
from bzrlib.errors import (NoSuchFile, FileExists,
26
25
                           TransportNotPossible,
27
26
                           ConnectionError,
41
40
from bzrlib.transport.local import LocalTransport
42
41
 
43
42
 
44
 
# TODO: Should possibly split transport-specific tests into their own files.
45
 
 
46
 
 
47
43
class TestTransport(TestCase):
48
44
    """Test the non transport-concrete class functionality."""
49
45
 
104
100
        finally:
105
101
            _set_protocol_handlers(saved_handlers)
106
102
 
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
 
 
118
103
 
119
104
class TestCoalesceOffsets(TestCase):
120
105
    
183
168
    def test_clone(self):
184
169
        transport = MemoryTransport()
185
170
        self.assertTrue(isinstance(transport, MemoryTransport))
186
 
        self.assertEqual("memory:///", transport.clone("/").base)
187
171
 
188
172
    def test_abspath(self):
189
173
        transport = MemoryTransport()
190
174
        self.assertEqual("memory:///relpath", transport.abspath('relpath'))
191
175
 
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'))
 
176
    def test_relpath(self):
 
177
        transport = MemoryTransport()
200
178
 
201
179
    def test_append_and_get(self):
202
180
        transport = MemoryTransport()
203
 
        transport.append_bytes('path', 'content')
 
181
        transport.append('path', StringIO('content'))
204
182
        self.assertEqual(transport.get('path').read(), 'content')
205
 
        transport.append_file('path', StringIO('content'))
 
183
        transport.append('path', StringIO('content'))
206
184
        self.assertEqual(transport.get('path').read(), 'contentcontent')
207
185
 
208
186
    def test_put_and_get(self):
209
187
        transport = MemoryTransport()
210
 
        transport.put_file('path', StringIO('content'))
 
188
        transport.put('path', StringIO('content'))
211
189
        self.assertEqual(transport.get('path').read(), 'content')
212
 
        transport.put_bytes('path', 'content')
 
190
        transport.put('path', StringIO('content'))
213
191
        self.assertEqual(transport.get('path').read(), 'content')
214
192
 
215
193
    def test_append_without_dir_fails(self):
216
194
        transport = MemoryTransport()
217
195
        self.assertRaises(NoSuchFile,
218
 
                          transport.append_bytes, 'dir/path', 'content')
 
196
                          transport.append, 'dir/path', StringIO('content'))
219
197
 
220
198
    def test_put_without_dir_fails(self):
221
199
        transport = MemoryTransport()
222
200
        self.assertRaises(NoSuchFile,
223
 
                          transport.put_file, 'dir/path', StringIO('content'))
 
201
                          transport.put, 'dir/path', StringIO('content'))
224
202
 
225
203
    def test_get_missing(self):
226
204
        transport = MemoryTransport()
232
210
 
233
211
    def test_has_present(self):
234
212
        transport = MemoryTransport()
235
 
        transport.append_bytes('foo', 'content')
 
213
        transport.append('foo', StringIO('content'))
236
214
        self.assertEquals(True, transport.has('foo'))
237
215
 
238
216
    def test_mkdir(self):
239
217
        transport = MemoryTransport()
240
218
        transport.mkdir('dir')
241
 
        transport.append_bytes('dir/path', 'content')
 
219
        transport.append('dir/path', StringIO('content'))
242
220
        self.assertEqual(transport.get('dir/path').read(), 'content')
243
221
 
244
222
    def test_mkdir_missing_parent(self):
260
238
    def test_iter_files_recursive(self):
261
239
        transport = MemoryTransport()
262
240
        transport.mkdir('dir')
263
 
        transport.put_bytes('dir/foo', 'content')
264
 
        transport.put_bytes('dir/bar', 'content')
265
 
        transport.put_bytes('bar', 'content')
 
241
        transport.put('dir/foo', StringIO('content'))
 
242
        transport.put('dir/bar', StringIO('content'))
 
243
        transport.put('bar', StringIO('content'))
266
244
        paths = set(transport.iter_files_recursive())
267
245
        self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths)
268
246
 
269
247
    def test_stat(self):
270
248
        transport = MemoryTransport()
271
 
        transport.put_bytes('foo', 'content')
272
 
        transport.put_bytes('bar', 'phowar')
 
249
        transport.put('foo', StringIO('content'))
 
250
        transport.put('bar', StringIO('phowar'))
273
251
        self.assertEqual(7, transport.stat('foo').st_size)
274
252
        self.assertEqual(6, transport.stat('bar').st_size)
275
253
 
341
319
        server = fakenfs.FakeNFSServer()
342
320
        server.setUp()
343
321
        try:
344
 
            # the url should be decorated appropriately
345
 
            self.assertStartsWith(server.get_url(), 'fakenfs+')
 
322
            # the server should be a relpath localhost server
 
323
            self.assertEqual(server.get_url(), 'fakenfs+.')
346
324
            # and we should be able to get a transport for it
347
325
            transport = get_transport(server.get_url())
348
326
            # which must be a FakeNFSTransportDecorator instance.
431
409
        base_url = self._server.get_url()
432
410
        # try getting the transport via the regular interface:
433
411
        t = get_transport(base_url)
434
 
        if not isinstance(t, self.transport_class):
 
412
        if not isinstance(t, self.transport_class): 
435
413
            # we did not get the correct transport class type. Override the
436
414
            # regular connection behaviour by direct construction.
437
415
            t = self.transport_class(base_url)
438
416
        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)