~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport.py

  • Committer: Matt Nordhoff
  • Date: 2009-06-23 05:12:07 UTC
  • mto: This revision was merged to the branch mainline in revision 4474.
  • Revision ID: mnordhoff@mattnordhoff.com-20090623051207-fksdtbzkwtnrw9dd
Update _add_text docstrings that still referred to add_text.

Show diffs side-by-side

added added

removed removed

Lines of Context:
363
363
    def test_abspath(self):
364
364
        # The abspath is always relative to the chroot_url.
365
365
        server = ChrootServer(get_transport('memory:///foo/bar/'))
366
 
        self.start_server(server)
 
366
        server.setUp()
367
367
        transport = get_transport(server.get_url())
368
368
        self.assertEqual(server.get_url(), transport.abspath('/'))
369
369
 
370
370
        subdir_transport = transport.clone('subdir')
371
371
        self.assertEqual(server.get_url(), subdir_transport.abspath('/'))
 
372
        server.tearDown()
372
373
 
373
374
    def test_clone(self):
374
375
        server = ChrootServer(get_transport('memory:///foo/bar/'))
375
 
        self.start_server(server)
 
376
        server.setUp()
376
377
        transport = get_transport(server.get_url())
377
378
        # relpath from root and root path are the same
378
379
        relpath_cloned = transport.clone('foo')
379
380
        abspath_cloned = transport.clone('/foo')
380
381
        self.assertEqual(server, relpath_cloned.server)
381
382
        self.assertEqual(server, abspath_cloned.server)
 
383
        server.tearDown()
382
384
 
383
385
    def test_chroot_url_preserves_chroot(self):
384
386
        """Calling get_transport on a chroot transport's base should produce a
391
393
            new_transport = get_transport(parent_url)
392
394
        """
393
395
        server = ChrootServer(get_transport('memory:///path/subpath'))
394
 
        self.start_server(server)
 
396
        server.setUp()
395
397
        transport = get_transport(server.get_url())
396
398
        new_transport = get_transport(transport.base)
397
399
        self.assertEqual(transport.server, new_transport.server)
398
400
        self.assertEqual(transport.base, new_transport.base)
 
401
        server.tearDown()
399
402
 
400
403
    def test_urljoin_preserves_chroot(self):
401
404
        """Using urlutils.join(url, '..') on a chroot URL should not produce a
407
410
            new_transport = get_transport(parent_url)
408
411
        """
409
412
        server = ChrootServer(get_transport('memory:///path/'))
410
 
        self.start_server(server)
 
413
        server.setUp()
411
414
        transport = get_transport(server.get_url())
412
415
        self.assertRaises(
413
416
            InvalidURLJoin, urlutils.join, transport.base, '..')
 
417
        server.tearDown()
414
418
 
415
419
 
416
420
class ChrootServerTest(TestCase):
424
428
        backing_transport = MemoryTransport()
425
429
        server = ChrootServer(backing_transport)
426
430
        server.setUp()
427
 
        try:
428
 
            self.assertTrue(server.scheme in _get_protocol_handlers().keys())
429
 
        finally:
430
 
            server.tearDown()
 
431
        self.assertTrue(server.scheme in _get_protocol_handlers().keys())
431
432
 
432
433
    def test_tearDown(self):
433
434
        backing_transport = MemoryTransport()
440
441
        backing_transport = MemoryTransport()
441
442
        server = ChrootServer(backing_transport)
442
443
        server.setUp()
443
 
        try:
444
 
            self.assertEqual('chroot-%d:///' % id(server), server.get_url())
445
 
        finally:
446
 
            server.tearDown()
 
444
        self.assertEqual('chroot-%d:///' % id(server), server.get_url())
 
445
        server.tearDown()
447
446
 
448
447
 
449
448
class ReadonlyDecoratorTransportTest(TestCase):
461
460
        import bzrlib.transport.readonly as readonly
462
461
        # connect to '.' via http which is not listable
463
462
        server = HttpServer()
464
 
        self.start_server(server)
465
 
        transport = get_transport('readonly+' + server.get_url())
466
 
        self.failUnless(isinstance(transport,
467
 
                                   readonly.ReadonlyTransportDecorator))
468
 
        self.assertEqual(False, transport.listable())
469
 
        self.assertEqual(True, transport.is_readonly())
 
463
        server.setUp()
 
464
        try:
 
465
            transport = get_transport('readonly+' + server.get_url())
 
466
            self.failUnless(isinstance(transport,
 
467
                                       readonly.ReadonlyTransportDecorator))
 
468
            self.assertEqual(False, transport.listable())
 
469
            self.assertEqual(True, transport.is_readonly())
 
470
        finally:
 
471
            server.tearDown()
470
472
 
471
473
 
472
474
class FakeNFSDecoratorTests(TestCaseInTempDir):
490
492
        from bzrlib.tests.http_server import HttpServer
491
493
        # connect to '.' via http which is not listable
492
494
        server = HttpServer()
493
 
        self.start_server(server)
494
 
        transport = self.get_nfs_transport(server.get_url())
495
 
        self.assertIsInstance(
496
 
            transport, bzrlib.transport.fakenfs.FakeNFSTransportDecorator)
497
 
        self.assertEqual(False, transport.listable())
498
 
        self.assertEqual(True, transport.is_readonly())
 
495
        server.setUp()
 
496
        try:
 
497
            transport = self.get_nfs_transport(server.get_url())
 
498
            self.assertIsInstance(
 
499
                transport, bzrlib.transport.fakenfs.FakeNFSTransportDecorator)
 
500
            self.assertEqual(False, transport.listable())
 
501
            self.assertEqual(True, transport.is_readonly())
 
502
        finally:
 
503
            server.tearDown()
499
504
 
500
505
    def test_fakenfs_server_default(self):
501
506
        # a FakeNFSServer() should bring up a local relpath server for itself
502
507
        import bzrlib.transport.fakenfs as fakenfs
503
508
        server = fakenfs.FakeNFSServer()
504
 
        self.start_server(server)
505
 
        # the url should be decorated appropriately
506
 
        self.assertStartsWith(server.get_url(), 'fakenfs+')
507
 
        # and we should be able to get a transport for it
508
 
        transport = get_transport(server.get_url())
509
 
        # which must be a FakeNFSTransportDecorator instance.
510
 
        self.assertIsInstance(transport, fakenfs.FakeNFSTransportDecorator)
 
509
        server.setUp()
 
510
        try:
 
511
            # the url should be decorated appropriately
 
512
            self.assertStartsWith(server.get_url(), 'fakenfs+')
 
513
            # and we should be able to get a transport for it
 
514
            transport = get_transport(server.get_url())
 
515
            # which must be a FakeNFSTransportDecorator instance.
 
516
            self.assertIsInstance(
 
517
                transport, fakenfs.FakeNFSTransportDecorator)
 
518
        finally:
 
519
            server.tearDown()
511
520
 
512
521
    def test_fakenfs_rename_semantics(self):
513
522
        # a FakeNFS transport must mangle the way rename errors occur to
578
587
    def setUp(self):
579
588
        super(TestTransportImplementation, self).setUp()
580
589
        self._server = self.transport_server()
581
 
        self.start_server(self._server)
 
590
        self._server.setUp()
 
591
        self.addCleanup(self._server.tearDown)
582
592
 
583
593
    def get_transport(self, relpath=None):
584
594
        """Return a connected transport to the local directory.