~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_groupcompress.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-27 21:47:08 UTC
  • mto: (3735.39.2 clean)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: john@arbash-meinel.com-20090327214708-sy13r2m4cu0qn72k
Change the attribute from 'lines' to 'chunks' to make it more
obvious that entries aren't guaranteed to end with '\n'.
Also, remove more of the duplication of the 2 compressor implementations into
the common base class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
 
68
68
    def test_empty_delta(self):
69
69
        compressor = self.compressor()
70
 
        self.assertEqual([], compressor.lines)
 
70
        self.assertEqual([], compressor.chunks)
71
71
 
72
72
    def test_one_nosha_delta(self):
73
73
        # diff against NUKK
76
76
            'strange\ncommon\n', None)
77
77
        self.assertEqual(sha_string('strange\ncommon\n'), sha1)
78
78
        expected_lines = 'f' '\x0f' 'strange\ncommon\n'
79
 
        self.assertEqual(expected_lines, ''.join(compressor.lines))
 
79
        self.assertEqual(expected_lines, ''.join(compressor.chunks))
80
80
        self.assertEqual(0, start_point)
81
81
        self.assertEqual(sum(map(len, expected_lines)), end_point)
82
82
 
90
90
        self.assertEqual('fulltext', kind)
91
91
        self.assertEqual(groupcompress._null_sha1, sha1)
92
92
        self.assertEqual(0, compressor.endpoint)
93
 
        self.assertEqual([], compressor.lines)
 
93
        self.assertEqual([], compressor.chunks)
94
94
        # Even after adding some content
95
95
        compressor.compress(('content',), 'some\nbytes\n', None)
96
96
        self.assertTrue(compressor.endpoint > 0)
107
107
        compressor = self.compressor()
108
108
        sha1_1, _, _, _, _ = compressor.compress(('label',),
109
109
            'strange\ncommon long line\nthat needs a 16 byte match\n', None)
110
 
        expected_lines = list(compressor.lines)
 
110
        expected_lines = list(compressor.chunks)
111
111
        sha1_2, _, end_point, _, _ = compressor.compress(('newlabel',),
112
112
            'common long line\nthat needs a 16 byte match\ndifferent\n', None)
113
113
        # get the first out
148
148
        compressor = self.compressor()
149
149
        sha1_1, _, _, _, _ = compressor.compress(('label',),
150
150
            'strange\ncommon long line\nthat needs a 16 byte match\n', None)
151
 
        expected_lines = list(compressor.lines)
 
151
        expected_lines = list(compressor.chunks)
152
152
        sha1_2, start_point, end_point, _, _ = compressor.compress(('newlabel',),
153
153
            'common long line\nthat needs a 16 byte match\ndifferent\n', None)
154
154
        self.assertEqual(sha_string('common long line\n'
164
164
            # add the line different, and the trailing newline
165
165
            '\x0adifferent\n', # insert 10 bytes
166
166
            ])
167
 
        self.assertEqualDiffEncoded(expected_lines, compressor.lines)
 
167
        self.assertEqualDiffEncoded(expected_lines, compressor.chunks)
168
168
        self.assertEqual(sum(map(len, expected_lines)), end_point)
169
169
 
170
170
    def test_three_nosha_delta(self):
175
175
            'strange\ncommon very very long line\nwith some extra text\n', None)
176
176
        sha1_2, _, _, _, _ = compressor.compress(('newlabel',),
177
177
            'different\nmoredifferent\nand then some more\n', None)
178
 
        expected_lines = list(compressor.lines)
 
178
        expected_lines = list(compressor.chunks)
179
179
        sha1_3, start_point, end_point, _, _ = compressor.compress(('label3',),
180
180
            'new\ncommon very very long line\nwith some extra text\n'
181
181
            'different\nmoredifferent\nand then some more\n',
196
196
            # Copy of second parent 'different' range
197
197
            '\x91\x3c\x2b' # copy, offset 0x3c, 0x2b bytes
198
198
            ])
199
 
        self.assertEqualDiffEncoded(expected_lines, compressor.lines)
 
199
        self.assertEqualDiffEncoded(expected_lines, compressor.chunks)
200
200
        self.assertEqual(sum(map(len, expected_lines)), end_point)
201
201
 
202
202
 
227
227
        compressor = self.compressor()
228
228
        sha1_1, _, _, _, _ = compressor.compress(('label',),
229
229
            'strange\ncommon long line\nthat needs a 16 byte match\n', None)
230
 
        expected_lines = list(compressor.lines)
 
230
        expected_lines = list(compressor.chunks)
231
231
        sha1_2, start_point, end_point, _, _ = compressor.compress(('newlabel',),
232
232
            'common long line\nthat needs a 16 byte match\ndifferent\n', None)
233
233
        self.assertEqual(sha_string('common long line\n'
243
243
            # add the line different, and the trailing newline
244
244
            '\x0adifferent\n', # insert 10 bytes
245
245
            ])
246
 
        self.assertEqualDiffEncoded(expected_lines, compressor.lines)
 
246
        self.assertEqualDiffEncoded(expected_lines, compressor.chunks)
247
247
        self.assertEqual(sum(map(len, expected_lines)), end_point)
248
248
 
249
249
    def test_three_nosha_delta(self):
254
254
            'strange\ncommon very very long line\nwith some extra text\n', None)
255
255
        sha1_2, _, _, _, _ = compressor.compress(('newlabel',),
256
256
            'different\nmoredifferent\nand then some more\n', None)
257
 
        expected_lines = list(compressor.lines)
 
257
        expected_lines = list(compressor.chunks)
258
258
        sha1_3, start_point, end_point, _, _ = compressor.compress(('label3',),
259
259
            'new\ncommon very very long line\nwith some extra text\n'
260
260
            'different\nmoredifferent\nand then some more\n',
275
275
            # Copy of second parent 'different' range
276
276
            '\x91\x3c\x2b' # copy, offset 0x3c, 0x2b bytes
277
277
            ])
278
 
        self.assertEqualDiffEncoded(expected_lines, compressor.lines)
 
278
        self.assertEqualDiffEncoded(expected_lines, compressor.chunks)
279
279
        self.assertEqual(sum(map(len, expected_lines)), end_point)
280
280
 
281
281