/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to breezy/tests/per_versionedfile.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
from gzip import GzipFile
25
25
from itertools import chain, izip
26
 
from StringIO import StringIO
27
26
 
28
 
from bzrlib import (
 
27
from .. import (
29
28
    errors,
30
29
    graph as _mod_graph,
31
30
    groupcompress,
35
34
    transport,
36
35
    ui,
37
36
    )
38
 
from bzrlib.errors import (
 
37
from ..errors import (
39
38
                           RevisionNotPresent,
40
39
                           RevisionAlreadyPresent,
41
40
                           )
42
 
from bzrlib.knit import (
 
41
from ..knit import (
43
42
    cleanup_pack_knit,
44
43
    make_file_factory,
45
44
    make_pack_factory,
46
45
    )
47
 
from bzrlib.tests import (
 
46
from ..sixish import (
 
47
    BytesIO,
 
48
    )
 
49
from . import (
48
50
    TestCase,
49
51
    TestCaseWithMemoryTransport,
50
52
    TestNotApplicable,
51
53
    TestSkipped,
52
54
    )
53
 
from bzrlib.tests.http_utils import TestCaseWithWebserver
54
 
from bzrlib.transport.memory import MemoryTransport
55
 
import bzrlib.versionedfile as versionedfile
56
 
from bzrlib.versionedfile import (
 
55
from .http_utils import TestCaseWithWebserver
 
56
from ..transport.memory import MemoryTransport
 
57
from .. import versionedfile as versionedfile
 
58
from ..versionedfile import (
57
59
    ConstantMapper,
58
60
    HashEscapedPrefixMapper,
59
61
    PrefixMapper,
60
62
    VirtualVersionedFiles,
61
63
    make_versioned_files_factory,
62
64
    )
63
 
from bzrlib.weave import WeaveFile
64
 
from bzrlib.weavefile import write_weave
65
 
from bzrlib.tests.scenarios import load_tests_apply_scenarios
 
65
from ..weave import WeaveFile
 
66
from ..weavefile import write_weave
 
67
from .scenarios import load_tests_apply_scenarios
66
68
 
67
69
 
68
70
load_tests = load_tests_apply_scenarios
405
407
 
406
408
    def test_add_lines_with_matching_blocks_noeol_last_line(self):
407
409
        """Add a text with an unchanged last line with no eol should work."""
408
 
        from bzrlib import multiparent
 
410
        from breezy import multiparent
409
411
        # Hand verified sha1 of the text we're adding.
410
412
        sha1 = '6a1d115ec7b60afb664dc14890b5af5ce3c827a4'
411
413
        # Create a mpdiff which adds a new line before the trailing line, and
426
428
        self.assertEqualDiff('newline\nline', vf.get_text('noeol2'))
427
429
 
428
430
    def test_make_mpdiffs(self):
429
 
        from bzrlib import multiparent
 
431
        from breezy import multiparent
430
432
        vf = self.get_file('foo')
431
433
        sha1s = self._setup_for_deltas(vf)
432
434
        new_vf = self.get_file('bar')
753
755
    def test_readonly_mode(self):
754
756
        t = self.get_transport()
755
757
        factory = self.get_factory()
756
 
        vf = factory('id', t, 0777, create=True, access_mode='w')
 
758
        vf = factory('id', t, 0o777, create=True, access_mode='w')
757
759
        vf = factory('id', t, access_mode='r')
758
760
        self.assertRaises(errors.ReadOnlyError, vf.add_lines, 'base', [], [])
759
761
        self.assertRaises(errors.ReadOnlyError,
936
938
class MergeCasesMixin(object):
937
939
 
938
940
    def doMerge(self, base, a, b, mp):
939
 
        from cStringIO import StringIO
940
941
        from textwrap import dedent
941
942
 
942
943
        def addcrlf(x):
956
957
                self.log('%12s | %s' % (state, line[:-1]))
957
958
 
958
959
        self.log('merge:')
959
 
        mt = StringIO()
 
960
        mt = BytesIO()
960
961
        mt.writelines(w.weave_merge(p))
961
962
        mt.seek(0)
962
963
        self.log(mt.getvalue())
1182
1183
 
1183
1184
    def log_contents(self, w):
1184
1185
        self.log('weave is:')
1185
 
        tmpf = StringIO()
 
1186
        tmpf = BytesIO()
1186
1187
        write_weave(w, tmpf)
1187
1188
        self.log(tmpf.getvalue())
1188
1189
 
1243
1244
            'version origin 1 b284f94827db1fa2970d9e2014f080413b547a7e\n'
1244
1245
            'origin\n'
1245
1246
            'end origin\n',
1246
 
            GzipFile(mode='rb', fileobj=StringIO(ft_data)).read())
 
1247
            GzipFile(mode='rb', fileobj=BytesIO(ft_data)).read())
1247
1248
        self.assertEqual(
1248
1249
            'version merged 4 32c2e79763b3f90e8ccde37f9710b6629c25a796\n'
1249
1250
            '1,2,3\nleft\nright\nmerged\nend merged\n',
1250
 
            GzipFile(mode='rb', fileobj=StringIO(delta_data)).read())
 
1251
            GzipFile(mode='rb', fileobj=BytesIO(delta_data)).read())
1251
1252
 
1252
1253
    def test_deannotation(self):
1253
1254
        """Test converting annotated knits to unannotated knits."""
1261
1262
            'version origin 1 00e364d235126be43292ab09cb4686cf703ddc17\n'
1262
1263
            'origin\n'
1263
1264
            'end origin\n',
1264
 
            GzipFile(mode='rb', fileobj=StringIO(ft_data)).read())
 
1265
            GzipFile(mode='rb', fileobj=BytesIO(ft_data)).read())
1265
1266
        self.assertEqual(
1266
1267
            'version merged 3 ed8bce375198ea62444dc71952b22cfc2b09226d\n'
1267
1268
            '2,2,2\nright\nmerged\nend merged\n',
1268
 
            GzipFile(mode='rb', fileobj=StringIO(delta_data)).read())
 
1269
            GzipFile(mode='rb', fileobj=BytesIO(delta_data)).read())
1269
1270
 
1270
1271
    def test_annotated_to_fulltext_no_eol(self):
1271
1272
        """Test adapting annotated knits to full texts (for -> weaves)."""
1693
1694
                ('ed8bce375198ea62444dc71952b22cfc2b09226d', 23)],
1694
1695
                results)
1695
1696
            # Check the added items got CHK keys.
1696
 
            self.assertEqual(set([
 
1697
            self.assertEqual({
1697
1698
                ('sha1:00e364d235126be43292ab09cb4686cf703ddc17',),
1698
1699
                ('sha1:51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44',),
1699
1700
                ('sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1',),
1700
1701
                ('sha1:a8478686da38e370e32e42e8a0c220e33ee9132f',),
1701
1702
                ('sha1:ed8bce375198ea62444dc71952b22cfc2b09226d',),
1702
 
                ]),
 
1703
                },
1703
1704
                files.keys())
1704
1705
        elif self.key_length == 2:
1705
1706
            self.assertEqual([
1715
1716
                ('ed8bce375198ea62444dc71952b22cfc2b09226d', 23)],
1716
1717
                results)
1717
1718
            # Check the added items got CHK keys.
1718
 
            self.assertEqual(set([
 
1719
            self.assertEqual({
1719
1720
                ('FileA', 'sha1:00e364d235126be43292ab09cb4686cf703ddc17'),
1720
1721
                ('FileA', 'sha1:51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44'),
1721
1722
                ('FileA', 'sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1'),
1726
1727
                ('FileB', 'sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1'),
1727
1728
                ('FileB', 'sha1:a8478686da38e370e32e42e8a0c220e33ee9132f'),
1728
1729
                ('FileB', 'sha1:ed8bce375198ea62444dc71952b22cfc2b09226d'),
1729
 
                ]),
 
1730
                },
1730
1731
                files.keys())
1731
1732
 
1732
1733
    def test_empty_lines(self):
2515
2516
                list(files.get_missing_compression_parent_keys()))
2516
2517
            files.insert_record_stream(entries)
2517
2518
            missing_bases = files.get_missing_compression_parent_keys()
2518
 
            self.assertEqual(set([self.get_simple_key('left')]),
 
2519
            self.assertEqual({self.get_simple_key('left')},
2519
2520
                set(missing_bases))
2520
2521
            self.assertEqual(set(keys), set(files.get_parent_map(keys)))
2521
2522
        else:
2539
2540
        files = self.get_versionedfiles()
2540
2541
        files.insert_record_stream(entries)
2541
2542
        missing_bases = files.get_missing_compression_parent_keys()
2542
 
        self.assertEqual(set([self.get_simple_key('left')]),
 
2543
        self.assertEqual({self.get_simple_key('left')},
2543
2544
            set(missing_bases))
2544
2545
        # 'merged' is inserted (although a commit of a write group involving
2545
2546
        # this versionedfiles would fail).
2630
2631
            lines[('otherchild\n', self.get_simple_key('otherchild'))] > 0)
2631
2632
 
2632
2633
    def test_make_mpdiffs(self):
2633
 
        from bzrlib import multiparent
 
2634
        from breezy import multiparent
2634
2635
        files = self.get_versionedfiles('source')
2635
2636
        # add texts that should trip the knit maximum delta chain threshold
2636
2637
        # as well as doing parallel chains of data in knits.
2732
2733
        else:
2733
2734
            key = ('foo', 'bar',)
2734
2735
        files.add_lines(key, (), [])
2735
 
        self.assertEqual(set([key]), set(files.keys()))
 
2736
        self.assertEqual({key}, set(files.keys()))
2736
2737
 
2737
2738
 
2738
2739
class VirtualVersionedFilesTests(TestCase):