def test_set_encoding(conn): newenc = "iso8859-1" if conn.client_encoding != "iso8859-1" else "utf-8" assert conn.client_encoding != newenc conn.client_encoding = newenc assert conn.client_encoding == newenc (enc, ) = conn.cursor().execute("show client_encoding").fetchone() assert encodings.pg2py(enc) == newenc
async def test_set_encoding(aconn): newenc = "iso8859-1" if aconn.client_encoding != "iso8859-1" else "utf-8" assert aconn.client_encoding != newenc with pytest.raises(AttributeError): aconn.client_encoding = newenc assert aconn.client_encoding != newenc await aconn.set_client_encoding(newenc) assert aconn.client_encoding == newenc cur = await aconn.cursor() await cur.execute("show client_encoding") (enc,) = await cur.fetchone() assert encodings.pg2py(enc) == newenc
def test_get_encoding(conn): (enc, ) = conn.cursor().execute("show client_encoding").fetchone() assert conn.client_encoding == encodings.pg2py(enc)
async def test_get_encoding(aconn): cur = await aconn.cursor() await cur.execute("show client_encoding") (enc,) = await cur.fetchone() assert aconn.client_encoding == encodings.pg2py(enc)
def test_pg2py_missing(pgenc): with pytest.raises(psycopg3.NotSupportedError): encodings.pg2py(pgenc.encode("utf-8"))
def test_pg2py(pyenc, pgenc): assert encodings.pg2py(pgenc.encode("utf-8")) == pyenc