Skip to content

Commit d52889d

Browse files
committed
Check license cache times with os.stat
Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent b596e4d commit d52889d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

tests/licensedcode/test_zzzz_cache.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import os
3030

3131
from commoncode.testcase import FileBasedTesting
32-
from commoncode import date
3332
from commoncode import fileutils
3433
from commoncode import hash
3534
from licensedcode import cache
@@ -140,12 +139,12 @@ def test_build_index(self):
140139
# when nothing changed a new index files is not created
141140
tree_before = open(checksum_file).read()
142141
idx_checksum_before = hash.sha1(cache_file)
143-
idx_date_before = date.get_file_mtime(cache_file)
142+
idx_date_before = os.stat(cache_file).st_mtime
144143
cache.get_cached_index(cache_dir, check_consistency, timeout,
145144
tree_base_dir, licenses_data_dir, rules_data_dir)
146145
assert tree_before == open(checksum_file).read()
147146
assert idx_checksum_before == hash.sha1(cache_file)
148-
assert idx_date_before == date.get_file_mtime(cache_file)
147+
assert idx_date_before == os.stat(cache_file).st_mtime
149148

150149
# now add some file in the source tree
151150
new_file = os.path.join(tree_base_dir, 'some file')
@@ -159,20 +158,20 @@ def test_build_index(self):
159158
tree_base_dir, licenses_data_dir, rules_data_dir)
160159
assert tree_before == open(checksum_file).read()
161160
assert idx_checksum_before == hash.sha1(cache_file)
162-
assert idx_date_before == date.get_file_mtime(cache_file)
161+
assert idx_date_before == os.stat(cache_file).st_mtime
163162

164163
# when check_consistency is True, the index is rebuilt when new
165164
# files are added
166165
check_consistency = True
167166
cache.get_cached_index(cache_dir, check_consistency, timeout,
168167
tree_base_dir, licenses_data_dir, rules_data_dir)
169168
assert tree_before != open(checksum_file).read()
170-
assert idx_date_before != date.get_file_mtime(cache_file)
169+
assert idx_date_before != os.stat(cache_file).st_mtime
171170

172171
# now add some ignored file in the source tree
173172
tree_before = open(checksum_file).read()
174173
idx_checksum_before = hash.sha1(cache_file)
175-
idx_date_before = date.get_file_mtime(cache_file)
174+
idx_date_before = os.stat(cache_file).st_mtime
176175
new_file = os.path.join(tree_base_dir, 'some file.pyc')
177176
with open(new_file, 'wb') as nf:
178177
nf.write('somthing')
@@ -183,7 +182,7 @@ def test_build_index(self):
183182

184183
assert tree_before == open(checksum_file).read()
185184
assert idx_checksum_before == hash.sha1(cache_file)
186-
assert idx_date_before == date.get_file_mtime(cache_file)
185+
assert idx_date_before == os.stat(cache_file).st_mtime
187186

188187
# if the treechecksum file dies the index is rebuilt
189188
fileutils.delete(checksum_file)
@@ -194,7 +193,7 @@ def test_build_index(self):
194193
tree_base_dir, licenses_data_dir, rules_data_dir)
195194

196195
assert tree_before == open(checksum_file).read()
197-
assert idx_date_before != date.get_file_mtime(cache_file)
196+
assert idx_date_before != os.stat(cache_file).st_mtime
198197

199198
# if the index cache file dies the index is rebuilt
200199
fileutils.delete(cache_file)

0 commit comments

Comments
 (0)