Skip to content

Commit ddfef28

Browse files
committed
fix(tests): revise old parser tests and relocate properly
1 parent 2c4de8b commit ddfef28

File tree

3 files changed

+53
-55
lines changed

3 files changed

+53
-55
lines changed

fmriprep/cli/parser.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33
"""Parser."""
44
import os
5+
import sys
56
from .. import config
67

78

@@ -281,20 +282,20 @@ def _bids_filter(value):
281282

282283
latest = check_latest()
283284
if latest is not None and currentv < latest:
284-
config.loggers.cli.warning("""\
285+
print("""\
285286
You are using fMRIPrep-%s, and a newer version of fMRIPrep is available: %s.
286287
Please check out our documentation about how and when to upgrade:
287288
https://fmriprep.readthedocs.io/en/latest/faq.html#upgrading""" % (
288-
config.execution.version, latest))
289+
currentv, latest), file=sys.stderr)
289290

290291
_blist = is_flagged()
291292
if _blist[0]:
292293
_reason = _blist[1] or 'unknown'
293-
config.loggers.cli.warning("""\
294+
print("""\
294295
WARNING: Version %s of fMRIPrep (current) has been FLAGGED
295296
(reason: %s).
296297
That means some severe flaw was found in it and we strongly
297-
discourage its usage.""" % (config.execution.version, _reason))
298+
discourage its usage.""" % (config.execution.version, _reason), file=sys.stderr)
298299

299300
return parser
300301

fmriprep/cli/tests/test_parser.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""Test parser."""
2+
from packaging.version import Version
23
import pytest
34
from ..parser import _build_parser
5+
from .. import version as _version
6+
from ... import config
47

58
MIN_ARGS = ['data/', 'out/', 'participant']
69

@@ -66,3 +69,48 @@ def test_memory_arg(tmp_path, argval, gb):
6669
opts = _build_parser().parse_args(args)
6770

6871
assert opts.memory_gb == gb
72+
73+
74+
@pytest.mark.parametrize('current,latest', [
75+
('1.0.0', '1.3.2'),
76+
('1.3.2', '1.3.2')
77+
])
78+
def test_get_parser_update(monkeypatch, capsys, current, latest):
79+
"""Make sure the out-of-date banner is shown."""
80+
expectation = Version(current) < Version(latest)
81+
82+
def _mock_check_latest(*args, **kwargs):
83+
return Version(latest)
84+
85+
monkeypatch.setattr(config.execution, 'version', current)
86+
monkeypatch.setattr(_version, 'check_latest', _mock_check_latest)
87+
88+
_build_parser()
89+
captured = capsys.readouterr().err
90+
91+
msg = """\
92+
You are using fMRIPrep-%s, and a newer version of fMRIPrep is available: %s.
93+
Please check out our documentation about how and when to upgrade:
94+
https://fmriprep.readthedocs.io/en/latest/faq.html#upgrading""" % (current, latest)
95+
96+
assert (msg in captured) is expectation
97+
98+
99+
@pytest.mark.parametrize('flagged', [
100+
(True, None),
101+
(True, 'random reason'),
102+
(False, None),
103+
])
104+
def test_get_parser_blacklist(monkeypatch, capsys, flagged):
105+
"""Make sure the blacklisting banner is shown."""
106+
def _mock_is_bl(*args, **kwargs):
107+
return flagged
108+
109+
monkeypatch.setattr(_version, 'is_flagged', _mock_is_bl)
110+
111+
_build_parser()
112+
captured = capsys.readouterr().err
113+
114+
assert ('FLAGGED' in captured) is flagged[0]
115+
if flagged[0]:
116+
assert ((flagged[1] or 'reason: unknown') in captured)

fmriprep/cli/tests/test_run.py

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)