Fix tests on Python 2

parent 80467731
...@@ -1094,22 +1094,24 @@ def test_assign_from_byteslike(byteslike): ...@@ -1094,22 +1094,24 @@ def test_assign_from_byteslike(byteslike):
b'hello' b'hello'
>>> test_assign_from_byteslike(bytearray(b'howdy')) >>> test_assign_from_byteslike(bytearray(b'howdy'))
b'howdy' b'howdy'
>>> test_assign_from_byteslike(pyarray.array('B', b'aloha'))
b'aloha'
>>> test_assign_from_byteslike(memoryview(b'bye!!'))
b'bye!!'
""" """
# fails on Python 2.7- with
# TypeError: an integer is required
# >>> test_assign_from_byteslike(pyarray.array('B', b'aloha'))
# b'aloha'
# fails on Python 2.6- with
# NameError: name 'memoryview' is not defined
# >>> test_assign_from_byteslike(memoryview(b'bye!!'))
# b'bye!!'
def assign(m):
m[:] = byteslike
cdef void *buf cdef void *buf
cdef unsigned char[:] mview cdef unsigned char[:] mview
buf = malloc(5) buf = malloc(5)
try: try:
mview = <unsigned char[:5]>(buf) mview = <unsigned char[:5]>(buf)
def assign(b):
b[:] = byteslike
assign(mview) assign(mview)
return bytes(mview) return (<unsigned char*>buf)[:5]
finally: finally:
free(buf) free(buf)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment