|
1 | 1 | """Test parser."""
|
| 2 | +from packaging.version import Version |
2 | 3 | import pytest
|
3 | 4 | from ..parser import _build_parser
|
| 5 | +from .. import version as _version |
| 6 | +from ... import config |
4 | 7 |
|
5 | 8 | MIN_ARGS = ['data/', 'out/', 'participant']
|
6 | 9 |
|
@@ -66,3 +69,48 @@ def test_memory_arg(tmp_path, argval, gb):
|
66 | 69 | opts = _build_parser().parse_args(args)
|
67 | 70 |
|
68 | 71 | 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) |
0 commit comments