~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport_implementations.py

integrate Memory tests into transport interface tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
215
215
        self.check_transport_contents('contents of dir_a/a', t, 'dir_a/a')
216
216
        self.check_transport_contents('contents of dir_b/b', t, 'dir_b/b')
217
217
 
 
218
        # mkdir of a dir with an absent parent
 
219
        self.assertRaises(NoSuchFile, t.mkdir, 'missing/dir')
 
220
 
218
221
    def test_copy_to(self):
219
222
        import tempfile
220
223
        from bzrlib.transport.memory import MemoryTransport
332
335
        self.check_transport_contents('some text\nfor a missing file\n',
333
336
                                      t, 'c')
334
337
        self.check_transport_contents('missing file r\n', t, 'd')
 
338
        
 
339
        # a file with no parent should fail..
 
340
        if not t.is_readonly():
 
341
            self.assertRaises(NoSuchFile,
 
342
                              t.append, 'missing/path', 
 
343
                              StringIO('content'))
335
344
 
336
345
    def test_append_file(self):
337
346
        t = self.get_transport()
662
671
        self.assertEqual(transport.base + 'relpath',
663
672
                         transport.abspath('relpath'))
664
673
 
665
 
        
666
674
###class HttpTransportTest(TestCaseWithWebserver):
667
675
###
668
676
###    readonly = True
671
679
###        from bzrlib.transport.http import HttpTransport
672
680
###        return HttpTransport('http://jasldkjsalkdjalksjdkljasd')
673
681
 
674
 
 
675
 
class TestMemoryTransport(TestCase):
676
 
 
677
 
    def test_get_transport(self):
678
 
        memory.MemoryTransport()
679
 
 
680
 
    def test_relpath(self):
681
 
        transport = memory.MemoryTransport()
682
 
 
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')
689
 
 
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')
696
 
 
697
 
    def test_append_without_dir_fails(self):
698
 
        transport = memory.MemoryTransport()
699
 
        self.assertRaises(NoSuchFile,
700
 
                          transport.append, 'dir/path', StringIO('content'))
701
 
 
702
 
    def test_put_without_dir_fails(self):
703
 
        transport = memory.MemoryTransport()
704
 
        self.assertRaises(NoSuchFile,
705
 
                          transport.put, 'dir/path', StringIO('content'))
706
 
 
707
 
    def test_get_missing(self):
708
 
        transport = memory.MemoryTransport()
709
 
        self.assertRaises(NoSuchFile, transport.get, 'foo')
710
 
 
711
 
    def test_has_missing(self):
712
 
        transport = memory.MemoryTransport()
713
 
        self.assertEquals(False, transport.has('foo'))
714
 
 
715
 
    def test_has_present(self):
716
 
        transport = memory.MemoryTransport()
717
 
        transport.append('foo', StringIO('content'))
718
 
        self.assertEquals(True, transport.has('foo'))
719
 
 
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')
725
 
 
726
 
    def test_mkdir_missing_parent(self):
727
 
        transport = memory.MemoryTransport()
728
 
        self.assertRaises(NoSuchFile,
729
 
                          transport.mkdir, 'dir/dir')
730
 
 
731
 
    def test_mkdir_twice(self):
732
 
        transport = memory.MemoryTransport()
733
 
        transport.mkdir('dir')
734
 
        self.assertRaises(FileExists, transport.mkdir, 'dir')
735
 
 
736
 
    def test_parameters(self):
737
 
        transport = memory.MemoryTransport()
738
 
        self.assertEqual(True, transport.listable())
739
 
        self.assertEqual(False, transport.should_cache())
740
 
 
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)
 
687
            return
 
688
        self.build_tree(['isolated/', 
 
689
                         'isolated/dir/',
 
690
                         'isolated/dir/foo',
 
691
                         'isolated/dir/bar',
 
692
                         'isolated/bar'],
 
693
                        transport=transport)
 
694
        transport = transport.clone('isolated')
747
695
        paths = set(transport.iter_files_recursive())
748
696
        self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths)
749
 
 
750
 
    def test_stat(self):
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)
756