]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test(cursor): make sure Column.name is right for invalid names too
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 20 Mar 2022 15:10:03 +0000 (16:10 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 10 May 2022 17:13:26 +0000 (19:13 +0200)
tests/test_cursor.py

index 646304240c193f2892c20257333df3a8656f7ea3..1d1b6275d038ecc97622a3a056c75491532f7660 100644 (file)
@@ -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()