~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

  • Committer: Robert Collins
  • Date: 2006-04-19 23:32:08 UTC
  • mto: (1711.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1674.
  • Revision ID: robertc@robertcollins.net-20060419233208-2ed6906796994316
Make knit the default format.
Adjust affect tests to either have knit specific values or to be more generic,
as appropriate.
Disable all SFTP prefetching for known paramikos - direct readv support is now
a TODO.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
            self.assertRaises(RevisionAlreadyPresent,
65
65
                f.add_lines, 'r1', [], [])
66
66
        verify_file(f)
67
 
        f = self.reopen_file()
 
67
        # this checks that reopen with create=True does not break anything.
 
68
        f = self.reopen_file(create=True)
68
69
        verify_file(f)
69
70
 
70
71
    def test_adds_with_parent_texts(self):
105
106
        f = self.reopen_file()
106
107
        verify_file(f)
107
108
 
 
109
    def test_add_unicode_content(self):
 
110
        # unicode content is not permitted in versioned files. 
 
111
        # versioned files version sequences of bytes only.
 
112
        vf = self.get_file()
 
113
        self.assertRaises(errors.BzrBadParameterUnicode,
 
114
            vf.add_lines, 'a', [], ['a\n', u'b\n', 'c\n'])
 
115
        self.assertRaises(
 
116
            (errors.BzrBadParameterUnicode, NotImplementedError),
 
117
            vf.add_lines_with_ghosts, 'a', [], ['a\n', u'b\n', 'c\n'])
 
118
 
 
119
    def test_inline_newline_throws(self):
 
120
        # \r characters are not permitted in lines being added
 
121
        vf = self.get_file()
 
122
        self.assertRaises(errors.BzrBadParameterContainsNewline, 
 
123
            vf.add_lines, 'a', [], ['a\n\n'])
 
124
        self.assertRaises(
 
125
            (errors.BzrBadParameterContainsNewline, NotImplementedError),
 
126
            vf.add_lines_with_ghosts, 'a', [], ['a\n\n'])
 
127
        # but inline CR's are allowed
 
128
        vf.add_lines('a', [], ['a\r\n'])
 
129
        try:
 
130
            vf.add_lines_with_ghosts('b', [], ['a\r\n'])
 
131
        except NotImplementedError:
 
132
            pass
 
133
 
108
134
    def test_get_delta(self):
109
135
        f = self.get_file()
110
136
        sha1s = self._setup_for_deltas(f)
637
663
        self.assertRaises(errors.ReadOnlyError, vf.fix_parents, 'base', [])
638
664
        self.assertRaises(errors.ReadOnlyError, vf.join, 'base')
639
665
        self.assertRaises(errors.ReadOnlyError, vf.clone_text, 'base', 'bar', ['foo'])
 
666
    
 
667
    def test_get_sha1(self):
 
668
        # check the sha1 data is available
 
669
        vf = self.get_file()
 
670
        # a simple file
 
671
        vf.add_lines('a', [], ['a\n'])
 
672
        # the same file, different metadata
 
673
        vf.add_lines('b', ['a'], ['a\n'])
 
674
        # a file differing only in last newline.
 
675
        vf.add_lines('c', [], ['a'])
 
676
        self.assertEqual(
 
677
            '3f786850e387550fdab836ed7e6dc881de23001b', vf.get_sha1('a'))
 
678
        self.assertEqual(
 
679
            '3f786850e387550fdab836ed7e6dc881de23001b', vf.get_sha1('b'))
 
680
        self.assertEqual(
 
681
            '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8', vf.get_sha1('c'))
640
682
        
641
683
 
642
684
class TestWeave(TestCaseWithTransport, VersionedFileTestMixIn):
678
720
        w._sha1s[1] =  'f0f265c6e75f1c8f9ab76dcf85528352c5f215ef'
679
721
        return w
680
722
 
681
 
    def reopen_file(self, name='foo'):
682
 
        return WeaveFile(name, get_transport(self.get_url('.')))
 
723
    def reopen_file(self, name='foo', create=False):
 
724
        return WeaveFile(name, get_transport(self.get_url('.')), create=create)
683
725
 
684
726
    def test_no_implicit_create(self):
685
727
        self.assertRaises(errors.NoSuchFile,
706
748
        knit.add_lines('v2', ['v1'], ['hello\n', 'there\n'])
707
749
        return knit
708
750
 
709
 
    def reopen_file(self, name='foo'):
710
 
        return KnitVersionedFile(name, get_transport(self.get_url('.')), delta=True)
 
751
    def reopen_file(self, name='foo', create=False):
 
752
        return KnitVersionedFile(name, get_transport(self.get_url('.')),
 
753
            delta=True,
 
754
            create=create)
711
755
 
712
756
    def test_detection(self):
713
757
        print "TODO for merging: create a corrupted knit."
791
835
    def test_readonly_http_works(self):
792
836
        # we should be able to read from http with a versioned file.
793
837
        vf = self.get_file()
 
838
        # try an empty file access
 
839
        readonly_vf = self.get_factory()('foo', get_transport(self.get_readonly_url('.')))
 
840
        self.assertEqual([], readonly_vf.versions())
 
841
        # now with feeling.
794
842
        vf.add_lines('1', [], ['a\n'])
795
843
        vf.add_lines('2', ['1'], ['b\n', 'a\n'])
796
844
        readonly_vf = self.get_factory()('foo', get_transport(self.get_readonly_url('.')))
 
845
        self.assertEqual(['1', '2'], vf.versions())
797
846
        for version in readonly_vf.versions():
798
847
            readonly_vf.get_lines(version)
799
848