]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test(numpy): account for 32 bits systems in size checks
authorStanley Kudrow <stankudrow@reply.no>
Thu, 31 Oct 2024 06:23:11 +0000 (09:23 +0300)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 5 Nov 2024 22:28:26 +0000 (23:28 +0100)
tests/types/test_numpy.py

index f9fabc48719644ea43b4bdad97d35123d98ffb0e..86e00783115c4110ae521532328583b2130ce4aa 100644 (file)
@@ -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(