From: Stanley Kudrow Date: Thu, 31 Oct 2024 06:23:11 +0000 (+0300) Subject: test(numpy): account for 32 bits systems in size checks X-Git-Tag: 3.2.4~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b75307bb502483bf6dad5f7bff2d86aa7580d04;p=thirdparty%2Fpsycopg.git test(numpy): account for 32 bits systems in size checks --- diff --git a/tests/types/test_numpy.py b/tests/types/test_numpy.py index f9fabc487..86e007831 100644 --- a/tests/types/test_numpy.py +++ b/tests/types/test_numpy.py @@ -1,3 +1,4 @@ +import struct from math import isnan import pytest @@ -20,17 +21,32 @@ skip_numpy2 = pytest.mark.skipif( ) +def _get_arch_size() -> int: + psize = struct.calcsize("P") * 8 + if psize not in (32, 64): + msg = f"the pointer size {psize} is unusual" + raise ValueError(msg) + return psize + + def test_classes_identities(): # Check if we know the class identities correctly. Maybe on different # platforms they are different. - assert np.ubyte is np.uint8 - assert np.ushort is np.uint16 - assert np.uint is np.uint64 - assert np.uintc is np.uint32 + size = _get_arch_size() + assert np.byte is np.int8 + assert np.ubyte is np.uint8 + assert np.short is np.int16 - assert np.intc is np.int32 - assert np.int_ is np.int64 + assert np.ushort is np.uint16 + + if size == 32: + assert np.uint is np.uint32 + assert np.uintc is np.uint32 + assert np.intc is np.int32 + else: + assert np.uint is np.uint64 + assert np.int_ is np.int64 @pytest.mark.parametrize(