75
75
file('foo', 'wb').write('g00dbye')
76
76
self.assertEquals(hc.get_sha1('foo'),
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)
82
self.assertEquals(len(hc._cache), 0)
79
file('foo2', 'wb').write('other file')
80
self.assertEquals(hc.get_sha1('foo2'), sha1('other file'))
83
self.assertEquals(hc.get_sha1('foo2'), None)
85
file('foo2', 'wb').write('new content')
86
self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))
84
88
self.assertEquals(hc.get_sha1('subdir'), None)
90
# it's likely neither are cached at the moment because they
91
# changed recently, but we can't be sure
88
# should now be safe to cache it
89
self.assertEquals(hc.get_sha1('foo'),
94
# should now be safe to cache it if we reread them
95
self.assertEquals(hc.get_sha1('foo'), sha1('g00dbye'))
91
96
self.assertEquals(len(hc._cache), 1)
97
self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))
98
self.assertEquals(len(hc._cache), 2)
93
100
# write out, read back in and check that we don't need to
94
101
# re-read any files
98
105
hc = HashCache('.')
99
106
hc.read('stat-cache')
101
self.assertEquals(len(hc._cache), 1)
108
self.assertEquals(len(hc._cache), 2)
102
109
self.assertEquals(hc.get_sha1('foo'), sha1('g00dbye'))
103
110
self.assertEquals(hc.hit_count, 1)
104
111
self.assertEquals(hc.miss_count, 0)
112
self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))