/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport_implementations.py

  • Committer: John Arbash Meinel
  • Date: 2007-07-11 23:45:20 UTC
  • mfrom: (2601 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2643.
  • Revision ID: john@arbash-meinel.com-20070711234520-do3h7zw8skbathpz
[merge] bzr.dev 2601

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from StringIO import StringIO as pyStringIO
26
26
import stat
27
27
import sys
 
28
import unittest
28
29
 
29
30
from bzrlib import (
30
31
    errors,
45
46
from bzrlib.osutils import getcwd
46
47
from bzrlib.smart import medium
47
48
from bzrlib.symbol_versioning import zero_eleven
48
 
from bzrlib.tests import TestCaseInTempDir, TestSkipped
 
49
from bzrlib.tests import TestCaseInTempDir, TestScenarioApplier, TestSkipped
49
50
from bzrlib.tests.test_transport import TestTransportImplementation
50
 
from bzrlib.transport import memory, remote
 
51
from bzrlib.transport import memory, remote, _get_transport_modules
51
52
import bzrlib.transport
52
53
 
53
54
 
 
55
class TransportTestProviderAdapter(TestScenarioApplier):
 
56
    """A tool to generate a suite testing all transports for a single test.
 
57
 
 
58
    This is done by copying the test once for each transport and injecting
 
59
    the transport_class and transport_server classes into each copy. Each copy
 
60
    is also given a new id() to make it easy to identify.
 
61
    """
 
62
 
 
63
    def __init__(self):
 
64
        self.scenarios = self._test_permutations()
 
65
 
 
66
    def get_transport_test_permutations(self, module):
 
67
        """Get the permutations module wants to have tested."""
 
68
        if getattr(module, 'get_test_permutations', None) is None:
 
69
            raise AssertionError("transport module %s doesn't provide get_test_permutations()"
 
70
                    % module.__name__)
 
71
            ##warning("transport module %s doesn't provide get_test_permutations()"
 
72
            ##       % module.__name__)
 
73
            return []
 
74
        return module.get_test_permutations()
 
75
 
 
76
    def _test_permutations(self):
 
77
        """Return a list of the klass, server_factory pairs to test."""
 
78
        result = []
 
79
        for module in _get_transport_modules():
 
80
            try:
 
81
                permutations = self.get_transport_test_permutations(
 
82
                    reduce(getattr, (module).split('.')[1:], __import__(module)))
 
83
                for (klass, server_factory) in permutations:
 
84
                    scenario = (server_factory.__name__,
 
85
                        {"transport_class":klass,
 
86
                         "transport_server":server_factory})
 
87
                    result.append(scenario)
 
88
            except errors.DependencyNotPresent, e:
 
89
                # Continue even if a dependency prevents us 
 
90
                # from running this test
 
91
                pass
 
92
        return result
 
93
 
 
94
 
 
95
 
54
96
class TransportTests(TestTransportImplementation):
55
97
 
56
98
    def setUp(self):
93
135
        t_b = t_a.clone('b')
94
136
        self.assertRaises(NoSuchFile, t_b.ensure_base)
95
137
 
 
138
    def test_external_url(self):
 
139
        """.external_url either works or raises InProcessTransport."""
 
140
        t = self.get_transport()
 
141
        try:
 
142
            t.external_url()
 
143
        except errors.InProcessTransport:
 
144
            pass
 
145
 
96
146
    def test_has(self):
97
147
        t = self.get_transport()
98
148
 
139
189
        self.assertListRaises(NoSuchFile, t.get_multi, ['a', 'b', 'c'])
140
190
        self.assertListRaises(NoSuchFile, t.get_multi, iter(['a', 'b', 'c']))
141
191
 
 
192
    def test_get_directory_read_gives_ReadError(self):
 
193
        """consistent errors for read() on a file returned by get()."""
 
194
        t = self.get_transport()
 
195
        if t.is_readonly():
 
196
            self.build_tree(['a directory/'])
 
197
        else:
 
198
            t.mkdir('a%20directory')
 
199
        # getting the file must either work or fail with a PathError
 
200
        try:
 
201
            a_file = t.get('a%20directory')
 
202
        except (errors.PathError, errors.RedirectRequested):
 
203
            # early failure return immediately.
 
204
            return
 
205
        # having got a file, read() must either work (i.e. http reading a dir listing) or
 
206
        # fail with ReadError
 
207
        try:
 
208
            a_file.read()
 
209
        except errors.ReadError:
 
210
            pass
 
211
 
142
212
    def test_get_bytes(self):
143
213
        t = self.get_transport()
144
214