Skip to content

Commit 7608513

Browse files
committed
test: More cleanup
1 parent 4df94c0 commit 7608513

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

templateflow/tests/test_conf.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
"""Tests the config module."""
2424

2525
from importlib import reload
26+
from importlib.util import find_spec
2627
from shutil import rmtree
2728

2829
import pytest
2930

3031
from templateflow import conf as tfc
3132

33+
have_datalad = find_spec('datalad') is not None
34+
3235

3336
def _find_message(lines, msg, reverse=True):
3437
if isinstance(lines, str):
@@ -61,10 +64,6 @@ def test_conf_init(monkeypatch, tmp_path, use_datalad):
6164
def test_setup_home(monkeypatch, tmp_path, capsys, use_datalad):
6265
"""Check the correct functioning of the installation hook."""
6366

64-
if use_datalad == 'on':
65-
# ImportError if not installed
66-
pass
67-
6867
home = (tmp_path / f'setup-home-{use_datalad}').absolute()
6968
monkeypatch.setenv('TEMPLATEFLOW_USE_DATALAD', use_datalad)
7069
monkeypatch.setenv('TEMPLATEFLOW_HOME', str(home))
@@ -76,7 +75,7 @@ def test_setup_home(monkeypatch, tmp_path, capsys, use_datalad):
7675
reload(tfc)
7776

7877
# Ensure mocks are up-to-date
79-
assert tfc.TF_USE_DATALAD is (use_datalad == 'on')
78+
assert tfc.TF_USE_DATALAD is (use_datalad == 'on' and have_datalad)
8079
assert str(tfc.TF_HOME) == str(home)
8180
# First execution, the S3 stub is created (or datalad install)
8281
assert tfc.TF_CACHED is False
@@ -92,11 +91,11 @@ def test_setup_home(monkeypatch, tmp_path, capsys, use_datalad):
9291
out = capsys.readouterr()[0]
9392
assert _find_message(out, 'TemplateFlow was not cached') is False
9493

95-
if use_datalad == 'on':
94+
if use_datalad == 'on' and have_datalad:
9695
assert _find_message(out, 'Updating TEMPLATEFLOW_HOME using DataLad')
9796
assert updated is True
9897

99-
elif use_datalad == 'off':
98+
else:
10099
# At this point, S3 should be up-to-date
101100
assert updated is False
102101
assert _find_message(out, 'TEMPLATEFLOW_HOME directory (S3 type) was up-to-date.')
@@ -114,11 +113,11 @@ def test_setup_home(monkeypatch, tmp_path, capsys, use_datalad):
114113
out = capsys.readouterr()[0]
115114
assert not _find_message(out, 'TemplateFlow was not cached')
116115

117-
if use_datalad == 'on':
116+
if use_datalad == 'on' and have_datalad:
118117
assert _find_message(out, 'Updating TEMPLATEFLOW_HOME using DataLad')
119118
assert updated is True
120119

121-
elif use_datalad == 'off':
120+
else:
122121
# At this point, S3 should be up-to-date
123122
assert updated is False
124123
assert _find_message(out, 'TEMPLATEFLOW_HOME directory (S3 type) was up-to-date.')

templateflow/tests/test_s3.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ def test_get_skel_file(tmp_path, monkeypatch):
4040
"""Exercise the skeleton file generation."""
4141

4242
home = (tmp_path / 's3-skel-file').resolve()
43-
monkeypatch.setenv('TEMPLATEFLOW_USE_DATALAD', 'off')
44-
monkeypatch.setenv('TEMPLATEFLOW_HOME', str(home))
45-
46-
# First execution, the S3 stub is created (or datalad install)
47-
reload(tfc)
4843

4944
md5content = b'anything'
5045

@@ -82,8 +77,6 @@ def test_update_s3(tmp_path, monkeypatch):
8277
"""Exercise updating the S3 skeleton."""
8378

8479
newhome = (tmp_path / 's3-update').resolve()
85-
monkeypatch.setenv('TEMPLATEFLOW_USE_DATALAD', 'off')
86-
monkeypatch.setenv('TEMPLATEFLOW_HOME', str(newhome))
8780

8881
assert tfc._s3.update(newhome, timeout=10)
8982
assert not tfc._s3.update(newhome, overwrite=False, timeout=10)

0 commit comments

Comments
 (0)