572
582
class TestLocalTransports(TestCase):
574
584
def test_get_transport_from_abspath(self):
575
here = os.path.abspath('.')
585
here = osutils.abspath('.')
576
586
t = get_transport(here)
577
587
self.assertIsInstance(t, LocalTransport)
578
588
self.assertEquals(t.base, urlutils.local_path_to_url(here) + '/')
580
590
def test_get_transport_from_relpath(self):
581
here = os.path.abspath('.')
591
here = osutils.abspath('.')
582
592
t = get_transport('.')
583
593
self.assertIsInstance(t, LocalTransport)
584
594
self.assertEquals(t.base, urlutils.local_path_to_url('.') + '/')
586
596
def test_get_transport_from_local_url(self):
587
here = os.path.abspath('.')
597
here = osutils.abspath('.')
588
598
here_url = urlutils.local_path_to_url(here) + '/'
589
599
t = get_transport(here_url)
590
600
self.assertIsInstance(t, LocalTransport)
591
601
self.assertEquals(t.base, here_url)
593
603
def test_local_abspath(self):
594
here = os.path.abspath('.')
604
here = osutils.abspath('.')
595
605
t = get_transport(here)
596
606
self.assertEquals(t.local_abspath(''), here)
712
722
self.assertIsNot(t1, t2)
715
def get_test_permutations():
716
"""Return transport permutations to be used in testing.
718
This module registers some transports, but they're only for testing
719
registration. We don't really want to run all the transport tests against
725
class TestRemoteTCPTransport(TestCase):
726
"""Tests for bzr:// transport (RemoteTCPTransport)."""
728
def test_relpath_with_implicit_port(self):
729
"""Connected transports with the same URL are the same, even if the
732
So t.relpath(url) should always be '' if t.base is the same as url, or
733
if the only difference is that one explicitly specifies the default
734
port and the other doesn't specify a port.
736
t_implicit_port = RemoteTCPTransport('bzr://host.com/')
737
self.assertEquals('', t_implicit_port.relpath('bzr://host.com/'))
738
self.assertEquals('', t_implicit_port.relpath('bzr://host.com:4155/'))
739
t_explicit_port = RemoteTCPTransport('bzr://host.com:4155/')
740
self.assertEquals('', t_explicit_port.relpath('bzr://host.com/'))
741
self.assertEquals('', t_explicit_port.relpath('bzr://host.com:4155/'))
743
def test_construct_uses_default_port(self):
744
"""If no port is specified, then RemoteTCPTransport uses
747
t = get_transport('bzr://host.com/')
748
self.assertEquals(BZR_DEFAULT_PORT, t._port)
750
def test_url_omits_default_port(self):
751
"""If a RemoteTCPTransport uses the default port, then its base URL
754
This is like how ":80" is omitted from "http://example.com/".
756
t = get_transport('bzr://host.com:4155/')
757
self.assertEquals('bzr://host.com/', t.base)
759
def test_url_includes_non_default_port(self):
760
"""Non-default ports are included in the transport's URL.
762
Contrast this to `test_url_omits_default_port`.
764
t = get_transport('bzr://host.com:666/')
765
self.assertEquals('bzr://host.com:666/', t.base)
768
class TestTransportTrace(TestCase):
771
transport = get_transport('trace+memory://')
772
self.assertIsInstance(
773
transport, bzrlib.transport.trace.TransportTraceDecorator)
775
def test_clone_preserves_activity(self):
776
transport = get_transport('trace+memory://')
777
transport2 = transport.clone('.')
778
self.assertTrue(transport is not transport2)
779
self.assertTrue(transport._activity is transport2._activity)
781
# the following specific tests are for the operations that have made use of
782
# logging in tests; we could test every single operation but doing that
783
# still won't cause a test failure when the top level Transport API
784
# changes; so there is little return doing that.
786
transport = get_transport('trace+memory:///')
787
transport.put_bytes('foo', 'barish')
790
# put_bytes records the bytes, not the content to avoid memory
792
expected_result.append(('put_bytes', 'foo', 6, None))
793
# get records the file name only.
794
expected_result.append(('get', 'foo'))
795
self.assertEqual(expected_result, transport._activity)
797
def test_readv(self):
798
transport = get_transport('trace+memory:///')
799
transport.put_bytes('foo', 'barish')
800
list(transport.readv('foo', [(0, 1), (3, 2)], adjust_for_latency=True,
803
# put_bytes records the bytes, not the content to avoid memory
805
expected_result.append(('put_bytes', 'foo', 6, None))
806
# readv records the supplied offset request
807
expected_result.append(('readv', 'foo', [(0, 1), (3, 2)], True, 6))
808
self.assertEqual(expected_result, transport._activity)