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

Merge test-run support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
    def test_lookup_no_keys_no_calls(self):
26
26
        calls = []
27
 
 
28
27
        def missing_content(location_keys):
29
28
            calls.append(location_keys)
30
29
            return ((location_key, False) for location_key in location_keys)
31
30
        self.assertEqual([],
32
 
                         list(bisect_multi_bytes(missing_content, 100, [])))
 
31
            list(bisect_multi_bytes(missing_content, 100, [])))
33
32
        self.assertEqual([], calls)
34
33
 
35
34
    def test_lookup_missing_key_no_content(self):
40
39
        for a given location, key pair.
41
40
        """
42
41
        calls = []
43
 
 
44
42
        def missing_content(location_keys):
45
43
            calls.append(location_keys)
46
44
            return ((location_key, False) for location_key in location_keys)
47
45
        self.assertEqual([],
48
 
                         list(bisect_multi_bytes(missing_content, 0, ['foo', 'bar'])))
 
46
            list(bisect_multi_bytes(missing_content, 0, ['foo', 'bar'])))
49
47
        self.assertEqual([[(0, 'foo'), (0, 'bar')]], calls)
50
48
 
51
49
    def test_lookup_missing_key_before_all_others(self):
52
50
        calls = []
53
 
 
54
51
        def missing_first_content(location_keys):
55
52
            # returns -1 for all keys unless the byte offset is 0 when it
56
53
            # returns False
64
61
            return result
65
62
        # given a 0 length file, this should terminate with one call.
66
63
        self.assertEqual([],
67
 
                         list(bisect_multi_bytes(missing_first_content, 0, ['foo', 'bar'])))
 
64
            list(bisect_multi_bytes(missing_first_content, 0, ['foo', 'bar'])))
68
65
        self.assertEqual([[(0, 'foo'), (0, 'bar')]], calls)
69
66
        del calls[:]
70
67
        # given a 2 length file, this should make two calls - 1, 0.
71
68
        self.assertEqual([],
72
 
                         list(bisect_multi_bytes(missing_first_content, 2, ['foo', 'bar'])))
 
69
            list(bisect_multi_bytes(missing_first_content, 2, ['foo', 'bar'])))
73
70
        self.assertEqual([
74
71
            [(1, 'foo'), (1, 'bar')],
75
72
            [(0, 'foo'), (0, 'bar')],
86
83
        # 800 thousand keys, and log2 of 800000 is 19 - so we're doing log2
87
84
        # steps in the worst case there.
88
85
        self.assertEqual([],
89
 
                         list(bisect_multi_bytes(
90
 
                             missing_first_content, 268435456 - 1, ['foo', 'bar'])))
 
86
            list(bisect_multi_bytes(
 
87
                missing_first_content, 268435456 - 1, ['foo', 'bar'])))
91
88
        self.assertEqual([
92
89
            [(134217727, 'foo'), (134217727, 'bar')],
93
90
            [(67108864, 'foo'), (67108864, 'bar')],
148
145
    def test_lookup_missing_key_after_all_others(self):
149
146
        calls = []
150
147
        end = None
151
 
 
152
148
        def missing_last_content(location_keys):
153
149
            # returns +1 for all keys unless the byte offset is 'end' when it
154
150
            # returns False
163
159
        # given a 0 length file, this should terminate with one call.
164
160
        end = 0
165
161
        self.assertEqual([],
166
 
                         list(bisect_multi_bytes(missing_last_content, 0, ['foo', 'bar'])))
 
162
            list(bisect_multi_bytes(missing_last_content, 0, ['foo', 'bar'])))
167
163
        self.assertEqual([[(0, 'foo'), (0, 'bar')]], calls)
168
164
        del calls[:]
169
165
        end = 2
170
166
        # given a 3 length file, this should make two calls - 1, 2.
171
167
        self.assertEqual([],
172
 
                         list(bisect_multi_bytes(missing_last_content, 3, ['foo', 'bar'])))
 
168
            list(bisect_multi_bytes(missing_last_content, 3, ['foo', 'bar'])))
173
169
        self.assertEqual([
174
170
            [(1, 'foo'), (1, 'bar')],
175
171
            [(2, 'foo'), (2, 'bar')],
180
176
        # test_lookup_missing_key_before_all_others for details about this
181
177
        # assertion.
182
178
        self.assertEqual([],
183
 
                         list(bisect_multi_bytes(
184
 
                             missing_last_content, 268435456 - 1, ['foo', 'bar'])))
 
179
            list(bisect_multi_bytes(
 
180
                missing_last_content, 268435456 - 1, ['foo', 'bar'])))
185
181
        self.assertEqual([
186
182
            [(134217727, 'foo'), (134217727, 'bar')],
187
183
            [(201326590, 'foo'), (201326590, 'bar')],
241
237
 
242
238
    def test_lookup_when_a_key_is_missing_continues(self):
243
239
        calls = []
244
 
 
245
240
        def missing_foo_otherwise_missing_first_content(location_keys):
246
241
            # returns -1 for all keys unless the byte offset is 0 when it
247
242
            # returns False
256
251
        # given a 2 length file, this should terminate with two calls, one for
257
252
        # both keys, and one for bar only.
258
253
        self.assertEqual([],
259
 
                         list(bisect_multi_bytes(
260
 
                             missing_foo_otherwise_missing_first_content, 2,
261
 
                             ['foo', 'bar'])))
 
254
            list(bisect_multi_bytes(
 
255
                missing_foo_otherwise_missing_first_content, 2,
 
256
                ['foo', 'bar'])))
262
257
        self.assertEqual([
263
258
            [(1, 'foo'), (1, 'bar')],
264
259
            [(0, 'bar')],
266
261
 
267
262
    def test_found_keys_returned_other_searches_continue(self):
268
263
        calls = []
269
 
 
270
264
        def find_bar_at_1_foo_missing_at_0(location_keys):
271
265
            calls.append(location_keys)
272
266
            result = []
281
275
        # given a 4 length file, this should terminate with three calls, two for
282
276
        # both keys, and one for foo only.
283
277
        self.assertEqual([('bar', 'bar-result')],
284
 
                         list(bisect_multi_bytes(
285
 
                             find_bar_at_1_foo_missing_at_0, 4,
286
 
                             ['foo', 'bar'])))
 
278
            list(bisect_multi_bytes(
 
279
                find_bar_at_1_foo_missing_at_0, 4,
 
280
                ['foo', 'bar'])))
287
281
        self.assertEqual([
288
282
            [(2, 'foo'), (2, 'bar')],
289
283
            [(1, 'foo'), (1, 'bar')],
292
286
 
293
287
    def test_searches_different_keys_in_different_directions(self):
294
288
        calls = []
295
 
 
296
289
        def missing_bar_at_1_foo_at_3(location_keys):
297
290
            calls.append(location_keys)
298
291
            result = []
312
305
            return result
313
306
        # given a 4 length file, this should terminate with two calls.
314
307
        self.assertEqual([],
315
 
                         list(bisect_multi_bytes(
316
 
                             missing_bar_at_1_foo_at_3, 4,
317
 
                             ['foo', 'bar'])))
 
308
            list(bisect_multi_bytes(
 
309
                missing_bar_at_1_foo_at_3, 4,
 
310
                ['foo', 'bar'])))
318
311
        self.assertEqual([
319
312
            [(2, 'foo'), (2, 'bar')],
320
313
            [(3, 'foo'), (1, 'bar')],
324
317
        # check that we can search down, up, down again -
325
318
        # so length 8, goes 4, 6, 5
326
319
        calls = []
327
 
 
328
320
        def missing_at_5(location_keys):
329
321
            calls.append(location_keys)
330
322
            result = []
340
332
            return result
341
333
        # given a 8 length file, this should terminate with three calls.
342
334
        self.assertEqual([],
343
 
                         list(bisect_multi_bytes(
344
 
                             missing_at_5, 8,
345
 
                             ['foo', 'bar'])))
 
335
            list(bisect_multi_bytes(
 
336
                missing_at_5, 8,
 
337
                ['foo', 'bar'])))
346
338
        self.assertEqual([
347
339
            [(4, 'foo'), (4, 'bar')],
348
340
            [(6, 'foo'), (6, 'bar')],
349
341
            [(5, 'foo'), (5, 'bar')],
350
342
            ], calls)
 
343