Skip to content

Commit bfb2bcf

Browse files
committed
MAINT: Fix test breaking with recent datalad versions
Resolves: #129.
1 parent 56dc91c commit bfb2bcf

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

templateflow/conf/tests/test_conf.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
from templateflow import conf as tfc
2929

3030

31+
def _find_message(lines, msg, reverse=True):
32+
if isinstance(lines, str):
33+
lines = lines.splitlines()
34+
35+
for line in reversed(lines):
36+
if line.strip().startswith(msg):
37+
return True
38+
return False
39+
40+
3141
@pytest.mark.parametrize('use_datalad', ['off', 'on'])
3242
def test_conf_init(monkeypatch, tmp_path, capsys, use_datalad):
3343
"""Check the correct functioning of config set-up."""
@@ -56,53 +66,54 @@ def test_setup_home(monkeypatch, tmp_path, capsys, use_datalad):
5666
# First execution, the S3 stub is created (or datalad install)
5767
assert tfc.TF_CACHED is False
5868
assert tfc.setup_home() is False
59-
out = capsys.readouterr()[0]
60-
assert out.startswith('TemplateFlow was not cached')
69+
70+
out = capsys.readouterr().out
71+
assert _find_message(out, 'TemplateFlow was not cached')
6172
assert ('TEMPLATEFLOW_HOME=%s' % home) in out
6273
assert home.exists()
6374
assert len(list(home.iterdir())) > 0
6475

6576
updated = tfc.setup_home(force=True) # Templateflow is now cached
6677
out = capsys.readouterr()[0]
67-
assert not out.startswith('TemplateFlow was not cached')
78+
assert _find_message(out, 'TemplateFlow was not cached') is False
6879

6980
if use_datalad == 'on':
70-
assert out.startswith('Updating TEMPLATEFLOW_HOME using DataLad')
81+
assert _find_message(out, 'Updating TEMPLATEFLOW_HOME using DataLad')
7182
assert updated is True
7283

7384
elif use_datalad == 'off':
7485
# At this point, S3 should be up-to-date
7586
assert updated is False
76-
assert out.startswith('TEMPLATEFLOW_HOME directory (S3 type) was up-to-date.')
87+
assert _find_message(out, 'TEMPLATEFLOW_HOME directory (S3 type) was up-to-date.')
7788

7889
# Let's force an update
7990
rmtree(str(home / 'tpl-MNI152NLin2009cAsym'))
8091
updated = tfc.setup_home(force=True)
8192
out = capsys.readouterr()[0]
8293
assert updated is True
83-
assert out.startswith('Updating TEMPLATEFLOW_HOME using S3.')
94+
assert _find_message(out, 'Updating TEMPLATEFLOW_HOME using S3.')
8495

8596
reload(tfc)
8697
assert tfc.TF_CACHED is True
8798
updated = tfc.setup_home() # Templateflow is now cached
8899
out = capsys.readouterr()[0]
89-
assert not out.startswith('TemplateFlow was not cached')
100+
assert not _find_message(out, 'TemplateFlow was not cached')
90101

91102
if use_datalad == 'on':
92-
assert out.startswith('Updating TEMPLATEFLOW_HOME using DataLad')
103+
assert _find_message(out, 'Updating TEMPLATEFLOW_HOME using DataLad')
93104
assert updated is True
94105

95106
elif use_datalad == 'off':
96107
# At this point, S3 should be up-to-date
97108
assert updated is False
98-
assert out.startswith('TEMPLATEFLOW_HOME directory (S3 type) was up-to-date.')
109+
assert _find_message(out, 'TEMPLATEFLOW_HOME directory (S3 type) was up-to-date.')
99110

100111
# Let's force an update
101112
rmtree(str(home / 'tpl-MNI152NLin2009cAsym'))
102113
updated = tfc.setup_home()
103114
out = capsys.readouterr()[0]
104115
assert updated is True
105-
assert out.startswith('Updating TEMPLATEFLOW_HOME using S3.')
116+
assert _find_message(out, 'Updating TEMPLATEFLOW_HOME using S3.')
106117

107118

108119
def test_layout(monkeypatch, tmp_path):

0 commit comments

Comments
 (0)