From: Daniele Varrazzo Date: Sun, 5 Jun 2022 23:10:05 +0000 (+0200) Subject: test(crdb): adapt array tests X-Git-Tag: 3.1~49^2~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=274220217105555157a87fd68a1b3aff318f3144;p=thirdparty%2Fpsycopg.git test(crdb): adapt array tests --- diff --git a/tests/fix_crdb.py b/tests/fix_crdb.py index d989582c8..b827fb66e 100644 --- a/tests/fix_crdb.py +++ b/tests/fix_crdb.py @@ -96,6 +96,7 @@ _crdb_reasons = { "deferrable": 48307, "do": 17511, "encoding": 35882, + "geometric types": 21286, "hstore": 41284, "infinity date": 41564, "interval style": 35807, diff --git a/tests/types/test_array.py b/tests/types/test_array.py index 07f99e146..e27f5bdfb 100644 --- a/tests/types/test_array.py +++ b/tests/types/test_array.py @@ -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)