156
156
transport.calls.pop(0))
158
158
def test_read_utf8_version_id(self):
159
unicode_revision_id = u"version-\N{CYRILLIC CAPITAL LETTER A}"
160
utf8_revision_id = unicode_revision_id.encode('utf-8')
159
161
transport = MockTransport([
160
162
_KnitIndex.HEADER,
161
u"version-\N{CYRILLIC CAPITAL LETTER A}"
162
u" option 0 1 :".encode("utf-8")
163
'%s option 0 1 :' % (utf8_revision_id,)
164
165
index = _KnitIndex(transport, "filename", "r")
166
index.has_version(u"version-\N{CYRILLIC CAPITAL LETTER A}"))
166
# _KnitIndex is a private class, and deals in utf8 revision_ids, not
167
# Unicode revision_ids.
168
self.assertTrue(index.has_version(utf8_revision_id))
169
self.assertFalse(index.has_version(unicode_revision_id))
168
171
def test_read_utf8_parents(self):
172
unicode_revision_id = u"version-\N{CYRILLIC CAPITAL LETTER A}"
173
utf8_revision_id = unicode_revision_id.encode('utf-8')
169
174
transport = MockTransport([
170
175
_KnitIndex.HEADER,
171
u"version option 0 1"
172
u" .version-\N{CYRILLIC CAPITAL LETTER A} :".encode("utf-8")
176
"version option 0 1 .%s :" % (utf8_revision_id,)
174
178
index = _KnitIndex(transport, "filename", "r")
175
self.assertEqual([u"version-\N{CYRILLIC CAPITAL LETTER A}"],
179
self.assertEqual([utf8_revision_id],
176
180
index.get_parents_with_ghosts("version"))
178
182
def test_read_ignore_corrupted_lines(self):
202
206
index = _KnitIndex(transport, "filename", "r")
203
207
self.assertEqual(2, index.num_versions())
204
self.assertEqual(1, index.lookup(u"version"))
205
self.assertEqual((3, 4), index.get_position(u"version"))
206
self.assertEqual(["options3"], index.get_options(u"version"))
207
self.assertEqual([u"parent", u"other"],
208
index.get_parents_with_ghosts(u"version"))
208
self.assertEqual(1, index.lookup("version"))
209
self.assertEqual((3, 4), index.get_position("version"))
210
self.assertEqual(["options3"], index.get_options("version"))
211
self.assertEqual(["parent", "other"],
212
index.get_parents_with_ghosts("version"))
210
214
def test_read_compressed_parents(self):
211
215
transport = MockTransport([
215
219
"c option 0 1 1 0 :",
217
221
index = _KnitIndex(transport, "filename", "r")
218
self.assertEqual([u"a"], index.get_parents(u"b"))
219
self.assertEqual([u"b", u"a"], index.get_parents(u"c"))
222
self.assertEqual(["a"], index.get_parents("b"))
223
self.assertEqual(["b", "a"], index.get_parents("c"))
221
225
def test_write_utf8_version_id(self):
226
unicode_revision_id = u"version-\N{CYRILLIC CAPITAL LETTER A}"
227
utf8_revision_id = unicode_revision_id.encode('utf-8')
222
228
transport = MockTransport([
223
229
_KnitIndex.HEADER
225
231
index = _KnitIndex(transport, "filename", "r")
226
index.add_version(u"version-\N{CYRILLIC CAPITAL LETTER A}",
227
["option"], 0, 1, [])
232
index.add_version(utf8_revision_id, ["option"], 0, 1, [])
228
233
self.assertEqual(("append_bytes", ("filename",
229
u"\nversion-\N{CYRILLIC CAPITAL LETTER A}"
230
u" option 0 1 :".encode("utf-8")),
234
"\n%s option 0 1 :" % (utf8_revision_id,)),
232
236
transport.calls.pop(0))
234
238
def test_write_utf8_parents(self):
239
unicode_revision_id = u"version-\N{CYRILLIC CAPITAL LETTER A}"
240
utf8_revision_id = unicode_revision_id.encode('utf-8')
235
241
transport = MockTransport([
236
242
_KnitIndex.HEADER
238
244
index = _KnitIndex(transport, "filename", "r")
239
index.add_version(u"version", ["option"], 0, 1,
240
[u"version-\N{CYRILLIC CAPITAL LETTER A}"])
245
index.add_version("version", ["option"], 0, 1, [utf8_revision_id])
241
246
self.assertEqual(("append_bytes", ("filename",
242
u"\nversion option 0 1"
243
u" .version-\N{CYRILLIC CAPITAL LETTER A} :".encode("utf-8")),
247
"\nversion option 0 1 .%s :" % (utf8_revision_id,)),
245
249
transport.calls.pop(0))
249
253
index = _KnitIndex(transport, "filename", "w", create=True)
250
254
self.assertEqual([], index.get_graph())
252
index.add_version(u"a", ["option"], 0, 1, [u"b"])
253
self.assertEqual([(u"a", [u"b"])], index.get_graph())
256
index.add_version("a", ["option"], 0, 1, ["b"])
257
self.assertEqual([("a", ["b"])], index.get_graph())
255
index.add_version(u"c", ["option"], 0, 1, [u"d"])
256
self.assertEqual([(u"a", [u"b"]), (u"c", [u"d"])],
259
index.add_version("c", ["option"], 0, 1, ["d"])
260
self.assertEqual([("a", ["b"]), ("c", ["d"])],
257
261
sorted(index.get_graph()))
259
263
def test_get_ancestry(self):
267
271
index = _KnitIndex(transport, "filename", "r")
269
273
self.assertEqual([], index.get_ancestry([]))
270
self.assertEqual([u"a"], index.get_ancestry([u"a"]))
271
self.assertEqual([u"a", u"b"], index.get_ancestry([u"b"]))
272
self.assertEqual([u"a", u"b", u"c"], index.get_ancestry([u"c"]))
273
self.assertEqual([u"a", u"b", u"c", u"d"], index.get_ancestry([u"d"]))
274
self.assertEqual([u"a", u"b"], index.get_ancestry([u"a", u"b"]))
275
self.assertEqual([u"a", u"b", u"c"], index.get_ancestry([u"a", u"c"]))
274
self.assertEqual(["a"], index.get_ancestry(["a"]))
275
self.assertEqual(["a", "b"], index.get_ancestry(["b"]))
276
self.assertEqual(["a", "b", "c"], index.get_ancestry(["c"]))
277
self.assertEqual(["a", "b", "c", "d"], index.get_ancestry(["d"]))
278
self.assertEqual(["a", "b"], index.get_ancestry(["a", "b"]))
279
self.assertEqual(["a", "b", "c"], index.get_ancestry(["a", "c"]))
277
self.assertRaises(RevisionNotPresent, index.get_ancestry, [u"e"])
281
self.assertRaises(RevisionNotPresent, index.get_ancestry, ["e"])
279
283
def test_get_ancestry_with_ghosts(self):
280
284
transport = MockTransport([
287
291
index = _KnitIndex(transport, "filename", "r")
289
293
self.assertEqual([], index.get_ancestry_with_ghosts([]))
290
self.assertEqual([u"a"], index.get_ancestry_with_ghosts([u"a"]))
291
self.assertEqual([u"a", u"e", u"b"],
292
index.get_ancestry_with_ghosts([u"b"]))
293
self.assertEqual([u"a", u"g", u"f", u"c"],
294
index.get_ancestry_with_ghosts([u"c"]))
295
self.assertEqual([u"a", u"g", u"f", u"c", u"k", u"j", u"h", u"d"],
296
index.get_ancestry_with_ghosts([u"d"]))
297
self.assertEqual([u"a", u"e", u"b"],
298
index.get_ancestry_with_ghosts([u"a", u"b"]))
299
self.assertEqual([u"a", u"g", u"f", u"c"],
300
index.get_ancestry_with_ghosts([u"a", u"c"]))
294
self.assertEqual(["a"], index.get_ancestry_with_ghosts(["a"]))
295
self.assertEqual(["a", "e", "b"],
296
index.get_ancestry_with_ghosts(["b"]))
297
self.assertEqual(["a", "g", "f", "c"],
298
index.get_ancestry_with_ghosts(["c"]))
299
self.assertEqual(["a", "g", "f", "c", "k", "j", "h", "d"],
300
index.get_ancestry_with_ghosts(["d"]))
301
self.assertEqual(["a", "e", "b"],
302
index.get_ancestry_with_ghosts(["a", "b"]))
303
self.assertEqual(["a", "g", "f", "c"],
304
index.get_ancestry_with_ghosts(["a", "c"]))
301
305
self.assertEqual(
302
[u"a", u"g", u"f", u"c", u"e", u"b", u"k", u"j", u"h", u"d"],
303
index.get_ancestry_with_ghosts([u"b", u"d"]))
306
["a", "g", "f", "c", "e", "b", "k", "j", "h", "d"],
307
index.get_ancestry_with_ghosts(["b", "d"]))
305
309
self.assertRaises(RevisionNotPresent,
306
index.get_ancestry_with_ghosts, [u"e"])
310
index.get_ancestry_with_ghosts, ["e"])
308
312
def test_num_versions(self):
309
313
transport = MockTransport([
314
318
self.assertEqual(0, index.num_versions())
315
319
self.assertEqual(0, len(index))
317
index.add_version(u"a", ["option"], 0, 1, [])
318
self.assertEqual(1, index.num_versions())
319
self.assertEqual(1, len(index))
321
index.add_version(u"a", ["option2"], 1, 2, [])
322
self.assertEqual(1, index.num_versions())
323
self.assertEqual(1, len(index))
325
index.add_version(u"b", ["option"], 0, 1, [])
321
index.add_version("a", ["option"], 0, 1, [])
322
self.assertEqual(1, index.num_versions())
323
self.assertEqual(1, len(index))
325
index.add_version("a", ["option2"], 1, 2, [])
326
self.assertEqual(1, index.num_versions())
327
self.assertEqual(1, len(index))
329
index.add_version("b", ["option"], 0, 1, [])
326
330
self.assertEqual(2, index.num_versions())
327
331
self.assertEqual(2, len(index))
335
339
self.assertEqual([], index.get_versions())
337
index.add_version(u"a", ["option"], 0, 1, [])
338
self.assertEqual([u"a"], index.get_versions())
340
index.add_version(u"a", ["option"], 0, 1, [])
341
self.assertEqual([u"a"], index.get_versions())
343
index.add_version(u"b", ["option"], 0, 1, [])
344
self.assertEqual([u"a", u"b"], index.get_versions())
341
index.add_version("a", ["option"], 0, 1, [])
342
self.assertEqual(["a"], index.get_versions())
344
index.add_version("a", ["option"], 0, 1, [])
345
self.assertEqual(["a"], index.get_versions())
347
index.add_version("b", ["option"], 0, 1, [])
348
self.assertEqual(["a", "b"], index.get_versions())
346
350
def test_idx_to_name(self):
347
351
transport = MockTransport([
352
356
index = _KnitIndex(transport, "filename", "r")
354
self.assertEqual(u"a", index.idx_to_name(0))
355
self.assertEqual(u"b", index.idx_to_name(1))
356
self.assertEqual(u"b", index.idx_to_name(-1))
357
self.assertEqual(u"a", index.idx_to_name(-2))
358
self.assertEqual("a", index.idx_to_name(0))
359
self.assertEqual("b", index.idx_to_name(1))
360
self.assertEqual("b", index.idx_to_name(-1))
361
self.assertEqual("a", index.idx_to_name(-2))
359
363
def test_lookup(self):
360
364
transport = MockTransport([
374
378
index = _KnitIndex(transport, "filename", "r")
376
index.add_version(u"a", ["option"], 0, 1, [u"b"])
380
index.add_version("a", ["option"], 0, 1, ["b"])
377
381
self.assertEqual(("append_bytes",
378
382
("filename", "\na option 0 1 .b :"),
379
383
{}), transport.calls.pop(0))
380
self.assertTrue(index.has_version(u"a"))
384
self.assertTrue(index.has_version("a"))
381
385
self.assertEqual(1, index.num_versions())
382
self.assertEqual((0, 1), index.get_position(u"a"))
383
self.assertEqual(["option"], index.get_options(u"a"))
384
self.assertEqual([u"b"], index.get_parents_with_ghosts(u"a"))
386
self.assertEqual((0, 1), index.get_position("a"))
387
self.assertEqual(["option"], index.get_options("a"))
388
self.assertEqual(["b"], index.get_parents_with_ghosts("a"))
386
index.add_version(u"a", ["opt"], 1, 2, [u"c"])
390
index.add_version("a", ["opt"], 1, 2, ["c"])
387
391
self.assertEqual(("append_bytes",
388
392
("filename", "\na opt 1 2 .c :"),
389
393
{}), transport.calls.pop(0))
390
self.assertTrue(index.has_version(u"a"))
394
self.assertTrue(index.has_version("a"))
391
395
self.assertEqual(1, index.num_versions())
392
self.assertEqual((1, 2), index.get_position(u"a"))
393
self.assertEqual(["opt"], index.get_options(u"a"))
394
self.assertEqual([u"c"], index.get_parents_with_ghosts(u"a"))
396
self.assertEqual((1, 2), index.get_position("a"))
397
self.assertEqual(["opt"], index.get_options("a"))
398
self.assertEqual(["c"], index.get_parents_with_ghosts("a"))
396
index.add_version(u"b", ["option"], 2, 3, [u"a"])
400
index.add_version("b", ["option"], 2, 3, ["a"])
397
401
self.assertEqual(("append_bytes",
398
402
("filename", "\nb option 2 3 0 :"),
399
403
{}), transport.calls.pop(0))
400
self.assertTrue(index.has_version(u"b"))
404
self.assertTrue(index.has_version("b"))
401
405
self.assertEqual(2, index.num_versions())
402
self.assertEqual((2, 3), index.get_position(u"b"))
403
self.assertEqual(["option"], index.get_options(u"b"))
404
self.assertEqual([u"a"], index.get_parents_with_ghosts(u"b"))
406
self.assertEqual((2, 3), index.get_position("b"))
407
self.assertEqual(["option"], index.get_options("b"))
408
self.assertEqual(["a"], index.get_parents_with_ghosts("b"))
406
410
def test_add_versions(self):
407
411
transport = MockTransport([
410
414
index = _KnitIndex(transport, "filename", "r")
412
416
index.add_versions([
413
(u"a", ["option"], 0, 1, [u"b"]),
414
(u"a", ["opt"], 1, 2, [u"c"]),
415
(u"b", ["option"], 2, 3, [u"a"])
417
("a", ["option"], 0, 1, ["b"]),
418
("a", ["opt"], 1, 2, ["c"]),
419
("b", ["option"], 2, 3, ["a"])
417
421
self.assertEqual(("append_bytes", ("filename",
418
422
"\na option 0 1 .b :"
419
423
"\na opt 1 2 .c :"
420
424
"\nb option 2 3 0 :"
421
425
), {}), transport.calls.pop(0))
422
self.assertTrue(index.has_version(u"a"))
423
self.assertTrue(index.has_version(u"b"))
426
self.assertTrue(index.has_version("a"))
427
self.assertTrue(index.has_version("b"))
424
428
self.assertEqual(2, index.num_versions())
425
self.assertEqual((1, 2), index.get_position(u"a"))
426
self.assertEqual((2, 3), index.get_position(u"b"))
427
self.assertEqual(["opt"], index.get_options(u"a"))
428
self.assertEqual(["option"], index.get_options(u"b"))
429
self.assertEqual([u"c"], index.get_parents_with_ghosts(u"a"))
430
self.assertEqual([u"a"], index.get_parents_with_ghosts(u"b"))
429
self.assertEqual((1, 2), index.get_position("a"))
430
self.assertEqual((2, 3), index.get_position("b"))
431
self.assertEqual(["opt"], index.get_options("a"))
432
self.assertEqual(["option"], index.get_options("b"))
433
self.assertEqual(["c"], index.get_parents_with_ghosts("a"))
434
self.assertEqual(["a"], index.get_parents_with_ghosts("b"))
432
436
def test_delay_create_and_add_versions(self):
433
437
transport = MockTransport()
438
442
self.assertEqual([], transport.calls)
440
444
index.add_versions([
441
(u"a", ["option"], 0, 1, [u"b"]),
442
(u"a", ["opt"], 1, 2, [u"c"]),
443
(u"b", ["option"], 2, 3, [u"a"])
445
("a", ["option"], 0, 1, ["b"]),
446
("a", ["opt"], 1, 2, ["c"]),
447
("b", ["option"], 2, 3, ["a"])
445
449
name, (filename, f), kwargs = transport.calls.pop(0)
446
450
self.assertEqual("put_file_non_atomic", name)
486
490
index = _KnitIndex(transport, "filename", "r")
488
self.assertEqual("fulltext", index.get_method(u"a"))
489
self.assertEqual("line-delta", index.get_method(u"b"))
490
self.assertRaises(errors.KnitIndexUnknownMethod, index.get_method, u"c")
492
self.assertEqual("fulltext", index.get_method("a"))
493
self.assertEqual("line-delta", index.get_method("b"))
494
self.assertRaises(errors.KnitIndexUnknownMethod, index.get_method, "c")
492
496
def test_get_options(self):
493
497
transport = MockTransport([
510
514
index = _KnitIndex(transport, "filename", "r")
512
self.assertEqual([], index.get_parents(u"a"))
513
self.assertEqual([u"a", u"c"], index.get_parents(u"b"))
514
self.assertEqual([u"b", u"a"], index.get_parents(u"c"))
516
self.assertEqual([], index.get_parents("a"))
517
self.assertEqual(["a", "c"], index.get_parents("b"))
518
self.assertEqual(["b", "a"], index.get_parents("c"))
516
520
def test_get_parents_with_ghosts(self):
517
521
transport = MockTransport([
523
527
index = _KnitIndex(transport, "filename", "r")
525
self.assertEqual([], index.get_parents_with_ghosts(u"a"))
526
self.assertEqual([u"a", u"c"], index.get_parents_with_ghosts(u"b"))
527
self.assertEqual([u"b", u"a", u"e"],
528
index.get_parents_with_ghosts(u"c"))
529
self.assertEqual([], index.get_parents_with_ghosts("a"))
530
self.assertEqual(["a", "c"], index.get_parents_with_ghosts("b"))
531
self.assertEqual(["b", "a", "e"],
532
index.get_parents_with_ghosts("c"))
530
534
def test_check_versions_present(self):
531
535
transport = MockTransport([
538
542
check = index.check_versions_present
544
self.assertRaises(RevisionNotPresent, check, [u"c"])
545
self.assertRaises(RevisionNotPresent, check, [u"a", u"b", u"c"])
548
self.assertRaises(RevisionNotPresent, check, ["c"])
549
self.assertRaises(RevisionNotPresent, check, ["a", "b", "c"])
548
552
class KnitTests(TestCaseWithTransport):