Skip to content

Commit 5f23068

Browse files
Swap to using unicode strings in tests.
1 parent efef144 commit 5f23068

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

softioc/device.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ def truncate_string(value):
284284
value = value.decode(errors="replace")
285285
return value[:39] if isinstance(value, str) else None
286286
else:
287-
# Python2 strings are equivalent to Python3 bytestrings
287+
if isinstance(value, bytes):
288+
value = value.decode("utf-8", errors="replace")
288289
return value[:39] if isinstance(value, str) else None
289290

290291
longin = _Device_In('longin', value_to_epics=convert_to_int)

tests/test_records.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ def idfn(fixture_value):
6161
(builder.stringIn, "", "", str),
6262
(builder.stringOut, b"abc", "abc", str),
6363
(builder.stringIn, b"abc", "abc", str),
64-
(builder.stringOut, b"a\xcfb", "a�b", str), # Invalid UTF-8
65-
(builder.stringIn, b"a\xcfb", "a�b", str), # Invalid UTF-8
66-
(builder.stringOut, b"a\xe2\x82\xacb", "a€b", str), # Valid UTF-8
67-
(builder.stringIn, b"a\xe2\x82\xacb", "a€b", str), # Valid UTF-8
68-
(builder.stringOut, "a€b", "a€b", str), # Valid UTF-8
69-
(builder.stringIn, "a€b", "a€b", str), # Valid UTF-8
64+
(builder.stringOut, b"a\xcfb", u"a�b", str), # Invalid UTF-8
65+
(builder.stringIn, b"a\xcfb", u"a�b", str), # Invalid UTF-8
66+
(builder.stringOut, b"a\xe2\x82\xacb", u"a€b", str), # Valid UTF-8
67+
(builder.stringIn, b"a\xe2\x82\xacb", u"a€b", str), # Valid UTF-8
68+
(builder.stringOut, u"a€b", u"a€b", str), # Valid UTF-8
69+
(builder.stringIn, u"a€b", u"a€b", str), # Valid UTF-8
7070
(
7171
builder.stringOut,
7272
"this string is much longer than 40 characters",
@@ -157,10 +157,6 @@ def record_value_asserts(
157157
"Arrays not equal: {} {}".format(actual_value, expected_value)
158158
assert type(actual_value) == expected_type
159159
else:
160-
# Python2 handles UTF-8 differently so needs extra encoding
161-
if sys.version_info < (3,) and expected_type == str:
162-
expected_value = expected_value.decode("utf-8", errors="replace")
163-
164160
assert actual_value == expected_value
165161
assert type(actual_value) == expected_type
166162

0 commit comments

Comments
 (0)