Skip to content

Commit e9ffbb8

Browse files
committed
Make sure that test failures are easy to find in the logs by putting all information into the assertion.
1 parent a8e0f62 commit e9ffbb8

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

tests/run/py_unicode_strings.pyx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ import sys
55

66
from libc.string cimport memcpy
77

8-
cdef bint Py_UNICODE_equal(const Py_UNICODE* u1, const Py_UNICODE* u2):
8+
cdef assert_Py_UNICODE_equal(const Py_UNICODE* u1, const Py_UNICODE* u2):
99
cdef size_t i = 0
1010
while u1[i] != 0 and u2[i] != 0 and u1[i] == u2[i]:
1111
i += 1
12-
if u1[i] != u2[i]:
13-
print(f"Mismatch at position {i}: {<long>u1[i]} != {<long>u2[i]}")
14-
return u1[i] == u2[i]
12+
assert u1[i] == u2[i], f"Mismatch at position {i}: {<long>u1[i]} != {<long>u2[i]} ({u1!r} != {u2!r})"
1513

1614

1715
ctypedef Py_UNICODE* LPWSTR
@@ -84,20 +82,20 @@ def test_python_to_c():
8482
"""
8583
cdef unicode u
8684

87-
assert Py_UNICODE_equal(c_pu_arr, uobj)
88-
assert Py_UNICODE_equal(c_pu_str, uobj)
89-
assert Py_UNICODE_equal(c_pu_str, <LPWSTR>uobj)
85+
assert_Py_UNICODE_equal(c_pu_arr, uobj)
86+
assert_Py_UNICODE_equal(c_pu_str, uobj)
87+
assert_Py_UNICODE_equal(c_pu_str, <LPWSTR>uobj)
9088
u = uobj[1:]
91-
assert Py_UNICODE_equal(c_pu_str + 1, u)
92-
assert Py_UNICODE_equal(c_wstr + 1, u)
89+
assert_Py_UNICODE_equal(c_pu_str + 1, u)
90+
assert_Py_UNICODE_equal(c_wstr + 1, u)
9391
u = uobj[:1]
94-
assert Py_UNICODE_equal(<Py_UNICODE*>u"u", u)
92+
assert_Py_UNICODE_equal(<Py_UNICODE*>u"u", u)
9593
u = uobj[1:7]
96-
assert Py_UNICODE_equal(<Py_UNICODE*>u"nicode", u)
94+
assert_Py_UNICODE_equal(<Py_UNICODE*>u"nicode", u)
9795
u = uobj[1]
98-
assert Py_UNICODE_equal(<Py_UNICODE*>u"n", u)
96+
assert_Py_UNICODE_equal(<Py_UNICODE*>u"n", u)
9997

100-
assert Py_UNICODE_equal(uwide_literal, <Py_UNICODE*>c_pu_wide_literal), (uwide_literal, <unicode>c_pu_wide_literal)
98+
assert_Py_UNICODE_equal(uwide_literal, <Py_UNICODE*>c_pu_wide_literal)
10199

102100
assert len(u"abc\0") == 4
103101
assert len(<Py_UNICODE*>u"abc\0") == 3

0 commit comments

Comments
 (0)