|
28 | 28 | from templateflow import conf as tfc |
29 | 29 |
|
30 | 30 |
|
| 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 | + |
31 | 41 | @pytest.mark.parametrize('use_datalad', ['off', 'on']) |
32 | 42 | def test_conf_init(monkeypatch, tmp_path, capsys, use_datalad): |
33 | 43 | """Check the correct functioning of config set-up.""" |
@@ -56,53 +66,54 @@ def test_setup_home(monkeypatch, tmp_path, capsys, use_datalad): |
56 | 66 | # First execution, the S3 stub is created (or datalad install) |
57 | 67 | assert tfc.TF_CACHED is False |
58 | 68 | 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') |
61 | 72 | assert ('TEMPLATEFLOW_HOME=%s' % home) in out |
62 | 73 | assert home.exists() |
63 | 74 | assert len(list(home.iterdir())) > 0 |
64 | 75 |
|
65 | 76 | updated = tfc.setup_home(force=True) # Templateflow is now cached |
66 | 77 | out = capsys.readouterr()[0] |
67 | | - assert not out.startswith('TemplateFlow was not cached') |
| 78 | + assert _find_message(out, 'TemplateFlow was not cached') is False |
68 | 79 |
|
69 | 80 | if use_datalad == 'on': |
70 | | - assert out.startswith('Updating TEMPLATEFLOW_HOME using DataLad') |
| 81 | + assert _find_message(out, 'Updating TEMPLATEFLOW_HOME using DataLad') |
71 | 82 | assert updated is True |
72 | 83 |
|
73 | 84 | elif use_datalad == 'off': |
74 | 85 | # At this point, S3 should be up-to-date |
75 | 86 | 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.') |
77 | 88 |
|
78 | 89 | # Let's force an update |
79 | 90 | rmtree(str(home / 'tpl-MNI152NLin2009cAsym')) |
80 | 91 | updated = tfc.setup_home(force=True) |
81 | 92 | out = capsys.readouterr()[0] |
82 | 93 | assert updated is True |
83 | | - assert out.startswith('Updating TEMPLATEFLOW_HOME using S3.') |
| 94 | + assert _find_message(out, 'Updating TEMPLATEFLOW_HOME using S3.') |
84 | 95 |
|
85 | 96 | reload(tfc) |
86 | 97 | assert tfc.TF_CACHED is True |
87 | 98 | updated = tfc.setup_home() # Templateflow is now cached |
88 | 99 | out = capsys.readouterr()[0] |
89 | | - assert not out.startswith('TemplateFlow was not cached') |
| 100 | + assert not _find_message(out, 'TemplateFlow was not cached') |
90 | 101 |
|
91 | 102 | if use_datalad == 'on': |
92 | | - assert out.startswith('Updating TEMPLATEFLOW_HOME using DataLad') |
| 103 | + assert _find_message(out, 'Updating TEMPLATEFLOW_HOME using DataLad') |
93 | 104 | assert updated is True |
94 | 105 |
|
95 | 106 | elif use_datalad == 'off': |
96 | 107 | # At this point, S3 should be up-to-date |
97 | 108 | 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.') |
99 | 110 |
|
100 | 111 | # Let's force an update |
101 | 112 | rmtree(str(home / 'tpl-MNI152NLin2009cAsym')) |
102 | 113 | updated = tfc.setup_home() |
103 | 114 | out = capsys.readouterr()[0] |
104 | 115 | assert updated is True |
105 | | - assert out.startswith('Updating TEMPLATEFLOW_HOME using S3.') |
| 116 | + assert _find_message(out, 'Updating TEMPLATEFLOW_HOME using S3.') |
106 | 117 |
|
107 | 118 |
|
108 | 119 | def test_layout(monkeypatch, tmp_path): |
|
0 commit comments