Skip to content

Commit c16f56b

Browse files
authored
Expose Collection.name (#1335)
* Expose Collection.name (missing api for LegacyGrpc) Signed-off-by: paul.profizi <[email protected]> * Add test (still have to expose the API for gRPC servers) Signed-off-by: paul.profizi <[email protected]> * Mark feature as requiring DPF 8.0 Signed-off-by: paul.profizi <[email protected]> * Fix decorators ordering Signed-off-by: paul.profizi <[email protected]> * Working Signed-off-by: paul.profizi <[email protected]> * Update src/ansys/dpf/gate/collection_grpcapi.py --------- Signed-off-by: paul.profizi <[email protected]>
1 parent 85121d4 commit c16f56b

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/ansys/dpf/core/collection.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import numpy as np
1212

13+
from ansys.dpf.core.check_version import version_requires
1314
from ansys.dpf.core.server_types import BaseServer
1415
from ansys.dpf.core.scoping import Scoping
1516
from ansys.dpf.core.label_space import LabelSpace
@@ -74,6 +75,33 @@ def _server(self, value):
7475
# step3: init environment
7576
self._api.init_collection_environment(self) # creates stub when gRPC
7677

78+
@property
79+
@version_requires("8.0")
80+
def name(self):
81+
"""Name of the Collection.
82+
83+
Notes
84+
-----
85+
Available starting with DPF 2024 R2 pre0.
86+
87+
Returns
88+
-------
89+
str
90+
"""
91+
out = self._api.collection_get_name(self)
92+
return out if out != '' else None
93+
94+
@name.setter
95+
@version_requires("8.0")
96+
def name(self, name: str):
97+
"""Set the name of the Collection.
98+
99+
Notes
100+
-----
101+
Available starting with DPF 2024 R2 pre0.
102+
"""
103+
self._api.collection_set_name(self, name=name)
104+
77105
@abc.abstractmethod
78106
def create_subtype(self, obj_by_copy):
79107
pass

tests/test_fieldscontainer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ def test_create_fields_container(server_type):
2929
assert fc._internal_obj is not None
3030

3131

32+
@pytest.mark.skipif(
33+
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0,
34+
reason="Renaming collections is supported via gRPC starting server version 8.0",
35+
)
36+
def test_rename_fields_container(server_type):
37+
fc = FieldsContainer(server=server_type)
38+
assert fc.name is None
39+
fc.name = "test"
40+
assert fc.name == "test"
41+
42+
3243
def test_empty_index(server_type):
3344
fc = FieldsContainer(server=server_type)
3445
with pytest.raises(IndexError):

0 commit comments

Comments
 (0)