Skip to content

Commit 74e9137

Browse files
authored
GDC set bytes and collection (#1471)
1 parent 9ad54f9 commit 74e9137

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/ansys/dpf/core/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,14 @@
105105

106106

107107
from ansys.dpf.core.collection import CollectionFactory as _CollectionFactory
108+
from ansys.dpf.core.collection import Collection as _Collection
108109

109110

110111
# register classes for collection types:
111-
CustomTypeFieldsCollection = _CollectionFactory(CustomTypeField)
112-
GenericDataContainersCollection = _CollectionFactory(GenericDataContainer)
113-
StringFieldsCollection = _CollectionFactory(StringField)
112+
CustomTypeFieldsCollection:type = _CollectionFactory(CustomTypeField)
113+
GenericDataContainersCollection:type = _CollectionFactory(GenericDataContainer)
114+
StringFieldsCollection:type = _CollectionFactory(StringField)
115+
AnyCollection:type = _Collection
114116

115117
# for matplotlib
116118
# solves "QApplication: invalid style override passed, ignoring it."

src/ansys/dpf/core/generic_data_container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def set_property(
107107
Property object.
108108
"""
109109

110-
if not isinstance(prop, (int, float, str)) and server_meet_version("8.1", self._server):
110+
if not isinstance(prop, (int, float, str, bytes)) and server_meet_version("8.1", self._server):
111111
self._api.generic_data_container_set_property_dpf_type(self, property_name, prop)
112112
else:
113113
any_dpf = Any.new_from(prop, self._server)

tests/test_generic_data_container.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from ansys.dpf import core as dpf
22
from conftest import (
3-
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0, SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0,
3+
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0,
4+
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0,
5+
raises_for_servers_version_under,
46
)
57
import pytest
68

@@ -122,8 +124,11 @@ def test_get_bytes_generic_data_container(server_type):
122124

123125
entity = "hello world"
124126
gdc.set_property("my-string", entity)
127+
gdc.set_property("my-bytes", entity.encode())
125128
new_entity = gdc.get_property("my-string")
126129
assert "hello world" == new_entity
130+
new_entity = gdc.get_property("my-bytes")
131+
assert "hello world" == new_entity
127132
new_entity = gdc.get_property("my-string", str)
128133
assert "hello world" == new_entity
129134
new_entity = gdc.get_property("my-string", dpf.types.string)
@@ -132,3 +137,14 @@ def test_get_bytes_generic_data_container(server_type):
132137
assert b"hello world" == new_entity
133138
new_entity = gdc.get_property("my-string", dpf.types.bytes)
134139
assert b"hello world" == new_entity
140+
new_entity = gdc.get_property("my-bytes", dpf.types.bytes)
141+
assert b"hello world" == new_entity
142+
143+
144+
@raises_for_servers_version_under("8.1")
145+
def test_set_collection_generic_data_container(server_type):
146+
coll = dpf.GenericDataContainersCollection(server=server_type)
147+
gdc = dpf.GenericDataContainer(server=server_type)
148+
coll.labels = ["body", "time"]
149+
gdc.set_property("coll", coll)
150+
assert gdc.get_property("coll", dpf.GenericDataContainersCollection).labels == ["body", "time"]

0 commit comments

Comments
 (0)