2031
2028
self.failIf(WeaveToKnit.is_compatible(k, k))
2034
class TestKnitCaching(KnitTests):
2036
def create_knit(self):
2037
k = self.make_test_knit(True)
2038
k.add_lines('text-1', [], split_lines(TEXT_1))
2039
k.add_lines('text-2', [], split_lines(TEXT_2))
2042
def test_no_caching(self):
2043
k = self.create_knit()
2044
# Nothing should be cached without setting 'enable_cache'
2045
self.assertEqual({}, k._data._cache)
2047
def test_cache_data_read_raw(self):
2048
k = self.create_knit()
2050
# Now cache and read
2053
def read_one_raw(version):
2054
pos_map = k._get_components_positions([version])
2055
method, index_memo, next = pos_map[version]
2056
lst = list(k._data.read_records_iter_raw([(version, index_memo)]))
2057
self.assertEqual(1, len(lst))
2060
val = read_one_raw('text-1')
2061
self.assertEqual({'text-1':val[1]}, k._data._cache)
2064
# After clear, new reads are not cached
2065
self.assertEqual({}, k._data._cache)
2067
val2 = read_one_raw('text-1')
2068
self.assertEqual(val, val2)
2069
self.assertEqual({}, k._data._cache)
2071
def test_cache_data_read(self):
2072
k = self.create_knit()
2074
def read_one(version):
2075
pos_map = k._get_components_positions([version])
2076
method, index_memo, next = pos_map[version]
2077
lst = list(k._data.read_records_iter([(version, index_memo)]))
2078
self.assertEqual(1, len(lst))
2081
# Now cache and read
2084
val = read_one('text-2')
2085
self.assertEqual(['text-2'], k._data._cache.keys())
2086
self.assertEqual('text-2', val[0])
2087
content, digest = k._data._parse_record('text-2',
2088
k._data._cache['text-2'])
2089
self.assertEqual(content, val[1])
2090
self.assertEqual(digest, val[2])
2093
self.assertEqual({}, k._data._cache)
2095
val2 = read_one('text-2')
2096
self.assertEqual(val, val2)
2097
self.assertEqual({}, k._data._cache)
2099
def test_cache_read(self):
2100
k = self.create_knit()
2103
text = k.get_text('text-1')
2104
self.assertEqual(TEXT_1, text)
2105
self.assertEqual(['text-1'], k._data._cache.keys())
2108
self.assertEqual({}, k._data._cache)
2110
text = k.get_text('text-1')
2111
self.assertEqual(TEXT_1, text)
2112
self.assertEqual({}, k._data._cache)
2115
2031
class TestKnitIndex(KnitTests):
2117
2033
def test_add_versions_dictionary_compresses(self):