241
259
class LowLevelKnitIndexTests(TestCase):
261
def get_knit_index(self, *args, **kwargs):
262
orig = knit._load_data
264
knit._load_data = orig
265
self.addCleanup(reset)
266
from bzrlib._knit_load_data_py import _load_data_py
267
knit._load_data = _load_data_py
268
return _KnitIndex(*args, **kwargs)
243
270
def test_no_such_file(self):
244
271
transport = MockTransport()
246
self.assertRaises(NoSuchFile, _KnitIndex, transport, "filename", "r")
247
self.assertRaises(NoSuchFile, _KnitIndex, transport,
248
"filename", "w", create=False)
273
self.assertRaises(NoSuchFile, self.get_knit_index,
274
transport, "filename", "r")
275
self.assertRaises(NoSuchFile, self.get_knit_index,
276
transport, "filename", "w", create=False)
250
278
def test_create_file(self):
251
279
transport = MockTransport()
253
index = _KnitIndex(transport, "filename", "w",
281
index = self.get_knit_index(transport, "filename", "w",
254
282
file_mode="wb", create=True)
255
283
self.assertEqual(
256
284
("put_bytes_non_atomic",
671
699
self.assertRaises(RevisionNotPresent, check, ["c"])
672
700
self.assertRaises(RevisionNotPresent, check, ["a", "b", "c"])
702
def test_impossible_parent(self):
703
"""Test we get KnitCorrupt if the parent couldn't possibly exist."""
704
transport = MockTransport([
707
"b option 0 1 4 :" # We don't have a 4th record
710
self.assertRaises(errors.KnitCorrupt,
711
self.get_knit_index, transport, 'filename', 'r')
713
if (str(e) == ('exceptions must be strings, classes, or instances,'
714
' not exceptions.IndexError')
715
and sys.version_info[0:2] >= (2,5)):
716
self.knownFailure('Pyrex <0.9.5 fails with TypeError when'
717
' raising new style exceptions with python'
722
def test_corrupted_parent(self):
723
transport = MockTransport([
727
"c option 0 1 1v :", # Can't have a parent of '1v'
730
self.assertRaises(errors.KnitCorrupt,
731
self.get_knit_index, transport, 'filename', 'r')
733
if (str(e) == ('exceptions must be strings, classes, or instances,'
734
' not exceptions.ValueError')
735
and sys.version_info[0:2] >= (2,5)):
736
self.knownFailure('Pyrex <0.9.5 fails with TypeError when'
737
' raising new style exceptions with python'
742
def test_corrupted_parent_in_list(self):
743
transport = MockTransport([
747
"c option 0 1 1 v :", # Can't have a parent of 'v'
750
self.assertRaises(errors.KnitCorrupt,
751
self.get_knit_index, transport, 'filename', 'r')
753
if (str(e) == ('exceptions must be strings, classes, or instances,'
754
' not exceptions.ValueError')
755
and sys.version_info[0:2] >= (2,5)):
756
self.knownFailure('Pyrex <0.9.5 fails with TypeError when'
757
' raising new style exceptions with python'
762
def test_invalid_position(self):
763
transport = MockTransport([
768
self.assertRaises(errors.KnitCorrupt,
769
self.get_knit_index, transport, 'filename', 'r')
771
if (str(e) == ('exceptions must be strings, classes, or instances,'
772
' not exceptions.ValueError')
773
and sys.version_info[0:2] >= (2,5)):
774
self.knownFailure('Pyrex <0.9.5 fails with TypeError when'
775
' raising new style exceptions with python'
780
def test_invalid_size(self):
781
transport = MockTransport([
786
self.assertRaises(errors.KnitCorrupt,
787
self.get_knit_index, transport, 'filename', 'r')
789
if (str(e) == ('exceptions must be strings, classes, or instances,'
790
' not exceptions.ValueError')
791
and sys.version_info[0:2] >= (2,5)):
792
self.knownFailure('Pyrex <0.9.5 fails with TypeError when'
793
' raising new style exceptions with python'
798
def test_short_line(self):
799
transport = MockTransport([
802
"b option 10 10 0", # This line isn't terminated, ignored
804
index = self.get_knit_index(transport, "filename", "r")
805
self.assertEqual(['a'], index.get_versions())
807
def test_skip_incomplete_record(self):
808
# A line with bogus data should just be skipped
809
transport = MockTransport([
812
"b option 10 10 0", # This line isn't terminated, ignored
813
"c option 20 10 0 :", # Properly terminated, and starts with '\n'
815
index = self.get_knit_index(transport, "filename", "r")
816
self.assertEqual(['a', 'c'], index.get_versions())
818
def test_trailing_characters(self):
819
# A line with bogus data should just be skipped
820
transport = MockTransport([
823
"b option 10 10 0 :a", # This line has extra trailing characters
824
"c option 20 10 0 :", # Properly terminated, and starts with '\n'
826
index = self.get_knit_index(transport, "filename", "r")
827
self.assertEqual(['a', 'c'], index.get_versions())
830
class LowLevelKnitIndexTests_c(LowLevelKnitIndexTests):
832
_test_needs_features = [CompiledKnitFeature]
834
def get_knit_index(self, *args, **kwargs):
835
orig = knit._load_data
837
knit._load_data = orig
838
self.addCleanup(reset)
839
from bzrlib._knit_load_data_c import _load_data_c
840
knit._load_data = _load_data_c
841
return _KnitIndex(*args, **kwargs)
675
845
class KnitTests(TestCaseWithTransport):
676
846
"""Class containing knit test helper routines."""