From: Daniele Varrazzo Date: Sun, 17 Apr 2022 22:52:27 +0000 (+0200) Subject: test(enum): add test to verify enums work with sql_ascii connections X-Git-Tag: 3.1~137^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e4e7c11bf382200b240abe8aadd10b2d803d78e;p=thirdparty%2Fpsycopg.git test(enum): add test to verify enums work with sql_ascii connections --- diff --git a/tests/types/test_enum.py b/tests/types/test_enum.py index 1f0b5af4a..8a1ffc7f4 100644 --- a/tests/types/test_enum.py +++ b/tests/types/test_enum.py @@ -66,6 +66,21 @@ def test_enum_loader(conn, testenum, encoding, fmt_in, fmt_out): assert cur.fetchone()[0] == enum(label) +@pytest.mark.parametrize("fmt_in", PyFormat) +@pytest.mark.parametrize("fmt_out", pq.Format) +def test_enum_loader_sqlascii(conn, testenum, fmt_in, fmt_out): + name, enum, labels = testenum + if name == "nonasciienum": + pytest.skip("ascii-only test") + + register_enum(EnumInfo.fetch(conn, name), enum, conn) + conn.execute("set client_encoding to sql_ascii") + + for label in labels: + cur = conn.execute(f"select %{fmt_in}::{name}", [label], binary=fmt_out) + assert cur.fetchone()[0] == enum(label) + + @pytest.mark.parametrize("encoding", encodings) @pytest.mark.parametrize("fmt_in", PyFormat) @pytest.mark.parametrize("fmt_out", pq.Format) @@ -80,6 +95,21 @@ def test_enum_dumper(conn, testenum, encoding, fmt_in, fmt_out): assert cur.fetchone()[0] == item +@pytest.mark.parametrize("fmt_in", PyFormat) +@pytest.mark.parametrize("fmt_out", pq.Format) +def test_enum_dumper_sqlascii(conn, testenum, fmt_in, fmt_out): + name, enum, labels = testenum + if name == "nonasciienum": + pytest.skip("ascii-only test") + + register_enum(EnumInfo.fetch(conn, name), enum, conn) + conn.execute("set client_encoding to sql_ascii") + + for item in enum: + cur = conn.execute(f"select %{fmt_in}", [item], binary=fmt_out) + assert cur.fetchone()[0] == item + + @pytest.mark.parametrize("encoding", encodings) @pytest.mark.parametrize("fmt_in", PyFormat) @pytest.mark.parametrize("fmt_out", pq.Format)