Skip to content

Commit 63399a9

Browse files
committed
Refactor test
1 parent c91b453 commit 63399a9

File tree

1 file changed

+21
-40
lines changed

1 file changed

+21
-40
lines changed

pydra/engine/tests/test_specs.py

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,7 @@ def test_input_file_hash_5(tmpdir):
372372
hash3 = inputs(in_file=[{"file": file_diffcontent, "int": 3}]).hash
373373
assert hash1 != hash3
374374

375-
376-
377-
def test_task_inputs_mandatory_with_xOR_TF():
378-
"""input spec with mandatory inputs"""
375+
class SimpleTask(ShellCommandTask):
379376
input_fields=[
380377
(
381378
"input_1",
@@ -401,49 +398,33 @@ def test_task_inputs_mandatory_with_xOR_TF():
401398
task_output_fields = []
402399
task_output_spec = SpecInfo(name="Output", fields=task_output_fields, bases=(ShellOutSpec,))
403400

404-
class MyTask(ShellCommandTask):
405-
input_spec = task_input_spec
406-
output_spec = task_output_spec
407-
executable = "cmd"
401+
input_spec = task_input_spec
402+
output_spec = task_output_spec
403+
executable = "cmd"
408404

409-
task = MyTask()
405+
406+
def test_task_inputs_mandatory_with_xOR_one_mandatory_is_enough():
407+
"""input spec with mandatory inputs"""
408+
task = SimpleTask()
410409
task.inputs.input_1 = True
411410
task.inputs.input_2 = attr.NOTHING
412411
task.inputs.check_fields_input_spec()
413412

414-
def test_task_inputs_mandatory_with_xOR_TT():
413+
def test_task_inputs_mandatory_with_xOR_zero_mandatory_raises_error():
415414
"""input spec with mandatory inputs"""
416-
input_fields=[
417-
(
418-
"input_1",
419-
bool,
420-
{
421-
"help_string": "help",
422-
"mandatory": True,
423-
"xor": ("input_1", "input_2"),
424-
}
425-
),
426-
(
427-
"input_2",
428-
bool,
429-
{
430-
"help_string": "help",
431-
"mandatory": True,
432-
"argstr": "--i2",
433-
"xor": ("input_1", "input_2"),
434-
}
435-
)
436-
]
437-
task_input_spec = SpecInfo(name="Input", fields=input_fields, bases=(ShellSpec,))
438-
task_output_fields = []
439-
task_output_spec = SpecInfo(name="Output", fields=task_output_fields, bases=(ShellOutSpec,))
415+
task = SimpleTask()
416+
task.inputs.input_1 = attr.NOTHING
417+
task.inputs.input_2 = attr.NOTHING
418+
task.inputs.check_fields_input_spec()
440419

441-
class MyTask(ShellCommandTask):
442-
input_spec = task_input_spec
443-
output_spec = task_output_spec
444-
executable = "cmd"
445420

446-
task = MyTask()
421+
def test_task_inputs_mandatory_with_xOR_two_mandatories_raises_error():
422+
"""input spec with mandatory inputs"""
423+
task = SimpleTask()
447424
task.inputs.input_1 = True
448425
task.inputs.input_2 = True
449-
task.inputs.check_fields_input_spec()
426+
427+
with pytest.raises(Exception) as excinfo:
428+
task.inputs.check_fields_input_spec()
429+
assert "input_2 is mutually exclusive with ('input_1', 'input_2')" in str(excinfo.value)
430+
assert excinfo.type is AttributeError

0 commit comments

Comments
 (0)