From f9b0876c7921f423bbb7dfc6025277eecd0ed8af Mon Sep 17 00:00:00 2001 From: cbellot Date: Mon, 28 Oct 2024 15:08:30 +0100 Subject: [PATCH 1/2] any to and from workflow --- src/ansys/dpf/core/any.py | 6 ++++++ src/ansys/dpf/core/server.py | 2 +- src/ansys/dpf/gate/any_grpcapi.py | 10 ++++++++++ tests/test_any.py | 9 +++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ansys/dpf/core/any.py b/src/ansys/dpf/core/any.py index ad60e8b983f..fc7d0f4738b 100644 --- a/src/ansys/dpf/core/any.py +++ b/src/ansys/dpf/core/any.py @@ -122,6 +122,7 @@ def _type_to_new_from_get_as_method(self, obj): data_tree, custom_type_field, collection, + workflow, ) if issubclass(obj, int): @@ -185,6 +186,11 @@ def _type_to_new_from_get_as_method(self, obj): self._api.any_new_from_any_collection, self._api.any_get_as_any_collection, ) + elif issubclass(obj, workflow.Workflow): + return ( + self._api.any_new_from_workflow, + self._api.any_get_as_workflow, + ) elif issubclass(obj, dpf_vector.DPFVectorInt): return ( self._api.any_new_from_int_collection, diff --git a/src/ansys/dpf/core/server.py b/src/ansys/dpf/core/server.py index 2a4ed82d700..83e3abd8fb1 100644 --- a/src/ansys/dpf/core/server.py +++ b/src/ansys/dpf/core/server.py @@ -73,7 +73,7 @@ def has_local_server(): return dpf.core.SERVER is not None -def _global_server(): +def _global_server() -> BaseServer: """Retrieve the global server if it exists. If the global server has not been specified, check the expected server type in diff --git a/src/ansys/dpf/gate/any_grpcapi.py b/src/ansys/dpf/gate/any_grpcapi.py index 28f9b100392..69e178d98c6 100644 --- a/src/ansys/dpf/gate/any_grpcapi.py +++ b/src/ansys/dpf/gate/any_grpcapi.py @@ -41,6 +41,7 @@ def _type_to_message_type(): data_tree, custom_type_field, collection_base, + workflow, ) return [(int, base_pb2.Type.INT), @@ -54,6 +55,7 @@ def _type_to_message_type(): (generic_data_container.GenericDataContainer, base_pb2.Type.GENERIC_DATA_CONTAINER), (scoping.Scoping, base_pb2.Type.SCOPING), (data_tree.DataTree, base_pb2.Type.DATA_TREE), + (workflow.Workflow, base_pb2.Type.WORKFLOW), (collection_base.CollectionBase, base_pb2.Type.COLLECTION, base_pb2.Type.ANY), (dpf_vector.DPFVectorInt, base_pb2.Type.COLLECTION, base_pb2.Type.INT), ] @@ -139,6 +141,10 @@ def any_get_as_any_collection(any): def any_get_as_int_collection(any): return AnyGRPCAPI._get_as(any).collection + @staticmethod + def any_get_as_workflow(any): + return AnyGRPCAPI._get_as(any).workflow + @staticmethod def _new_from(any, client=None): from ansys.grpc.dpf import dpf_any_pb2 @@ -220,3 +226,7 @@ def any_new_from_scoping(any): @staticmethod def any_new_from_data_tree(any): return AnyGRPCAPI._new_from(any, any._server) + + @staticmethod + def any_new_from_workflow(any): + return AnyGRPCAPI._new_from(any, any._server) diff --git a/tests/test_any.py b/tests/test_any.py index bf3897fe1ff..b0f07df6093 100644 --- a/tests/test_any.py +++ b/tests/test_any.py @@ -120,3 +120,12 @@ def test_cast_scoping_any(server_type): new_entity = any_dpf.cast() assert entity.location == new_entity.location + + +@conftest.raises_for_servers_version_under("9.1") +def test_cast_workflow_any(server_type): + entity = dpf.Workflow(server=server_type) + any_dpf = dpf.Any.new_from(entity) + new_entity = any_dpf.cast() + + assert new_entity.input_names == [] From 1639c645ae8ded1df0a2816458bfee0d12e1483f Mon Sep 17 00:00:00 2001 From: cbellot Date: Mon, 18 Nov 2024 15:24:57 +0100 Subject: [PATCH 2/2] retro --- tests/test_any.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_any.py b/tests/test_any.py index b0f07df6093..5ec94862828 100644 --- a/tests/test_any.py +++ b/tests/test_any.py @@ -122,7 +122,10 @@ def test_cast_scoping_any(server_type): assert entity.location == new_entity.location -@conftest.raises_for_servers_version_under("9.1") +@pytest.mark.skipif( + not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, + reason="for_each not implemented below 8.0", +) def test_cast_workflow_any(server_type): entity = dpf.Workflow(server=server_type) any_dpf = dpf.Any.new_from(entity)