Skip to content

Commit 151c325

Browse files
committed
debugged up python, workflow design unittests
1 parent 6ed002f commit 151c325

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

pydra/design/tests/test_python.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def func(a: int) -> float:
2323
outputs = sorted(list_fields(SampleDef.Outputs), key=sort_key)
2424
assert inputs == [
2525
python.arg(name="a", type=int),
26-
python.arg(name="function", type=ty.Callable, default=func),
26+
python.arg(name="function", type=ty.Callable, hash_eq=True, default=func),
2727
]
2828
assert outputs == [python.out(name="out", type=float)]
2929
definition = SampleDef(a=1)
@@ -45,7 +45,7 @@ def func(a: int, k: float = 2.0) -> float:
4545
outputs = sorted(list_fields(SampleDef.Outputs), key=sort_key)
4646
assert inputs == [
4747
python.arg(name="a", type=int),
48-
python.arg(name="function", type=ty.Callable, default=func),
48+
python.arg(name="function", type=ty.Callable, hash_eq=True, default=func),
4949
python.arg(name="k", type=float, default=2.0),
5050
]
5151
assert outputs == [python.out(name="out", type=float)]
@@ -69,7 +69,7 @@ def func(a: int) -> float:
6969
outputs = sorted(list_fields(SampleDef.Outputs), key=sort_key)
7070
assert inputs == [
7171
python.arg(name="a", type=int, help="The argument to be doubled"),
72-
python.arg(name="function", type=ty.Callable, default=func),
72+
python.arg(name="function", type=ty.Callable, hash_eq=True, default=func),
7373
]
7474
assert outputs == [
7575
python.out(name="b", type=Decimal, help="the doubled output"),
@@ -94,7 +94,7 @@ def func(a: int) -> int:
9494
outputs = sorted(list_fields(SampleDef.Outputs), key=sort_key)
9595
assert inputs == [
9696
python.arg(name="a", type=float),
97-
python.arg(name="function", type=ty.Callable, default=func),
97+
python.arg(name="function", type=ty.Callable, hash_eq=True, default=func),
9898
]
9999
assert outputs == [python.out(name="b", type=float)]
100100
intf = SampleDef(a=1)
@@ -118,6 +118,7 @@ def SampleDef(a: int, b: float) -> tuple[float, float]:
118118
python.arg(
119119
name="function",
120120
type=ty.Callable,
121+
hash_eq=True,
121122
default=attrs.fields(SampleDef).function.default,
122123
),
123124
]
@@ -149,6 +150,7 @@ def SampleDef(a: int, b: float) -> tuple[float, float]:
149150
python.arg(
150151
name="function",
151152
type=ty.Callable,
153+
hash_eq=True,
152154
default=attrs.fields(SampleDef).function.default,
153155
),
154156
]
@@ -183,6 +185,7 @@ def SampleDef(a: int, b: float) -> tuple[float, float]:
183185
python.arg(
184186
name="function",
185187
type=ty.Callable,
188+
hash_eq=True,
186189
default=attrs.fields(SampleDef).function.default,
187190
),
188191
]
@@ -225,6 +228,7 @@ def SampleDef(a: int, b: float) -> tuple[float, float]:
225228
python.arg(
226229
name="function",
227230
type=ty.Callable,
231+
hash_eq=True,
228232
default=attrs.fields(SampleDef).function.default,
229233
),
230234
]
@@ -272,6 +276,7 @@ def function(a, b):
272276
python.arg(
273277
name="function",
274278
type=ty.Callable,
279+
hash_eq=True,
275280
default=attrs.fields(SampleDef).function.default,
276281
),
277282
]
@@ -342,6 +347,7 @@ def function(a, b):
342347
python.arg(
343348
name="function",
344349
type=ty.Callable,
350+
hash_eq=True,
345351
default=attrs.fields(SampleDef).function.default,
346352
),
347353
]

pydra/design/tests/test_workflow.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ def MyTestWorkflow(a, b):
5757
assert list_fields(MyTestWorkflow) == [
5858
workflow.arg(name="a"),
5959
workflow.arg(name="b"),
60-
workflow.arg(name="constructor", type=ty.Callable, default=constructor),
60+
workflow.arg(
61+
name="constructor", type=ty.Callable, hash_eq=True, default=constructor
62+
),
6163
]
6264
assert list_fields(MyTestWorkflow.Outputs) == [
6365
workflow.out(name="out"),
@@ -108,7 +110,9 @@ def MyTestShellWorkflow(
108110
workflow.arg(name="input_video", type=video.Mp4),
109111
workflow.arg(name="watermark", type=image.Png),
110112
workflow.arg(name="watermark_dims", type=tuple[int, int], default=(10, 10)),
111-
workflow.arg(name="constructor", type=ty.Callable, default=constructor),
113+
workflow.arg(
114+
name="constructor", type=ty.Callable, hash_eq=True, default=constructor
115+
),
112116
]
113117
assert list_fields(MyTestShellWorkflow.Outputs) == [
114118
workflow.out(name="output_video", type=video.Mp4),
@@ -161,7 +165,9 @@ class Outputs(WorkflowOutputs):
161165
assert sorted(list_fields(MyTestWorkflow), key=attrgetter("name")) == [
162166
workflow.arg(name="a", type=int),
163167
workflow.arg(name="b", type=float, help="A float input", converter=a_converter),
164-
workflow.arg(name="constructor", type=ty.Callable, default=constructor),
168+
workflow.arg(
169+
name="constructor", type=ty.Callable, hash_eq=True, default=constructor
170+
),
165171
]
166172
assert list_fields(MyTestWorkflow.Outputs) == [
167173
workflow.out(name="out", type=float),
@@ -290,7 +296,10 @@ def MyTestWorkflow(a: int, b: float) -> tuple[float, float]:
290296
workflow.arg(name="a", type=int, help="An integer input"),
291297
workflow.arg(name="b", type=float, help="A float input"),
292298
workflow.arg(
293-
name="constructor", type=ty.Callable, default=MyTestWorkflow().constructor
299+
name="constructor",
300+
type=ty.Callable,
301+
hash_eq=True,
302+
default=MyTestWorkflow().constructor,
294303
),
295304
]
296305
assert list_fields(MyTestWorkflow.Outputs) == [
@@ -330,7 +339,10 @@ def MyTestWorkflow(a: int, b: float):
330339
workflow.arg(name="a", type=int),
331340
workflow.arg(name="b", type=float),
332341
workflow.arg(
333-
name="constructor", type=ty.Callable, default=MyTestWorkflow().constructor
342+
name="constructor",
343+
type=ty.Callable,
344+
hash_eq=True,
345+
default=MyTestWorkflow().constructor,
334346
),
335347
]
336348
assert list_fields(MyTestWorkflow.Outputs) == [

pydra/design/workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def make(wrapped: ty.Callable | type) -> TaskDef:
165165
)
166166

167167
parsed_inputs["constructor"] = arg(
168-
name="constructor", type=ty.Callable, default=constructor
168+
name="constructor", type=ty.Callable, hash_eq=True, default=constructor
169169
)
170170
for inpt_name in lazy:
171171
parsed_inputs[inpt_name].lazy = True

pydra/engine/specs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ def __iter__(self) -> ty.Generator[str, None, None]:
363363

364364
def __eq__(self, other: ty.Any) -> bool:
365365
"""Check if two task definitions are equal"""
366-
values = attrs.asdict(self)
366+
values = attrs.asdict(self, recurse=False)
367367
try:
368-
other_values = attrs.asdict(other)
368+
other_values = attrs.asdict(other, recurse=False)
369369
except AttributeError:
370370
return False
371371
if set(values) != set(other_values):

0 commit comments

Comments
 (0)