]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test(numpy): add dump tests with list of numpy values
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 19 Dec 2022 15:01:39 +0000 (15:01 +0000)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 5 Aug 2023 14:21:30 +0000 (15:21 +0100)
tests/types/test_numpy.py

index 0d283392ceae032527fea965bab27ad8c72bfeed..fac83ed84dc7abfa2e86dcf1db8422b6ad62af4d 100644 (file)
@@ -92,6 +92,9 @@ def test_dump_int(conn, val, nptype, expr, fmt_in):
     cur.execute(f"select {expr} = %{fmt_in.value}", (val,))
     assert cur.fetchone()[0] is True
 
+    cur.execute(f"select array[{expr}] = %{fmt_in.value}", ([val],))
+    assert cur.fetchone()[0] is True
+
 
 @pytest.mark.parametrize(
     "nptype, val, pgtype",
@@ -128,11 +131,20 @@ def test_dump_float(conn, nptype, val, pgtype, fmt_in):
     else:
         assert rec[0] == rec[1]
 
+    cur.execute(
+        f"select array['{val}']::{pgtype}[], %(obj){fmt_in.value}", {"obj": [val]}
+    )
+    rec = cur.fetchone()
+    if nptype is np.float16:
+        assert rec[0][0] == pytest.approx(rec[1][0], 1e-3)
+    else:
+        assert rec[0][0] == rec[1][0]
+
 
 @pytest.mark.slow
 @pytest.mark.parametrize("fmt", PyFormat)
 def test_random(conn, faker, fmt):
-    faker.types = [t for t in faker.types if issubclass(t, np.generic)]
+    faker.types = [t for t in faker.types if issubclass(t, (list, np.generic))]
     faker.format = fmt
     faker.choose_schema(ncols=20)
     faker.make_records(50)