@@ -323,11 +323,18 @@ def text_file(tmp_path):
323
323
324
324
325
325
def test_persistent_hash_cache (cache_path , text_file ):
326
+ """
327
+ Test the persistent hash cache with a text file
328
+
329
+ The cache is used to store the hash of the text file, and the hash is
330
+ retrieved from the cache when the file is unchanged.
331
+ """
326
332
# Test hash is stable between calls
327
333
hsh = hash_object (text_file , persistent_cache = cache_path )
328
334
assert hsh == hash_object (text_file , persistent_cache = cache_path )
329
335
330
- # Test that cached hash has been used
336
+ # Test that cached hash has been used by explicitly modifying it and seeing that the
337
+ # hash is the same as the modified hash
331
338
cache_files = list (cache_path .iterdir ())
332
339
assert len (cache_files ) == 1
333
340
modified_hash = "modified" .encode ()
@@ -342,6 +349,10 @@ def test_persistent_hash_cache(cache_path, text_file):
342
349
343
350
344
351
def test_persistent_hash_cache_cleanup1 (cache_path , text_file ):
352
+ """
353
+ Test the persistent hash is cleaned up after use if the periods between cleanups
354
+ is greater than the environment variable PYDRA_HASH_CACHE_CLEANUP_PERIOD
355
+ """
345
356
with mock .patch .dict (
346
357
os .environ ,
347
358
{
@@ -350,21 +361,28 @@ def test_persistent_hash_cache_cleanup1(cache_path, text_file):
350
361
},
351
362
):
352
363
persistent_cache = PersistentCache ()
353
- hsh = hash_object (text_file , persistent_cache = persistent_cache )
364
+ hash_object (text_file , persistent_cache = persistent_cache )
354
365
assert len (list (cache_path .iterdir ())) == 1
355
366
persistent_cache .clean_up ()
356
367
assert len (list (cache_path .iterdir ())) == 0
357
368
358
369
359
370
def test_persistent_hash_cache_cleanup2 (cache_path , text_file ):
371
+ """
372
+ Test the persistent hash is cleaned up after use if the periods between cleanups
373
+ is greater than the explicitly provided cleanup_period
374
+ """
360
375
persistent_cache = PersistentCache (cache_path , cleanup_period = - 100 )
361
- hsh = hash_object (text_file , persistent_cache = persistent_cache )
376
+ hash_object (text_file , persistent_cache = persistent_cache )
362
377
assert len (list (cache_path .iterdir ())) == 1
363
378
time .sleep (2 )
364
379
persistent_cache .clean_up ()
365
380
assert len (list (cache_path .iterdir ())) == 0
366
381
367
382
368
383
def test_persistent_hash_cache_not_dir (text_file ):
384
+ """
385
+ Test that an error is raised if the provided cache path is not a directory
386
+ """
369
387
with pytest .raises (ValueError , match = "is not a directory" ):
370
388
PersistentCache (text_file .fspath )
0 commit comments