242
260
class LowLevelKnitIndexTests(TestCase):
262
def get_knit_index(self, *args, **kwargs):
263
orig = knit._load_data
265
knit._load_data = orig
266
self.addCleanup(reset)
267
from bzrlib._knit_load_data_py import _load_data_py
268
knit._load_data = _load_data_py
269
return _KnitIndex(*args, **kwargs)
244
271
def test_no_such_file(self):
245
272
transport = MockTransport()
247
self.assertRaises(NoSuchFile, _KnitIndex, transport, "filename", "r")
248
self.assertRaises(NoSuchFile, _KnitIndex, transport,
249
"filename", "w", create=False)
274
self.assertRaises(NoSuchFile, self.get_knit_index,
275
transport, "filename", "r")
276
self.assertRaises(NoSuchFile, self.get_knit_index,
277
transport, "filename", "w", create=False)
251
279
def test_create_file(self):
252
280
transport = MockTransport()
254
index = _KnitIndex(transport, "filename", "w",
282
index = self.get_knit_index(transport, "filename", "w",
255
283
file_mode="wb", create=True)
256
284
self.assertEqual(
257
285
("put_bytes_non_atomic",
672
700
self.assertRaises(RevisionNotPresent, check, ["c"])
673
701
self.assertRaises(RevisionNotPresent, check, ["a", "b", "c"])
703
def test_impossible_parent(self):
704
"""Test we get KnitCorrupt if the parent couldn't possibly exist."""
705
transport = MockTransport([
708
"b option 0 1 4 :" # We don't have a 4th record
711
self.assertRaises(errors.KnitCorrupt,
712
self.get_knit_index, transport, 'filename', 'r')
714
if (str(e) == ('exceptions must be strings, classes, or instances,'
715
' not exceptions.IndexError')
716
and sys.version_info[0:2] >= (2,5)):
717
self.knownFailure('Pyrex <0.9.5 fails with TypeError when'
718
' raising new style exceptions with python'
723
def test_corrupted_parent(self):
724
transport = MockTransport([
728
"c option 0 1 1v :", # Can't have a parent of '1v'
731
self.assertRaises(errors.KnitCorrupt,
732
self.get_knit_index, transport, 'filename', 'r')
734
if (str(e) == ('exceptions must be strings, classes, or instances,'
735
' not exceptions.ValueError')
736
and sys.version_info[0:2] >= (2,5)):
737
self.knownFailure('Pyrex <0.9.5 fails with TypeError when'
738
' raising new style exceptions with python'
743
def test_corrupted_parent_in_list(self):
744
transport = MockTransport([
748
"c option 0 1 1 v :", # Can't have a parent of 'v'
751
self.assertRaises(errors.KnitCorrupt,
752
self.get_knit_index, transport, 'filename', 'r')
754
if (str(e) == ('exceptions must be strings, classes, or instances,'
755
' not exceptions.ValueError')
756
and sys.version_info[0:2] >= (2,5)):
757
self.knownFailure('Pyrex <0.9.5 fails with TypeError when'
758
' raising new style exceptions with python'
763
def test_invalid_position(self):
764
transport = MockTransport([
769
self.assertRaises(errors.KnitCorrupt,
770
self.get_knit_index, transport, 'filename', 'r')
772
if (str(e) == ('exceptions must be strings, classes, or instances,'
773
' not exceptions.ValueError')
774
and sys.version_info[0:2] >= (2,5)):
775
self.knownFailure('Pyrex <0.9.5 fails with TypeError when'
776
' raising new style exceptions with python'
781
def test_invalid_size(self):
782
transport = MockTransport([
787
self.assertRaises(errors.KnitCorrupt,
788
self.get_knit_index, transport, 'filename', 'r')
790
if (str(e) == ('exceptions must be strings, classes, or instances,'
791
' not exceptions.ValueError')
792
and sys.version_info[0:2] >= (2,5)):
793
self.knownFailure('Pyrex <0.9.5 fails with TypeError when'
794
' raising new style exceptions with python'
799
def test_short_line(self):
800
transport = MockTransport([
803
"b option 10 10 0", # This line isn't terminated, ignored
805
index = self.get_knit_index(transport, "filename", "r")
806
self.assertEqual(['a'], index.get_versions())
808
def test_skip_incomplete_record(self):
809
# A line with bogus data should just be skipped
810
transport = MockTransport([
813
"b option 10 10 0", # This line isn't terminated, ignored
814
"c option 20 10 0 :", # Properly terminated, and starts with '\n'
816
index = self.get_knit_index(transport, "filename", "r")
817
self.assertEqual(['a', 'c'], index.get_versions())
819
def test_trailing_characters(self):
820
# A line with bogus data should just be skipped
821
transport = MockTransport([
824
"b option 10 10 0 :a", # This line has extra trailing characters
825
"c option 20 10 0 :", # Properly terminated, and starts with '\n'
827
index = self.get_knit_index(transport, "filename", "r")
828
self.assertEqual(['a', 'c'], index.get_versions())
831
class LowLevelKnitIndexTests_c(LowLevelKnitIndexTests):
833
_test_needs_features = [CompiledKnitFeature]
835
def get_knit_index(self, *args, **kwargs):
836
orig = knit._load_data
838
knit._load_data = orig
839
self.addCleanup(reset)
840
from bzrlib._knit_load_data_c import _load_data_c
841
knit._load_data = _load_data_c
842
return _KnitIndex(*args, **kwargs)
676
846
class KnitTests(TestCaseWithTransport):
677
847
"""Class containing knit test helper routines."""