A code-declared node's shim names only its triggering ports, so a non-triggering input with no value yet reaches the function as its own default instead of failing the call
This commit is contained in:
@@ -240,6 +240,28 @@ def test_a_port_named_like_its_function_still_calls_the_function():
|
||||
assert namespace["process"](scale=2.0) == {"scaled": 4.0}
|
||||
|
||||
|
||||
@node(
|
||||
requires=["value", Port("factor", "float", trigger=False)],
|
||||
provides=Port("scaled", "float"),
|
||||
)
|
||||
def scale_by(value, factor=3.0):
|
||||
return value * factor
|
||||
|
||||
|
||||
def test_a_port_that_does_not_trigger_may_be_missing_from_the_call():
|
||||
"""The engine leaves out an input with no value yet, so the default applies."""
|
||||
flow = Flow(
|
||||
"optional",
|
||||
nodes=[scale_by],
|
||||
inputs=[Port("value", "float", initial=1.0), Port("factor", "float")],
|
||||
)
|
||||
namespace: dict = {}
|
||||
exec(compile(flow.shims()["scale_by"], "<shim>", "exec"), namespace)
|
||||
|
||||
assert namespace["process"](value=2.0) == {"scaled": 6.0}
|
||||
assert namespace["process"](value=2.0, factor=0.5) == {"scaled": 1.0}
|
||||
|
||||
|
||||
def reads_settings(settings):
|
||||
return settings
|
||||
|
||||
|
||||
Reference in New Issue
Block a user