730
730
def get_bogus_transport(self):
731
731
from bzrlib.transport.http import HttpTransport
732
732
return HttpTransport('http://jasldkjsalkdjalksjdkljasd')
735
class TestMemoryTransport(TestCase):
737
def test_get_transport(self):
738
memory.MemoryTransport()
740
def test_clone(self):
741
transport = memory.MemoryTransport()
742
self.failUnless(transport.clone() is transport)
744
def test_abspath(self):
745
transport = memory.MemoryTransport()
746
self.assertEqual("in-memory:relpath", transport.abspath('relpath'))
748
def test_relpath(self):
749
transport = memory.MemoryTransport()
751
def test_append_and_get(self):
752
transport = memory.MemoryTransport()
753
transport.append('path', StringIO('content'))
754
self.assertEqual(transport.get('path').read(), 'content')
755
transport.append('path', StringIO('content'))
756
self.assertEqual(transport.get('path').read(), 'contentcontent')
758
def test_put_and_get(self):
759
transport = memory.MemoryTransport()
760
transport.put('path', StringIO('content'))
761
self.assertEqual(transport.get('path').read(), 'content')
762
transport.put('path', StringIO('content'))
763
self.assertEqual(transport.get('path').read(), 'content')
765
def test_append_without_dir_fails(self):
766
transport = memory.MemoryTransport()
767
self.assertRaises(NoSuchFile,
768
transport.append, 'dir/path', StringIO('content'))
770
def test_put_without_dir_fails(self):
771
transport = memory.MemoryTransport()
772
self.assertRaises(NoSuchFile,
773
transport.put, 'dir/path', StringIO('content'))
775
def test_get_missing(self):
776
transport = memory.MemoryTransport()
777
self.assertRaises(NoSuchFile, transport.get, 'foo')
779
def test_has_missing(self):
780
transport = memory.MemoryTransport()
781
self.assertEquals(False, transport.has('foo'))
783
def test_has_present(self):
784
transport = memory.MemoryTransport()
785
transport.append('foo', StringIO('content'))
786
self.assertEquals(True, transport.has('foo'))
788
def test_mkdir(self):
789
transport = memory.MemoryTransport()
790
transport.mkdir('dir')
791
transport.append('dir/path', StringIO('content'))
792
self.assertEqual(transport.get('dir/path').read(), 'content')
794
def test_mkdir_missing_parent(self):
795
transport = memory.MemoryTransport()
796
self.assertRaises(NoSuchFile,
797
transport.mkdir, 'dir/dir')
799
def test_mkdir_twice(self):
800
transport = memory.MemoryTransport()
801
transport.mkdir('dir')
802
self.assertRaises(FileExists, transport.mkdir, 'dir')
804
def test_parameters(self):
805
transport = memory.MemoryTransport()
806
self.assertEqual(True, transport.listable())
807
self.assertEqual(False, transport.should_cache())
809
def test_iter_files_recursive(self):
810
transport = memory.MemoryTransport()
811
transport.mkdir('dir')
812
transport.put('dir/foo', StringIO('content'))
813
transport.put('dir/bar', StringIO('content'))
814
transport.put('bar', StringIO('content'))
815
paths = set(transport.iter_files_recursive())
816
self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths)
819
transport = memory.MemoryTransport()
820
transport.put('foo', StringIO('content'))
821
transport.put('bar', StringIO('phowar'))
822
self.assertEqual(7, transport.stat('foo').st_size)
823
self.assertEqual(6, transport.stat('bar').st_size)