Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
DevEncoded attribute should produce a bytes object in python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
vxgmichel committed Sep 7, 2018
1 parent 7ae4667 commit aa87ae5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
11 changes: 9 additions & 2 deletions ext/device_attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ namespace PyDeviceAttribute

Tango::DevVarCharArray& r_encoded_data_array = r_buffer.encoded_data;
char* r_ch_ptr = (char*)r_encoded_data_array.get_buffer();
bopy::str r_encoded_data(r_ch_ptr, r_encoded_data_array.length());

bopy::object r_encoded_data(
bopy::handle<>(PyBytes_FromStringAndSize(
r_ch_ptr, r_encoded_data_array.length())));

py_value.attr(value_attr_name) =
bopy::make_tuple(r_encoded_format, r_encoded_data);
Expand All @@ -268,7 +271,11 @@ namespace PyDeviceAttribute

Tango::DevVarCharArray& w_encoded_data_array = w_buffer.encoded_data;
char* w_ch_ptr = (char*)w_encoded_data_array.get_buffer();
bopy::str w_encoded_data(w_ch_ptr, w_encoded_data_array.length());

bopy::object w_encoded_data(
bopy::handle<>(PyBytes_FromStringAndSize(
w_ch_ptr, w_encoded_data_array.length())));

py_value.attr(w_value_attr_name) =
bopy::make_tuple(w_encoded_format, w_encoded_data);
}
Expand Down
18 changes: 17 additions & 1 deletion tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
import enum

from tango import DevState, AttrWriteType, GreenMode, DevFailed
from tango import DevState, AttrWriteType, GreenMode, DevFailed, DevEncoded
from tango.server import Device
from tango.server import command, attribute, device_property
from tango.test_utils import DeviceTestContext, assert_close, \
Expand Down Expand Up @@ -392,3 +392,19 @@ def test_get_enum_labels_success(good_enum):
def test_get_enum_labels_fail(bad_enum):
with pytest.raises(EnumTypeError):
get_enum_labels(bad_enum)


# DevEncoded

def test_read_write_dev_encoded(server_green_mode):

class TestDevice(Device):
green_mode = server_green_mode

@attribute(dtype=DevEncoded,
access=AttrWriteType.READ)
def attr(self):
return ("uint8", b"\xd2\xd3")

with DeviceTestContext(TestDevice) as proxy:
assert proxy.attr == ("uint8", b"\xd2\xd3")

0 comments on commit aa87ae5

Please sign in to comment.