@@ -120,15 +120,19 @@ def test_build_index(self):
120120 licenses_data_dir = self .get_test_loc ('cache/data/licenses' , copy = True )
121121 rules_data_dir = self .get_test_loc ('cache/data/rules' , copy = True )
122122
123+ # now add some file in the mock source tree
124+ new_file = os .path .join (tree_base_dir , 'some.py' )
125+ with open (new_file , 'wb' ) as nf :
126+ nf .write ('somthing' )
127+
123128 timeout = 10
124129
125130 assert not os .path .exists (checksum_file )
126131 assert not os .path .exists (cache_file )
127132 assert not os .path .exists (lock_file )
128133
129- check_consistency = True
130-
131134 # when a new index is built, new index files are created
135+ check_consistency = True
132136 cache .get_cached_index (cache_dir , check_consistency , timeout ,
133137 tree_base_dir , licenses_data_dir , rules_data_dir )
134138
@@ -139,12 +143,10 @@ def test_build_index(self):
139143 # when nothing changed a new index files is not created
140144 tree_before = open (checksum_file ).read ()
141145 idx_checksum_before = hash .sha1 (cache_file )
142- idx_date_before = os .stat (cache_file ).st_mtime
143146 cache .get_cached_index (cache_dir , check_consistency , timeout ,
144147 tree_base_dir , licenses_data_dir , rules_data_dir )
145148 assert tree_before == open (checksum_file ).read ()
146149 assert idx_checksum_before == hash .sha1 (cache_file )
147- assert idx_date_before == os .stat (cache_file ).st_mtime
148150
149151 # now add some file in the source tree
150152 new_file = os .path .join (tree_base_dir , 'some file' )
@@ -158,33 +160,31 @@ def test_build_index(self):
158160 tree_base_dir , licenses_data_dir , rules_data_dir )
159161 assert tree_before == open (checksum_file ).read ()
160162 assert idx_checksum_before == hash .sha1 (cache_file )
161- assert idx_date_before == os .stat (cache_file ).st_mtime
162163
163164 # when check_consistency is True, the index is rebuilt when new
164165 # files are added
165166 check_consistency = True
166167 cache .get_cached_index (cache_dir , check_consistency , timeout ,
167168 tree_base_dir , licenses_data_dir , rules_data_dir )
168169 assert tree_before != open (checksum_file ).read ()
169- assert idx_date_before != os .stat (cache_file ).st_mtime
170170
171171 # now add some ignored file in the source tree
172172 tree_before = open (checksum_file ).read ()
173173 idx_checksum_before = hash .sha1 (cache_file )
174- idx_date_before = os .stat (cache_file ).st_mtime
175174 new_file = os .path .join (tree_base_dir , 'some file.pyc' )
176175 with open (new_file , 'wb' ) as nf :
177176 nf .write ('somthing' )
178177
178+ # when check_consistency is True, the index is not rebuilt when new
179+ # files are added that are ignored
179180 check_consistency = True
180181 cache .get_cached_index (cache_dir , check_consistency , timeout ,
181182 tree_base_dir , licenses_data_dir , rules_data_dir )
182183
183184 assert tree_before == open (checksum_file ).read ()
184185 assert idx_checksum_before == hash .sha1 (cache_file )
185- assert idx_date_before == os .stat (cache_file ).st_mtime
186186
187- # if the treechecksum file dies the index is rebuilt
187+ # if the treechecksum file dies, the index is rebuilt
188188 fileutils .delete (checksum_file )
189189 idx_checksum_before = hash .sha1 (cache_file )
190190
@@ -193,52 +193,19 @@ def test_build_index(self):
193193 tree_base_dir , licenses_data_dir , rules_data_dir )
194194
195195 assert tree_before == open (checksum_file ).read ()
196- assert idx_date_before != os .stat (cache_file ).st_mtime
197196
198197 # if the index cache file dies the index is rebuilt
199198 fileutils .delete (cache_file )
200199
201200 check_consistency = False
202- cache .get_cached_index (cache_dir , check_consistency , timeout ,
203- tree_base_dir , licenses_data_dir , rules_data_dir )
204-
205- assert tree_before == open (checksum_file ).read ()
206- assert os .path .exists (cache_file )
207-
208- # reset tests caches
209- cache ._LICENSE_SYMBOLS_BY_SPDX_KEY = {}
210- cache ._LICENSES_BY_KEY_INDEX = None
211- cache ._UNKNOWN_SPDX_SYMBOL = None
212- cache ._LICENSES_BY_KEY = None
213-
214- def test__load_index (self ):
215- cache_dir = self .get_temp_dir ('index_cache' )
216-
217- lock_file , checksum_file , cache_file = get_license_cache_paths (cache_dir = cache_dir )
218- tree_base_dir = self .get_temp_dir ('src_dir' )
219- licenses_data_dir = self .get_test_loc ('cache/data/licenses' , copy = True )
220- rules_data_dir = self .get_test_loc ('cache/data/rules' , copy = True )
221-
222- timeout = 10
223-
224- assert not os .path .exists (checksum_file )
225- assert not os .path .exists (cache_file )
226- assert not os .path .exists (lock_file )
227-
228- check_consistency = True
229-
230- # Create a basic index
231201 idx1 = cache .get_cached_index (cache_dir , check_consistency , timeout ,
232- tree_base_dir , licenses_data_dir , rules_data_dir )
233-
234- assert os .path .exists (checksum_file )
235- assert os .path .exists (cache_file )
236- assert not os .path .exists (lock_file )
202+ tree_base_dir , licenses_data_dir , rules_data_dir )
237203
204+ # load index, forced from file
238205 idx2 = cache .load_index (cache_file )
239206 assert idx1 .to_dict (True ) == idx2 .to_dict (True )
240207
241- # reset tests caches
208+ # reset global caches
242209 cache ._LICENSE_SYMBOLS_BY_SPDX_KEY = {}
243210 cache ._LICENSES_BY_KEY_INDEX = None
244211 cache ._UNKNOWN_SPDX_SYMBOL = None
0 commit comments