From: Daniele Varrazzo Date: Thu, 29 Oct 2020 14:06:19 +0000 (+0100) Subject: Fixed tests with PostgreSQL 9.6 and previous X-Git-Tag: 3.0.dev0~414 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2481a2499021468f1980c825d0a249beccfa055a;p=thirdparty%2Fpsycopg.git Fixed tests with PostgreSQL 9.6 and previous Such database version doesn't allow to emit unknown oid literals. However specifying a different type for unknown, such as text, will fail as soon as the value is used in a typed context, which is a far more useful use case. --- diff --git a/tests/test_cursor.py b/tests/test_cursor.py index 9a9038dca..8ffbb3cc5 100644 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -63,7 +63,8 @@ def test_execute_many_results(conn): def test_execute_sequence(conn): cur = conn.cursor() - rv = cur.execute("select %s, %s, %s", [1, "foo", None]) + cast = "::text" if conn.pgconn.server_version < 100000 else "" + rv = cur.execute(f"select %s, %s, %s{cast}", [1, "foo", None]) assert rv is cur assert len(cur._results) == 1 assert cur.pgresult.get_value(0, 0) == b"1" @@ -83,7 +84,8 @@ def test_execute_empty_query(conn, query): def test_fetchone(conn): cur = conn.cursor() - cur.execute("select %s, %s, %s", [1, "foo", None]) + cast = "::text" if conn.pgconn.server_version < 100000 else "" + cur.execute(f"select %s, %s, %s{cast}", [1, "foo", None]) assert cur.pgresult.fformat(0) == 0 row = cur.fetchone() @@ -96,7 +98,8 @@ def test_fetchone(conn): def test_execute_binary_result(conn): cur = conn.cursor(format=psycopg3.pq.Format.BINARY) - cur.execute("select %s, %s", ["foo", None]) + cast = "::text" if conn.pgconn.server_version < 100000 else "" + cur.execute(f"select %s, %s{cast}", ["foo", None]) assert cur.pgresult.fformat(0) == 1 row = cur.fetchone() diff --git a/tests/test_cursor_async.py b/tests/test_cursor_async.py index dabada93f..3462b093b 100644 --- a/tests/test_cursor_async.py +++ b/tests/test_cursor_async.py @@ -66,7 +66,8 @@ async def test_execute_many_results(aconn): async def test_execute_sequence(aconn): cur = aconn.cursor() - rv = await cur.execute("select %s, %s, %s", [1, "foo", None]) + cast = "::text" if aconn.pgconn.server_version < 100000 else "" + rv = await cur.execute(f"select %s, %s, %s{cast}", [1, "foo", None]) assert rv is cur assert len(cur._results) == 1 assert cur.pgresult.get_value(0, 0) == b"1" @@ -86,7 +87,8 @@ async def test_execute_empty_query(aconn, query): async def test_fetchone(aconn): cur = aconn.cursor() - await cur.execute("select %s, %s, %s", [1, "foo", None]) + cast = "::text" if aconn.pgconn.server_version < 100000 else "" + await cur.execute(f"select %s, %s, %s{cast}", [1, "foo", None]) assert cur.pgresult.fformat(0) == 0 row = await cur.fetchone() @@ -99,7 +101,8 @@ async def test_fetchone(aconn): async def test_execute_binary_result(aconn): cur = aconn.cursor(format=psycopg3.pq.Format.BINARY) - await cur.execute("select %s, %s", ["foo", None]) + cast = "::text" if aconn.pgconn.server_version < 100000 else "" + await cur.execute(f"select %s, %s{cast}", ["foo", None]) assert cur.pgresult.fformat(0) == 1 row = await cur.fetchone() diff --git a/tests/types/test_singletons.py b/tests/types/test_singletons.py index 14ff018d8..c3c41e283 100644 --- a/tests/types/test_singletons.py +++ b/tests/types/test_singletons.py @@ -11,7 +11,8 @@ from psycopg3.types import builtins def test_roundtrip_bool(conn, b, fmt_in, fmt_out): cur = conn.cursor(format=fmt_out) ph = "%s" if fmt_in == Format.TEXT else "%b" - result = cur.execute(f"select {ph}", (b,)).fetchone()[0] + cast = "" if conn.pgconn.server_version > 100000 else "::bool" + result = cur.execute(f"select {ph}{cast}", (b,)).fetchone()[0] assert cur.pgresult.fformat(0) == fmt_out if b is not None: assert cur.pgresult.ftype(0) == builtins["bool"].oid