~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Robert Collins
  • Date: 2006-01-05 22:30:59 UTC
  • mto: (1534.1.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1536.
  • Revision ID: robertc@robertcollins.net-20060105223059-a8b64f7b47cf12fb
 * bzrlib.osutils.safe_unicode now exists to provide parameter coercion
   for functions that need unicode strings. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
                          _load_module_by_name,
25
25
                          TestCase,
26
26
                          TestCaseInTempDir,
27
 
                          TestCaseWithTransport,
28
27
                          TestSkipped,
29
28
                          TextTestRunner,
30
29
                          )
65
64
 
66
65
class TestSkippedTest(TestCase):
67
66
    """Try running a test which is skipped, make sure it's reported properly."""
68
 
 
69
67
    def test_skipped_test(self):
70
68
        # must be hidden in here so it's not run as a real test
71
69
        def skipping_test():
74
72
        test = unittest.FunctionTestCase(skipping_test)
75
73
        result = runner.run(test)
76
74
        self.assertTrue(result.wasSuccessful())
77
 
 
78
 
 
79
 
class TestTransportProviderAdapter(TestCase):
80
 
    """A group of tests that test the transport implementation adaption core.
81
 
 
82
 
    This will be generalised in the future which is why it is in this 
83
 
    test file even though it is specific to transport tests at the moment.
84
 
    """
85
 
 
86
 
    def test_get_transport_permutations(self):
87
 
        # this checks that we the module get_test_permutations call
88
 
        # is made by the adapter get_transport_test_permitations method.
89
 
        class MockModule(object):
90
 
            def get_test_permutations(self):
91
 
                return sample_permutation
92
 
        sample_permutation = [(1,2), (3,4)]
93
 
        from bzrlib.transport import TransportTestProviderAdapter
94
 
        adapter = TransportTestProviderAdapter()
95
 
        self.assertEqual(sample_permutation,
96
 
                         adapter.get_transport_test_permutations(MockModule()))
97
 
 
98
 
    def test_adapter_checks_all_modules(self):
99
 
        # this checks that the adapter returns as many permurtations as
100
 
        # there are in all the registered# transport modules for there
101
 
        # - we assume if this matches its probably doing the right thing
102
 
        # especially in combination with the tests for setting the right
103
 
        # classes below.
104
 
        from bzrlib.transport import (TransportTestProviderAdapter,
105
 
                                      _get_transport_modules
106
 
                                      )
107
 
        modules = _get_transport_modules()
108
 
        permutation_count = 0
109
 
        for module in modules:
110
 
            permutation_count += len(reduce(getattr, 
111
 
                (module + ".get_test_permutations").split('.')[1:],
112
 
                 __import__(module))())
113
 
        input_test = TestTransportProviderAdapter(
114
 
            "test_adapter_sets_transport_class")
115
 
        adapter = TransportTestProviderAdapter()
116
 
        self.assertEqual(permutation_count,
117
 
                         len(list(iter(adapter.adapt(input_test)))))
118
 
 
119
 
    def test_adapter_sets_transport_class(self):
120
 
        # when the adapter adapts a test it needs to 
121
 
        # place one of the permutations from the transport
122
 
        # providers in each test case copy. This checks
123
 
        # that it does not just use the same one all the time.
124
 
        # and that the id is set correctly so that debugging is
125
 
        # easy.
126
 
        from bzrlib.transport.local import (LocalTransport,
127
 
                                            LocalRelpathServer,
128
 
                                            LocalAbspathServer,
129
 
                                            LocalURLServer
130
 
                                            )
131
 
        from bzrlib.transport.sftp import (SFTPTransport,
132
 
                                           SFTPAbsoluteServer,
133
 
                                           SFTPHomeDirServer,
134
 
                                           SFTPSiblingAbsoluteServer,
135
 
                                           )
136
 
        from bzrlib.transport.http import (HttpTransport,
137
 
                                           HttpServer
138
 
                                           )
139
 
        from bzrlib.transport.ftp import FtpTransport
140
 
        from bzrlib.transport.memory import (MemoryTransport,
141
 
                                             MemoryServer
142
 
                                             )
143
 
        from bzrlib.transport import TransportTestProviderAdapter
144
 
        # FIXME. What we want is a factory for the things
145
 
        # needed to test the implementation. I.e. for transport we want:
146
 
        # the class that connections should get; a local server factory
147
 
        # so we would want the following permutations:
148
 
        # LocalTransport relpath-factory
149
 
        # LocalTransport abspath-factory
150
 
        # LocalTransport file://-factory
151
 
        # SFTPTransport homedir-factory
152
 
        # SFTPTransport abssolute-factory
153
 
        # HTTPTransport http-factory
154
 
        # HTTPTransport https-factory
155
 
        # etc, but we are currently lacking in this, so print out that
156
 
        # this should be fixed.
157
 
        input_test = TestTransportProviderAdapter(
158
 
            "test_adapter_sets_transport_class")
159
 
        suite = TransportTestProviderAdapter().adapt(input_test)
160
 
        test_iter = iter(suite)
161
 
        http_test = test_iter.next()
162
 
        local_relpath_test = test_iter.next()
163
 
        local_abspath_test = test_iter.next()
164
 
        local_urlpath_test = test_iter.next()
165
 
        memory_test = test_iter.next()
166
 
        readonly_test = test_iter.next()
167
 
        sftp_abs_test = test_iter.next()
168
 
        sftp_homedir_test = test_iter.next()
169
 
        sftp_sibling_abs_test = test_iter.next()
170
 
        # ftp_test = test_iter.next()
171
 
        self.assertRaises(StopIteration, test_iter.next)
172
 
        self.assertEqual(LocalTransport, local_relpath_test.transport_class)
173
 
        self.assertEqual(LocalRelpathServer, local_relpath_test.transport_server)
174
 
        
175
 
        self.assertEqual(LocalTransport, local_abspath_test.transport_class)
176
 
        self.assertEqual(LocalAbspathServer, local_abspath_test.transport_server)
177
 
 
178
 
        self.assertEqual(LocalTransport, local_urlpath_test.transport_class)
179
 
        self.assertEqual(LocalURLServer, local_urlpath_test.transport_server)
180
 
 
181
 
        self.assertEqual(SFTPTransport, sftp_abs_test.transport_class)
182
 
        self.assertEqual(SFTPAbsoluteServer, sftp_abs_test.transport_server)
183
 
        self.assertEqual(SFTPTransport, sftp_homedir_test.transport_class)
184
 
        self.assertEqual(SFTPHomeDirServer, sftp_homedir_test.transport_server)
185
 
        self.assertEqual(SFTPTransport, sftp_sibling_abs_test.transport_class)
186
 
        self.assertEqual(SFTPSiblingAbsoluteServer,
187
 
                         sftp_sibling_abs_test.transport_server)
188
 
 
189
 
        self.assertEqual(HttpTransport, http_test.transport_class)
190
 
        self.assertEqual(HttpServer, http_test.transport_server)
191
 
        # self.assertEqual(FtpTransport, ftp_test.transport_class)
192
 
 
193
 
        self.assertEqual(MemoryTransport, memory_test.transport_class)
194
 
        self.assertEqual(MemoryServer, memory_test.transport_server)
195
 
        
196
 
        # we could test all of them for .id, but two is probably sufficient.
197
 
        self.assertEqual("bzrlib.tests.test_selftest."
198
 
                         "TestTransportProviderAdapter."
199
 
                         "test_adapter_sets_transport_class(MemoryServer)",
200
 
                         memory_test.id())
201
 
        self.assertEqual("bzrlib.tests.test_selftest."
202
 
                         "TestTransportProviderAdapter."
203
 
                         "test_adapter_sets_transport_class(LocalRelpathServer)",
204
 
                         local_relpath_test.id())
205
 
 
206
 
 
207
 
class TestBranchProviderAdapter(TestCase):
208
 
    """A group of tests that test the branch implementation test adapter."""
209
 
 
210
 
    def test_adapted_tests(self):
211
 
        # check that constructor parameters are passed through to the adapted
212
 
        # test.
213
 
        from bzrlib.branch import BranchTestProviderAdapter
214
 
        input_test = TestBranchProviderAdapter(
215
 
            "test_adapted_tests")
216
 
        server1 = "a"
217
 
        server2 = "b"
218
 
        formats = ["c", "d"]
219
 
        adapter = BranchTestProviderAdapter(server1, server2, formats)
220
 
        suite = adapter.adapt(input_test)
221
 
        tests = list(iter(suite))
222
 
        self.assertEqual(2, len(tests))
223
 
        self.assertEqual(tests[0].branch_format, formats[0])
224
 
        self.assertEqual(tests[0].transport_server, server1)
225
 
        self.assertEqual(tests[0].transport_readonly_server, server2)
226
 
        self.assertEqual(tests[1].branch_format, formats[1])
227
 
        self.assertEqual(tests[1].transport_server, server1)
228
 
        self.assertEqual(tests[1].transport_readonly_server, server2)
229
 
 
230
 
 
231
 
class TestTestCaseWithTransport(TestCaseWithTransport):
232
 
    """Tests for the convenience functions TestCaseWithTransport introduces."""
233
 
 
234
 
    def test_get_readonly_url_none(self):
235
 
        from bzrlib.transport import get_transport
236
 
        from bzrlib.transport.memory import MemoryServer
237
 
        from bzrlib.transport.readonly import ReadonlyTransportDecorator
238
 
        self.transport_server = MemoryServer
239
 
        self.transport_readonly_server = None
240
 
        # calling get_readonly_transport() constructs a decorator on the url
241
 
        # for the server
242
 
        url = self.get_readonly_url()
243
 
        url2 = self.get_readonly_url('foo/bar')
244
 
        t = get_transport(url)
245
 
        t2 = get_transport(url2)
246
 
        self.failUnless(isinstance(t, ReadonlyTransportDecorator))
247
 
        self.failUnless(isinstance(t2, ReadonlyTransportDecorator))
248
 
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
249
 
 
250
 
    def test_get_readonly_url_http(self):
251
 
        from bzrlib.transport import get_transport
252
 
        from bzrlib.transport.local import LocalRelpathServer
253
 
        from bzrlib.transport.http import HttpServer, HttpTransport
254
 
        self.transport_server = LocalRelpathServer
255
 
        self.transport_readonly_server = HttpServer
256
 
        # calling get_readonly_transport() gives us a HTTP server instance.
257
 
        url = self.get_readonly_url()
258
 
        url2 = self.get_readonly_url('foo/bar')
259
 
        t = get_transport(url)
260
 
        t2 = get_transport(url2)
261
 
        self.failUnless(isinstance(t, HttpTransport))
262
 
        self.failUnless(isinstance(t2, HttpTransport))
263
 
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))