8000 moving tests with xor to test_shelltask_inputspec.py by djarecka · Pull Request #604 · nipype/pydra · GitHub
[go: up one dir, main page]

Skip to content

moving tests with xor to test_shelltask_inputspec.py #604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

moving tests with xor to test_shelltask_inputspec.py
  • Loading branch information
djarecka committed Dec 2, 2022
commit f74ee502f78d4daa029430476c16a44dc2bdcee6
102 changes: 102 additions & 0 deletions pydra/engine/tests/test_shelltask_inputspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2133,3 +2133,105 @@ def test_shell_cmd_inputs_di(tmpdir, use_validator):
image_dimensionality=5,
)
assert "value of image_dimensionality" in str(excinfo.value)


# tests with XOR in input metadata


class SimpleTaskXor(ShellCommandTask):
input_fields = [
(
"input_1",
str,
{
"help_string": "help",
"mandatory": True,
"xor": ("input_1", "input_2", "input_3"),
},
),
(
"input_2",
bool,
{
"help_string": "help",
"mandatory": True,
"argstr": "--i2",
"xor": ("input_1", "input_2", "input_3"),
},
),
(
"input_3",
bool,
{
"help_string": "help",
"mandatory": True,
"xor": ("input_1", "input_2", "input_3"),
},
),
]
task_input_spec = SpecInfo(name="Input", fields=input_fields, bases=(ShellSpec,))
task_output_fields = []
task_output_spec = SpecInfo(
name="Output", fields=task_output_fields, bases=(ShellOutSpec,)
)

input_spec = task_input_spec
output_spec = task_output_spec
executable = "cmd"


def test_task_inputs_mandatory_with_xOR_one_mandatory_is_OK():
"""input spec with mandatory inputs"""
task = SimpleTaskXor()
task.inputs.input_1 = "Input1"
task.inputs.input_2 = attr.NOTHING
task.inputs.check_fields_input_spec()


def test_task_inputs_mandatory_with_xOR_one_mandatory_out_3_is_OK():
"""input spec with mandatory inputs"""
task = SimpleTaskXor()
task.inputs.input_1 = attr.NOTHING
task.inputs.input_2 = attr.NOTHING
task.inputs.input_3 = True
task.inputs.check_fields_input_spec()


def test_task_inputs_mandatory_with_xOR_zero_mandatory_raises_error():
"""input spec with mandatory inputs"""
task = SimpleTaskXor()
task.inputs.input_1 = attr.NOTHING
task.inputs.input_2 = attr.NOTHING
with pytest.raises(Exception) as excinfo:
task.inputs.check_fields_input_spec()
assert "input_1 is mandatory, but no value provided" in str(excinfo.value)
assert excinfo.type is AttributeError


def test_task_inputs_mandatory_with_xOR_two_mandatories_raises_error():
"""input spec with mandatory inputs"""
task = SimpleTaskXor()
task.inputs.input_1 = "Input1"
task.inputs.input_2 = True

with pytest.raises(Exception) as excinfo:
task.inputs.check_fields_input_spec()
assert "input_2 is mutually exclusive with ('input_1', 'input_2'" in str(
excinfo.value
)
assert excinfo.type is AttributeError


def test_task_inputs_mandatory_with_xOR_3_mandatories_raises_error():
"""input spec with mandatory inputs"""
task = SimpleTaskXor()
task.inputs.input_1 = "Input1"
task.inputs.input_2 = True
task.inputs.input_3 = False

with pytest.raises(Exception) as excinfo:
task.inputs.check_fields_input_spec()
assert "input_2 is mutually exclusive with ('input_1', 'input_2', 'input_3'" in str(
excinfo.value
)
assert excinfo.type is AttributeError
102 changes: 0 additions & 102 deletions pydra/engine/tests/test_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@
DockerSpec,
SingularitySpec,
LazyField,
ShellOutSpec,
)
from ..task import TaskBase, ShellCommandTask
from ..helpers import make_klass
import pytest
import attr


def test_basespec():
Expand Down Expand Up @@ -369,102 +366,3 @@ def test_input_file_hash_5(tmpdir):
f.write("hi")
hash3 = inputs(in_file=[{"file": file_diffcontent, "int": 3}]).hash
assert hash1 != hash3


class SimpleTask(ShellCommandTask):
input_fields = [
(
"input_1",
str,
{
"help_string": "help",
"mandatory": True,
"xor": ("input_1", "input_2", "input_3"),
},
),
(
"input_2",
bool,
{
"help_string": "help",
"mandatory": True,
"argstr": "--i2",
"xor": ("input_1", "input_2", "input_3"),
},
),
(
"input_3",
bool,
{
"help_string": "help",
"mandatory": True,
"xor": ("input_1", "input_2", "input_3"),
},
),
]
task_input_spec = SpecInfo(name="Input", fields=input_fields, bases=(ShellSpec,))
task_output_fields = []
task_output_spec = SpecInfo(
name="Output", fields=task_output_fields, bases=(ShellOutSpec,)
)

input_spec = task_input_spec
output_spec = task_output_spec
executable = "cmd"


def test_task_inputs_mandatory_with_xOR_one_mandatory_is_OK():
"""input spec with mandatory inputs"""
task = SimpleTask()
task.inputs.input_1 = "Input1"
task.inputs.input_2 = attr.NOTHING
task.inputs.check_fields_input_spec()


def test_task_inputs_mandatory_with_xOR_one_mandatory_out_3_is_OK():
"""input spec with mandatory inputs"""
task = SimpleTask()
task.inputs.input_1 = attr.NOTHING
task.inputs.input_2 = attr.NOTHING
task.inputs.input_3 = True
task.inputs.check_fields_input_spec()


def test_task_inputs_mandatory_with_xOR_zero_mandatory_raises_error():
"""input spec with mandatory inputs"""
task = SimpleTask()
task.inputs.input_1 = attr.NOTHING
task.inputs.input_2 = attr.NOTHING
with pytest.raises(Exception) as excinfo:
task.inputs.check_fields_input_spec()
assert "input_1 is mandatory, but no value provided" in str(excinfo.value)
assert excinfo.type is AttributeError


def test_task_inputs_mandatory_with_xOR_two_mandatories_raises_error():
"""input spec with mandatory inputs"""
task = SimpleTask()
task.inputs.input_1 = "Input1"
task.inputs.input_2 = True

with pytest.raises(Exception) as excinfo:
task.inputs.check_fields_input_spec()
assert "input_2 is mutually exclusive with ('input_1', 'input_2'" in str(
excinfo.value
)
assert excinfo.type is AttributeError


def test_task_inputs_mandatory_with_xOR_3_mandatories_raises_error():
"""input spec with mandatory inputs"""
task = SimpleTask()
task.inputs.input_1 = "Input1"
task.inputs.input_2 = True
task.inputs.input_3 = False

with pytest.raises(Exception) as excinfo:
task.inputs.check_fields_input_spec()
assert "input_2 is mutually exclusive with ('input_1', 'input_2', 'input_3'" in str(
excinfo.value
)
assert excinfo.type is AttributeError
0