From: Daniele Varrazzo Date: Sun, 20 Mar 2022 15:10:03 +0000 (+0100) Subject: test(cursor): make sure Column.name is right for invalid names too X-Git-Tag: 3.1~109^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb8390e2541b1ae565fac06ce2eb54f4c5cacdfb;p=thirdparty%2Fpsycopg.git test(cursor): make sure Column.name is right for invalid names too --- diff --git a/tests/test_cursor.py b/tests/test_cursor.py index 646304240..1d1b6275d 100644 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -744,6 +744,20 @@ class TestColumn: assert col.name == "foo" assert col.type_code == 23 + def test_name_not_a_name(self, conn): + cur = conn.cursor() + (res,) = cur.execute("""select 'x' as "foo-bar" """).fetchone() + assert res == "x" + assert cur.description[0].name == "foo-bar" + + @pytest.mark.parametrize("encoding", ["utf8", "latin9"]) + def test_name_encode(self, conn, encoding): + conn.execute(f"set client_encoding to {encoding}") + cur = conn.cursor() + (res,) = cur.execute("""select 'x' as "\u20ac" """).fetchone() + assert res == "x" + assert cur.description[0].name == "\u20ac" + def test_str(conn): cur = conn.cursor()