From c16f56b0a6bfcee694cd83c2ba9169cb36ce6add Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Wed, 7 Feb 2024 18:33:53 +0100 Subject: [PATCH] Expose Collection.name (#1335) * Expose Collection.name (missing api for LegacyGrpc) Signed-off-by: paul.profizi * Add test (still have to expose the API for gRPC servers) Signed-off-by: paul.profizi * Mark feature as requiring DPF 8.0 Signed-off-by: paul.profizi * Fix decorators ordering Signed-off-by: paul.profizi * Working Signed-off-by: paul.profizi * Update src/ansys/dpf/gate/collection_grpcapi.py --------- Signed-off-by: paul.profizi --- src/ansys/dpf/core/collection.py | 28 ++++++++++++++++++++++++++++ tests/test_fieldscontainer.py | 11 +++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/ansys/dpf/core/collection.py b/src/ansys/dpf/core/collection.py index 6f9770aee0..c6f5a49e69 100644 --- a/src/ansys/dpf/core/collection.py +++ b/src/ansys/dpf/core/collection.py @@ -10,6 +10,7 @@ import numpy as np +from ansys.dpf.core.check_version import version_requires from ansys.dpf.core.server_types import BaseServer from ansys.dpf.core.scoping import Scoping from ansys.dpf.core.label_space import LabelSpace @@ -74,6 +75,33 @@ def _server(self, value): # step3: init environment self._api.init_collection_environment(self) # creates stub when gRPC + @property + @version_requires("8.0") + def name(self): + """Name of the Collection. + + Notes + ----- + Available starting with DPF 2024 R2 pre0. + + Returns + ------- + str + """ + out = self._api.collection_get_name(self) + return out if out != '' else None + + @name.setter + @version_requires("8.0") + def name(self, name: str): + """Set the name of the Collection. + + Notes + ----- + Available starting with DPF 2024 R2 pre0. + """ + self._api.collection_set_name(self, name=name) + @abc.abstractmethod def create_subtype(self, obj_by_copy): pass diff --git a/tests/test_fieldscontainer.py b/tests/test_fieldscontainer.py index 6fdb172ca0..a907c60ac3 100644 --- a/tests/test_fieldscontainer.py +++ b/tests/test_fieldscontainer.py @@ -29,6 +29,17 @@ def test_create_fields_container(server_type): assert fc._internal_obj is not None +@pytest.mark.skipif( + not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, + reason="Renaming collections is supported via gRPC starting server version 8.0", +) +def test_rename_fields_container(server_type): + fc = FieldsContainer(server=server_type) + assert fc.name is None + fc.name = "test" + assert fc.name == "test" + + def test_empty_index(server_type): fc = FieldsContainer(server=server_type) with pytest.raises(IndexError):