Skip to content

Commit

Permalink
improve testing for PyPy, see also #188
Browse files Browse the repository at this point in the history
  • Loading branch information
ilanschnell committed Feb 18, 2023
1 parent 09f502d commit 59f5875
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
22 changes: 18 additions & 4 deletions bitarray/test_bitarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

is_py3k = bool(sys.version_info[0] == 3)
pyodide = bool(platform.machine() == 'wasm32')
is_pypy = bool(platform.python_implementation() == 'PyPy')

if is_py3k:
from io import BytesIO
Expand Down Expand Up @@ -342,6 +343,7 @@ def test_buffer_readonly(self):
self.assertEQUAL(a, bitarray('00001111', 'little'))
self.check_obj(a)

@skipIf(is_pypy)
def test_buffer_writeable(self):
a = bitarray(buffer=bytearray([65]))
self.assertFalse(a.readonly)
Expand Down Expand Up @@ -604,6 +606,7 @@ def test_wrong_args(self):
# too many args
self.assertRaises(TypeError, bitarray, 0, 'big', 0)

@skipIf(is_pypy)
def test_weakref(self):
a = bitarray('0100')
b = weakref.proxy(a)
Expand Down Expand Up @@ -1084,6 +1087,7 @@ def test_setslice_self_shared_buffer_2(self):
a[15:7:-1] = b
self.assertEqual(a, bitarray('11111111 00000011 00000000'))

@skipIf(is_pypy)
def test_setslice_self_shared_buffer_3(self):
# Requires to check for (in setslice_bitarray()):
#
Expand Down Expand Up @@ -1540,6 +1544,7 @@ def test_pickle(self):
self.assertEQUAL(a, b)
self.check_obj(b)

@skipIf(is_pypy)
def test_overflow(self):
a = bitarray(1)
for i in -7, -1, 0, 1:
Expand Down Expand Up @@ -1785,6 +1790,7 @@ def test_equality_random(self):
b.invert(n - 1) # flip last bit
self.assertReallyNotEqual(a, b)

@skipIf(is_pypy)
def test_sizeof(self):
a = bitarray()
size = sys.getsizeof(a)
Expand Down Expand Up @@ -3723,7 +3729,7 @@ def test_tofile_BytesIO(self):
a.tofile(f)
self.assertEqual(f.getvalue(), data)

@skipIf(sys.version_info[0] == 2)
@skipIf(sys.version_info[0] == 2 or is_pypy)
def test_mmap(self):
with open(self.tmpfname, 'wb') as fo:
fo.write(1000 * b'\0')
Expand All @@ -3743,7 +3749,7 @@ def test_mmap(self):
self.assertEqual(self.read_file(), 1000 * b'\x55')

# pyodide hits emscripten mmap bug
@skipIf(sys.version_info[0] == 2 or pyodide)
@skipIf(sys.version_info[0] == 2 or pyodide or is_pypy)
def test_mmap_2(self):
with open(self.tmpfname, 'wb') as fo:
fo.write(1000 * b'\x22')
Expand All @@ -3758,7 +3764,7 @@ def test_mmap_2(self):

self.assertEqual(self.read_file(), 1000 * b'\x33')

@skipIf(sys.version_info[0] == 2)
@skipIf(sys.version_info[0] == 2 or is_pypy)
def test_mmap_readonly(self):
with open(self.tmpfname, 'wb') as fo:
fo.write(994 * b'\x89' + b'Veedon')
Expand Down Expand Up @@ -3817,6 +3823,7 @@ def test_ambiguous_code(self):
]:
self.assertRaises(ValueError, decodetree, d)

@skipIf(is_pypy)
def test_sizeof(self):
dt = decodetree({'.': bitarray('1')})
self.assertTrue(0 < sys.getsizeof(dt) < 100)
Expand Down Expand Up @@ -3870,6 +3877,7 @@ def test_decode(self):
self.assertEqual(''.join(a.iterdecode(t)), '')
self.check_obj(a)

@skipIf(is_pypy)
def test_large(self):
d = {i: bitarray(bool((1 << j) & i) for j in range(10))
for i in range(1024)}
Expand Down Expand Up @@ -4160,6 +4168,7 @@ def test_bytes(self):
self.assertEqual(a, zeros(800))
self.check_obj(a)

@skipIf(is_pypy)
def test_bytearray(self):
b = bytearray(100 * [0])
a = bitarray(buffer=b, endian='little')
Expand Down Expand Up @@ -4188,7 +4197,7 @@ def test_bytearray(self):
self.check_obj(a)

# Python 2's array cannot be used as buffer
@skipIf(sys.version_info[0] == 2)
@skipIf(sys.version_info[0] == 2 or is_pypy)
def test_array(self):
a = array.array('B', [0, 255, 64])
b = bitarray(None, 'little', a)
Expand Down Expand Up @@ -4237,6 +4246,7 @@ def test_bitarray(self):
self.check_obj(a)
self.check_obj(b)

@skipIf(is_pypy)
def test_bitarray_shared_sections(self):
a = urandom(0x2000)
b = bitarray(buffer=memoryview(a)[0x100:0x300])
Expand Down Expand Up @@ -4297,6 +4307,7 @@ def test_invalid_buffer(self):
set([1, 2, 3]),):
self.assertRaises(TypeError, bitarray, buffer=arg)

@skipIf(is_pypy)
def test_del_import_object(self):
b = bytearray(100 * [0])
a = bitarray(buffer=b)
Expand All @@ -4306,6 +4317,7 @@ def test_del_import_object(self):
self.assertTrue(a.all())
self.check_obj(a)

@skipIf(is_pypy)
def test_readonly_errors(self):
a = bitarray(buffer=b'A')
info = buffer_info(a)
Expand Down Expand Up @@ -4337,6 +4349,7 @@ def test_readonly_errors(self):
self.assertRaises(TypeError, a.__ilshift__, 1)
self.check_obj(a)

@skipIf(is_pypy)
def test_resize_errors(self):
a = bitarray(buffer=bytearray([123]))
info = buffer_info(a)
Expand Down Expand Up @@ -4574,6 +4587,7 @@ def test_buffer_import_readonly(self):
self.assertTrue(info['readonly'])
self.assertTrue(info['imported'])

@skipIf(is_pypy)
def test_buffer_import_writable(self):
c = bytearray([15, 95])
self.assertRaisesMessage(
Expand Down
8 changes: 4 additions & 4 deletions bitarray/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from bitarray import (bitarray, frozenbitarray, decodetree, bits2bytes,
_set_default_endian)
from bitarray.test_bitarray import Util, skipIf, DEBUG
from bitarray.test_bitarray import Util, skipIf, SYSINFO, DEBUG

from bitarray.util import (
zeros, urandom, pprint, make_endian, rindex, strip, count_n,
Expand Down Expand Up @@ -1220,7 +1220,7 @@ def test_decode_header_errors(self):
bytearray([0x01, 0x10, c]))

def test_decode_header_overflow(self):
nbytes = tuple.__itemsize__
nbytes = SYSINFO[1]
self.assertRaisesMessage(
OverflowError,
"sizeof(Py_ssize_t) = %d: cannot read 9 bytes" % nbytes,
Expand Down Expand Up @@ -1261,15 +1261,15 @@ def test_decode_errors(self):
ValueError, "decode error (n=3): 32768 >= 32768",
sc_decode, b"\x02\x00\x80\xc3\x01\x00\x80\x00\0")

if tuple.__itemsize__ == 4:
if SYSINFO[1] == 4:
msg = "read 4 bytes got negative value: -2147483648"
else:
msg = "decode error (n=4): 2147483648 >= 16"
self.assertRaisesMessage(
ValueError, msg,
sc_decode, b"\x01\x10\xc4\x01\x00\x00\x00\x80\0")

if tuple.__itemsize__ == 4:
if SYSINFO[1] == 4:
msg = "read 4 bytes got negative value: -1"
else:
msg = "decode error (n=4): 4294967295 >= 16"
Expand Down

0 comments on commit 59f5875

Please sign in to comment.