Skip to content

Commit 090baa5

Browse files
committed
debugged 'xor' arg attribute
1 parent b33bbdf commit 090baa5

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

pydra/engine/specs.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -504,17 +504,14 @@ def _rule_violations(self) -> list[str]:
504504
# Collect alternative fields associated with this field.
505505
if field.xor:
506506
mutually_exclusive = {name: self[name] for name in field.xor}
507-
are_set = [
508-
f"{n}={v!r}" for n, v in mutually_exclusive.items() if is_set(v)
509-
]
507+
are_set = [f"{n}={v!r}" for n, v in mutually_exclusive.items() if v]
510508
if len(are_set) > 1:
511509
errors.append(
512-
f"Mutually exclusive fields {field.xor} are set together: "
513-
+ ", ".join(are_set)
510+
f"Mutually exclusive fields ({', '.join(are_set)}) are set together"
514511
)
515-
elif field.mandatory and not are_set:
512+
elif not are_set:
516513
errors.append(
517-
f"At least one of the mutually exclusive fields {field.xor} "
514+
f"At least one of the mutually exclusive fields ({', '.join(field.xor)}) "
518515
f"should be set"
519516
)
520517

pydra/engine/tests/test_shelltask_inputspec.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,16 +1453,19 @@ class Outputs(ShellOutputs):
14531453
@shell.define
14541454
class SimpleXor(ShellDef["SimpleTaskXor.Outputs"]):
14551455

1456-
input_1: str = shell.arg(
1456+
input_1: str | None = shell.arg(
1457+
default=None,
14571458
help="help",
14581459
xor=("input_1", "input_2", "input_3"),
14591460
)
1460-
input_2: bool = shell.arg(
1461+
input_2: bool | None = shell.arg(
1462+
default=None,
14611463
help="help",
14621464
argstr="--i2",
14631465
xor=("input_1", "input_2", "input_3"),
14641466
)
1465-
input_3: bool = shell.arg(
1467+
input_3: bool | None = shell.arg(
1468+
default=None,
14661469
help="help",
14671470
xor=("input_1", "input_2", "input_3"),
14681471
)
@@ -1478,29 +1481,24 @@ def test_task_inputs_mandatory_with_xOR_one_mandatory_is_OK():
14781481
"""input definition with mandatory inputs"""
14791482
simple_xor = SimpleXor()
14801483
simple_xor.input_1 = "Input1"
1481-
simple_xor.input_2 = attrs.NOTHING
14821484
simple_xor._check_rules()
14831485

14841486

14851487
def test_task_inputs_mandatory_with_xOR_one_mandatory_out_3_is_OK():
14861488
"""input definition with mandatory inputs"""
14871489
simple_xor = SimpleXor()
1488-
simple_xor.input_1 = attrs.NOTHING
1489-
simple_xor.input_2 = attrs.NOTHING
14901490
simple_xor.input_3 = True
14911491
simple_xor._check_rules()
14921492

14931493

14941494
def test_task_inputs_mandatory_with_xOR_zero_mandatory_raises_error():
14951495
"""input definition with mandatory inputs"""
14961496
simple_xor = SimpleXor()
1497-
simple_xor.input_1 = attrs.NOTHING
1498-
simple_xor.input_2 = attrs.NOTHING
1499-
with pytest.raises(Exception) as excinfo:
1497+
simple_xor.input_2 = False
1498+
with pytest.raises(
1499+
ValueError, match="At least one of the mutually exclusive fields"
1500+
):
15001501
simple_xor._check_rules()
1501-
assert "input_1 is mandatory" in str(excinfo.value)
1502-
assert "no alternative provided by ['input_2', 'input_3']" in str(excinfo.value)
1503-
assert excinfo.type is AttributeError
15041502

15051503

15061504
def test_task_inputs_mandatory_with_xOR_two_mandatories_raises_error():
@@ -1509,10 +1507,10 @@ def test_task_inputs_mandatory_with_xOR_two_mandatories_raises_error():
15091507
simple_xor.input_1 = "Input1"
15101508
simple_xor.input_2 = True
15111509

1512-
with pytest.raises(Exception) as excinfo:
1510+
with pytest.raises(
1511+
ValueError, match="Mutually exclusive fields .* are set together"
1512+
):
15131513
simple_xor._check_rules()
1514-
assert "input_1 is mutually exclusive with ['input_2']" in str(excinfo.value)
1515-
assert excinfo.type is AttributeError
15161514

15171515

15181516
def test_task_inputs_mandatory_with_xOR_3_mandatories_raises_error():
@@ -1522,9 +1520,8 @@ def test_task_inputs_mandatory_with_xOR_3_mandatories_raises_error():
15221520
simple_xor.input_2 = True
15231521
simple_xor.input_3 = False
15241522

1525-
with pytest.raises(Exception) as excinfo:
1523+
with pytest.raises(
1524+
ValueError,
1525+
match=r".*Mutually exclusive fields \(input_1='Input1', input_2=True\) are set together",
1526+
):
15261527
simple_xor._check_rules()
1527-
assert "input_1 is mutually exclusive with ['input_2', 'input_3']" in str(
1528-
excinfo.value
1529-
)
1530-
assert excinfo.type is AttributeError

0 commit comments

Comments
 (0)