@@ -44,31 +44,36 @@ def test_get_skel_file(tmp_path, monkeypatch):
4444 # First execution, the S3 stub is created (or datalad install)
4545 reload (tfc )
4646
47- local_md5 = tfc ._s3 .TF_SKEL_MD5
48- monkeypatch .setattr (tfc ._s3 , 'TF_SKEL_MD5' , 'invent' )
49- new_skel = tfc ._s3 ._get_skeleton_file ()
47+ md5content = b'anything'
48+
49+ def mock_get (* args , ** kwargs ):
50+ class MockResponse :
51+ status_code = 200
52+ ok = True
53+ content = md5content
54+
55+ return MockResponse ()
56+
57+ monkeypatch .setattr (requests , 'get' , mock_get )
58+
59+ # Mismatching the local MD5 causes an update
60+ new_skel = tfc ._s3 ._get_skeleton_file (timeout = 10 )
5061 assert new_skel is not None
5162 assert Path (new_skel ).exists ()
52- assert Path (new_skel ).stat (). st_size > 0
63+ assert Path (new_skel ).read_bytes () == b'anything'
5364
54- latest_md5 = (
55- requests .get (
56- tfc ._s3 .TF_SKEL_URL (release = 'master' , ext = 'md5' , allow_redirects = True ), timeout = 10
57- )
58- .content .decode ()
59- .split ()[0 ]
60- )
61- monkeypatch .setattr (tfc ._s3 , 'TF_SKEL_MD5' , latest_md5 )
62- assert tfc ._s3 ._get_skeleton_file () is None
65+ md5content = tfc ._s3 .load_data .readable ('templateflow-skel.md5' ).read_bytes ()
66+ # Matching the local MD5 skips the update
67+ assert tfc ._s3 ._get_skeleton_file (timeout = 10 ) is None
6368
64- monkeypatch . setattr ( tfc . _s3 , 'TF_SKEL_MD5' , local_md5 )
69+ # Bad URL fails to update
6570 monkeypatch .setattr (tfc ._s3 , 'TF_SKEL_URL' , 'http://weird/{release}/{ext}' .format )
66- assert tfc ._s3 ._get_skeleton_file () is None
71+ assert tfc ._s3 ._get_skeleton_file (timeout = 10 ) is None
6772
6873 monkeypatch .setattr (
6974 tfc ._s3 , 'TF_SKEL_URL' , tfc ._s3 .TF_SKEL_URL (release = '{release}' , ext = '{ext}z' ).format
7075 )
71- assert tfc ._s3 ._get_skeleton_file () is None
76+ assert tfc ._s3 ._get_skeleton_file (timeout = 10 ) is None
7277
7378
7479def test_update_s3 (tmp_path , monkeypatch ):
@@ -78,19 +83,19 @@ def test_update_s3(tmp_path, monkeypatch):
7883 monkeypatch .setenv ('TEMPLATEFLOW_USE_DATALAD' , 'off' )
7984 monkeypatch .setenv ('TEMPLATEFLOW_HOME' , str (newhome ))
8085
81- assert tfc ._s3 .update (newhome )
82- assert not tfc ._s3 .update (newhome , overwrite = False )
86+ assert tfc ._s3 .update (newhome , timeout = 10 )
87+ assert not tfc ._s3 .update (newhome , overwrite = False , timeout = 10 )
8388 for p in (newhome / 'tpl-MNI152NLin6Sym' ).glob ('*.nii.gz' ):
8489 p .unlink ()
85- assert tfc ._s3 .update (newhome , overwrite = False )
90+ assert tfc ._s3 .update (newhome , overwrite = False , timeout = 10 )
8691
8792 # This should cover the remote zip file fetching
88- monkeypatch .setattr (tfc ._s3 , 'TF_SKEL_MD5' , 'invent' )
89- assert tfc ._s3 .update (newhome , local = False )
90- assert not tfc ._s3 .update (newhome , local = False , overwrite = False )
93+ # monkeypatch.setattr(tfc._s3, 'TF_SKEL_MD5', 'invent')
94+ assert tfc ._s3 .update (newhome , local = False , timeout = 10 )
95+ assert not tfc ._s3 .update (newhome , local = False , overwrite = False , timeout = 10 )
9196 for p in (newhome / 'tpl-MNI152NLin6Sym' ).glob ('*.nii.gz' ):
9297 p .unlink ()
93- assert tfc ._s3 .update (newhome , local = False , overwrite = False )
98+ assert tfc ._s3 .update (newhome , local = False , overwrite = False , timeout = 10 )
9499
95100
96101def test_s3_400_error (monkeypatch ):
0 commit comments