1010)
1111
1212from fsspec import filesystem
13+ from pathlib import Path
14+
15+ # NOTE: windows time.time() implementation appears to have 16 millisecond precision, so
16+ # we need to add a small delay, in order to avoid prune checks appearing to happen at the
17+ # exact same moment something earlier was created / accessed.
18+ # see: https://stackoverflow.com/a/1938096/1144523
1319
1420
1521# Utilities ===================================================================
1622
1723
24+ def _sleep ():
25+ # time-based issues keep arising erratically in windows checks, so try to shoot
26+ # well past
27+ time .sleep (0.3 )
28+
29+
1830@pytest .fixture
1931def some_file (tmp_dir2 ):
2032 p = tmp_dir2 / "some_file.txt"
@@ -34,7 +46,7 @@ def test_touch_access_time_manual(some_file):
3446def test_touch_access_time_auto (some_file ):
3547 orig_access = some_file .stat ().st_atime
3648
37- time . sleep ( 0.2 )
49+ _sleep ( )
3850 new_time = touch_access_time (some_file )
3951
4052 assert some_file .stat ().st_atime == new_time
@@ -55,9 +67,14 @@ def test_pins_cache_url_hash_name():
5567 cache = PinsUrlCache (fs = filesystem ("file" ))
5668 hashed = cache .hash_name ("http://example.com/a.txt" , True )
5769
70+ p_hash = Path (hashed )
71+
5872 # should have form <url_hash>/<version_placeholder>/<filename>
59- assert hashed .endswith ("/a.txt" )
60- assert hashed .count ("/" ) == 2
73+ assert p_hash .name == "a.txt"
74+
75+ # count parent dirs, excluding root (e.g. "." or "/")
76+ n_parents = len (p_hash .parents ) - 1
77+ assert n_parents == 2
6178
6279
6380@pytest .mark .skip ("TODO" )
@@ -106,6 +123,8 @@ def pin2_v3(a_cache):
106123
107124
108125def test_cache_pruner_old_versions_none (a_cache , pin1_v1 ):
126+ _sleep ()
127+
109128 pruner = CachePruner (a_cache )
110129
111130 old = pruner .old_versions (days = 1 )
@@ -114,6 +133,8 @@ def test_cache_pruner_old_versions_none(a_cache, pin1_v1):
114133
115134
116135def test_cache_pruner_old_versions_days0 (a_cache , pin1_v1 ):
136+ _sleep ()
137+
117138 pruner = CachePruner (a_cache )
118139 old = pruner .old_versions (days = 0 )
119140
@@ -122,6 +143,8 @@ def test_cache_pruner_old_versions_days0(a_cache, pin1_v1):
122143
123144
124145def test_cache_pruner_old_versions_some (a_cache , pin1_v1 , pin1_v2 ):
146+ _sleep ()
147+
125148 # create: tmp_dir/pin1/version1
126149
127150 pruner = CachePruner (a_cache )
@@ -133,6 +156,8 @@ def test_cache_pruner_old_versions_some(a_cache, pin1_v1, pin1_v2):
133156
134157
135158def test_cache_pruner_old_versions_multi_pins (a_cache , pin1_v2 , pin2_v3 ):
159+ _sleep ()
160+
136161 pruner = CachePruner (a_cache )
137162 old = pruner .old_versions (days = 1 )
138163
@@ -141,6 +166,8 @@ def test_cache_pruner_old_versions_multi_pins(a_cache, pin1_v2, pin2_v3):
141166
142167
143168def test_cache_prune_prompt (a_cache , pin1_v1 , pin2_v3 , monkeypatch ):
169+ _sleep ()
170+
144171 cache_prune (days = 1 , cache_root = a_cache .parent , prompt = False )
145172
146173 versions = list (a_cache .glob ("*/*" ))
0 commit comments