]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test(crdb): adapt array tests
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 5 Jun 2022 23:10:05 +0000 (01:10 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 12 Jul 2022 11:58:34 +0000 (12:58 +0100)
tests/fix_crdb.py
tests/types/test_array.py

index d989582c87acda8eff39d246f8c939bdf0c611e9..b827fb66eb5ad1c4081df8190fb34dba7215d39a 100644 (file)
@@ -96,6 +96,7 @@ _crdb_reasons = {
     "deferrable": 48307,
     "do": 17511,
     "encoding": 35882,
+    "geometric types": 21286,
     "hstore": 41284,
     "infinity date": 41564,
     "interval style": 35807,
index 07f99e1463a3374c1c07f94d9e31e9f0411b2f7f..e27f5bdfbb6b637166ef564ee6217a74e7a7d8da 100644 (file)
@@ -11,7 +11,6 @@ from psycopg.postgres import types as builtins
 
 
 tests_str = [
-    ([], "{}"),
     ([[[[[["a"]]]]]], "{{{{{{a}}}}}}"),
     ([[[[[[None]]]]]], "{{{{{{NULL}}}}}}"),
     (["foo", "bar", "baz"], "{foo,bar,baz}"),
@@ -28,6 +27,15 @@ tests_str = [
 ]
 
 
+@pytest.mark.parametrize("fmt_in", PyFormat)
+@pytest.mark.parametrize("type", ["text", "int4"])
+def test_dump_empty_list(conn, fmt_in, type):
+    cur = conn.cursor()
+    cur.execute(f"select %{fmt_in.value}::{type}[] = %s::{type}[]", ([], "{}"))
+    assert cur.fetchone()[0]
+
+
+@pytest.mark.crdb("skip", reason="nested array")
 @pytest.mark.parametrize("fmt_in", PyFormat)
 @pytest.mark.parametrize("obj, want", tests_str)
 def test_dump_list_str(conn, obj, want, fmt_in):
@@ -36,6 +44,14 @@ def test_dump_list_str(conn, obj, want, fmt_in):
     assert cur.fetchone()[0]
 
 
+@pytest.mark.parametrize("fmt_out", pq.Format)
+def test_load_empty_list_str(conn, fmt_out):
+    cur = conn.cursor(binary=fmt_out)
+    cur.execute("select %s::text[]", ([],))
+    assert cur.fetchone()[0] == []
+
+
+@pytest.mark.crdb("skip", reason="nested array")
 @pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize("want, obj", tests_str)
 def test_load_list_str(conn, obj, want, fmt_out):
@@ -64,13 +80,13 @@ def test_all_chars(conn, fmt_in, fmt_out):
 
 
 tests_int = [
-    ([], "{}"),
     ([10, 20, -30], "{10,20,-30}"),
     ([10, None, 30], "{10,null,30}"),
     ([[10, 20], [30, 40]], "{{10,20},{30,40}}"),
 ]
 
 
+@pytest.mark.crdb("skip", reason="nested array")
 @pytest.mark.parametrize("obj, want", tests_int)
 def test_dump_list_int(conn, obj, want):
     cur = conn.cursor()
@@ -94,6 +110,7 @@ def test_bad_binary_array(input):
         tx.get_dumper(input, PyFormat.BINARY).dump(input)
 
 
+@pytest.mark.crdb("skip", reason="nested array")
 @pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize("want, obj", tests_int)
 def test_load_list_int(conn, obj, want, fmt_out):
@@ -111,6 +128,7 @@ def test_load_list_int(conn, obj, want, fmt_out):
     assert got == want
 
 
+@pytest.mark.crdb("skip", reason="composite")
 def test_array_register(conn):
     conn.execute("create table mytype (data text)")
     cur = conn.execute("""select '(foo)'::mytype, '{"(foo)"}'::mytype[]""")
@@ -127,6 +145,7 @@ def test_array_register(conn):
     assert res[1] == ["(foo)"]
 
 
+@pytest.mark.crdb("skip", reason="aclitem")
 def test_array_of_unknown_builtin(conn):
     user = conn.execute("select user").fetchone()[0]
     # we cannot load this type, but we understand it is an array
@@ -209,12 +228,15 @@ def test_empty_list(conn, fmt_in):
     cur = conn.cursor()
     cur.execute("create table test (id serial primary key, data date[])")
     with conn.transaction():
-        cur.execute(f"insert into test (data) values (%{fmt_in.value})", ([],))
+        cur.execute(
+            f"insert into test (data) values (%{fmt_in.value}) returning id", ([],)
+        )
+        id = cur.fetchone()[0]
     cur.execute("select data from test")
     assert cur.fetchone() == ([],)
 
     # test untyped list in a filter
-    cur.execute(f"select data from test where id = any(%{fmt_in.value})", ([1],))
+    cur.execute(f"select data from test where id = any(%{fmt_in.value})", ([id],))
     assert cur.fetchone()
     cur.execute(f"select data from test where id = any(%{fmt_in.value})", ([],))
     assert not cur.fetchone()
@@ -231,6 +253,7 @@ def test_empty_list_after_choice(conn, fmt_in):
     assert cur.fetchall() == [([1.0],), ([],)]
 
 
+@pytest.mark.crdb("skip", reason="geometric types")
 def test_dump_list_no_comma_separator(conn):
     class Box:
         def __init__(self, x1, y1, x2, y2):
@@ -257,12 +280,14 @@ def test_dump_list_no_comma_separator(conn):
     assert got == "{(3,4),(1,2);(5,4),(3,2)}"
 
 
+@pytest.mark.crdb("skip", reason="geometric types")
 def test_load_array_no_comma_separator(conn):
     cur = conn.execute("select '{(2,2),(1,1);(5,6),(3,4)}'::box[]")
     # Not parsed at the moment, but split ok on ; separator
     assert cur.fetchone()[0] == ["(2,2),(1,1)", "(5,6),(3,4)"]
 
 
+@pytest.mark.crdb("skip", reason="array with bounds")
 @pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize(
     "obj, want",
@@ -276,6 +301,7 @@ def test_array_with_bounds(conn, obj, want, fmt_out):
     assert got == want
 
 
+@pytest.mark.crdb("skip", reason="array with bounds")
 @pytest.mark.parametrize("fmt_out", pq.Format)
 def test_all_chars_with_bounds(conn, fmt_out):
     cur = conn.cursor(binary=fmt_out)