~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

[merge] jam-integration 1527, including branch-formats, help text, misc bug fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import os
20
20
import sys
21
21
import unittest
 
22
import warnings
22
23
 
 
24
import bzrlib
23
25
from bzrlib.tests import (
24
26
                          _load_module_by_name,
 
27
                          ChrootedTestCase,
25
28
                          TestCase,
26
29
                          TestCaseInTempDir,
 
30
                          TestCaseWithTransport,
27
31
                          TestSkipped,
28
32
                          TextTestRunner,
29
33
                          )
 
34
import bzrlib.errors as errors
30
35
 
31
36
 
32
37
class SelftestTests(TestCase):
78
83
class TestTransportProviderAdapter(TestCase):
79
84
    """A group of tests that test the transport implementation adaption core.
80
85
 
 
86
    This is a meta test that the tests are applied to all available 
 
87
    transports.
 
88
 
81
89
    This will be generalised in the future which is why it is in this 
82
90
    test file even though it is specific to transport tests at the moment.
83
91
    """
106
114
        modules = _get_transport_modules()
107
115
        permutation_count = 0
108
116
        for module in modules:
109
 
            permutation_count += len(reduce(getattr, 
110
 
                (module + ".get_test_permutations").split('.')[1:],
111
 
                 __import__(module))())
 
117
            try:
 
118
                permutation_count += len(reduce(getattr, 
 
119
                    (module + ".get_test_permutations").split('.')[1:],
 
120
                     __import__(module))())
 
121
            except errors.DependencyNotPresent:
 
122
                pass
112
123
        input_test = TestTransportProviderAdapter(
113
124
            "test_adapter_sets_transport_class")
114
125
        adapter = TransportTestProviderAdapter()
122
133
        # that it does not just use the same one all the time.
123
134
        # and that the id is set correctly so that debugging is
124
135
        # easy.
 
136
        # 
 
137
        # An instance of this test is actually used as the input
 
138
        # for adapting it to all the available transports
 
139
        # (or i think so - ??? mbp)
125
140
        from bzrlib.transport.local import (LocalTransport,
126
141
                                            LocalRelpathServer,
127
142
                                            LocalAbspathServer,
128
143
                                            LocalURLServer
129
144
                                            )
130
 
        from bzrlib.transport.sftp import (SFTPTransport,
131
 
                                           SFTPAbsoluteServer,
132
 
                                           SFTPHomeDirServer,
133
 
                                           SFTPSiblingAbsoluteServer,
134
 
                                           )
 
145
        try:
 
146
            from bzrlib.transport.sftp import (SFTPTransport,
 
147
                                               SFTPAbsoluteServer,
 
148
                                               SFTPHomeDirServer,
 
149
                                               SFTPSiblingAbsoluteServer,
 
150
                                               )
 
151
        except errors.ParamikoNotPresent, e:
 
152
            warnings.warn(str(e))
 
153
            has_paramiko = False
 
154
        else:
 
155
            has_paramiko = True
135
156
        from bzrlib.transport.http import (HttpTransport,
136
157
                                           HttpServer
137
158
                                           )
156
177
        input_test = TestTransportProviderAdapter(
157
178
            "test_adapter_sets_transport_class")
158
179
        suite = TransportTestProviderAdapter().adapt(input_test)
 
180
        # tests are generated in collation order. 
 
181
        # XXX: but i'm not sure the order should really be part of the 
 
182
        # contract of the adapter, should it -- mbp 20060201
159
183
        test_iter = iter(suite)
160
184
        http_test = test_iter.next()
161
185
        local_relpath_test = test_iter.next()
162
186
        local_abspath_test = test_iter.next()
163
187
        local_urlpath_test = test_iter.next()
164
188
        memory_test = test_iter.next()
165
 
        sftp_abs_test = test_iter.next()
166
 
        sftp_homedir_test = test_iter.next()
167
 
        sftp_sibling_abs_test = test_iter.next()
 
189
        readonly_test = test_iter.next()
 
190
        if has_paramiko:
 
191
            sftp_abs_test = test_iter.next()
 
192
            sftp_homedir_test = test_iter.next()
 
193
            sftp_sibling_abs_test = test_iter.next()
168
194
        # ftp_test = test_iter.next()
 
195
        # should now be at the end of the test
169
196
        self.assertRaises(StopIteration, test_iter.next)
170
197
        self.assertEqual(LocalTransport, local_relpath_test.transport_class)
171
198
        self.assertEqual(LocalRelpathServer, local_relpath_test.transport_server)
176
203
        self.assertEqual(LocalTransport, local_urlpath_test.transport_class)
177
204
        self.assertEqual(LocalURLServer, local_urlpath_test.transport_server)
178
205
 
179
 
        self.assertEqual(SFTPTransport, sftp_abs_test.transport_class)
180
 
        self.assertEqual(SFTPAbsoluteServer, sftp_abs_test.transport_server)
181
 
        self.assertEqual(SFTPTransport, sftp_homedir_test.transport_class)
182
 
        self.assertEqual(SFTPHomeDirServer, sftp_homedir_test.transport_server)
183
 
        self.assertEqual(SFTPTransport, sftp_sibling_abs_test.transport_class)
184
 
        self.assertEqual(SFTPSiblingAbsoluteServer,
185
 
                         sftp_sibling_abs_test.transport_server)
 
206
        if has_paramiko:
 
207
            self.assertEqual(SFTPTransport, sftp_abs_test.transport_class)
 
208
            self.assertEqual(SFTPAbsoluteServer, sftp_abs_test.transport_server)
 
209
            self.assertEqual(SFTPTransport, sftp_homedir_test.transport_class)
 
210
            self.assertEqual(SFTPHomeDirServer, sftp_homedir_test.transport_server)
 
211
            self.assertEqual(SFTPTransport, sftp_sibling_abs_test.transport_class)
 
212
            self.assertEqual(SFTPSiblingAbsoluteServer,
 
213
                             sftp_sibling_abs_test.transport_server)
186
214
 
187
215
        self.assertEqual(HttpTransport, http_test.transport_class)
188
216
        self.assertEqual(HttpServer, http_test.transport_server)
200
228
                         "TestTransportProviderAdapter."
201
229
                         "test_adapter_sets_transport_class(LocalRelpathServer)",
202
230
                         local_relpath_test.id())
 
231
 
 
232
 
 
233
class TestBranchProviderAdapter(TestCase):
 
234
    """A group of tests that test the branch implementation test adapter."""
 
235
 
 
236
    def test_adapted_tests(self):
 
237
        # check that constructor parameters are passed through to the adapted
 
238
        # test.
 
239
        from bzrlib.branch import BranchTestProviderAdapter
 
240
        input_test = TestBranchProviderAdapter(
 
241
            "test_adapted_tests")
 
242
        server1 = "a"
 
243
        server2 = "b"
 
244
        formats = ["c", "d"]
 
245
        adapter = BranchTestProviderAdapter(server1, server2, formats)
 
246
        suite = adapter.adapt(input_test)
 
247
        tests = list(iter(suite))
 
248
        self.assertEqual(2, len(tests))
 
249
        self.assertEqual(tests[0].branch_format, formats[0])
 
250
        self.assertEqual(tests[0].transport_server, server1)
 
251
        self.assertEqual(tests[0].transport_readonly_server, server2)
 
252
        self.assertEqual(tests[1].branch_format, formats[1])
 
253
        self.assertEqual(tests[1].transport_server, server1)
 
254
        self.assertEqual(tests[1].transport_readonly_server, server2)
 
255
 
 
256
 
 
257
class TestTestCaseWithTransport(TestCaseWithTransport):
 
258
    """Tests for the convenience functions TestCaseWithTransport introduces."""
 
259
 
 
260
    def test_get_readonly_url_none(self):
 
261
        from bzrlib.transport import get_transport
 
262
        from bzrlib.transport.memory import MemoryServer
 
263
        from bzrlib.transport.readonly import ReadonlyTransportDecorator
 
264
        self.transport_server = MemoryServer
 
265
        self.transport_readonly_server = None
 
266
        # calling get_readonly_transport() constructs a decorator on the url
 
267
        # for the server
 
268
        url = self.get_readonly_url()
 
269
        url2 = self.get_readonly_url('foo/bar')
 
270
        t = get_transport(url)
 
271
        t2 = get_transport(url2)
 
272
        self.failUnless(isinstance(t, ReadonlyTransportDecorator))
 
273
        self.failUnless(isinstance(t2, ReadonlyTransportDecorator))
 
274
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
 
275
 
 
276
    def test_get_readonly_url_http(self):
 
277
        from bzrlib.transport import get_transport
 
278
        from bzrlib.transport.local import LocalRelpathServer
 
279
        from bzrlib.transport.http import HttpServer, HttpTransport
 
280
        self.transport_server = LocalRelpathServer
 
281
        self.transport_readonly_server = HttpServer
 
282
        # calling get_readonly_transport() gives us a HTTP server instance.
 
283
        url = self.get_readonly_url()
 
284
        url2 = self.get_readonly_url('foo/bar')
 
285
        t = get_transport(url)
 
286
        t2 = get_transport(url2)
 
287
        self.failUnless(isinstance(t, HttpTransport))
 
288
        self.failUnless(isinstance(t2, HttpTransport))
 
289
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
 
290
 
 
291
 
 
292
class TestChrootedTest(ChrootedTestCase):
 
293
 
 
294
    def test_root_is_root(self):
 
295
        from bzrlib.transport import get_transport
 
296
        t = get_transport(self.get_readonly_url())
 
297
        url = t.base
 
298
        self.assertEqual(url, t.clone('..').base)