File tree Expand file tree Collapse file tree 3 files changed +37
-13
lines changed Expand file tree Collapse file tree 3 files changed +37
-13
lines changed Original file line number Diff line number Diff line change @@ -226,6 +226,7 @@ jobs:
226
226
no_output_timeout : 2h
227
227
command : |
228
228
docker run -ti --rm=false \
229
+ -e TEST_READONLY_FILESYSTEM=1 -v $HOME:/home/readonly:ro \
229
230
--entrypoint="pytest" poldracklab/fmriprep:latest \
230
231
/src/fmriprep/fmriprep -svx --doctest-modules
231
232
Original file line number Diff line number Diff line change 1
1
"""Test version checks."""
2
+ from os import getenv
2
3
from datetime import datetime
3
4
from pathlib import Path
4
5
from packaging .version import Version
@@ -161,3 +162,21 @@ def mock_get(*args, **kwargs):
161
162
assert reason == test_reason
162
163
else :
163
164
assert reason is None
165
+
166
+
167
+ def test_readonly (tmp_path , monkeypatch ):
168
+ """Test behavior when $HOME/.cache/fmriprep/latest can't be written out."""
169
+ home_path = Path ('/home/readonly' ) if getenv ('TEST_READONLY_FILESYSTEM' ) \
170
+ else tmp_path
171
+ monkeypatch .setenv ('HOME' , str (home_path ))
172
+ cachedir = home_path / '.cache'
173
+
174
+ if getenv ('TEST_READONLY_FILESYSTEM' ) is None :
175
+ cachedir .mkdir (mode = 0o555 , exist_ok = True )
176
+
177
+ # Make sure creating the folder will raise the exception.
178
+ with pytest .raises (OSError ):
179
+ (cachedir / 'fmriprep' ).mkdir (parents = True )
180
+
181
+ # Should not raise
182
+ check_latest ()
Original file line number Diff line number Diff line change @@ -19,21 +19,25 @@ def check_latest():
19
19
date = None
20
20
outdated = None
21
21
cachefile = Path .home () / '.cache' / 'fmriprep' / 'latest'
22
- cachefile .parent .mkdir (parents = True , exist_ok = True )
23
-
24
22
try :
25
- latest , date = cachefile .read_text ().split ('|' )
26
- except Exception :
27
- pass
28
- else :
23
+ cachefile .parent .mkdir (parents = True , exist_ok = True )
24
+ except OSError :
25
+ cachefile = None
26
+
27
+ if cachefile and cachefile .exists ():
29
28
try :
30
- latest = Version (latest )
31
- date = datetime .strptime (date , DATE_FMT )
32
- except (InvalidVersion , ValueError ):
33
- latest = None
29
+ latest , date = cachefile .read_text ().split ('|' )
30
+ except Exception :
31
+ pass
34
32
else :
35
- if abs ((datetime .now () - date ).days ) > RELEASE_EXPIRY_DAYS :
36
- outdated = True
33
+ try :
34
+ latest = Version (latest )
35
+ date = datetime .strptime (date , DATE_FMT )
36
+ except (InvalidVersion , ValueError ):
37
+ latest = None
38
+ else :
39
+ if abs ((datetime .now () - date ).days ) > RELEASE_EXPIRY_DAYS :
40
+ outdated = True
37
41
38
42
if latest is None or outdated is True :
39
43
try :
@@ -49,7 +53,7 @@ def check_latest():
49
53
else :
50
54
latest = None
51
55
52
- if latest is not None :
56
+ if cachefile is not None and latest is not None :
53
57
try :
54
58
cachefile .write_text ('|' .join (('%s' % latest , datetime .now ().strftime (DATE_FMT ))))
55
59
except Exception :
You can’t perform that action at this time.
0 commit comments