/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/test_vf_search.py

  • Committer: Jelmer Vernooij
  • Date: 2018-08-08 02:14:32 UTC
  • mfrom: (7063 work)
  • mto: This revision was merged to the branch mainline in revision 7065.
  • Revision ID: jelmer@jelmer.uk-20180808021432-nomib3je4cu2xqkm
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#   rev3  /
36
36
#     |  /
37
37
#   rev4
38
 
ancestry_1 = {'rev1': [NULL_REVISION], 'rev2a': ['rev1'], 'rev2b': ['rev1'],
39
 
              'rev3': ['rev2a'], 'rev4': ['rev3', 'rev2b']}
 
38
ancestry_1 = {b'rev1': [NULL_REVISION], b'rev2a': [b'rev1'], b'rev2b': [b'rev1'],
 
39
              b'rev3': [b'rev2a'], b'rev4': [b'rev3', b'rev2b']}
40
40
 
41
41
# Ancestry 2:
42
42
#
49
49
# rev3a
50
50
#   |
51
51
# rev4a
52
 
ancestry_2 = {'rev1a': [NULL_REVISION], 'rev2a': ['rev1a'],
53
 
              'rev1b': [NULL_REVISION], 'rev3a': ['rev2a'], 'rev4a': ['rev3a']}
 
52
ancestry_2 = {b'rev1a': [NULL_REVISION], b'rev2a': [b'rev1a'],
 
53
              b'rev1b': [NULL_REVISION], b'rev3a': [b'rev2a'], b'rev4a': [b'rev3a']}
54
54
 
55
55
 
56
56
# Extended history shortcut
65
65
#       d |
66
66
#       |\|
67
67
#       e f
68
 
extended_history_shortcut = {'a': [NULL_REVISION],
69
 
                             'b': ['a'],
70
 
                             'c': ['b'],
71
 
                             'd': ['c'],
72
 
                             'e': ['d'],
73
 
                             'f': ['a', 'd'],
 
68
extended_history_shortcut = {b'a': [NULL_REVISION],
 
69
                             b'b': [b'a'],
 
70
                             b'c': [b'b'],
 
71
                             b'd': [b'c'],
 
72
                             b'e': [b'd'],
 
73
                             b'f': [b'a', b'd'],
74
74
                            }
75
75
 
76
76
 
83
83
        # Used when pulling from a stacked repository, so test some revisions
84
84
        # being satisfied from the stacking branch.
85
85
        g = self.make_graph(
86
 
            {"tip":["mid"], "mid":["base"], "tag":["base"],
87
 
             "base":[NULL_REVISION], NULL_REVISION:[]})
88
 
        result = vf_search.SearchResult({'tip', 'tag'},
89
 
            {NULL_REVISION}, 4, {'tip', 'mid', 'tag', 'base'})
90
 
        result = result.refine({'tip'}, {'mid'})
 
86
            {b"tip": [b"mid"], b"mid": [b"base"], b"tag": [b"base"],
 
87
             b"base": [NULL_REVISION], NULL_REVISION:[]})
 
88
        result = vf_search.SearchResult({b'tip', b'tag'},
 
89
            {NULL_REVISION}, 4, {b'tip', b'mid', b'tag', b'base'})
 
90
        result = result.refine({b'tip'}, {b'mid'})
91
91
        recipe = result.get_recipe()
92
92
        # We should be starting from tag (original head) and mid (seen ref)
93
 
        self.assertEqual({'mid', 'tag'}, recipe[1])
 
93
        self.assertEqual({b'mid', b'tag'}, recipe[1])
94
94
        # We should be stopping at NULL (original stop) and tip (seen head)
95
 
        self.assertEqual({NULL_REVISION, 'tip'}, recipe[2])
 
95
        self.assertEqual({NULL_REVISION, b'tip'}, recipe[2])
96
96
        self.assertEqual(3, recipe[3])
97
 
        result = result.refine({'mid', 'tag', 'base'},
 
97
        result = result.refine({b'mid', b'tag', b'base'},
98
98
            {NULL_REVISION})
99
99
        recipe = result.get_recipe()
100
100
        # We should be starting from nothing (NULL was known as a cut point)
103
103
        # tag (seen head) and mid(seen mid-point head). We could come back and
104
104
        # define this as not including mid, for minimal results, but it is
105
105
        # still 'correct' to include mid, and simpler/easier.
106
 
        self.assertEqual({NULL_REVISION, 'tip', 'tag', 'mid'}, recipe[2])
 
106
        self.assertEqual({NULL_REVISION, b'tip', b'tag', b'mid'}, recipe[2])
107
107
        self.assertEqual(0, recipe[3])
108
108
        self.assertTrue(result.is_empty())
109
109
 
122
122
        self.assertSearchResult([], [], 0, None)
123
123
 
124
124
    def test_ancestry_1(self):
125
 
        self.assertSearchResult(['rev4'], [NULL_REVISION], len(ancestry_1),
 
125
        self.assertSearchResult([b'rev4'], [NULL_REVISION], len(ancestry_1),
126
126
                                ancestry_1)
127
127
 
128
128
    def test_ancestry_2(self):
129
 
        self.assertSearchResult(['rev1b', 'rev4a'], [NULL_REVISION],
 
129
        self.assertSearchResult([b'rev1b', b'rev4a'], [NULL_REVISION],
130
130
                                len(ancestry_2), ancestry_2)
131
 
        self.assertSearchResult(['rev1b', 'rev4a'], [],
 
131
        self.assertSearchResult([b'rev1b', b'rev4a'], [],
132
132
                                len(ancestry_2)+1, ancestry_2,
133
133
                                missing_keys=[NULL_REVISION])
134
134
 
135
135
    def test_partial_search(self):
136
136
        parent_map = dict((k, extended_history_shortcut[k])
137
 
                          for k in ['e', 'f'])
138
 
        self.assertSearchResult(['e', 'f'], ['d', 'a'], 2,
 
137
                          for k in [b'e', b'f'])
 
138
        self.assertSearchResult([b'e', b'f'], [b'd', b'a'], 2,
139
139
                                parent_map)
140
140
        parent_map.update((k, extended_history_shortcut[k])
141
 
                          for k in ['d', 'a'])
142
 
        self.assertSearchResult(['e', 'f'], ['c', NULL_REVISION], 4,
 
141
                          for k in [b'd', b'a'])
 
142
        self.assertSearchResult([b'e', b'f'], [b'c', NULL_REVISION], 4,
143
143
                                parent_map)
144
 
        parent_map['c'] = extended_history_shortcut['c']
145
 
        self.assertSearchResult(['e', 'f'], ['b'], 6,
 
144
        parent_map[b'c'] = extended_history_shortcut[b'c']
 
145
        self.assertSearchResult([b'e', b'f'], [b'b'], 6,
146
146
                                parent_map, missing_keys=[NULL_REVISION])
147
 
        parent_map['b'] = extended_history_shortcut['b']
148
 
        self.assertSearchResult(['e', 'f'], [], 7,
 
147
        parent_map[b'b'] = extended_history_shortcut[b'b']
 
148
        self.assertSearchResult([b'e', b'f'], [], 7,
149
149
                                parent_map, missing_keys=[NULL_REVISION])
150
150
 
151
151
 
159
159
                         (sorted(start), sorted(stop), count))
160
160
 
161
161
    def test_empty_ancestry(self):
162
 
        self.assertSearchResult([], [], 0, {}, (), ['tip-rev-id'], 10)
 
162
        self.assertSearchResult([], [], 0, {}, (), [b'tip-rev-id'], 10)
163
163
 
164
164
    def test_ancestry_1(self):
165
 
        self.assertSearchResult(['rev4'], ['rev1'], 4,
166
 
                                ancestry_1, (), ['rev1'], 10)
167
 
        self.assertSearchResult(['rev2a', 'rev2b'], ['rev1'], 2,
168
 
                                ancestry_1, (), ['rev1'], 1)
 
165
        self.assertSearchResult([b'rev4'], [b'rev1'], 4,
 
166
                                ancestry_1, (), [b'rev1'], 10)
 
167
        self.assertSearchResult([b'rev2a', b'rev2b'], [b'rev1'], 2,
 
168
                                ancestry_1, (), [b'rev1'], 1)
169
169
 
170
170
 
171
171
    def test_multiple_heads(self):
172
 
        self.assertSearchResult(['e', 'f'], ['a'], 5,
173
 
                                extended_history_shortcut, (), ['a'], 10)
 
172
        self.assertSearchResult([b'e', b'f'], [b'a'], 5,
 
173
                                extended_history_shortcut, (), [b'a'], 10)
174
174
        # Note that even though we only take 1 step back, we find 'f', which
175
175
        # means the described search will still find d and c.
176
 
        self.assertSearchResult(['f'], ['a'], 4,
177
 
                                extended_history_shortcut, (), ['a'], 1)
178
 
        self.assertSearchResult(['f'], ['a'], 4,
179
 
                                extended_history_shortcut, (), ['a'], 2)
 
176
        self.assertSearchResult([b'f'], [b'a'], 4,
 
177
                                extended_history_shortcut, (), [b'a'], 1)
 
178
        self.assertSearchResult([b'f'], [b'a'], 4,
 
179
                                extended_history_shortcut, (), [b'a'], 2)
180
180
 
181
181
 
182
182
class TestPendingAncestryResultRefine(tests.TestCase):
188
188
        # Used when pulling from a stacked repository, so test some revisions
189
189
        # being satisfied from the stacking branch.
190
190
        g = self.make_graph(
191
 
            {"tip":["mid"], "mid":["base"], "tag":["base"],
192
 
             "base":[NULL_REVISION], NULL_REVISION:[]})
193
 
        result = vf_search.PendingAncestryResult(['tip', 'tag'], None)
194
 
        result = result.refine({'tip'}, {'mid'})
195
 
        self.assertEqual({'mid', 'tag'}, result.heads)
196
 
        result = result.refine({'mid', 'tag', 'base'},
 
191
            {b"tip": [b"mid"], b"mid": [b"base"], b"tag": [b"base"],
 
192
             b"base":[NULL_REVISION], NULL_REVISION:[]})
 
193
        result = vf_search.PendingAncestryResult([b'tip', b'tag'], None)
 
194
        result = result.refine({b'tip'}, {b'mid'})
 
195
        self.assertEqual({b'mid', b'tag'}, result.heads)
 
196
        result = result.refine({b'mid', b'tag', b'base'},
197
197
            {NULL_REVISION})
198
198
        self.assertEqual({NULL_REVISION}, result.heads)
199
199
        self.assertTrue(result.is_empty())
236
236
        # ancestries.
237
237
        class StubGraph(object):
238
238
            def iter_ancestry(self, keys):
239
 
                return [(NULL_REVISION, ()), ('foo', (NULL_REVISION,))]
240
 
        result = vf_search.PendingAncestryResult(['rev-3'], None)
 
239
                return [(NULL_REVISION, ()), (b'foo', (NULL_REVISION,))]
 
240
        result = vf_search.PendingAncestryResult([b'rev-3'], None)
241
241
        result_keys = result._get_keys(StubGraph())
242
242
        # Only the non-null keys from the ancestry appear.
243
 
        self.assertEqual({'foo'}, set(result_keys))
 
243
        self.assertEqual({b'foo'}, set(result_keys))