~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tests/test_groupcompress.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-04 17:02:18 UTC
  • mto: (0.17.34 trunk)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: john@arbash-meinel.com-20090304170218-c3thty7hh2yfrnye
First cut at meta-info as text form.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
    return standard_tests
50
50
 
51
51
 
52
 
class TestGroupCompressor(TestCaseWithTransport):
 
52
class TestGroupCompressor(tests.TestCase):
53
53
    """Tests for GroupCompressor"""
54
54
 
55
55
    def test_empty_delta(self):
166
166
        # and the second
167
167
        self.assertEqual((['common\ndifferent\nmoredifferent\n'],
168
168
            sha_2), compressor.extract(('newlabel',)))
 
169
 
 
170
 
 
171
class TestGroupCompressBlock(tests.TestCase):
 
172
 
 
173
    def test_from_empty_bytes(self):
 
174
        self.assertRaises(errors.InvalidGroupCompressBlock,
 
175
                          groupcompress.GroupCompressBlock.from_bytes, '')
 
176
 
 
177
    def test_from_bytes(self):
 
178
        block = groupcompress.GroupCompressBlock.from_bytes('gcb1p\n')
 
179
        self.assertIsInstance(block, groupcompress.GroupCompressBlock)
 
180
 
 
181
    def test_add_entry(self):
 
182
        gcb = groupcompress.GroupCompressBlock()
 
183
        e = gcb.add_entry(('foo', 'bar'), 'fulltext', 'abcd'*10, 0, 100)
 
184
        self.assertIsInstance(e, groupcompress.GroupCompressBlockEntry)
 
185
        self.assertEqual(('foo', 'bar'), e.key)
 
186
        self.assertEqual('fulltext', e.type)
 
187
        self.assertEqual('abcd'*10, e.sha1)
 
188
        self.assertEqual(0, e.start)
 
189
        self.assertEqual(100, e.length)
 
190
 
 
191
    def test_to_bytes(self):
 
192
        gcb = groupcompress.GroupCompressBlock()
 
193
        gcb.add_entry(('foo', 'bar'), 'fulltext', 'abcd'*10, 0, 100)
 
194
        gcb.add_entry(('bing',), 'fulltext', 'abcd'*10, 100, 100)
 
195
        self.assertEqualDiff('gcb1p\n' # group compress block v1 plain
 
196
                             '183\n' # Length of all meta-info
 
197
                             'key:bing\n'
 
198
                             'type:fulltext\n'
 
199
                             'sha1:abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\n'
 
200
                             'start:100\n'
 
201
                             'length:100\n'
 
202
                             '\n'
 
203
                             'key:foo\x00bar\n'
 
204
                             'type:fulltext\n'
 
205
                             'sha1:abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\n'
 
206
                             'start:0\n'
 
207
                             'length:100\n'
 
208
                             '\n', gcb.to_bytes())