Skip to content

Commit 51872bb

Browse files
committed
fixed up unittests to match slightly more expressive error messages
1 parent f10bfdb commit 51872bb

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

pydra/engine/specs.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ def check_metadata(self):
294294
# not allowing for default if the field is mandatory
295295
if not fld.default == attr.NOTHING and mdata.get("mandatory"):
296296
raise AttributeError(
297-
"default value should not be set when the field is mandatory"
297+
f"default value ({fld.default!r}) should not be set when the field "
298+
f"('{fld.name}') in {self}) is mandatory"
298299
)
299300
# setting default if value not provided and default is available
300301
if getattr(self, fld.name) is None:
@@ -385,19 +386,19 @@ def check_metadata(self):
385386
raise TypeError(
386387
f"Type of '{fld.name}' should be either pathlib.Path or "
387388
f"typing.Union[pathlib.Path, bool] (not {fld.type}) because "
388-
f"it has a value for output_file_template ({mdata['output_file_template']})"
389+
f"it has a value for output_file_template ({mdata['output_file_template']!r})"
389390
)
390391
if fld.default not in [attr.NOTHING, True, False]:
391392
raise AttributeError(
392-
f"default value ({fld.default}) should not be set together with "
393-
f"output_file_template ({mdata['output_file_template']}) for "
393+
f"default value ({fld.default!r}) should not be set together with "
394+
f"output_file_template ({mdata['output_file_template']!r}) for "
394395
f"'{fld.name}' field in {self}"
395396
)
396397
# not allowing for default if the field is mandatory
397398
if not fld.default == attr.NOTHING and mdata.get("mandatory"):
398399
raise AttributeError(
399-
f"default value ({fld.default}) should not be set when the field "
400-
f"('{fld.name}' in {self}) is mandatory"
400+
f"default value ({fld.default!r}) should not be set when the field "
401+
f"('{fld.name}') in {self}) is mandatory"
401402
)
402403
# setting default if value not provided and default is available
403404
if getattr(self, fld.name) is None:

pydra/engine/tests/test_shelltask.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -648,12 +648,10 @@ def test_shell_cmd_inputspec_4c_exception(plugin):
648648
)
649649

650650
# separate command into exec + args
651-
with pytest.raises(Exception) as excinfo:
651+
with pytest.raises(
652+
Exception, match="default value \('Hello'\) should not be set when the field"
653+
):
652654
ShellCommandTask(name="shelly", executable=cmd_exec, input_spec=my_input_spec)
653-
assert (
654-
str(excinfo.value)
655-
== "default value should not be set when the field is mandatory"
656-
)
657655

658656

659657
def test_shell_cmd_inputspec_4d_exception(plugin):
@@ -680,12 +678,10 @@ def test_shell_cmd_inputspec_4d_exception(plugin):
680678
)
681679

682680
# separate command into exec + args
683-
with pytest.raises(Exception) as excinfo:
681+
with pytest.raises(
682+
Exception, match="default value \('Hello'\) should not be set together"
683+
) as excinfo:
684684
ShellCommandTask(name="shelly", executable=cmd_exec, input_spec=my_input_spec)
685-
assert (
686-
str(excinfo.value)
687-
== "default value should not be set together with output_file_template"
688-
)
689685

690686

691687
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])

0 commit comments

Comments
 (0)