diff --git a/src/ansys/dpf/core/any.py b/src/ansys/dpf/core/any.py index bf2a0f70383..78de897bb96 100644 --- a/src/ansys/dpf/core/any.py +++ b/src/ansys/dpf/core/any.py @@ -113,6 +113,7 @@ def _type_to_new_from_get_as_method(self, obj): from ansys.dpf.core import ( collection, custom_type_field, + data_sources, data_tree, dpf_operator, field, @@ -205,6 +206,11 @@ def _type_to_new_from_get_as_method(self, obj): self._api.any_new_from_operator, self._api.any_get_as_operator, ) + elif issubclass(obj, data_sources.DataSources): + return ( + self._api.any_new_from_data_sources, + self._api.any_get_as_data_sources, + ) elif issubclass(obj, Any): return ( lambda x: x, diff --git a/src/ansys/dpf/gate/any_grpcapi.py b/src/ansys/dpf/gate/any_grpcapi.py index fbdbd99f4ee..4575c7733f8 100644 --- a/src/ansys/dpf/gate/any_grpcapi.py +++ b/src/ansys/dpf/gate/any_grpcapi.py @@ -36,6 +36,7 @@ def _type_to_message_type(): field, fields_container, property_field, + data_sources, generic_data_container, string_field, scoping, @@ -62,6 +63,7 @@ def _type_to_message_type(): (collection_base.CollectionBase, base_pb2.Type.COLLECTION, base_pb2.Type.ANY), (dpf_vector.DPFVectorInt, base_pb2.Type.COLLECTION, base_pb2.Type.INT), (dpf_operator.Operator, base_pb2.Type.OPERATOR), + (data_sources.DataSources, base_pb2.Type.DATA_SOURCES), ] @staticmethod @@ -137,6 +139,10 @@ def any_get_as_generic_data_container(any): def any_get_as_scoping(any): return AnyGRPCAPI._get_as(any).scoping + @staticmethod + def any_get_as_data_sources(any): + return AnyGRPCAPI._get_as(any).data_sources + @staticmethod def any_get_as_data_tree(any): return AnyGRPCAPI._get_as(any).data_tree @@ -239,6 +245,10 @@ def any_new_from_generic_data_container(any): def any_new_from_scoping(any): return AnyGRPCAPI._new_from(any, any._server) + @staticmethod + def any_new_from_data_sources(any): + return AnyGRPCAPI._new_from(any, any._server) + @staticmethod def any_new_from_data_tree(any): return AnyGRPCAPI._new_from(any, any._server) diff --git a/tests/test_any.py b/tests/test_any.py index 28a29a56314..f023c47d554 100644 --- a/tests/test_any.py +++ b/tests/test_any.py @@ -122,6 +122,19 @@ def test_cast_scoping_any(server_type): assert entity.location == new_entity.location +@pytest.mark.skipif( + not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, + reason="Requires 24R2.", +) +def test_cast_data_sources_any(server_type): + # Not available through grpc yet + entity = dpf.DataSources(server=server_type, result_path="test.pth") + any_dpf = dpf.Any.new_from(entity) + new_entity = any_dpf.cast() + + assert entity.result_files[0] == new_entity.result_files[0] + + @pytest.mark.skipif( not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0, reason="for_each not implemented below 8.0. Failing for gRPC CLayer below 10.0 for any.whl",