Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/ansys/dpf/core/any.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ansys.dpf.core import server as server_module
from ansys.dpf.core import errors
from ansys.dpf.core.common import type_to_internal_object_keyword
from ansys.dpf.gate import any_abstract_api


class Any:
Expand Down Expand Up @@ -55,6 +56,7 @@ def _type_to_new_from_get_as_method(any_dpf):
generic_data_container,
string_field,
scoping,
data_tree,
)

return [
Expand Down Expand Up @@ -97,6 +99,11 @@ def _type_to_new_from_get_as_method(any_dpf):
any_dpf._api.any_new_from_scoping,
any_dpf._api.any_get_as_scoping,
),
(
data_tree.DataTree,
any_dpf._api.any_new_from_data_tree,
any_dpf._api.any_get_as_data_tree,
),
]

@staticmethod
Expand Down Expand Up @@ -138,7 +145,7 @@ def new_from(obj, server=None):
raise TypeError(f"{obj.__class__} is not currently supported by the Any class.")

@property
def _api(self):
def _api(self) -> any_abstract_api.AnyAbstractAPI:
from ansys.dpf.gate import any_capi, any_grpcapi

if not self._api_instance:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_generic_data_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ def test_set_get_property_generic_data_container(server_type):
assert entity.location == new_entity.location


@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0, reason="Available for servers >=7.0"
)
def test_set_get_data_tree_generic_data_container(server_type):
gdc = dpf.GenericDataContainer(server=server_type)
entity = dpf.DataTree(server=server_type)
entity.add(name="john")
gdc.set_property("persons", entity)
new_entity = gdc.get_property("persons", dpf.DataTree)
assert new_entity.get_as("name") == "john"


@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0, reason="Available for servers >=7.0"
)
Expand Down