Skip to content

Commit

Permalink
GDC set bytes and collection (#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellot000 authored Mar 18, 2024
1 parent 9ad54f9 commit 74e9137
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/ansys/dpf/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@


from ansys.dpf.core.collection import CollectionFactory as _CollectionFactory
from ansys.dpf.core.collection import Collection as _Collection


# register classes for collection types:
CustomTypeFieldsCollection = _CollectionFactory(CustomTypeField)
GenericDataContainersCollection = _CollectionFactory(GenericDataContainer)
StringFieldsCollection = _CollectionFactory(StringField)
CustomTypeFieldsCollection:type = _CollectionFactory(CustomTypeField)
GenericDataContainersCollection:type = _CollectionFactory(GenericDataContainer)
StringFieldsCollection:type = _CollectionFactory(StringField)
AnyCollection:type = _Collection

# for matplotlib
# solves "QApplication: invalid style override passed, ignoring it."
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/dpf/core/generic_data_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def set_property(
Property object.
"""

if not isinstance(prop, (int, float, str)) and server_meet_version("8.1", self._server):
if not isinstance(prop, (int, float, str, bytes)) and server_meet_version("8.1", self._server):
self._api.generic_data_container_set_property_dpf_type(self, property_name, prop)
else:
any_dpf = Any.new_from(prop, self._server)
Expand Down
18 changes: 17 additions & 1 deletion tests/test_generic_data_container.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from ansys.dpf import core as dpf
from conftest import (
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0, SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0,
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0,
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0,
raises_for_servers_version_under,
)
import pytest

Expand Down Expand Up @@ -122,8 +124,11 @@ def test_get_bytes_generic_data_container(server_type):

entity = "hello world"
gdc.set_property("my-string", entity)
gdc.set_property("my-bytes", entity.encode())
new_entity = gdc.get_property("my-string")
assert "hello world" == new_entity
new_entity = gdc.get_property("my-bytes")
assert "hello world" == new_entity
new_entity = gdc.get_property("my-string", str)
assert "hello world" == new_entity
new_entity = gdc.get_property("my-string", dpf.types.string)
Expand All @@ -132,3 +137,14 @@ def test_get_bytes_generic_data_container(server_type):
assert b"hello world" == new_entity
new_entity = gdc.get_property("my-string", dpf.types.bytes)
assert b"hello world" == new_entity
new_entity = gdc.get_property("my-bytes", dpf.types.bytes)
assert b"hello world" == new_entity


@raises_for_servers_version_under("8.1")
def test_set_collection_generic_data_container(server_type):
coll = dpf.GenericDataContainersCollection(server=server_type)
gdc = dpf.GenericDataContainer(server=server_type)
coll.labels = ["body", "time"]
gdc.set_property("coll", coll)
assert gdc.get_property("coll", dpf.GenericDataContainersCollection).labels == ["body", "time"]

0 comments on commit 74e9137

Please sign in to comment.