~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: 2007-04-28 15:04:17 UTC
  • mfrom: (2466 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2566.
  • Revision ID: john@arbash-meinel.com-20070428150417-trp3pi0pzd411pu4
[merge] bzr.dev 2466

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, 2007 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
from bzrlib import (
 
25
    errors,
 
26
    urlutils,
 
27
    )
25
28
from bzrlib.errors import (ConnectionError,
26
29
                           DependencyNotPresent,
27
30
                           FileExists,
34
37
from bzrlib.tests import TestCase, TestCaseInTempDir
35
38
from bzrlib.transport import (_CoalescedOffset,
36
39
                              _get_protocol_handlers,
 
40
                              _set_protocol_handlers,
37
41
                              _get_transport_modules,
38
42
                              get_transport,
39
 
                              _protocol_handlers,
40
43
                              register_lazy_transport,
41
 
                              _set_protocol_handlers,
 
44
                              register_transport_proto,
 
45
                              _clear_protocol_handlers,
42
46
                              Transport,
43
47
                              )
44
48
from bzrlib.transport.chroot import ChrootServer
55
59
 
56
60
    def test__get_set_protocol_handlers(self):
57
61
        handlers = _get_protocol_handlers()
58
 
        self.assertNotEqual({}, handlers)
 
62
        self.assertNotEqual([], handlers.keys( ))
59
63
        try:
60
 
            _set_protocol_handlers({})
61
 
            self.assertEqual({}, _get_protocol_handlers())
 
64
            _clear_protocol_handlers()
 
65
            self.assertEqual([], _get_protocol_handlers().keys())
62
66
        finally:
63
67
            _set_protocol_handlers(handlers)
64
68
 
67
71
        class SampleHandler(object):
68
72
            """I exist, isnt that enough?"""
69
73
        try:
70
 
            my_handlers = {}
71
 
            _set_protocol_handlers(my_handlers)
 
74
            _clear_protocol_handlers()
 
75
            register_transport_proto('foo')
72
76
            register_lazy_transport('foo', 'bzrlib.tests.test_transport', 'TestTransport.SampleHandler')
 
77
            register_transport_proto('bar')
73
78
            register_lazy_transport('bar', 'bzrlib.tests.test_transport', 'TestTransport.SampleHandler')
74
79
            self.assertEqual([SampleHandler.__module__, 'bzrlib.transport.chroot'],
75
80
                             _get_transport_modules())
80
85
        """Transport with missing dependency causes no error"""
81
86
        saved_handlers = _get_protocol_handlers()
82
87
        try:
 
88
            register_transport_proto('foo')
83
89
            register_lazy_transport('foo', 'bzrlib.tests.test_transport',
84
90
                    'BadTransportHandler')
85
91
            try:
100
106
        """Transport with missing dependency causes no error"""
101
107
        saved_handlers = _get_protocol_handlers()
102
108
        try:
103
 
            _set_protocol_handlers({})
 
109
            _clear_protocol_handlers()
 
110
            register_transport_proto('foo')
104
111
            register_lazy_transport('foo', 'bzrlib.tests.test_transport',
105
112
                    'BackupTransportHandler')
106
113
            register_lazy_transport('foo', 'bzrlib.tests.test_transport',
121
128
        self.assertEqual('/etc',
122
129
                         t._combine_paths('/home/sarah', '/etc'))
123
130
 
 
131
    def test_local_abspath_non_local_transport(self):
 
132
        # the base implementation should throw
 
133
        t = MemoryTransport()
 
134
        e = self.assertRaises(errors.NotLocalUrl, t.local_abspath, 't')
 
135
        self.assertEqual('memory:///t is not a local path.', str(e))
 
136
 
124
137
 
125
138
class TestCoalesceOffsets(TestCase):
126
139
    
361
374
        backing_transport = MemoryTransport()
362
375
        server = ChrootServer(backing_transport)
363
376
        server.setUp()
364
 
        self.assertTrue(server.scheme in _protocol_handlers.keys())
 
377
        self.assertTrue(server.scheme in _get_protocol_handlers().keys())
365
378
 
366
379
    def test_tearDown(self):
367
380
        backing_transport = MemoryTransport()
368
381
        server = ChrootServer(backing_transport)
369
382
        server.setUp()
370
383
        server.tearDown()
371
 
        self.assertFalse(server.scheme in _protocol_handlers.keys())
 
384
        self.assertFalse(server.scheme in _get_protocol_handlers().keys())
372
385
 
373
386
    def test_get_url(self):
374
387
        backing_transport = MemoryTransport()
461
474
        transport = self.get_nfs_transport('.')
462
475
        self.build_tree(['from/', 'from/foo', 'to/', 'to/bar'],
463
476
                        transport=transport)
464
 
        self.assertRaises(bzrlib.errors.ResourceBusy,
 
477
        self.assertRaises(errors.ResourceBusy,
465
478
                          transport.rename, 'from', 'to')
466
479
 
467
480
 
560
573
        self.assertIsInstance(t, LocalTransport)
561
574
        self.assertEquals(t.base, here_url)
562
575
 
 
576
    def test_local_abspath(self):
 
577
        here = os.path.abspath('.')
 
578
        t = get_transport(here)
 
579
        self.assertEquals(t.local_abspath(''), here)
 
580
 
563
581
 
564
582
class TestWin32LocalTransport(TestCase):
565
583