Skip to content

Commit

Permalink
Fix test for platforms where HDF5 char roundtrip does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Dec 5, 2023
1 parent 0fa9b91 commit 2bc3bfa
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion test/python/unittest/API/APITest.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,24 @@ def attributeRoundTrip(self, file_ending):
self.assertEqual(series.get_attribute("char"), "c")
self.assertEqual(series.get_attribute("pystring"), "howdy!")
self.assertEqual(series.get_attribute("pystring2"), "howdy, too!")
self.assertEqual(bytes(series.get_attribute("pystring3")),
if file_ending == 'h5':
# A byte string b"hello" is always (really?) a vector of unsigned
# chars.
# HDF5 does not distinguish a platform char type, only explicitly
# signed or unsigned chars. Depending on the signed-ness of char
# on the current platform, the unsigned char from the byte string
# might then be interpreted as a char, not as an unsigned char.
# This means that the roundtrip might not work on platforms with
# unsigned char.
try:
as_bytes = bytes(series.get_attribute("pystring3"))
self.assertEqual(as_bytes, b"howdy, again!")
except TypeError:
self.assertEqual(
series.get_attribute("pystring3"),
[c for c in "howdy, again!"])
else:
self.assertEqual(bytes(series.get_attribute("pystring3")),
b"howdy, again!")
self.assertEqual(series.get_attribute("pyint"), 13)
self.assertAlmostEqual(series.get_attribute("pyfloat"), 3.1416)
Expand Down

0 comments on commit 2bc3bfa

Please sign in to comment.