From 7ea4a0be8c2ade47f3c3fb4f8a502981f95e561d Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 2 Jan 2022 18:58:17 +0100 Subject: [PATCH] Fix test suite to run on database in locales different from English --- tests/pq/test_misc.py | 2 +- tests/pq/test_pgresult.py | 4 +++- tests/test_connection.py | 4 +++- tests/test_connection_async.py | 4 +++- tests/test_errors.py | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/pq/test_misc.py b/tests/pq/test_misc.py index ec65bb3ff..ca809a856 100644 --- a/tests/pq/test_misc.py +++ b/tests/pq/test_misc.py @@ -8,7 +8,7 @@ def test_error_message(pgconn): res = pgconn.exec_(b"wat") assert res.status == pq.ExecStatus.FATAL_ERROR msg = pq.error_message(pgconn) - assert msg == 'syntax error at or near "wat"\nLINE 1: wat\n ^' + assert "wat" in msg assert msg == pq.error_message(res) primary = res.error_field(pq.DiagnosticField.MESSAGE_PRIMARY) assert primary.decode("ascii") in msg diff --git a/tests/pq/test_pgresult.py b/tests/pq/test_pgresult.py index 0cfcfcf45..a40b54feb 100644 --- a/tests/pq/test_pgresult.py +++ b/tests/pq/test_pgresult.py @@ -52,7 +52,9 @@ def test_error_message(pgconn): def test_error_field(pgconn): res = pgconn.exec_(b"select wat") - assert res.error_field(pq.DiagnosticField.SEVERITY) == b"ERROR" + assert ( + res.error_field(pq.DiagnosticField.SEVERITY_NONLOCALIZED) == b"ERROR" + ) assert res.error_field(pq.DiagnosticField.SQLSTATE) == b"42703" assert b"wat" in res.error_field(pq.DiagnosticField.MESSAGE_PRIMARY) res.clear() diff --git a/tests/test_connection.py b/tests/test_connection.py index 84cb81f25..3581a122d 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -410,7 +410,9 @@ def test_notice_handlers(conn, caplog): conn.add_notice_handler(cb1) conn.add_notice_handler(cb2) conn.add_notice_handler("the wrong thing") - conn.add_notice_handler(lambda diag: severities.append(diag.severity)) + conn.add_notice_handler( + lambda diag: severities.append(diag.severity_nonlocalized) + ) conn.pgconn.exec_(b"set client_min_messages to notice") cur = conn.cursor() diff --git a/tests/test_connection_async.py b/tests/test_connection_async.py index 705b5f931..c047b4646 100644 --- a/tests/test_connection_async.py +++ b/tests/test_connection_async.py @@ -416,7 +416,9 @@ async def test_notice_handlers(aconn, caplog): aconn.add_notice_handler(cb1) aconn.add_notice_handler(cb2) aconn.add_notice_handler("the wrong thing") - aconn.add_notice_handler(lambda diag: severities.append(diag.severity)) + aconn.add_notice_handler( + lambda diag: severities.append(diag.severity_nonlocalized) + ) aconn.pgconn.exec_(b"set client_min_messages to notice") cur = aconn.cursor() diff --git a/tests/test_errors.py b/tests/test_errors.py index 892b1f686..131d66056 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -20,7 +20,7 @@ def test_error_diag(conn): exc = excinfo.value diag = exc.diag assert diag.sqlstate == "42P01" - assert diag.severity == "ERROR" + assert diag.severity_nonlocalized == "ERROR" def test_diag_all_attrs(pgconn): -- 2.47.3