Skip to content

Commit e27886d

Browse files
authored
Merge pull request #604 from djarecka/move_tests
moving tests with xor to test_shelltask_inputspec.py
2 parents 68cfa5d + f74ee50 commit e27886d

File tree

2 files changed

+102
-102
lines changed

2 files changed

+102
-102
lines changed

pydra/engine/tests/test_shelltask_inputspec.py

+102
Original file line numberDiff line numberDiff line change
@@ -2133,3 +2133,105 @@ def test_shell_cmd_inputs_di(tmpdir, use_validator):
21332133
image_dimensionality=5,
21342134
)
21352135
assert "value of image_dimensionality" in str(excinfo.value)
2136+
2137+
2138+
# tests with XOR in input metadata
2139+
2140+
2141+
class SimpleTaskXor(ShellCommandTask):
2142+
input_fields = [
2143+
(
2144+
"input_1",
2145+
str,
2146+
{
2147+
"help_string": "help",
2148+
"mandatory": True,
2149+
"xor": ("input_1", "input_2", "input_3"),
2150+
},
2151+
),
2152+
(
2153+
"input_2",
2154+
bool,
2155+
{
2156+
"help_string": "help",
2157+
"mandatory": True,
2158+
"argstr": "--i2",
2159+
"xor": ("input_1", "input_2", "input_3"),
2160+
},
2161+
),
2162+
(
2163+
"input_3",
2164+
bool,
2165+
{
2166+
"help_string": "help",
2167+
"mandatory": True,
2168+
"xor": ("input_1", "input_2", "input_3"),
2169+
},
2170+
),
2171+
]
2172+
task_input_spec = SpecInfo(name="Input", fields=input_fields, bases=(ShellSpec,))
2173+
task_output_fields = []
2174+
task_output_spec = SpecInfo(
2175+
name="Output", fields=task_output_fields, bases=(ShellOutSpec,)
2176+
)
2177+
2178+
input_spec = task_input_spec
2179+
output_spec = task_output_spec
2180+
executable = "cmd"
2181+
2182+
2183+
def test_task_inputs_mandatory_with_xOR_one_mandatory_is_OK():
2184+
"""input spec with mandatory inputs"""
2185+
task = SimpleTaskXor()
2186+
task.inputs.input_1 = "Input1"
2187+
task.inputs.input_2 = attr.NOTHING
2188+
task.inputs.check_fields_input_spec()
2189+
2190+
2191+
def test_task_inputs_mandatory_with_xOR_one_mandatory_out_3_is_OK():
2192+
"""input spec with mandatory inputs"""
2193+
task = SimpleTaskXor()
2194+
task.inputs.input_1 = attr.NOTHING
2195+
task.inputs.input_2 = attr.NOTHING
2196+
task.inputs.input_3 = True
2197+
task.inputs.check_fields_input_spec()
2198+
2199+
2200+
def test_task_inputs_mandatory_with_xOR_zero_mandatory_raises_error():
2201+
"""input spec with mandatory inputs"""
2202+
task = SimpleTaskXor()
2203+
task.inputs.input_1 = attr.NOTHING
2204+
task.inputs.input_2 = attr.NOTHING
2205+
with pytest.raises(Exception) as excinfo:
2206+
task.inputs.check_fields_input_spec()
2207+
assert "input_1 is mandatory, but no value provided" in str(excinfo.value)
2208+
assert excinfo.type is AttributeError
2209+
2210+
2211+
def test_task_inputs_mandatory_with_xOR_two_mandatories_raises_error():
2212+
"""input spec with mandatory inputs"""
2213+
task = SimpleTaskXor()
2214+
task.inputs.input_1 = "Input1"
2215+
task.inputs.input_2 = True
2216+
2217+
with pytest.raises(Exception) as excinfo:
2218+
task.inputs.check_fields_input_spec()
2219+
assert "input_2 is mutually exclusive with ('input_1', 'input_2'" in str(
2220+
excinfo.value
2221+
)
2222+
assert excinfo.type is AttributeError
2223+
2224+
2225+
def test_task_inputs_mandatory_with_xOR_3_mandatories_raises_error():
2226+
"""input spec with mandatory inputs"""
2227+
task = SimpleTaskXor()
2228+
task.inputs.input_1 = "Input1"
2229+
task.inputs.input_2 = True
2230+
task.inputs.input_3 = False
2231+
2232+
with pytest.raises(Exception) as excinfo:
2233+
task.inputs.check_fields_input_spec()
2234+
assert "input_2 is mutually exclusive with ('input_1', 'input_2', 'input_3'" in str(
2235+
excinfo.value
2236+
)
2237+
assert excinfo.type is AttributeError

pydra/engine/tests/test_specs.py

-102
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@
1414
DockerSpec,
1515
SingularitySpec,
1616
LazyField,
17-
ShellOutSpec,
1817
)
19-
from ..task import TaskBase, ShellCommandTask
2018
from ..helpers import make_klass
2119
import pytest
22-
import attr
2320

2421

2522
def test_basespec():
@@ -369,102 +366,3 @@ def test_input_file_hash_5(tmpdir):
369366
f.write("hi")
370367
hash3 = inputs(in_file=[{"file": file_diffcontent, "int": 3}]).hash
371368
assert hash1 != hash3
372-
373-
374-
class SimpleTask(ShellCommandTask):
375-
input_fields = [
376-
(
377-
"input_1",
378-
str,
379-
{
380-
"help_string": "help",
381-
"mandatory": True,
382-
"xor": ("input_1", "input_2", "input_3"),
383-
},
384-
),
385-
(
386-
"input_2",
387-
bool,
388-
{
389-
"help_string": "help",
390-
"mandatory": True,
391-
"argstr": "--i2",
392-
"xor": ("input_1", "input_2", "input_3"),
393-
},
394-
),
395-
(
396-
"input_3",
397-
bool,
398-
{
399-
"help_string": "help",
400-
"mandatory": True,
401-
"xor": ("input_1", "input_2", "input_3"),
402-
},
403-
),
404-
]
405-
task_input_spec = SpecInfo(name="Input", fields=input_fields, bases=(ShellSpec,))
406-
task_output_fields = []
407-
task_output_spec = SpecInfo(
408-
name="Output", fields=task_output_fields, bases=(ShellOutSpec,)
409-
)
410-
411-
input_spec = task_input_spec
412-
output_spec = task_output_spec
413-
executable = "cmd"
414-
415-
416-
def test_task_inputs_mandatory_with_xOR_one_mandatory_is_OK():
417-
"""input spec with mandatory inputs"""
418-
task = SimpleTask()
419-
task.inputs.input_1 = "Input1"
420-
task.inputs.input_2 = attr.NOTHING
421-
task.inputs.check_fields_input_spec()
422-
423-
424-
def test_task_inputs_mandatory_with_xOR_one_mandatory_out_3_is_OK():
425-
"""input spec with mandatory inputs"""
426-
task = SimpleTask()
427-
task.inputs.input_1 = attr.NOTHING
428-
task.inputs.input_2 = attr.NOTHING
429-
task.inputs.input_3 = True
430-
task.inputs.check_fields_input_spec()
431-
432-
433-
def test_task_inputs_mandatory_with_xOR_zero_mandatory_raises_error():
434-
"""input spec with mandatory inputs"""
435-
task = SimpleTask()
436-
task.inputs.input_1 = attr.NOTHING
437-
task.inputs.input_2 = attr.NOTHING
438-
with pytest.raises(Exception) as excinfo:
439-
task.inputs.check_fields_input_spec()
440-
assert "input_1 is mandatory, but no value provided" in str(excinfo.value)
441-
assert excinfo.type is AttributeError
442-
443-
444-
def test_task_inputs_mandatory_with_xOR_two_mandatories_raises_error():
445-
"""input spec with mandatory inputs"""
446-
task = SimpleTask()
447-
task.inputs.input_1 = "Input1"
448-
task.inputs.input_2 = True
449-
450-
with pytest.raises(Exception) as excinfo:
451-
task.inputs.check_fields_input_spec()
452-
assert "input_2 is mutually exclusive with ('input_1', 'input_2'" in str(
453-
excinfo.value
454-
)
455-
assert excinfo.type is AttributeError
456-
457-
458-
def test_task_inputs_mandatory_with_xOR_3_mandatories_raises_error():
459-
"""input spec with mandatory inputs"""
460-
task = SimpleTask()
461-
task.inputs.input_1 = "Input1"
462-
task.inputs.input_2 = True
463-
task.inputs.input_3 = False
464-
465-
with pytest.raises(Exception) as excinfo:
466-
task.inputs.check_fields_input_spec()
467-
assert "input_2 is mutually exclusive with ('input_1', 'input_2', 'input_3'" in str(
468-
excinfo.value
469-
)
470-
assert excinfo.type is AttributeError

0 commit comments

Comments
 (0)