From: Daniele Varrazzo Date: Wed, 20 Jan 2021 01:56:52 +0000 (+0100) Subject: Added test to verify queries failing if int is dumped as int8 or numeric X-Git-Tag: 3.0.dev0~142 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c82f94297a25d003a33688774c4cd1e00ae4735;p=thirdparty%2Fpsycopg.git Added test to verify queries failing if int is dumped as int8 or numeric I wanted these so badly. --- diff --git a/tests/test_adapt.py b/tests/test_adapt.py index a32ea2e4f..1782e939e 100644 --- a/tests/test_adapt.py +++ b/tests/test_adapt.py @@ -1,3 +1,5 @@ +import datetime as dt + import pytest import psycopg3 @@ -228,7 +230,7 @@ def test_none_type_argument(conn, fmt_in): assert cur.fetchone()[0] -@pytest.mark.parametrize("fmt_in", [Format.TEXT, Format.BINARY]) +@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY]) def test_return_untyped(conn, fmt_in): # Analyze and check for changes using strings in untyped/typed contexts cur = conn.cursor() @@ -243,6 +245,16 @@ def test_return_untyped(conn, fmt_in): assert cur.execute("select data from testjson").fetchone() == ({},) +@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY]) +def test_no_cast_needed(conn, fmt_in): + # Verify that there is no need of cast in certain common scenario + cur = conn.execute("select '2021-01-01'::date + %s", [3]) + assert cur.fetchone()[0] == dt.date(2021, 1, 4) + + cur = conn.execute("select '[10, 20, 30]'::jsonb -> %s", [1]) + assert cur.fetchone()[0] == 20 + + def test_optimised_adapters(): if psycopg3.pq.__impl__ == "python": pytest.skip("test C module only")