~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: abentley
  • Date: 2006-04-20 23:47:53 UTC
  • mfrom: (1681 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1683.
  • Revision ID: abentley@lappy-20060420234753-6a6874b76f09f86d
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by 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 version 2 as published by
127
127
                         len(list(iter(adapter.adapt(input_test)))))
128
128
 
129
129
    def test_adapter_sets_transport_class(self):
130
 
        # when the adapter adapts a test it needs to 
131
 
        # place one of the permutations from the transport
132
 
        # providers in each test case copy. This checks
133
 
        # that it does not just use the same one all the time.
134
 
        # and that the id is set correctly so that debugging is
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)
140
 
        from bzrlib.transport.local import (LocalTransport,
141
 
                                            LocalRelpathServer,
142
 
                                            LocalAbspathServer,
143
 
                                            LocalURLServer
144
 
                                            )
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
156
 
        from bzrlib.transport.http import (HttpTransport,
157
 
                                           HttpServer
158
 
                                           )
159
 
        from bzrlib.transport.ftp import FtpTransport
160
 
        from bzrlib.transport.memory import (MemoryTransport,
161
 
                                             MemoryServer
162
 
                                             )
163
 
        from bzrlib.transport import TransportTestProviderAdapter
164
 
        # FIXME. What we want is a factory for the things
165
 
        # needed to test the implementation. I.e. for transport we want:
166
 
        # the class that connections should get; a local server factory
167
 
        # so we would want the following permutations:
168
 
        # LocalTransport relpath-factory
169
 
        # LocalTransport abspath-factory
170
 
        # LocalTransport file://-factory
171
 
        # SFTPTransport homedir-factory
172
 
        # SFTPTransport abssolute-factory
173
 
        # HTTPTransport http-factory
174
 
        # HTTPTransport https-factory
175
 
        # etc, but we are currently lacking in this, so print out that
176
 
        # this should be fixed.
 
130
        # Check that the test adapter inserts a transport and server into the
 
131
        # generated test.
 
132
        #
 
133
        # This test used to know about all the possible transports and the
 
134
        # order they were returned but that seems overly brittle (mbp
 
135
        # 20060307)
177
136
        input_test = TestTransportProviderAdapter(
178
137
            "test_adapter_sets_transport_class")
 
138
        from bzrlib.transport import TransportTestProviderAdapter
179
139
        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
183
 
        test_iter = iter(suite)
184
 
        http_test = test_iter.next()
185
 
        local_relpath_test = test_iter.next()
186
 
        local_abspath_test = test_iter.next()
187
 
        local_urlpath_test = test_iter.next()
188
 
        memory_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()
194
 
        # ftp_test = test_iter.next()
195
 
        # should now be at the end of the test
196
 
        self.assertRaises(StopIteration, test_iter.next)
197
 
        self.assertEqual(LocalTransport, local_relpath_test.transport_class)
198
 
        self.assertEqual(LocalRelpathServer, local_relpath_test.transport_server)
199
 
        
200
 
        self.assertEqual(LocalTransport, local_abspath_test.transport_class)
201
 
        self.assertEqual(LocalAbspathServer, local_abspath_test.transport_server)
202
 
 
203
 
        self.assertEqual(LocalTransport, local_urlpath_test.transport_class)
204
 
        self.assertEqual(LocalURLServer, local_urlpath_test.transport_server)
205
 
 
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)
214
 
 
215
 
        self.assertEqual(HttpTransport, http_test.transport_class)
216
 
        self.assertEqual(HttpServer, http_test.transport_server)
217
 
        # self.assertEqual(FtpTransport, ftp_test.transport_class)
218
 
 
219
 
        self.assertEqual(MemoryTransport, memory_test.transport_class)
220
 
        self.assertEqual(MemoryServer, memory_test.transport_server)
221
 
        
222
 
        # we could test all of them for .id, but two is probably sufficient.
223
 
        self.assertEqual("bzrlib.tests.test_selftest."
224
 
                         "TestTransportProviderAdapter."
225
 
                         "test_adapter_sets_transport_class(MemoryServer)",
226
 
                         memory_test.id())
227
 
        self.assertEqual("bzrlib.tests.test_selftest."
228
 
                         "TestTransportProviderAdapter."
229
 
                         "test_adapter_sets_transport_class(LocalRelpathServer)",
230
 
                         local_relpath_test.id())
 
140
        tests = list(iter(suite))
 
141
        self.assertTrue(len(tests) > 6)
 
142
        # there are at least that many builtin transports
 
143
        one_test = tests[0]
 
144
        self.assertTrue(issubclass(one_test.transport_class, 
 
145
                                   bzrlib.transport.Transport))
 
146
        self.assertTrue(issubclass(one_test.transport_server, 
 
147
                                   bzrlib.transport.Server))
231
148
 
232
149
 
233
150
class TestBranchProviderAdapter(TestCase):
437
354
    def test_get_readonly_url_http(self):
438
355
        from bzrlib.transport import get_transport
439
356
        from bzrlib.transport.local import LocalRelpathServer
440
 
        from bzrlib.transport.http import HttpServer, HttpTransport
 
357
        from bzrlib.transport.http import HttpServer, HttpTransportBase
441
358
        self.transport_server = LocalRelpathServer
442
359
        self.transport_readonly_server = HttpServer
443
360
        # calling get_readonly_transport() gives us a HTTP server instance.
444
361
        url = self.get_readonly_url()
445
362
        url2 = self.get_readonly_url('foo/bar')
 
363
        # the transport returned may be any HttpTransportBase subclass
446
364
        t = get_transport(url)
447
365
        t2 = get_transport(url2)
448
 
        self.failUnless(isinstance(t, HttpTransport))
449
 
        self.failUnless(isinstance(t2, HttpTransport))
 
366
        self.failUnless(isinstance(t, HttpTransportBase))
 
367
        self.failUnless(isinstance(t2, HttpTransportBase))
450
368
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
451
369
 
452
370
    def test_is_directory(self):
457
375
        self.assertRaises(AssertionError, self.assertIsDirectory, 'a_file', t)
458
376
        self.assertRaises(AssertionError, self.assertIsDirectory, 'not_here', t)
459
377
 
 
378
 
460
379
class TestChrootedTest(ChrootedTestCase):
461
380
 
462
381
    def test_root_is_root(self):
464
383
        t = get_transport(self.get_readonly_url())
465
384
        url = t.base
466
385
        self.assertEqual(url, t.clone('..').base)
 
386
 
 
387
 
 
388
class TestExtraAssertions(TestCase):
 
389
    """Tests for new test assertions in bzrlib test suite"""
 
390
 
 
391
    def test_assert_isinstance(self):
 
392
        self.assertIsInstance(2, int)
 
393
        self.assertIsInstance(u'', basestring)
 
394
        self.assertRaises(AssertionError, self.assertIsInstance, None, int)
 
395
        self.assertRaises(AssertionError, self.assertIsInstance, 23.3, int)
 
396
 
 
397
 
 
398
class TestConvenienceMakers(TestCaseWithTransport):
 
399
    """Test for the make_* convenience functions."""
 
400
 
 
401
    def test_make_branch_and_tree_with_format(self):
 
402
        # we should be able to supply a format to make_branch_and_tree
 
403
        self.make_branch_and_tree('a', format=bzrlib.bzrdir.BzrDirMetaFormat1())
 
404
        self.make_branch_and_tree('b', format=bzrlib.bzrdir.BzrDirFormat6())
 
405
        self.assertIsInstance(bzrlib.bzrdir.BzrDir.open('a')._format,
 
406
                              bzrlib.bzrdir.BzrDirMetaFormat1)
 
407
        self.assertIsInstance(bzrlib.bzrdir.BzrDir.open('b')._format,
 
408
                              bzrlib.bzrdir.BzrDirFormat6)
 
409