~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

create thread for bbc

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from itertools import chain, izip
25
25
from StringIO import StringIO
26
26
 
27
 
import bzrlib
28
27
from bzrlib import (
29
28
    errors,
 
29
    groupcompress,
 
30
    knit as _mod_knit,
30
31
    osutils,
31
32
    progress,
32
33
    )
35
36
                           RevisionAlreadyPresent,
36
37
                           WeaveParentMismatch
37
38
                           )
38
 
from bzrlib import knit as _mod_knit
39
39
from bzrlib.knit import (
40
40
    cleanup_pack_knit,
41
41
    make_file_factory,
121
121
            'key_length':1,
122
122
            'support_partial_insertion': False,
123
123
            }),
 
124
        ('groupcompress-nograph', {
 
125
            'cleanup':groupcompress.cleanup_pack_group,
 
126
            'factory':groupcompress.make_pack_factory(False, False, 1),
 
127
            'graph': False,
 
128
            'key_length':1,
 
129
            'support_partial_insertion':False,
 
130
            }),
124
131
        ]
125
132
    len_two_scenarios = [
126
133
        ('weave-prefix', {
145
152
            'key_length':2,
146
153
            'support_partial_insertion': True,
147
154
            }),
 
155
        ('groupcompress', {
 
156
            'cleanup':groupcompress.cleanup_pack_group,
 
157
            'factory':groupcompress.make_pack_factory(True, False, 1),
 
158
            'graph': True,
 
159
            'key_length':1,
 
160
            'support_partial_insertion':False,
 
161
            }),
148
162
        ]
149
163
    scenarios = len_one_scenarios + len_two_scenarios
150
164
    return multiply_tests(to_adapt, scenarios, result)
179
193
 
180
194
 
181
195
def get_diamond_files(files, key_length, trailing_eol=True, left_only=False,
182
 
    nograph=False):
 
196
    nograph=False, nokeys=False):
183
197
    """Get a diamond graph to exercise deltas and merges.
184
198
 
185
199
    This creates a 5-node graph in files. If files supports 2-length keys two
192
206
    :param nograph: If True, do not provide parents to the add_lines calls;
193
207
        this is useful for tests that need inserted data but have graphless
194
208
        stores.
 
209
    :param nokeys: If True, pass None is as the key for all insertions.
 
210
        Currently implies nograph.
195
211
    :return: The results of the add_lines calls.
196
212
    """
 
213
    if nokeys:
 
214
        nograph = True
197
215
    if key_length == 1:
198
216
        prefixes = [()]
199
217
    else:
210
228
        else:
211
229
            result = [prefix + suffix for suffix in suffix_list]
212
230
            return result
 
231
    def get_key(suffix):
 
232
        if nokeys:
 
233
            return (None, )
 
234
        else:
 
235
            return (suffix,)
213
236
    # we loop over each key because that spreads the inserts across prefixes,
214
237
    # which is how commit operates.
215
238
    for prefix in prefixes:
216
 
        result.append(files.add_lines(prefix + ('origin',), (),
 
239
        result.append(files.add_lines(prefix + get_key('origin'), (),
217
240
            ['origin' + last_char]))
218
241
    for prefix in prefixes:
219
 
        result.append(files.add_lines(prefix + ('base',),
 
242
        result.append(files.add_lines(prefix + get_key('base'),
220
243
            get_parents([('origin',)]), ['base' + last_char]))
221
244
    for prefix in prefixes:
222
 
        result.append(files.add_lines(prefix + ('left',),
 
245
        result.append(files.add_lines(prefix + get_key('left'),
223
246
            get_parents([('base',)]),
224
247
            ['base\n', 'left' + last_char]))
225
248
    if not left_only:
226
249
        for prefix in prefixes:
227
 
            result.append(files.add_lines(prefix + ('right',),
 
250
            result.append(files.add_lines(prefix + get_key('right'),
228
251
                get_parents([('base',)]),
229
252
                ['base\n', 'right' + last_char]))
230
253
        for prefix in prefixes:
231
 
            result.append(files.add_lines(prefix + ('merged',),
 
254
            result.append(files.add_lines(prefix + get_key('merged'),
232
255
                get_parents([('left',), ('right',)]),
233
256
                ['base\n', 'left\n', 'right\n', 'merged' + last_char]))
234
257
    return result
1487
1510
        """Each parameterised test can be constructed on a transport."""
1488
1511
        files = self.get_versionedfiles()
1489
1512
 
1490
 
    def get_diamond_files(self, files, trailing_eol=True, left_only=False):
 
1513
    def get_diamond_files(self, files, trailing_eol=True, left_only=False,
 
1514
        nokeys=False):
1491
1515
        return get_diamond_files(files, self.key_length,
1492
1516
            trailing_eol=trailing_eol, nograph=not self.graph,
1493
 
            left_only=left_only)
 
1517
            left_only=left_only, nokeys=nokeys)
1494
1518
 
1495
1519
    def test_add_lines_nostoresha(self):
1496
1520
        """When nostore_sha is supplied using old content raises."""
1544
1568
                ('ed8bce375198ea62444dc71952b22cfc2b09226d', 23)],
1545
1569
                results)
1546
1570
 
 
1571
    def test_add_lines_no_key_generates_chk_key(self):
 
1572
        files = self.get_versionedfiles()
 
1573
        # save code by using the stock data insertion helper.
 
1574
        adds = self.get_diamond_files(files, nokeys=True)
 
1575
        results = []
 
1576
        # We can only validate the first 2 elements returned from add_lines.
 
1577
        for add in adds:
 
1578
            self.assertEqual(3, len(add))
 
1579
            results.append(add[:2])
 
1580
        if self.key_length == 1:
 
1581
            self.assertEqual([
 
1582
                ('00e364d235126be43292ab09cb4686cf703ddc17', 7),
 
1583
                ('51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44', 5),
 
1584
                ('a8478686da38e370e32e42e8a0c220e33ee9132f', 10),
 
1585
                ('9ef09dfa9d86780bdec9219a22560c6ece8e0ef1', 11),
 
1586
                ('ed8bce375198ea62444dc71952b22cfc2b09226d', 23)],
 
1587
                results)
 
1588
            # Check the added items got CHK keys.
 
1589
            self.assertEqual(set([
 
1590
                ('sha1:00e364d235126be43292ab09cb4686cf703ddc17',),
 
1591
                ('sha1:51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44',),
 
1592
                ('sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1',),
 
1593
                ('sha1:a8478686da38e370e32e42e8a0c220e33ee9132f',),
 
1594
                ('sha1:ed8bce375198ea62444dc71952b22cfc2b09226d',),
 
1595
                ]),
 
1596
                files.keys())
 
1597
        elif self.key_length == 2:
 
1598
            self.assertEqual([
 
1599
                ('00e364d235126be43292ab09cb4686cf703ddc17', 7),
 
1600
                ('00e364d235126be43292ab09cb4686cf703ddc17', 7),
 
1601
                ('51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44', 5),
 
1602
                ('51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44', 5),
 
1603
                ('a8478686da38e370e32e42e8a0c220e33ee9132f', 10),
 
1604
                ('a8478686da38e370e32e42e8a0c220e33ee9132f', 10),
 
1605
                ('9ef09dfa9d86780bdec9219a22560c6ece8e0ef1', 11),
 
1606
                ('9ef09dfa9d86780bdec9219a22560c6ece8e0ef1', 11),
 
1607
                ('ed8bce375198ea62444dc71952b22cfc2b09226d', 23),
 
1608
                ('ed8bce375198ea62444dc71952b22cfc2b09226d', 23)],
 
1609
                results)
 
1610
            # Check the added items got CHK keys.
 
1611
            self.assertEqual(set([
 
1612
                ('FileA', 'sha1:00e364d235126be43292ab09cb4686cf703ddc17'),
 
1613
                ('FileA', 'sha1:51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44'),
 
1614
                ('FileA', 'sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1'),
 
1615
                ('FileA', 'sha1:a8478686da38e370e32e42e8a0c220e33ee9132f'),
 
1616
                ('FileA', 'sha1:ed8bce375198ea62444dc71952b22cfc2b09226d'),
 
1617
                ('FileB', 'sha1:00e364d235126be43292ab09cb4686cf703ddc17'),
 
1618
                ('FileB', 'sha1:51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44'),
 
1619
                ('FileB', 'sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1'),
 
1620
                ('FileB', 'sha1:a8478686da38e370e32e42e8a0c220e33ee9132f'),
 
1621
                ('FileB', 'sha1:ed8bce375198ea62444dc71952b22cfc2b09226d'),
 
1622
                ]),
 
1623
                files.keys())
 
1624
 
1547
1625
    def test_empty_lines(self):
1548
1626
        """Empty files can be stored."""
1549
1627
        f = self.get_versionedfiles()
1584
1662
             'knit-ft', 'knit-delta', 'chunked', 'fulltext',
1585
1663
             'knit-annotated-ft-gz', 'knit-annotated-delta-gz', 'knit-ft-gz',
1586
1664
             'knit-delta-gz',
1587
 
             'knit-delta-closure', 'knit-delta-closure-ref'])
 
1665
             'knit-delta-closure', 'knit-delta-closure-ref',
 
1666
             'groupcompress-block', 'groupcompress-block-ref'])
1588
1667
 
1589
1668
    def capture_stream(self, f, entries, on_seen, parents):
1590
1669
        """Capture a stream for testing."""
1591
1670
        for factory in entries:
1592
1671
            on_seen(factory.key)
1593
1672
            self.assertValidStorageKind(factory.storage_kind)
1594
 
            self.assertEqual(f.get_sha1s([factory.key])[factory.key],
1595
 
                factory.sha1)
 
1673
            if factory.sha1 is not None:
 
1674
                self.assertEqual(f.get_sha1s([factory.key])[factory.key],
 
1675
                    factory.sha1)
1596
1676
            self.assertEqual(parents[factory.key], factory.parents)
1597
1677
            self.assertIsInstance(factory.get_bytes_as(factory.storage_kind),
1598
1678
                str)
1735
1815
        for factory in entries:
1736
1816
            seen.add(factory.key)
1737
1817
            self.assertValidStorageKind(factory.storage_kind)
1738
 
            self.assertEqual(files.get_sha1s([factory.key])[factory.key],
1739
 
                factory.sha1)
 
1818
            if factory.sha1 is not None:
 
1819
                self.assertEqual(files.get_sha1s([factory.key])[factory.key],
 
1820
                                 factory.sha1)
1740
1821
            self.assertEqual(parent_map[factory.key], factory.parents)
1741
1822
            # currently no stream emits mpdiff
1742
1823
            self.assertRaises(errors.UnavailableRepresentation,
1940
2021
                self.assertEqual(None, factory.parents)
1941
2022
            else:
1942
2023
                self.assertValidStorageKind(factory.storage_kind)
1943
 
                self.assertEqual(files.get_sha1s([factory.key])[factory.key],
1944
 
                    factory.sha1)
 
2024
                if factory.sha1 is not None:
 
2025
                    sha1 = files.get_sha1s([factory.key])[factory.key]
 
2026
                    self.assertEqual(sha1, factory.sha1)
1945
2027
                self.assertEqual(parents[factory.key], factory.parents)
1946
2028
                self.assertIsInstance(factory.get_bytes_as(factory.storage_kind),
1947
2029
                    str)