Skip to content

Commit c899f99

Browse files
committed
Fixed tests to work on Python 2.7
... and without having ruff messing with test values Signed-off-by: Thomas Calmant <thomas.calmant@gmail.com>
1 parent dbdf7ec commit c899f99

2 files changed

Lines changed: 12 additions & 24 deletions

File tree

tests/test_v1.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,18 +337,12 @@ def test_char_array(self):
337337
jobj = self.read_file("testCharArray.ser")
338338
pobj = javaobj.loads(jobj)
339339
_logger.debug(pobj)
340-
self.assertEqual(
341-
pobj,
342-
[
343-
"\u0000",
344-
"\ud800",
345-
"\u0001",
346-
"\udc00",
347-
"\u0002",
348-
"\uffff",
349-
"\u0003",
350-
],
351-
)
340+
# Compare by code points to avoid Python 2/3 string literal ambiguity
341+
# (ruff strips u"" prefixes; \u-escapes in plain str are literal in Py2)
342+
expected_codepoints = [0x0000, 0xD800, 0x0001, 0xDC00, 0x0002, 0xFFFF, 0x0003]
343+
self.assertEqual(len(pobj), len(expected_codepoints))
344+
for actual, cp in zip(pobj, expected_codepoints):
345+
self.assertEqual(ord(actual), cp)
352346
self._try_marshalling(jobj, pobj)
353347

354348
def test_2d_array(self):

tests/test_v2.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -417,18 +417,12 @@ def test_char_array(self):
417417
jobj = self.read_file("testCharArray.ser")
418418
pobj = javaobj.loads(jobj)
419419
_logger.debug(pobj)
420-
self.assertEqual(
421-
pobj,
422-
[
423-
"\u0000",
424-
"\ud800",
425-
"\u0001",
426-
"\udc00",
427-
"\u0002",
428-
"\uffff",
429-
"\u0003",
430-
],
431-
)
420+
# Compare by code points to avoid Python 2/3 string literal ambiguity
421+
# (ruff strips u"" prefixes; \u-escapes in plain str are literal in Py2)
422+
expected_codepoints = [0x0000, 0xD800, 0x0001, 0xDC00, 0x0002, 0xFFFF, 0x0003]
423+
self.assertEqual(len(pobj), len(expected_codepoints))
424+
for actual, cp in zip(pobj, expected_codepoints):
425+
self.assertEqual(ord(actual), cp)
432426

433427
def test_2d_array(self):
434428
"""

0 commit comments

Comments
 (0)