671
679
### from bzrlib.transport.http import HttpTransport
672
680
### return HttpTransport('http://jasldkjsalkdjalksjdkljasd')
675
class TestMemoryTransport(TestCase):
677
def test_get_transport(self):
678
memory.MemoryTransport()
680
def test_relpath(self):
681
transport = memory.MemoryTransport()
683
def test_append_and_get(self):
684
transport = memory.MemoryTransport()
685
transport.append('path', StringIO('content'))
686
self.assertEqual(transport.get('path').read(), 'content')
687
transport.append('path', StringIO('content'))
688
self.assertEqual(transport.get('path').read(), 'contentcontent')
690
def test_put_and_get(self):
691
transport = memory.MemoryTransport()
692
transport.put('path', StringIO('content'))
693
self.assertEqual(transport.get('path').read(), 'content')
694
transport.put('path', StringIO('content'))
695
self.assertEqual(transport.get('path').read(), 'content')
697
def test_append_without_dir_fails(self):
698
transport = memory.MemoryTransport()
699
self.assertRaises(NoSuchFile,
700
transport.append, 'dir/path', StringIO('content'))
702
def test_put_without_dir_fails(self):
703
transport = memory.MemoryTransport()
704
self.assertRaises(NoSuchFile,
705
transport.put, 'dir/path', StringIO('content'))
707
def test_get_missing(self):
708
transport = memory.MemoryTransport()
709
self.assertRaises(NoSuchFile, transport.get, 'foo')
711
def test_has_missing(self):
712
transport = memory.MemoryTransport()
713
self.assertEquals(False, transport.has('foo'))
715
def test_has_present(self):
716
transport = memory.MemoryTransport()
717
transport.append('foo', StringIO('content'))
718
self.assertEquals(True, transport.has('foo'))
720
def test_mkdir(self):
721
transport = memory.MemoryTransport()
722
transport.mkdir('dir')
723
transport.append('dir/path', StringIO('content'))
724
self.assertEqual(transport.get('dir/path').read(), 'content')
726
def test_mkdir_missing_parent(self):
727
transport = memory.MemoryTransport()
728
self.assertRaises(NoSuchFile,
729
transport.mkdir, 'dir/dir')
731
def test_mkdir_twice(self):
732
transport = memory.MemoryTransport()
733
transport.mkdir('dir')
734
self.assertRaises(FileExists, transport.mkdir, 'dir')
736
def test_parameters(self):
737
transport = memory.MemoryTransport()
738
self.assertEqual(True, transport.listable())
739
self.assertEqual(False, transport.should_cache())
741
682
def test_iter_files_recursive(self):
742
transport = memory.MemoryTransport()
743
transport.mkdir('dir')
744
transport.put('dir/foo', StringIO('content'))
745
transport.put('dir/bar', StringIO('content'))
746
transport.put('bar', StringIO('content'))
683
transport = self.get_transport()
684
if not transport.listable():
685
self.assertRaises(TransportNotPossible,
686
transport.iter_files_recursive)
688
self.build_tree(['isolated/',
694
transport = transport.clone('isolated')
747
695
paths = set(transport.iter_files_recursive())
748
696
self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths)
751
transport = memory.MemoryTransport()
752
transport.put('foo', StringIO('content'))
753
transport.put('bar', StringIO('phowar'))
754
self.assertEqual(7, transport.stat('foo').st_size)
755
self.assertEqual(6, transport.stat('bar').st_size)