From 59f587569fe51cfc40868fc221dcbc4ac1a3c958 Mon Sep 17 00:00:00 2001 From: Ilan Schnell Date: Fri, 17 Feb 2023 21:17:12 -0600 Subject: [PATCH] improve testing for PyPy, see also #188 --- bitarray/test_bitarray.py | 22 ++++++++++++++++++---- bitarray/test_util.py | 8 ++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/bitarray/test_bitarray.py b/bitarray/test_bitarray.py index 9630d416..22186a93 100644 --- a/bitarray/test_bitarray.py +++ b/bitarray/test_bitarray.py @@ -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 @@ -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) @@ -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) @@ -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()): # @@ -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: @@ -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) @@ -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') @@ -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') @@ -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') @@ -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) @@ -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)} @@ -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') @@ -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) @@ -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]) @@ -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) @@ -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) @@ -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) @@ -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( diff --git a/bitarray/test_util.py b/bitarray/test_util.py index 39ec4c80..412575c3 100644 --- a/bitarray/test_util.py +++ b/bitarray/test_util.py @@ -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, @@ -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, @@ -1261,7 +1261,7 @@ 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" @@ -1269,7 +1269,7 @@ def test_decode_errors(self): 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"