1
"""Tests for the FileChangeCache in loggerhead.changecache."""
6
from loggerhead.changecache import FileChangeCache
9
def __init__(self, revid):
15
self.fetched_revids = set()
16
def get_file_changes_uncached(self, entries):
19
self.fetched_revids.add(entry.revid)
20
output.append(entry.revid)
24
class TestFileChangeCache(object):
26
# setup_method and teardown_method are so i can run the tests with
27
# py.test and take advantage of the error reporting.
28
def setup_method(self, meth):
31
def teardown_method(self, meth):
35
self.cache_folders = []
38
for folder in self.cache_folders:
42
def makeHistoryAndEntriesForRevids(self, revids, fill_cache_with=[]):
43
cache_folder = tempfile.mkdtemp()
44
self.cache_folders.append(cache_folder)
45
self.history = MockHistory()
46
self.cache = FileChangeCache(self.history, cache_folder)
48
self.entries = [MockEntry(revid) for revid in revids]
50
self.cache.get_file_changes([entry for entry in self.entries
51
if entry.revid in fill_cache_with])
52
self.history.fetched_revids.clear()
55
def test_empty_cache(self):
56
"""An empty cache passes all the revids through to the history object.
59
self.makeHistoryAndEntriesForRevids(revids)
61
result = self.cache.get_file_changes(self.entries)
63
assert result == revids
64
assert self.history.fetched_revids == set(revids)
66
def test_full_cache(self):
67
"""A full cache passes none of the revids through to the history
71
self.makeHistoryAndEntriesForRevids(revids, fill_cache_with=revids)
73
result = self.cache.get_file_changes(self.entries)
75
assert result == revids
76
assert self.history.fetched_revids == set()
78
def test_partial_cache(self):
79
"""A partially full cache passes some of the revids through to the
80
history object, and preserves the ordering of the argument list.
82
# To test the preservation of argument order code, we put the uncached
83
# revid at the beginning, middle and then end of the list of revids
86
cached_revids = ['a', 'b']
87
revids = cached_revids[:]
88
revids.insert(i, 'uncached')
89
self.makeHistoryAndEntriesForRevids(
90
revids, fill_cache_with=cached_revids)
92
result = self.cache.get_file_changes(self.entries)
93
assert result == revids
95
assert self.history.fetched_revids == set(['uncached'])