35
class TestHashCache(InTempDir):
36
"""Functional tests for hashcache"""
35
class TestStatCache(InTempDir):
36
"""Functional tests for statcache"""
38
38
from bzrlib.hashcache import HashCache
42
# make a dummy bzr directory just to hold the cache
44
42
hc = HashCache('.')
46
44
file('foo', 'wb').write('hello')
77
75
file('foo', 'wb').write('g00dbye')
78
76
self.assertEquals(hc.get_sha1('foo'),
81
file('foo2', 'wb').write('other file')
82
self.assertEquals(hc.get_sha1('foo2'), sha1('other file'))
85
self.assertEquals(hc.get_sha1('foo2'), None)
87
file('foo2', 'wb').write('new content')
88
self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))
79
# this is not quite guaranteed to be true; we might have
80
# crossed a 1s boundary before
81
self.assertEquals(hc.danger_count, 1)
90
83
self.assertEquals(hc.get_sha1('subdir'), None)
92
# it's likely neither are cached at the moment because they
93
# changed recently, but we can't be sure
96
# should now be safe to cache it if we reread them
97
self.assertEquals(hc.get_sha1('foo'), sha1('g00dbye'))
98
self.assertEquals(len(hc._cache), 1)
99
self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))
100
self.assertEquals(len(hc._cache), 2)
102
# write out, read back in and check that we don't need to
110
self.assertEquals(len(hc._cache), 2)
111
self.assertEquals(hc.get_sha1('foo'), sha1('g00dbye'))
112
self.assertEquals(hc.hit_count, 1)
113
self.assertEquals(hc.miss_count, 0)
114
self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))