~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

Merge from integration

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
 
23
24
import bzrlib
24
25
from bzrlib.tests import (
30
31
                          TestSkipped,
31
32
                          TextTestRunner,
32
33
                          )
 
34
import bzrlib.errors as errors
33
35
 
34
36
 
35
37
class SelftestTests(TestCase):
81
83
class TestTransportProviderAdapter(TestCase):
82
84
    """A group of tests that test the transport implementation adaption core.
83
85
 
 
86
    This is a meta test that the tests are applied to all available 
 
87
    transports.
 
88
 
84
89
    This will be generalised in the future which is why it is in this 
85
90
    test file even though it is specific to transport tests at the moment.
86
91
    """
109
114
        modules = _get_transport_modules()
110
115
        permutation_count = 0
111
116
        for module in modules:
112
 
            permutation_count += len(reduce(getattr, 
113
 
                (module + ".get_test_permutations").split('.')[1:],
114
 
                 __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
115
123
        input_test = TestTransportProviderAdapter(
116
124
            "test_adapter_sets_transport_class")
117
125
        adapter = TransportTestProviderAdapter()
125
133
        # that it does not just use the same one all the time.
126
134
        # and that the id is set correctly so that debugging is
127
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)
128
140
        from bzrlib.transport.local import (LocalTransport,
129
141
                                            LocalRelpathServer,
130
142
                                            LocalAbspathServer,
131
143
                                            LocalURLServer
132
144
                                            )
133
 
        from bzrlib.transport.sftp import (SFTPTransport,
134
 
                                           SFTPAbsoluteServer,
135
 
                                           SFTPHomeDirServer,
136
 
                                           SFTPSiblingAbsoluteServer,
137
 
                                           )
 
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
138
156
        from bzrlib.transport.http import (HttpTransport,
139
157
                                           HttpServer
140
158
                                           )
159
177
        input_test = TestTransportProviderAdapter(
160
178
            "test_adapter_sets_transport_class")
161
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
162
183
        test_iter = iter(suite)
163
184
        http_test = test_iter.next()
164
185
        local_relpath_test = test_iter.next()
166
187
        local_urlpath_test = test_iter.next()
167
188
        memory_test = test_iter.next()
168
189
        readonly_test = test_iter.next()
169
 
        sftp_abs_test = test_iter.next()
170
 
        sftp_homedir_test = test_iter.next()
171
 
        sftp_sibling_abs_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()
172
194
        # ftp_test = test_iter.next()
 
195
        # should now be at the end of the test
173
196
        self.assertRaises(StopIteration, test_iter.next)
174
197
        self.assertEqual(LocalTransport, local_relpath_test.transport_class)
175
198
        self.assertEqual(LocalRelpathServer, local_relpath_test.transport_server)
180
203
        self.assertEqual(LocalTransport, local_urlpath_test.transport_class)
181
204
        self.assertEqual(LocalURLServer, local_urlpath_test.transport_server)
182
205
 
183
 
        self.assertEqual(SFTPTransport, sftp_abs_test.transport_class)
184
 
        self.assertEqual(SFTPAbsoluteServer, sftp_abs_test.transport_server)
185
 
        self.assertEqual(SFTPTransport, sftp_homedir_test.transport_class)
186
 
        self.assertEqual(SFTPHomeDirServer, sftp_homedir_test.transport_server)
187
 
        self.assertEqual(SFTPTransport, sftp_sibling_abs_test.transport_class)
188
 
        self.assertEqual(SFTPSiblingAbsoluteServer,
189
 
                         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)
190
214
 
191
215
        self.assertEqual(HttpTransport, http_test.transport_class)
192
216
        self.assertEqual(HttpServer, http_test.transport_server)