Skip to content

Commit

Permalink
fix: todo
Browse files Browse the repository at this point in the history
  • Loading branch information
mkundu1 committed Dec 17, 2024
1 parent e1a6865 commit d75d801
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
9 changes: 3 additions & 6 deletions src/ansys/fluent/core/services/datamodel_se.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ def add_on_affected_at_type_path(
return subscription

def add_on_command_executed(
self, rules: str, path: str, command: str, obj, cb: Callable
self, rules: str, path: str, obj, cb: Callable
) -> EventSubscription:
"""Add on command executed."""
request_dict = {
Expand All @@ -817,7 +817,6 @@ def add_on_command_executed(
"rules": rules,
"commandExecutedEventRequest": {
"path": path,
"command": command,
},
}
]
Expand Down Expand Up @@ -1326,13 +1325,11 @@ def add_on_affected_at_type_path(
self.rules, convert_path_to_se_path(self.path), child_type, self, cb
)

def add_on_command_executed(self, command: str, cb: Callable) -> EventSubscription:
def add_on_command_executed(self, cb: Callable) -> EventSubscription:
"""Register a callback for when a command is executed.
Parameters
----------
command : str
command name
cb : Callable
Callback function
Expand All @@ -1342,7 +1339,7 @@ def add_on_command_executed(self, command: str, cb: Callable) -> EventSubscripti
EventSubscription instance which can be used to unregister the callback
"""
return self.service.add_on_command_executed(
self.rules, convert_path_to_se_path(self.path), command, self, cb
self.rules, convert_path_to_se_path(self.path), self, cb
)


Expand Down
4 changes: 2 additions & 2 deletions tests/test_datamodel_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def cb(obj, cmd, args):
executed += 1

# TODO: In C++ API, we don't need to pass the command name
subscription = service.add_on_command_executed(app_name, "/", "C", root, cb)
subscription = service.add_on_command_executed(app_name, "/", root, cb)
assert executed == 0
assert command is None
assert arguments is None
Expand Down Expand Up @@ -437,7 +437,7 @@ def test_datamodel_api_on_bad_input(
app_name, "/", "CC", "isActive", root, lambda _: None
)
with pytest.raises(RuntimeError if new_api else SubscribeEventError): # TODO: issue
service.add_on_command_executed(app_name, "/BB", "C", root, lambda _: None)
service.add_on_command_executed(app_name, "/BB", root, lambda _: None)


@pytest.mark.fluent_version(">=25.2")
Expand Down
6 changes: 3 additions & 3 deletions tests/test_datamodel_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def test_add_on_command_executed(new_meshing_session):
meshing = new_meshing_session
data = []
subscription = meshing.meshing.add_on_command_executed(
"ImportGeometry", lambda obj, command, args: data.append(True)
lambda obj, command, args: data.append(True)
)
assert data == []
meshing.workflow.InitializeWorkflow(WorkflowType="Watertight Geometry")
Expand Down Expand Up @@ -651,8 +651,8 @@ def test_on_command_executed_lifetime(new_solver_session):
root = create_root_using_datamodelgen(solver._se_service, app_name)
root.A["A1"] = {}
data = []
_ = root.A["A1"].add_on_command_executed("C", lambda *args: data.append(1))
root.A["A1"].add_on_command_executed("C", lambda *args: data.append(2))
_ = root.A["A1"].add_on_command_executed(lambda *args: data.append(1))
root.A["A1"].add_on_command_executed(lambda *args: data.append(2))
gc.collect()
assert "/test/command_executed/A:A1/C" in solver._se_service.subscriptions
assert "/test/command_executed/A:A1/C-1" in solver._se_service.subscriptions
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mapped_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def cb(obj, cmd, args):
arguments = args
executed = True

subscription = service.add_on_command_executed(app_name, "/", "C", root, cb)
subscription = service.add_on_command_executed(app_name, "/", root, cb)
assert not executed
assert command is None
assert arguments is None
Expand Down

0 comments on commit d75d801

Please sign in to comment.