Skip to content

Commit

Permalink
Add a test illustrating python and postgres encoding mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
dlax committed Mar 9, 2023
1 parent 618e0db commit d51dd82
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ def test_encoding(postgresql, data, execute):
assert blocking.query and "blocking éléphant" in blocking.query


@pytest.mark.parametrize(
"pyenc, pgenc",
[
("utf8", "UTF8"),
pytest.param("ascii", "SQL_ASCII", marks=pytest.mark.xfail),
],
)
def test_postgres_and_python_encoding(pyenc: str, pgenc: str, data, postgresql) -> None:
dbname = pyenc
with psycopg.connect(postgresql.info.dsn, autocommit=True) as conn:
conn.execute(f"CREATE DATABASE {dbname} ENCODING {pgenc} TEMPLATE template0")
with psycopg.connect(postgresql.info.dsn, dbname=dbname) as conn:
conn.execute("SELECT 'encoding'")
(running,) = data.pg_get_activities()
assert "'encoding'" in running.query
assert running.encoding.lower() == pyenc


def test_filters_dbname(data, execute):
data_filtered = attr.evolve(data, filters=types.Filters(dbname="temp"))
execute("SELECT pg_sleep(2)", dbname="template1", autocommit=True)
Expand Down

0 comments on commit d51dd82

Please sign in to comment.