Skip to content

Commit b954c63

Browse files
authored
any to and from workflow (#1839)
* any to and from workflow * retro
1 parent f9d1e2b commit b954c63

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

src/ansys/dpf/core/any.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def _type_to_new_from_get_as_method(self, obj):
122122
data_tree,
123123
custom_type_field,
124124
collection,
125+
workflow,
125126
)
126127

127128
if issubclass(obj, int):
@@ -185,6 +186,11 @@ def _type_to_new_from_get_as_method(self, obj):
185186
self._api.any_new_from_any_collection,
186187
self._api.any_get_as_any_collection,
187188
)
189+
elif issubclass(obj, workflow.Workflow):
190+
return (
191+
self._api.any_new_from_workflow,
192+
self._api.any_get_as_workflow,
193+
)
188194
elif issubclass(obj, dpf_vector.DPFVectorInt):
189195
return (
190196
self._api.any_new_from_int_collection,

src/ansys/dpf/core/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def has_local_server():
7373
return dpf.core.SERVER is not None
7474

7575

76-
def _global_server():
76+
def _global_server() -> BaseServer:
7777
"""Retrieve the global server if it exists.
7878
7979
If the global server has not been specified, check the expected server type in

src/ansys/dpf/gate/any_grpcapi.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def _type_to_message_type():
4141
data_tree,
4242
custom_type_field,
4343
collection_base,
44+
workflow,
4445
)
4546

4647
return [(int, base_pb2.Type.INT),
@@ -54,6 +55,7 @@ def _type_to_message_type():
5455
(generic_data_container.GenericDataContainer, base_pb2.Type.GENERIC_DATA_CONTAINER),
5556
(scoping.Scoping, base_pb2.Type.SCOPING),
5657
(data_tree.DataTree, base_pb2.Type.DATA_TREE),
58+
(workflow.Workflow, base_pb2.Type.WORKFLOW),
5759
(collection_base.CollectionBase, base_pb2.Type.COLLECTION, base_pb2.Type.ANY),
5860
(dpf_vector.DPFVectorInt, base_pb2.Type.COLLECTION, base_pb2.Type.INT),
5961
]
@@ -139,6 +141,10 @@ def any_get_as_any_collection(any):
139141
def any_get_as_int_collection(any):
140142
return AnyGRPCAPI._get_as(any).collection
141143

144+
@staticmethod
145+
def any_get_as_workflow(any):
146+
return AnyGRPCAPI._get_as(any).workflow
147+
142148
@staticmethod
143149
def _new_from(any, client=None):
144150
from ansys.grpc.dpf import dpf_any_pb2
@@ -220,3 +226,7 @@ def any_new_from_scoping(any):
220226
@staticmethod
221227
def any_new_from_data_tree(any):
222228
return AnyGRPCAPI._new_from(any, any._server)
229+
230+
@staticmethod
231+
def any_new_from_workflow(any):
232+
return AnyGRPCAPI._new_from(any, any._server)

tests/test_any.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,15 @@ def test_cast_scoping_any(server_type):
120120
new_entity = any_dpf.cast()
121121

122122
assert entity.location == new_entity.location
123+
124+
125+
@pytest.mark.skipif(
126+
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0,
127+
reason="for_each not implemented below 8.0",
128+
)
129+
def test_cast_workflow_any(server_type):
130+
entity = dpf.Workflow(server=server_type)
131+
any_dpf = dpf.Any.new_from(entity)
132+
new_entity = any_dpf.cast()
133+
134+
assert new_entity.input_names == []

0 commit comments

Comments
 (0)