Skip to content

Commit

Permalink
Merge pull request #604 from djarecka/move_tests
Browse files Browse the repository at this point in the history
moving tests with xor to test_shelltask_inputspec.py
  • Loading branch information
djarecka authored Dec 2, 2022
2 parents 68cfa5d + f74ee50 commit e27886d
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 102 deletions.
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 comments on commit e27886d

Please sign in to comment.