Skip to content

Commit 5e0c249

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a2da63c commit 5e0c249

File tree

2 files changed

+56
-45
lines changed

2 files changed

+56
-45
lines changed

pydra/engine/specs.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,17 @@ def check_fields_input_spec(self):
162162
mdata = fld.metadata
163163
# checking if the mandatory field is provided
164164
if getattr(self, fld.name) is attr.NOTHING:
165-
if mdata.get("mandatory"):
165+
if mdata.get("mandatory"):
166166
# checking if the mandatory field is provided elsewhere in the xor list
167167
in_exclusion_list = mdata.get("xor") is not None
168-
alreday_populated = in_exclusion_list and [getattr(self, el) for el in mdata["xor"] if (getattr(self, el) is not attr.NOTHING)]
169-
if alreday_populated: #another input satisfies mandatory attribute via xor condition
168+
alreday_populated = in_exclusion_list and [
169+
getattr(self, el)
170+
for el in mdata["xor"]
171+
if (getattr(self, el) is not attr.NOTHING)
172+
]
173+
if (
174+
alreday_populated
175+
): # another input satisfies mandatory attribute via xor condition
170176
continue
171177
else:
172178
raise AttributeError(

pydra/engine/tests/test_specs.py

+47-42
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
LazyField,
1717
ShellOutSpec,
1818
)
19-
from ..task import (
20-
TaskBase,
21-
ShellCommandTask
22-
)
19+
from ..task import TaskBase, ShellCommandTask
2320
from ..helpers import make_klass
2421
import pytest
2522
import attr
2623

24+
2725
def test_basespec():
2826
spec = BaseSpec()
2927
assert (
@@ -372,40 +370,43 @@ def test_input_file_hash_5(tmpdir):
372370
hash3 = inputs(in_file=[{"file": file_diffcontent, "int": 3}]).hash
373371
assert hash1 != hash3
374372

373+
375374
class SimpleTask(ShellCommandTask):
376-
input_fields=[
377-
(
378-
"input_1",
379-
str,
380-
{
381-
"help_string": "help",
382-
"mandatory": True,
383-
"xor": ("input_1", "input_2", "input_3"),
384-
}
385-
),
386-
(
387-
"input_2",
388-
bool,
389-
{
390-
"help_string": "help",
391-
"mandatory": True,
392-
"argstr": "--i2",
393-
"xor": ("input_1", "input_2", "input_3"),
394-
}
395-
),
396-
(
397-
"input_3",
398-
bool,
399-
{
400-
"help_string": "help",
401-
"mandatory": True,
402-
"xor": ("input_1", "input_2", "input_3"),
403-
}
404-
)
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+
),
405404
]
406405
task_input_spec = SpecInfo(name="Input", fields=input_fields, bases=(ShellSpec,))
407406
task_output_fields = []
408-
task_output_spec = SpecInfo(name="Output", fields=task_output_fields, bases=(ShellOutSpec,))
407+
task_output_spec = SpecInfo(
408+
name="Output", fields=task_output_fields, bases=(ShellOutSpec,)
409+
)
409410

410411
input_spec = task_input_spec
411412
output_spec = task_output_spec
@@ -415,7 +416,7 @@ class SimpleTask(ShellCommandTask):
415416
def test_task_inputs_mandatory_with_xOR_one_mandatory_is_OK():
416417
"""input spec with mandatory inputs"""
417418
task = SimpleTask()
418-
task.inputs.input_1 = 'Input1'
419+
task.inputs.input_1 = "Input1"
419420
task.inputs.input_2 = attr.NOTHING
420421
task.inputs.check_fields_input_spec()
421422

@@ -443,23 +444,27 @@ def test_task_inputs_mandatory_with_xOR_zero_mandatory_raises_error():
443444
def test_task_inputs_mandatory_with_xOR_two_mandatories_raises_error():
444445
"""input spec with mandatory inputs"""
445446
task = SimpleTask()
446-
task.inputs.input_1 = 'Input1'
447+
task.inputs.input_1 = "Input1"
447448
task.inputs.input_2 = True
448-
449+
449450
with pytest.raises(Exception) as excinfo:
450451
task.inputs.check_fields_input_spec()
451-
assert "input_2 is mutually exclusive with ('input_1', 'input_2'" in str(excinfo.value)
452+
assert "input_2 is mutually exclusive with ('input_1', 'input_2'" in str(
453+
excinfo.value
454+
)
452455
assert excinfo.type is AttributeError
453456

454457

455458
def test_task_inputs_mandatory_with_xOR_3_mandatories_raises_error():
456459
"""input spec with mandatory inputs"""
457460
task = SimpleTask()
458-
task.inputs.input_1 = 'Input1'
461+
task.inputs.input_1 = "Input1"
459462
task.inputs.input_2 = True
460463
task.inputs.input_3 = False
461-
464+
462465
with pytest.raises(Exception) as excinfo:
463466
task.inputs.check_fields_input_spec()
464-
assert "input_2 is mutually exclusive with ('input_1', 'input_2', 'input_3'" in str(excinfo.value)
465-
assert excinfo.type is AttributeError
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)