|
3 | 3 | # vi: set ft=python sts=4 ts=4 sw=4 et:
|
4 | 4 | import os
|
5 | 5 | import simplejson as json
|
| 6 | +import logging |
6 | 7 |
|
7 | 8 | import pytest
|
8 | 9 | from unittest import mock
|
@@ -236,6 +237,41 @@ class DerivedInterface1(nib.BaseInterface):
|
236 | 237 | obj._check_version_requirements(obj.inputs)
|
237 | 238 |
|
238 | 239 |
|
| 240 | +def test_input_version_missing(caplog): |
| 241 | + class DerivedInterface(nib.BaseInterface): |
| 242 | + class input_spec(nib.TraitedSpec): |
| 243 | + foo = nib.traits.Int(min_ver="0.9") |
| 244 | + bar = nib.traits.Int(max_ver="0.9") |
| 245 | + |
| 246 | + _version = "misparsed-garbage" |
| 247 | + |
| 248 | + obj = DerivedInterface() |
| 249 | + obj.inputs.foo = 1 |
| 250 | + obj.inputs.bar = 1 |
| 251 | + with caplog.at_level(logging.WARNING, logger="nipype.interface"): |
| 252 | + obj._check_version_requirements(obj.inputs) |
| 253 | + assert len(caplog.records) == 2 |
| 254 | + |
| 255 | + |
| 256 | +def test_input_version_missing_error(): |
| 257 | + from nipype import config |
| 258 | + |
| 259 | + class DerivedInterface(nib.BaseInterface): |
| 260 | + class input_spec(nib.TraitedSpec): |
| 261 | + foo = nib.traits.Int(min_ver="0.9") |
| 262 | + bar = nib.traits.Int(max_ver="0.9") |
| 263 | + |
| 264 | + _version = "misparsed-garbage" |
| 265 | + |
| 266 | + with mock.patch.object(config, "getboolean", return_value=True): |
| 267 | + obj = DerivedInterface(foo=1) |
| 268 | + with pytest.raises(ValueError): |
| 269 | + obj._check_version_requirements(obj.inputs) |
| 270 | + obj = DerivedInterface(bar=1) |
| 271 | + with pytest.raises(ValueError): |
| 272 | + obj._check_version_requirements(obj.inputs) |
| 273 | + |
| 274 | + |
239 | 275 | def test_output_version():
|
240 | 276 | class InputSpec(nib.TraitedSpec):
|
241 | 277 | foo = nib.traits.Int(desc="a random int")
|
@@ -457,7 +493,7 @@ def test_global_CommandLine_output(tmpdir):
|
457 | 493 | ci = BET()
|
458 | 494 | assert ci.terminal_output == "stream" # default case
|
459 | 495 |
|
460 |
| - with mock.patch.object(nib.CommandLine, '_terminal_output'): |
| 496 | + with mock.patch.object(nib.CommandLine, "_terminal_output"): |
461 | 497 | nib.CommandLine.set_default_terminal_output("allatonce")
|
462 | 498 | ci = nib.CommandLine(command="ls -l")
|
463 | 499 | assert ci.terminal_output == "allatonce"
|
|
0 commit comments