~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

  • Committer: Jelmer Vernooij
  • Date: 2009-04-06 02:54:14 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4255.
  • Revision ID: jelmer@samba.org-20090406025414-65tpjwcmjp5wa5oj
Merge bzr.dev.

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
    knit as _mod_knit,
30
30
    osutils,
31
31
    progress,
32
32
    )
35
35
                           RevisionAlreadyPresent,
36
36
                           WeaveParentMismatch
37
37
                           )
38
 
from bzrlib import knit as _mod_knit
39
38
from bzrlib.knit import (
40
39
    cleanup_pack_knit,
41
40
    make_file_factory,
179
178
 
180
179
 
181
180
def get_diamond_files(files, key_length, trailing_eol=True, left_only=False,
182
 
    nograph=False):
 
181
    nograph=False, nokeys=False):
183
182
    """Get a diamond graph to exercise deltas and merges.
184
183
 
185
184
    This creates a 5-node graph in files. If files supports 2-length keys two
192
191
    :param nograph: If True, do not provide parents to the add_lines calls;
193
192
        this is useful for tests that need inserted data but have graphless
194
193
        stores.
 
194
    :param nokeys: If True, pass None is as the key for all insertions.
 
195
        Currently implies nograph.
195
196
    :return: The results of the add_lines calls.
196
197
    """
 
198
    if nokeys:
 
199
        nograph = True
197
200
    if key_length == 1:
198
201
        prefixes = [()]
199
202
    else:
210
213
        else:
211
214
            result = [prefix + suffix for suffix in suffix_list]
212
215
            return result
 
216
    def get_key(suffix):
 
217
        if nokeys:
 
218
            return (None, )
 
219
        else:
 
220
            return (suffix,)
213
221
    # we loop over each key because that spreads the inserts across prefixes,
214
222
    # which is how commit operates.
215
223
    for prefix in prefixes:
216
 
        result.append(files.add_lines(prefix + ('origin',), (),
 
224
        result.append(files.add_lines(prefix + get_key('origin'), (),
217
225
            ['origin' + last_char]))
218
226
    for prefix in prefixes:
219
 
        result.append(files.add_lines(prefix + ('base',),
 
227
        result.append(files.add_lines(prefix + get_key('base'),
220
228
            get_parents([('origin',)]), ['base' + last_char]))
221
229
    for prefix in prefixes:
222
 
        result.append(files.add_lines(prefix + ('left',),
 
230
        result.append(files.add_lines(prefix + get_key('left'),
223
231
            get_parents([('base',)]),
224
232
            ['base\n', 'left' + last_char]))
225
233
    if not left_only:
226
234
        for prefix in prefixes:
227
 
            result.append(files.add_lines(prefix + ('right',),
 
235
            result.append(files.add_lines(prefix + get_key('right'),
228
236
                get_parents([('base',)]),
229
237
                ['base\n', 'right' + last_char]))
230
238
        for prefix in prefixes:
231
 
            result.append(files.add_lines(prefix + ('merged',),
 
239
            result.append(files.add_lines(prefix + get_key('merged'),
232
240
                get_parents([('left',), ('right',)]),
233
241
                ['base\n', 'left\n', 'right\n', 'merged' + last_char]))
234
242
    return result
1487
1495
        """Each parameterised test can be constructed on a transport."""
1488
1496
        files = self.get_versionedfiles()
1489
1497
 
1490
 
    def get_diamond_files(self, files, trailing_eol=True, left_only=False):
 
1498
    def get_diamond_files(self, files, trailing_eol=True, left_only=False,
 
1499
        nokeys=False):
1491
1500
        return get_diamond_files(files, self.key_length,
1492
1501
            trailing_eol=trailing_eol, nograph=not self.graph,
1493
 
            left_only=left_only)
 
1502
            left_only=left_only, nokeys=nokeys)
1494
1503
 
1495
1504
    def test_add_lines_nostoresha(self):
1496
1505
        """When nostore_sha is supplied using old content raises."""
1544
1553
                ('ed8bce375198ea62444dc71952b22cfc2b09226d', 23)],
1545
1554
                results)
1546
1555
 
 
1556
    def test_add_lines_no_key_generates_chk_key(self):
 
1557
        files = self.get_versionedfiles()
 
1558
        # save code by using the stock data insertion helper.
 
1559
        adds = self.get_diamond_files(files, nokeys=True)
 
1560
        results = []
 
1561
        # We can only validate the first 2 elements returned from add_lines.
 
1562
        for add in adds:
 
1563
            self.assertEqual(3, len(add))
 
1564
            results.append(add[:2])
 
1565
        if self.key_length == 1:
 
1566
            self.assertEqual([
 
1567
                ('00e364d235126be43292ab09cb4686cf703ddc17', 7),
 
1568
                ('51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44', 5),
 
1569
                ('a8478686da38e370e32e42e8a0c220e33ee9132f', 10),
 
1570
                ('9ef09dfa9d86780bdec9219a22560c6ece8e0ef1', 11),
 
1571
                ('ed8bce375198ea62444dc71952b22cfc2b09226d', 23)],
 
1572
                results)
 
1573
            # Check the added items got CHK keys.
 
1574
            self.assertEqual(set([
 
1575
                ('sha1:00e364d235126be43292ab09cb4686cf703ddc17',),
 
1576
                ('sha1:51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44',),
 
1577
                ('sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1',),
 
1578
                ('sha1:a8478686da38e370e32e42e8a0c220e33ee9132f',),
 
1579
                ('sha1:ed8bce375198ea62444dc71952b22cfc2b09226d',),
 
1580
                ]),
 
1581
                files.keys())
 
1582
        elif self.key_length == 2:
 
1583
            self.assertEqual([
 
1584
                ('00e364d235126be43292ab09cb4686cf703ddc17', 7),
 
1585
                ('00e364d235126be43292ab09cb4686cf703ddc17', 7),
 
1586
                ('51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44', 5),
 
1587
                ('51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44', 5),
 
1588
                ('a8478686da38e370e32e42e8a0c220e33ee9132f', 10),
 
1589
                ('a8478686da38e370e32e42e8a0c220e33ee9132f', 10),
 
1590
                ('9ef09dfa9d86780bdec9219a22560c6ece8e0ef1', 11),
 
1591
                ('9ef09dfa9d86780bdec9219a22560c6ece8e0ef1', 11),
 
1592
                ('ed8bce375198ea62444dc71952b22cfc2b09226d', 23),
 
1593
                ('ed8bce375198ea62444dc71952b22cfc2b09226d', 23)],
 
1594
                results)
 
1595
            # Check the added items got CHK keys.
 
1596
            self.assertEqual(set([
 
1597
                ('FileA', 'sha1:00e364d235126be43292ab09cb4686cf703ddc17'),
 
1598
                ('FileA', 'sha1:51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44'),
 
1599
                ('FileA', 'sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1'),
 
1600
                ('FileA', 'sha1:a8478686da38e370e32e42e8a0c220e33ee9132f'),
 
1601
                ('FileA', 'sha1:ed8bce375198ea62444dc71952b22cfc2b09226d'),
 
1602
                ('FileB', 'sha1:00e364d235126be43292ab09cb4686cf703ddc17'),
 
1603
                ('FileB', 'sha1:51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44'),
 
1604
                ('FileB', 'sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1'),
 
1605
                ('FileB', 'sha1:a8478686da38e370e32e42e8a0c220e33ee9132f'),
 
1606
                ('FileB', 'sha1:ed8bce375198ea62444dc71952b22cfc2b09226d'),
 
1607
                ]),
 
1608
                files.keys())
 
1609
 
1547
1610
    def test_empty_lines(self):
1548
1611
        """Empty files can be stored."""
1549
1612
        f = self.get_versionedfiles()
1591
1654
        for factory in entries:
1592
1655
            on_seen(factory.key)
1593
1656
            self.assertValidStorageKind(factory.storage_kind)
1594
 
            self.assertEqual(f.get_sha1s([factory.key])[factory.key],
1595
 
                factory.sha1)
 
1657
            if factory.sha1 is not None:
 
1658
                self.assertEqual(f.get_sha1s([factory.key])[factory.key],
 
1659
                    factory.sha1)
1596
1660
            self.assertEqual(parents[factory.key], factory.parents)
1597
1661
            self.assertIsInstance(factory.get_bytes_as(factory.storage_kind),
1598
1662
                str)
1735
1799
        for factory in entries:
1736
1800
            seen.add(factory.key)
1737
1801
            self.assertValidStorageKind(factory.storage_kind)
1738
 
            self.assertEqual(files.get_sha1s([factory.key])[factory.key],
1739
 
                factory.sha1)
 
1802
            if factory.sha1 is not None:
 
1803
                self.assertEqual(files.get_sha1s([factory.key])[factory.key],
 
1804
                                 factory.sha1)
1740
1805
            self.assertEqual(parent_map[factory.key], factory.parents)
1741
1806
            # currently no stream emits mpdiff
1742
1807
            self.assertRaises(errors.UnavailableRepresentation,
1940
2005
                self.assertEqual(None, factory.parents)
1941
2006
            else:
1942
2007
                self.assertValidStorageKind(factory.storage_kind)
1943
 
                self.assertEqual(files.get_sha1s([factory.key])[factory.key],
1944
 
                    factory.sha1)
 
2008
                if factory.sha1 is not None:
 
2009
                    sha1 = files.get_sha1s([factory.key])[factory.key]
 
2010
                    self.assertEqual(sha1, factory.sha1)
1945
2011
                self.assertEqual(parents[factory.key], factory.parents)
1946
2012
                self.assertIsInstance(factory.get_bytes_as(factory.storage_kind),
1947
2013
                    str)