Skip to content

Commit f0a29e9

Browse files
authored
fix(any): fix cast of Any to DataSources (#2487)
1 parent a175c71 commit f0a29e9

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/ansys/dpf/core/any.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def _type_to_new_from_get_as_method(self, obj):
113113
from ansys.dpf.core import (
114114
collection,
115115
custom_type_field,
116+
data_sources,
116117
data_tree,
117118
dpf_operator,
118119
field,
@@ -205,6 +206,11 @@ def _type_to_new_from_get_as_method(self, obj):
205206
self._api.any_new_from_operator,
206207
self._api.any_get_as_operator,
207208
)
209+
elif issubclass(obj, data_sources.DataSources):
210+
return (
211+
self._api.any_new_from_data_sources,
212+
self._api.any_get_as_data_sources,
213+
)
208214
elif issubclass(obj, Any):
209215
return (
210216
lambda x: x,

src/ansys/dpf/gate/any_grpcapi.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def _type_to_message_type():
3636
field,
3737
fields_container,
3838
property_field,
39+
data_sources,
3940
generic_data_container,
4041
string_field,
4142
scoping,
@@ -62,6 +63,7 @@ def _type_to_message_type():
6263
(collection_base.CollectionBase, base_pb2.Type.COLLECTION, base_pb2.Type.ANY),
6364
(dpf_vector.DPFVectorInt, base_pb2.Type.COLLECTION, base_pb2.Type.INT),
6465
(dpf_operator.Operator, base_pb2.Type.OPERATOR),
66+
(data_sources.DataSources, base_pb2.Type.DATA_SOURCES),
6567
]
6668

6769
@staticmethod
@@ -137,6 +139,10 @@ def any_get_as_generic_data_container(any):
137139
def any_get_as_scoping(any):
138140
return AnyGRPCAPI._get_as(any).scoping
139141

142+
@staticmethod
143+
def any_get_as_data_sources(any):
144+
return AnyGRPCAPI._get_as(any).data_sources
145+
140146
@staticmethod
141147
def any_get_as_data_tree(any):
142148
return AnyGRPCAPI._get_as(any).data_tree
@@ -239,6 +245,10 @@ def any_new_from_generic_data_container(any):
239245
def any_new_from_scoping(any):
240246
return AnyGRPCAPI._new_from(any, any._server)
241247

248+
@staticmethod
249+
def any_new_from_data_sources(any):
250+
return AnyGRPCAPI._new_from(any, any._server)
251+
242252
@staticmethod
243253
def any_new_from_data_tree(any):
244254
return AnyGRPCAPI._new_from(any, any._server)

tests/test_any.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,19 @@ def test_cast_scoping_any(server_type):
122122
assert entity.location == new_entity.location
123123

124124

125+
@pytest.mark.skipif(
126+
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0,
127+
reason="Requires 24R2.",
128+
)
129+
def test_cast_data_sources_any(server_type):
130+
# Not available through grpc yet
131+
entity = dpf.DataSources(server=server_type, result_path="test.pth")
132+
any_dpf = dpf.Any.new_from(entity)
133+
new_entity = any_dpf.cast()
134+
135+
assert entity.result_files[0] == new_entity.result_files[0]
136+
137+
125138
@pytest.mark.skipif(
126139
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0,
127140
reason="for_each not implemented below 8.0. Failing for gRPC CLayer below 10.0 for any.whl",

0 commit comments

Comments
 (0)