From: Daniele Varrazzo Date: Fri, 14 May 2021 17:42:29 +0000 (+0200) Subject: Add test for timestamptz timezone load behaviour X-Git-Tag: 3.0.dev0~42^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=498df49169ca9db598b7442da6a3f5fbc33bea05;p=thirdparty%2Fpsycopg.git Add test for timestamptz timezone load behaviour --- diff --git a/tests/types/test_date.py b/tests/types/test_date.py index 607eb45d9..e38651aa6 100644 --- a/tests/types/test_date.py +++ b/tests/types/test_date.py @@ -280,6 +280,25 @@ def test_load_datetimetz_tzname(conn, val, expr, datestyle_in, datestyle_out): assert cur.fetchone()[0] == as_dt(val) +@pytest.mark.parametrize( + "tzname, expr, tzoff", + [ + ("UTC", "2000-1-1", 0), + ("UTC", "2000-7-1", 0), + ("Europe/Rome", "2000-1-1", 3600), + ("Europe/Rome", "2000-7-1", 7200), + ("Europe/Rome", "1000-1-1", 2996), + ("NOSUCH0", "2000-1-1", 0), + ], +) +@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY]) +def test_load_datetimetz_tz(conn, fmt_out, tzname, expr, tzoff): + conn.execute("select set_config('TimeZone', %s, true)", [tzname]) + cur = conn.cursor(binary=fmt_out) + ts = cur.execute("select %s::timestamptz", [expr]).fetchone()[0] + assert ts.utcoffset().total_seconds() == tzoff + + @pytest.mark.parametrize( "val, type", [