2323"""Tests the config module."""
2424
2525from importlib import reload
26+ from importlib .util import find_spec
2627from shutil import rmtree
2728
2829import pytest
2930
3031from templateflow import conf as tfc
3132
33+ have_datalad = find_spec ('datalad' ) is not None
34+
3235
3336def _find_message (lines , msg , reverse = True ):
3437 if isinstance (lines , str ):
@@ -61,10 +64,6 @@ def test_conf_init(monkeypatch, tmp_path, use_datalad):
6164def 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.' )
0 commit comments