36
36
class KnitTests(TestCaseWithTransport):
37
37
"""Class containing knit test helper routines."""
39
def make_test_knit(self, annotate=False):
39
def make_test_knit(self, annotate=False, delay_create=False):
41
41
factory = KnitPlainFactory()
44
return KnitVersionedFile('test', get_transport('.'), access_mode='w', factory=factory, create=True)
44
return KnitVersionedFile('test', get_transport('.'), access_mode='w',
45
factory=factory, create=True,
46
delay_create=delay_create)
47
49
class BasicKnitTests(KnitTests):
342
345
self.assertEqual(['revid', 'revid2', 'revid3'], knit.versions())
343
346
self.assertEqual(['revid2'], knit.get_parents('revid3'))
348
def test_delay_create(self):
349
"""Test that passing delay_create=True creates files late"""
350
knit = self.make_test_knit(annotate=True, delay_create=True)
351
self.failIfExists('test.knit')
352
self.failIfExists('test.kndx')
353
knit.add_lines_with_ghosts('revid', ['a_ghost'], ['a\n'])
354
self.failUnlessExists('test.knit')
355
self.assertFileEqual(
356
"# bzr knit index 8\n"
358
"revid fulltext 0 84 .a_ghost :",
361
def test_create_parent_dir(self):
362
"""create_parent_dir can create knits in nonexistant dirs"""
363
# Has no effect if we don't set 'delay_create'
364
trans = get_transport('.')
365
self.assertRaises(NoSuchFile, KnitVersionedFile, 'dir/test',
366
trans, access_mode='w', factory=None,
367
create=True, create_parent_dir=True)
368
# Nothing should have changed yet
369
knit = KnitVersionedFile('dir/test', trans, access_mode='w',
370
factory=None, create=True,
371
create_parent_dir=True,
373
self.failIfExists('dir/test.knit')
374
self.failIfExists('dir/test.kndx')
375
self.failIfExists('dir')
376
knit.add_lines('revid', [], ['a\n'])
377
self.failUnlessExists('dir')
378
self.failUnlessExists('dir/test.knit')
379
self.assertFileEqual(
380
"# bzr knit index 8\n"
382
"revid fulltext 0 84 :",
385
def test_create_mode_700(self):
386
trans = get_transport('.')
387
if not trans._can_roundtrip_unix_modebits():
388
# Can't roundtrip, so no need to run this test
390
knit = KnitVersionedFile('dir/test', trans, access_mode='w',
391
factory=None, create=True,
392
create_parent_dir=True,
396
knit.add_lines('revid', [], ['a\n'])
397
self.assertTransportMode(trans, 'dir', 0700)
398
self.assertTransportMode(trans, 'dir/test.knit', 0600)
399
self.assertTransportMode(trans, 'dir/test.kndx', 0600)
401
def test_create_mode_770(self):
402
trans = get_transport('.')
403
if not trans._can_roundtrip_unix_modebits():
404
# Can't roundtrip, so no need to run this test
406
knit = KnitVersionedFile('dir/test', trans, access_mode='w',
407
factory=None, create=True,
408
create_parent_dir=True,
412
knit.add_lines('revid', [], ['a\n'])
413
self.assertTransportMode(trans, 'dir', 0770)
414
self.assertTransportMode(trans, 'dir/test.knit', 0660)
415
self.assertTransportMode(trans, 'dir/test.kndx', 0660)
417
def test_create_mode_777(self):
418
trans = get_transport('.')
419
if not trans._can_roundtrip_unix_modebits():
420
# Can't roundtrip, so no need to run this test
422
knit = KnitVersionedFile('dir/test', trans, access_mode='w',
423
factory=None, create=True,
424
create_parent_dir=True,
428
knit.add_lines('revid', [], ['a\n'])
429
self.assertTransportMode(trans, 'dir', 0777)
430
self.assertTransportMode(trans, 'dir/test.knit', 0666)
431
self.assertTransportMode(trans, 'dir/test.kndx', 0666)
345
433
def test_plan_merge(self):
346
434
my_knit = self.make_test_knit(annotate=True)
347
435
my_knit.add_lines('text1', [], split_lines(TEXT_1))