]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test: add test to verify the wrong array oid with numbers
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 5 May 2022 21:04:10 +0000 (23:04 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 8 May 2022 19:11:44 +0000 (21:11 +0200)
The array binary dumper does the right thing; the text one picks
numeric[] unconditionally. It was clearly made on purpose, but #293
shows that it's a bad idea.

tests/types/test_array.py

index eeacd1bc8550adc39a93b6306ef99b1563a5773f..a0b27c3c3b94d259683c8893e19249de65d830c8 100644 (file)
@@ -139,10 +139,25 @@ def test_array_of_unknown_builtin(conn):
     assert res[1] == [val]
 
 
-@pytest.mark.parametrize("array, type", [([1, 32767], "int2"), ([1, 32768], "int4")])
-def test_array_mixed_numbers(array, type):
+@pytest.mark.parametrize(
+    "array, type",
+    [
+        ([0], "int2"),
+        ([1, 2**15 - 1], "int2"),
+        ([1, -(2**15)], "int2"),
+        ([1, 2**15], "int4"),
+        ([1, 2**31 - 1], "int4"),
+        ([1, -(2**31)], "int4"),
+        ([1, 2**31], "int8"),
+        ([1, 2**63 - 1], "int8"),
+        ([1, -(2**63)], "int8"),
+        ([1, 2**63], "numeric"),
+    ],
+)
+@pytest.mark.parametrize("fmt_in", PyFormat)
+def test_numbers_array(array, type, fmt_in):
     tx = Transformer()
-    dumper = tx.get_dumper(array, PyFormat.BINARY)
+    dumper = tx.get_dumper(array, fmt_in)
     dumper.dump(array)
     assert dumper.oid == builtins[type].array_oid