Skip to content

Commit

Permalink
Expose Collection.name (#1335)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
PProfizi authored Feb 7, 2024
1 parent 85121d4 commit c16f56b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/ansys/dpf/core/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/test_fieldscontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit c16f56b

Please sign in to comment.