/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/per_versionedfile.py

  • Committer: Breezy landing bot
  • Author(s): Martin
  • Date: 2017-06-05 01:55:02 UTC
  • mfrom: (6651.4.3 plugin_rewrite)
  • Revision ID: breezy.the.bot@gmail.com-20170605015502-tqiyvpz3qt00fge1
Rewrite of plugin module

Merged from https://code.launchpad.net/~gz/brz/plugin_rewrite/+merge/325033

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
2
2
#
3
3
# Authors:
4
4
#   Johan Rydberg <jrydberg@gnu.org>
21
21
# TODO: might be nice to create a versionedfile with some type of corruption
22
22
# considered typical and check that it can be detected/corrected.
23
23
 
24
 
from itertools import chain, izip
25
 
from StringIO import StringIO
 
24
from gzip import GzipFile
 
25
import itertools
26
26
 
27
 
from bzrlib import (
 
27
from .. import (
28
28
    errors,
29
29
    graph as _mod_graph,
30
30
    groupcompress,
31
31
    knit as _mod_knit,
32
32
    osutils,
33
33
    progress,
 
34
    transport,
34
35
    ui,
35
36
    )
36
 
from bzrlib.errors import (
 
37
from ..errors import (
37
38
                           RevisionNotPresent,
38
39
                           RevisionAlreadyPresent,
39
 
                           WeaveParentMismatch
40
40
                           )
41
 
from bzrlib.knit import (
 
41
from ..knit import (
42
42
    cleanup_pack_knit,
43
43
    make_file_factory,
44
44
    make_pack_factory,
45
 
    KnitAnnotateFactory,
46
 
    KnitPlainFactory,
47
 
    )
48
 
from bzrlib.tests import (
 
45
    )
 
46
from ..sixish import (
 
47
    BytesIO,
 
48
    zip,
 
49
    )
 
50
from . import (
49
51
    TestCase,
50
52
    TestCaseWithMemoryTransport,
51
53
    TestNotApplicable,
52
54
    TestSkipped,
53
 
    condition_isinstance,
54
 
    split_suite_by_condition,
55
 
    multiply_tests,
56
55
    )
57
 
from bzrlib.tests.http_utils import TestCaseWithWebserver
58
 
from bzrlib.trace import mutter
59
 
from bzrlib.transport import get_transport
60
 
from bzrlib.transport.memory import MemoryTransport
61
 
from bzrlib.tsort import topo_sort
62
 
from bzrlib.tuned_gzip import GzipFile
63
 
import bzrlib.versionedfile as versionedfile
64
 
from bzrlib.versionedfile import (
 
56
from .http_utils import TestCaseWithWebserver
 
57
from ..transport.memory import MemoryTransport
 
58
from .. import versionedfile as versionedfile
 
59
from ..versionedfile import (
65
60
    ConstantMapper,
66
61
    HashEscapedPrefixMapper,
67
62
    PrefixMapper,
68
63
    VirtualVersionedFiles,
69
64
    make_versioned_files_factory,
70
65
    )
71
 
from bzrlib.weave import WeaveFile
72
 
from bzrlib.weavefile import read_weave, write_weave
73
 
 
74
 
 
75
 
def load_tests(standard_tests, module, loader):
76
 
    """Parameterize VersionedFiles tests for different implementations."""
77
 
    to_adapt, result = split_suite_by_condition(
78
 
        standard_tests, condition_isinstance(TestVersionedFiles))
79
 
    # We want to be sure of behaviour for:
80
 
    # weaves prefix layout (weave texts)
81
 
    # individually named weaves (weave inventories)
82
 
    # annotated knits - prefix|hash|hash-escape layout, we test the third only
83
 
    #                   as it is the most complex mapper.
84
 
    # individually named knits
85
 
    # individual no-graph knits in packs (signatures)
86
 
    # individual graph knits in packs (inventories)
87
 
    # individual graph nocompression knits in packs (revisions)
88
 
    # plain text knits in packs (texts)
89
 
    len_one_scenarios = [
90
 
        ('weave-named', {
91
 
            'cleanup':None,
92
 
            'factory':make_versioned_files_factory(WeaveFile,
93
 
                ConstantMapper('inventory')),
94
 
            'graph':True,
95
 
            'key_length':1,
96
 
            'support_partial_insertion': False,
97
 
            }),
98
 
        ('named-knit', {
99
 
            'cleanup':None,
100
 
            'factory':make_file_factory(False, ConstantMapper('revisions')),
101
 
            'graph':True,
102
 
            'key_length':1,
103
 
            'support_partial_insertion': False,
104
 
            }),
105
 
        ('named-nograph-nodelta-knit-pack', {
106
 
            'cleanup':cleanup_pack_knit,
107
 
            'factory':make_pack_factory(False, False, 1),
108
 
            'graph':False,
109
 
            'key_length':1,
110
 
            'support_partial_insertion': False,
111
 
            }),
112
 
        ('named-graph-knit-pack', {
113
 
            'cleanup':cleanup_pack_knit,
114
 
            'factory':make_pack_factory(True, True, 1),
115
 
            'graph':True,
116
 
            'key_length':1,
117
 
            'support_partial_insertion': True,
118
 
            }),
119
 
        ('named-graph-nodelta-knit-pack', {
120
 
            'cleanup':cleanup_pack_knit,
121
 
            'factory':make_pack_factory(True, False, 1),
122
 
            'graph':True,
123
 
            'key_length':1,
124
 
            'support_partial_insertion': False,
125
 
            }),
126
 
        ('groupcompress-nograph', {
127
 
            'cleanup':groupcompress.cleanup_pack_group,
128
 
            'factory':groupcompress.make_pack_factory(False, False, 1),
129
 
            'graph': False,
130
 
            'key_length':1,
131
 
            'support_partial_insertion':False,
132
 
            }),
133
 
        ]
134
 
    len_two_scenarios = [
135
 
        ('weave-prefix', {
136
 
            'cleanup':None,
137
 
            'factory':make_versioned_files_factory(WeaveFile,
138
 
                PrefixMapper()),
139
 
            'graph':True,
140
 
            'key_length':2,
141
 
            'support_partial_insertion': False,
142
 
            }),
143
 
        ('annotated-knit-escape', {
144
 
            'cleanup':None,
145
 
            'factory':make_file_factory(True, HashEscapedPrefixMapper()),
146
 
            'graph':True,
147
 
            'key_length':2,
148
 
            'support_partial_insertion': False,
149
 
            }),
150
 
        ('plain-knit-pack', {
151
 
            'cleanup':cleanup_pack_knit,
152
 
            'factory':make_pack_factory(True, True, 2),
153
 
            'graph':True,
154
 
            'key_length':2,
155
 
            'support_partial_insertion': True,
156
 
            }),
157
 
        ('groupcompress', {
158
 
            'cleanup':groupcompress.cleanup_pack_group,
159
 
            'factory':groupcompress.make_pack_factory(True, False, 1),
160
 
            'graph': True,
161
 
            'key_length':1,
162
 
            'support_partial_insertion':False,
163
 
            }),
164
 
        ]
165
 
    scenarios = len_one_scenarios + len_two_scenarios
166
 
    return multiply_tests(to_adapt, scenarios, result)
 
66
from ..weave import WeaveFile
 
67
from ..weavefile import write_weave
 
68
from .scenarios import load_tests_apply_scenarios
 
69
 
 
70
 
 
71
load_tests = load_tests_apply_scenarios
167
72
 
168
73
 
169
74
def get_diamond_vf(f, trailing_eol=True, left_only=False):
280
185
            versions = f.versions()
281
186
            self.assertTrue('r0' in versions)
282
187
            self.assertTrue('r1' in versions)
283
 
            self.assertEquals(f.get_lines('r0'), ['a\n', 'b\n'])
284
 
            self.assertEquals(f.get_text('r0'), 'a\nb\n')
285
 
            self.assertEquals(f.get_lines('r1'), ['b\n', 'c\n'])
 
188
            self.assertEqual(f.get_lines('r0'), ['a\n', 'b\n'])
 
189
            self.assertEqual(f.get_text('r0'), 'a\nb\n')
 
190
            self.assertEqual(f.get_lines('r1'), ['b\n', 'c\n'])
286
191
            self.assertEqual(2, len(f))
287
192
            self.assertEqual(2, f.num_versions())
288
193
 
314
219
            self.assertTrue('r0' in versions)
315
220
            self.assertTrue('r1' in versions)
316
221
            self.assertTrue('r2' in versions)
317
 
            self.assertEquals(f.get_lines('r0'), ['a\n', 'b\n'])
318
 
            self.assertEquals(f.get_lines('r1'), ['b\n', 'c\n'])
319
 
            self.assertEquals(f.get_lines('r2'), ['c\n', 'd\n'])
 
222
            self.assertEqual(f.get_lines('r0'), ['a\n', 'b\n'])
 
223
            self.assertEqual(f.get_lines('r1'), ['b\n', 'c\n'])
 
224
            self.assertEqual(f.get_lines('r2'), ['c\n', 'd\n'])
320
225
            self.assertEqual(3, f.num_versions())
321
226
            origins = f.annotate('r1')
322
 
            self.assertEquals(origins[0][0], 'r0')
323
 
            self.assertEquals(origins[1][0], 'r1')
 
227
            self.assertEqual(origins[0][0], 'r0')
 
228
            self.assertEqual(origins[1][0], 'r1')
324
229
            origins = f.annotate('r2')
325
 
            self.assertEquals(origins[0][0], 'r1')
326
 
            self.assertEquals(origins[1][0], 'r2')
 
230
            self.assertEqual(origins[0][0], 'r1')
 
231
            self.assertEqual(origins[1][0], 'r2')
327
232
 
328
233
        verify_file(f)
329
234
        f = self.reopen_file()
503
408
 
504
409
    def test_add_lines_with_matching_blocks_noeol_last_line(self):
505
410
        """Add a text with an unchanged last line with no eol should work."""
506
 
        from bzrlib import multiparent
 
411
        from breezy import multiparent
507
412
        # Hand verified sha1 of the text we're adding.
508
413
        sha1 = '6a1d115ec7b60afb664dc14890b5af5ce3c827a4'
509
414
        # Create a mpdiff which adds a new line before the trailing line, and
524
429
        self.assertEqualDiff('newline\nline', vf.get_text('noeol2'))
525
430
 
526
431
    def test_make_mpdiffs(self):
527
 
        from bzrlib import multiparent
 
432
        from breezy import multiparent
528
433
        vf = self.get_file('foo')
529
434
        sha1s = self._setup_for_deltas(vf)
530
435
        new_vf = self.get_file('bar')
693
598
        f.add_lines('r0', [], ['a\n', 'b\n'])
694
599
        f.add_lines('r1', ['r0'], ['c\n', 'b\n'])
695
600
        origins = f.annotate('r1')
696
 
        self.assertEquals(origins[0][0], 'r1')
697
 
        self.assertEquals(origins[1][0], 'r0')
 
601
        self.assertEqual(origins[0][0], 'r1')
 
602
        self.assertEqual(origins[1][0], 'r0')
698
603
 
699
604
        self.assertRaises(RevisionNotPresent,
700
605
            f.annotate, 'foo')
844
749
                                 ['base', 'a_ghost'],
845
750
                                 ['line\n', 'line_b\n', 'line_c\n'])
846
751
        origins = vf.annotate('references_ghost')
847
 
        self.assertEquals(('base', 'line\n'), origins[0])
848
 
        self.assertEquals(('base', 'line_b\n'), origins[1])
849
 
        self.assertEquals(('references_ghost', 'line_c\n'), origins[2])
 
752
        self.assertEqual(('base', 'line\n'), origins[0])
 
753
        self.assertEqual(('base', 'line_b\n'), origins[1])
 
754
        self.assertEqual(('references_ghost', 'line_c\n'), origins[2])
850
755
 
851
756
    def test_readonly_mode(self):
852
 
        transport = get_transport(self.get_url('.'))
 
757
        t = self.get_transport()
853
758
        factory = self.get_factory()
854
 
        vf = factory('id', transport, 0777, create=True, access_mode='w')
855
 
        vf = factory('id', transport, access_mode='r')
 
759
        vf = factory('id', t, 0o777, create=True, access_mode='w')
 
760
        vf = factory('id', t, access_mode='r')
856
761
        self.assertRaises(errors.ReadOnlyError, vf.add_lines, 'base', [], [])
857
762
        self.assertRaises(errors.ReadOnlyError,
858
763
                          vf.add_lines_with_ghosts,
880
785
class TestWeave(TestCaseWithMemoryTransport, VersionedFileTestMixIn):
881
786
 
882
787
    def get_file(self, name='foo'):
883
 
        return WeaveFile(name, get_transport(self.get_url('.')), create=True,
884
 
            get_scope=self.get_transaction)
 
788
        return WeaveFile(name, self.get_transport(),
 
789
                         create=True,
 
790
                         get_scope=self.get_transaction)
885
791
 
886
792
    def get_file_corrupted_text(self):
887
 
        w = WeaveFile('foo', get_transport(self.get_url('.')), create=True,
888
 
            get_scope=self.get_transaction)
 
793
        w = WeaveFile('foo', self.get_transport(),
 
794
                      create=True,
 
795
                      get_scope=self.get_transaction)
889
796
        w.add_lines('v1', [], ['hello\n'])
890
797
        w.add_lines('v2', ['v1'], ['hello\n', 'there\n'])
891
798
 
919
826
        return w
920
827
 
921
828
    def reopen_file(self, name='foo', create=False):
922
 
        return WeaveFile(name, get_transport(self.get_url('.')), create=create,
923
 
            get_scope=self.get_transaction)
 
829
        return WeaveFile(name, self.get_transport(),
 
830
                         create=create,
 
831
                         get_scope=self.get_transaction)
924
832
 
925
833
    def test_no_implicit_create(self):
926
834
        self.assertRaises(errors.NoSuchFile,
927
835
                          WeaveFile,
928
836
                          'foo',
929
 
                          get_transport(self.get_url('.')),
 
837
                          self.get_transport(),
930
838
                          get_scope=self.get_transaction)
931
839
 
932
840
    def get_factory(self):
936
844
class TestPlanMergeVersionedFile(TestCaseWithMemoryTransport):
937
845
 
938
846
    def setUp(self):
939
 
        TestCaseWithMemoryTransport.setUp(self)
 
847
        super(TestPlanMergeVersionedFile, self).setUp()
940
848
        mapper = PrefixMapper()
941
849
        factory = make_file_factory(True, mapper)
942
850
        self.vf1 = factory(self.get_transport('root-1'))
982
890
    def test_get_record_stream(self):
983
891
        self.setup_abcde()
984
892
        def get_record(suffix):
985
 
            return self.plan_merge_vf.get_record_stream(
986
 
                [('root', suffix)], 'unordered', True).next()
 
893
            return next(self.plan_merge_vf.get_record_stream(
 
894
                [('root', suffix)], 'unordered', True))
987
895
        self.assertEqual('a', get_record('A').get_bytes_as('fulltext'))
988
896
        self.assertEqual('c', get_record('C').get_bytes_as('fulltext'))
989
897
        self.assertEqual('e', get_record('E:').get_bytes_as('fulltext'))
999
907
        # we should be able to read from http with a versioned file.
1000
908
        vf = self.get_file()
1001
909
        # try an empty file access
1002
 
        readonly_vf = self.get_factory()('foo', get_transport(self.get_readonly_url('.')))
 
910
        readonly_vf = self.get_factory()('foo',
 
911
            transport.get_transport_from_url(self.get_readonly_url('.')))
1003
912
        self.assertEqual([], readonly_vf.versions())
 
913
 
 
914
    def test_readonly_http_works_with_feeling(self):
 
915
        # we should be able to read from http with a versioned file.
 
916
        vf = self.get_file()
1004
917
        # now with feeling.
1005
918
        vf.add_lines('1', [], ['a\n'])
1006
919
        vf.add_lines('2', ['1'], ['b\n', 'a\n'])
1007
 
        readonly_vf = self.get_factory()('foo', get_transport(self.get_readonly_url('.')))
 
920
        readonly_vf = self.get_factory()('foo',
 
921
            transport.get_transport_from_url(self.get_readonly_url('.')))
1008
922
        self.assertEqual(['1', '2'], vf.versions())
 
923
        self.assertEqual(['1', '2'], readonly_vf.versions())
1009
924
        for version in readonly_vf.versions():
1010
925
            readonly_vf.get_lines(version)
1011
926
 
1013
928
class TestWeaveHTTP(TestCaseWithWebserver, TestReadonlyHttpMixin):
1014
929
 
1015
930
    def get_file(self):
1016
 
        return WeaveFile('foo', get_transport(self.get_url('.')), create=True,
1017
 
            get_scope=self.get_transaction)
 
931
        return WeaveFile('foo', self.get_transport(),
 
932
                         create=True,
 
933
                         get_scope=self.get_transaction)
1018
934
 
1019
935
    def get_factory(self):
1020
936
        return WeaveFile
1023
939
class MergeCasesMixin(object):
1024
940
 
1025
941
    def doMerge(self, base, a, b, mp):
1026
 
        from cStringIO import StringIO
1027
942
        from textwrap import dedent
1028
943
 
1029
944
        def addcrlf(x):
1030
945
            return x + '\n'
1031
946
 
1032
947
        w = self.get_file()
1033
 
        w.add_lines('text0', [], map(addcrlf, base))
1034
 
        w.add_lines('text1', ['text0'], map(addcrlf, a))
1035
 
        w.add_lines('text2', ['text0'], map(addcrlf, b))
 
948
        w.add_lines('text0', [], list(map(addcrlf, base)))
 
949
        w.add_lines('text1', ['text0'], list(map(addcrlf, a)))
 
950
        w.add_lines('text2', ['text0'], list(map(addcrlf, b)))
1036
951
 
1037
952
        self.log_contents(w)
1038
953
 
1043
958
                self.log('%12s | %s' % (state, line[:-1]))
1044
959
 
1045
960
        self.log('merge:')
1046
 
        mt = StringIO()
 
961
        mt = BytesIO()
1047
962
        mt.writelines(w.weave_merge(p))
1048
963
        mt.seek(0)
1049
964
        self.log(mt.getvalue())
1050
965
 
1051
 
        mp = map(addcrlf, mp)
 
966
        mp = list(map(addcrlf, mp))
1052
967
        self.assertEqual(mt.readlines(), mp)
1053
968
 
1054
969
 
1264
1179
class TestWeaveMerge(TestCaseWithMemoryTransport, MergeCasesMixin):
1265
1180
 
1266
1181
    def get_file(self, name='foo'):
1267
 
        return WeaveFile(name, get_transport(self.get_url('.')), create=True)
 
1182
        return WeaveFile(name, self.get_transport(),
 
1183
                         create=True)
1268
1184
 
1269
1185
    def log_contents(self, w):
1270
1186
        self.log('weave is:')
1271
 
        tmpf = StringIO()
 
1187
        tmpf = BytesIO()
1272
1188
        write_weave(w, tmpf)
1273
1189
        self.log(tmpf.getvalue())
1274
1190
 
1309
1225
        """Grab the interested adapted texts for tests."""
1310
1226
        # origin is a fulltext
1311
1227
        entries = f.get_record_stream([('origin',)], 'unordered', False)
1312
 
        base = entries.next()
 
1228
        base = next(entries)
1313
1229
        ft_data = ft_adapter.get_bytes(base)
1314
1230
        # merged is both a delta and multiple parents.
1315
1231
        entries = f.get_record_stream([('merged',)], 'unordered', False)
1316
 
        merged = entries.next()
 
1232
        merged = next(entries)
1317
1233
        delta_data = delta_adapter.get_bytes(merged)
1318
1234
        return ft_data, delta_data
1319
1235
 
1329
1245
            'version origin 1 b284f94827db1fa2970d9e2014f080413b547a7e\n'
1330
1246
            'origin\n'
1331
1247
            'end origin\n',
1332
 
            GzipFile(mode='rb', fileobj=StringIO(ft_data)).read())
 
1248
            GzipFile(mode='rb', fileobj=BytesIO(ft_data)).read())
1333
1249
        self.assertEqual(
1334
1250
            'version merged 4 32c2e79763b3f90e8ccde37f9710b6629c25a796\n'
1335
1251
            '1,2,3\nleft\nright\nmerged\nend merged\n',
1336
 
            GzipFile(mode='rb', fileobj=StringIO(delta_data)).read())
 
1252
            GzipFile(mode='rb', fileobj=BytesIO(delta_data)).read())
1337
1253
 
1338
1254
    def test_deannotation(self):
1339
1255
        """Test converting annotated knits to unannotated knits."""
1347
1263
            'version origin 1 00e364d235126be43292ab09cb4686cf703ddc17\n'
1348
1264
            'origin\n'
1349
1265
            'end origin\n',
1350
 
            GzipFile(mode='rb', fileobj=StringIO(ft_data)).read())
 
1266
            GzipFile(mode='rb', fileobj=BytesIO(ft_data)).read())
1351
1267
        self.assertEqual(
1352
1268
            'version merged 3 ed8bce375198ea62444dc71952b22cfc2b09226d\n'
1353
1269
            '2,2,2\nright\nmerged\nend merged\n',
1354
 
            GzipFile(mode='rb', fileobj=StringIO(delta_data)).read())
 
1270
            GzipFile(mode='rb', fileobj=BytesIO(delta_data)).read())
1355
1271
 
1356
1272
    def test_annotated_to_fulltext_no_eol(self):
1357
1273
        """Test adapting annotated knits to full texts (for -> weaves)."""
1463
1379
class TestVersionedFiles(TestCaseWithMemoryTransport):
1464
1380
    """Tests for the multiple-file variant of VersionedFile."""
1465
1381
 
 
1382
    # We want to be sure of behaviour for:
 
1383
    # weaves prefix layout (weave texts)
 
1384
    # individually named weaves (weave inventories)
 
1385
    # annotated knits - prefix|hash|hash-escape layout, we test the third only
 
1386
    #                   as it is the most complex mapper.
 
1387
    # individually named knits
 
1388
    # individual no-graph knits in packs (signatures)
 
1389
    # individual graph knits in packs (inventories)
 
1390
    # individual graph nocompression knits in packs (revisions)
 
1391
    # plain text knits in packs (texts)
 
1392
    len_one_scenarios = [
 
1393
        ('weave-named', {
 
1394
            'cleanup':None,
 
1395
            'factory':make_versioned_files_factory(WeaveFile,
 
1396
                ConstantMapper('inventory')),
 
1397
            'graph':True,
 
1398
            'key_length':1,
 
1399
            'support_partial_insertion': False,
 
1400
            }),
 
1401
        ('named-knit', {
 
1402
            'cleanup':None,
 
1403
            'factory':make_file_factory(False, ConstantMapper('revisions')),
 
1404
            'graph':True,
 
1405
            'key_length':1,
 
1406
            'support_partial_insertion': False,
 
1407
            }),
 
1408
        ('named-nograph-nodelta-knit-pack', {
 
1409
            'cleanup':cleanup_pack_knit,
 
1410
            'factory':make_pack_factory(False, False, 1),
 
1411
            'graph':False,
 
1412
            'key_length':1,
 
1413
            'support_partial_insertion': False,
 
1414
            }),
 
1415
        ('named-graph-knit-pack', {
 
1416
            'cleanup':cleanup_pack_knit,
 
1417
            'factory':make_pack_factory(True, True, 1),
 
1418
            'graph':True,
 
1419
            'key_length':1,
 
1420
            'support_partial_insertion': True,
 
1421
            }),
 
1422
        ('named-graph-nodelta-knit-pack', {
 
1423
            'cleanup':cleanup_pack_knit,
 
1424
            'factory':make_pack_factory(True, False, 1),
 
1425
            'graph':True,
 
1426
            'key_length':1,
 
1427
            'support_partial_insertion': False,
 
1428
            }),
 
1429
        ('groupcompress-nograph', {
 
1430
            'cleanup':groupcompress.cleanup_pack_group,
 
1431
            'factory':groupcompress.make_pack_factory(False, False, 1),
 
1432
            'graph': False,
 
1433
            'key_length':1,
 
1434
            'support_partial_insertion':False,
 
1435
            }),
 
1436
        ]
 
1437
    len_two_scenarios = [
 
1438
        ('weave-prefix', {
 
1439
            'cleanup':None,
 
1440
            'factory':make_versioned_files_factory(WeaveFile,
 
1441
                PrefixMapper()),
 
1442
            'graph':True,
 
1443
            'key_length':2,
 
1444
            'support_partial_insertion': False,
 
1445
            }),
 
1446
        ('annotated-knit-escape', {
 
1447
            'cleanup':None,
 
1448
            'factory':make_file_factory(True, HashEscapedPrefixMapper()),
 
1449
            'graph':True,
 
1450
            'key_length':2,
 
1451
            'support_partial_insertion': False,
 
1452
            }),
 
1453
        ('plain-knit-pack', {
 
1454
            'cleanup':cleanup_pack_knit,
 
1455
            'factory':make_pack_factory(True, True, 2),
 
1456
            'graph':True,
 
1457
            'key_length':2,
 
1458
            'support_partial_insertion': True,
 
1459
            }),
 
1460
        ('groupcompress', {
 
1461
            'cleanup':groupcompress.cleanup_pack_group,
 
1462
            'factory':groupcompress.make_pack_factory(True, False, 1),
 
1463
            'graph': True,
 
1464
            'key_length':1,
 
1465
            'support_partial_insertion':False,
 
1466
            }),
 
1467
        ]
 
1468
 
 
1469
    scenarios = len_one_scenarios + len_two_scenarios
 
1470
 
1466
1471
    def get_versionedfiles(self, relpath='files'):
1467
1472
        transport = self.get_transport(relpath)
1468
1473
        if relpath != '.':
1479
1484
        else:
1480
1485
            return ('FileA',) + (suffix,)
1481
1486
 
 
1487
    def test_add_fallback_implies_without_fallbacks(self):
 
1488
        f = self.get_versionedfiles('files')
 
1489
        if getattr(f, 'add_fallback_versioned_files', None) is None:
 
1490
            raise TestNotApplicable("%s doesn't support fallbacks"
 
1491
                                    % (f.__class__.__name__,))
 
1492
        g = self.get_versionedfiles('fallback')
 
1493
        key_a = self.get_simple_key('a')
 
1494
        g.add_lines(key_a, [], ['\n'])
 
1495
        f.add_fallback_versioned_files(g)
 
1496
        self.assertTrue(key_a in f.get_parent_map([key_a]))
 
1497
        self.assertFalse(key_a in f.without_fallbacks().get_parent_map([key_a]))
 
1498
 
1482
1499
    def test_add_lines(self):
1483
1500
        f = self.get_versionedfiles()
1484
1501
        key0 = self.get_simple_key('r0')
1620
1637
                vf._add_text, new_key, [], ''.join(lines),
1621
1638
                nostore_sha=sha)
1622
1639
            # and no new version should have been added.
1623
 
            record = vf.get_record_stream([new_key], 'unordered', True).next()
 
1640
            record = next(vf.get_record_stream([new_key], 'unordered', True))
1624
1641
            self.assertEqual('absent', record.storage_kind)
1625
1642
 
1626
1643
    def test_add_lines_nostoresha(self):
1678
1695
                ('ed8bce375198ea62444dc71952b22cfc2b09226d', 23)],
1679
1696
                results)
1680
1697
            # Check the added items got CHK keys.
1681
 
            self.assertEqual(set([
 
1698
            self.assertEqual({
1682
1699
                ('sha1:00e364d235126be43292ab09cb4686cf703ddc17',),
1683
1700
                ('sha1:51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44',),
1684
1701
                ('sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1',),
1685
1702
                ('sha1:a8478686da38e370e32e42e8a0c220e33ee9132f',),
1686
1703
                ('sha1:ed8bce375198ea62444dc71952b22cfc2b09226d',),
1687
 
                ]),
 
1704
                },
1688
1705
                files.keys())
1689
1706
        elif self.key_length == 2:
1690
1707
            self.assertEqual([
1700
1717
                ('ed8bce375198ea62444dc71952b22cfc2b09226d', 23)],
1701
1718
                results)
1702
1719
            # Check the added items got CHK keys.
1703
 
            self.assertEqual(set([
 
1720
            self.assertEqual({
1704
1721
                ('FileA', 'sha1:00e364d235126be43292ab09cb4686cf703ddc17'),
1705
1722
                ('FileA', 'sha1:51c64a6f4fc375daf0d24aafbabe4d91b6f4bb44'),
1706
1723
                ('FileA', 'sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1'),
1711
1728
                ('FileB', 'sha1:9ef09dfa9d86780bdec9219a22560c6ece8e0ef1'),
1712
1729
                ('FileB', 'sha1:a8478686da38e370e32e42e8a0c220e33ee9132f'),
1713
1730
                ('FileB', 'sha1:ed8bce375198ea62444dc71952b22cfc2b09226d'),
1714
 
                ]),
 
1731
                },
1715
1732
                files.keys())
1716
1733
 
1717
1734
    def test_empty_lines(self):
1985
2002
        key = self.get_simple_key('foo')
1986
2003
        files.add_lines(key, (), ['my text\n', 'content'])
1987
2004
        stream = files.get_record_stream([key], 'unordered', False)
1988
 
        record = stream.next()
 
2005
        record = next(stream)
1989
2006
        if record.storage_kind in ('chunked', 'fulltext'):
1990
2007
            # chunked and fulltext representations are for direct use not wire
1991
2008
            # serialisation: check they are able to be used directly. To send
2012
2029
        :param records: A list to collect the seen records.
2013
2030
        :return: A generator of the records in stream.
2014
2031
        """
2015
 
        # We make assertions during copying to catch things early for
2016
 
        # easier debugging.
2017
 
        for record, ref_record in izip(stream, expected):
 
2032
        # We make assertions during copying to catch things early for easier
 
2033
        # debugging. This must use the iterating zip() from the future.
 
2034
        for record, ref_record in zip(stream, expected):
2018
2035
            records.append(record)
2019
2036
            self.assertEqual(ref_record.key, record.key)
2020
2037
            self.assertEqual(ref_record.storage_kind, record.storage_kind)
2428
2445
        origin_entries = source.get_record_stream(origin_keys, 'unordered', False)
2429
2446
        end_entries = source.get_record_stream(end_keys, 'topological', False)
2430
2447
        start_entries = source.get_record_stream(start_keys, 'topological', False)
2431
 
        entries = chain(origin_entries, end_entries, start_entries)
 
2448
        entries = itertools.chain(origin_entries, end_entries, start_entries)
2432
2449
        try:
2433
2450
            files.insert_record_stream(entries)
2434
2451
        except RevisionNotPresent:
2460
2477
        streams = []
2461
2478
        for key in reversed(keys):
2462
2479
            streams.append(source.get_record_stream([key], 'unordered', False))
2463
 
        deltas = chain(*streams[:-1])
 
2480
        deltas = itertools.chain.from_iterable(streams[:-1])
2464
2481
        files = self.get_versionedfiles()
2465
2482
        try:
2466
2483
            files.insert_record_stream(deltas)
2500
2517
                list(files.get_missing_compression_parent_keys()))
2501
2518
            files.insert_record_stream(entries)
2502
2519
            missing_bases = files.get_missing_compression_parent_keys()
2503
 
            self.assertEqual(set([self.get_simple_key('left')]),
 
2520
            self.assertEqual({self.get_simple_key('left')},
2504
2521
                set(missing_bases))
2505
2522
            self.assertEqual(set(keys), set(files.get_parent_map(keys)))
2506
2523
        else:
2524
2541
        files = self.get_versionedfiles()
2525
2542
        files.insert_record_stream(entries)
2526
2543
        missing_bases = files.get_missing_compression_parent_keys()
2527
 
        self.assertEqual(set([self.get_simple_key('left')]),
 
2544
        self.assertEqual({self.get_simple_key('left')},
2528
2545
            set(missing_bases))
2529
2546
        # 'merged' is inserted (although a commit of a write group involving
2530
2547
        # this versionedfiles would fail).
2615
2632
            lines[('otherchild\n', self.get_simple_key('otherchild'))] > 0)
2616
2633
 
2617
2634
    def test_make_mpdiffs(self):
2618
 
        from bzrlib import multiparent
 
2635
        from breezy import multiparent
2619
2636
        files = self.get_versionedfiles('source')
2620
2637
        # add texts that should trip the knit maximum delta chain threshold
2621
2638
        # as well as doing parallel chains of data in knits.
2717
2734
        else:
2718
2735
            key = ('foo', 'bar',)
2719
2736
        files.add_lines(key, (), [])
2720
 
        self.assertEqual(set([key]), set(files.keys()))
 
2737
        self.assertEqual({key}, set(files.keys()))
2721
2738
 
2722
2739
 
2723
2740
class VirtualVersionedFilesTests(TestCase):
2731
2748
        return ret
2732
2749
 
2733
2750
    def setUp(self):
2734
 
        TestCase.setUp(self)
 
2751
        super(VirtualVersionedFilesTests, self).setUp()
2735
2752
        self._lines = {}
2736
2753
        self._parent_map = {}
2737
2754
        self.texts = VirtualVersionedFiles(self._get_parent_map,
2753
2770
                          [])
2754
2771
 
2755
2772
    def test_get_sha1s_nonexistent(self):
2756
 
        self.assertEquals({}, self.texts.get_sha1s([("NONEXISTENT",)]))
 
2773
        self.assertEqual({}, self.texts.get_sha1s([("NONEXISTENT",)]))
2757
2774
 
2758
2775
    def test_get_sha1s(self):
2759
2776
        self._lines["key"] = ["dataline1", "dataline2"]
2760
 
        self.assertEquals({("key",): osutils.sha_strings(self._lines["key"])},
 
2777
        self.assertEqual({("key",): osutils.sha_strings(self._lines["key"])},
2761
2778
                           self.texts.get_sha1s([("key",)]))
2762
2779
 
2763
2780
    def test_get_parent_map(self):
2764
2781
        self._parent_map = {"G": ("A", "B")}
2765
 
        self.assertEquals({("G",): (("A",),("B",))},
 
2782
        self.assertEqual({("G",): (("A",),("B",))},
2766
2783
                          self.texts.get_parent_map([("G",), ("L",)]))
2767
2784
 
2768
2785
    def test_get_record_stream(self):
2769
2786
        self._lines["A"] = ["FOO", "BAR"]
2770
2787
        it = self.texts.get_record_stream([("A",)], "unordered", True)
2771
 
        record = it.next()
2772
 
        self.assertEquals("chunked", record.storage_kind)
2773
 
        self.assertEquals("FOOBAR", record.get_bytes_as("fulltext"))
2774
 
        self.assertEquals(["FOO", "BAR"], record.get_bytes_as("chunked"))
 
2788
        record = next(it)
 
2789
        self.assertEqual("chunked", record.storage_kind)
 
2790
        self.assertEqual("FOOBAR", record.get_bytes_as("fulltext"))
 
2791
        self.assertEqual(["FOO", "BAR"], record.get_bytes_as("chunked"))
2775
2792
 
2776
2793
    def test_get_record_stream_absent(self):
2777
2794
        it = self.texts.get_record_stream([("A",)], "unordered", True)
2778
 
        record = it.next()
2779
 
        self.assertEquals("absent", record.storage_kind)
 
2795
        record = next(it)
 
2796
        self.assertEqual("absent", record.storage_kind)
2780
2797
 
2781
2798
    def test_iter_lines_added_or_present_in_keys(self):
2782
2799
        self._lines["A"] = ["FOO", "BAR"]
2783
2800
        self._lines["B"] = ["HEY"]
2784
2801
        self._lines["C"] = ["Alberta"]
2785
2802
        it = self.texts.iter_lines_added_or_present_in_keys([("A",), ("B",)])
2786
 
        self.assertEquals(sorted([("FOO", "A"), ("BAR", "A"), ("HEY", "B")]),
 
2803
        self.assertEqual(sorted([("FOO", "A"), ("BAR", "A"), ("HEY", "B")]),
2787
2804
            sorted(list(it)))
2788
2805
 
2789
2806