Skip to content

Commit 00fe598

Browse files
feat: add test for Operator.id
1 parent 7414859 commit 00fe598

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

src/ansys/dpf/core/dpf_operator.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def progress_bar(self) -> bool:
242242
def progress_bar(self, value: bool) -> None:
243243
self._progress_bar = value
244244

245-
def connect(self, pin, inpt, pin_out=0, operator_as_input=False):
245+
def connect(self, pin, inpt, pin_out=0):
246246
"""Connect an input on the operator using a pin number.
247247
248248
Parameters
@@ -276,10 +276,7 @@ def connect(self, pin, inpt, pin_out=0, operator_as_input=False):
276276
if inpt is self:
277277
raise ValueError("Cannot connect to itself.")
278278
elif isinstance(inpt, Operator):
279-
if operator_as_input:
280-
self._api.operator_connect_operator_as_input(self, pin, inpt)
281-
else:
282-
self._api.operator_connect_operator_output(self, pin, inpt, pin_out)
279+
self._api.operator_connect_operator_output(self, pin, inpt, pin_out)
283280
elif isinstance(inpt, Output):
284281
self._api.operator_connect_operator_output(self, pin, inpt._operator, inpt._pin)
285282
elif isinstance(inpt, list):
@@ -664,8 +661,8 @@ def config(self, value):
664661
@property
665662
def id(self):
666663
if self._id is None:
667-
operator_id_op = Operator("operator_id")
668-
operator_id_op.inputs.operator.connect(self, operator_as_input=True)
664+
operator_id_op = Operator("operator_id", server=self._server)
665+
operator_id_op.connect_operator_as_input(0, self)
669666
self._id = operator_id_op.outputs.id()
670667

671668
return self._id

src/ansys/dpf/core/inputs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __init__(self, spec, pin, operator, count_ellipsis=-1):
7070
self.name += str(self._count_ellipsis + 1)
7171
self._update_doc_str(docstr, self.name)
7272

73-
def connect(self, inpt, operator_as_input=False):
73+
def connect(self, inpt):
7474
"""Connect any input (entity or operator output) to a specified input pin of this operator.
7575
7676
Parameters
@@ -85,7 +85,7 @@ def connect(self, inpt, operator_as_input=False):
8585
# always convert ranges to lists
8686
if isinstance(inpt, range):
8787
inpt = list(inpt)
88-
elif not operator_as_input and isinstance(inpt, core.Operator):
88+
elif isinstance(inpt, core.Operator):
8989
if hasattr(inpt, "outputs"):
9090
inpt = inpt.outputs
9191
else:
@@ -150,7 +150,7 @@ def connect(self, inpt, operator_as_input=False):
150150
corresponding_pins[0][1]: weakref.ref(inpt)
151151
}
152152
else:
153-
self._operator().connect(self._pin, inpt, operator_as_input=operator_as_input)
153+
self._operator().connect(self._pin, inpt)
154154
self._operator().inputs._connected_inputs[self._pin] = (
155155
weakref.ref(inpt) if hasattr(inpt, "__weakref__") else inpt
156156
)

tests/test_operator.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,3 +1424,19 @@ def test_operator_input_output_streams(server_in_process, simple_bar):
14241424
time_provider.connect(pin=3, inpt=streams)
14251425
times = time_provider.outputs.time_freq_support()
14261426
assert times
1427+
1428+
1429+
@pytest.mark.skipif(
1430+
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0,
1431+
reason="Operator `workflow_to_workflow_topology` does not exist below 10.0",
1432+
)
1433+
def test_operator_id(server_type):
1434+
ids = set()
1435+
1436+
for _ in range(10):
1437+
op = ops.utility.forward(server=server_type)
1438+
1439+
assert op.id >= 0
1440+
assert op.id not in ids
1441+
1442+
ids.add(op.id)

0 commit comments

Comments
 (0)