From: Denis Laxalde Date: Fri, 5 Nov 2021 08:41:39 +0000 (+0100) Subject: Fix mypy errors in test_errors.py X-Git-Tag: 3.0.3~3^2~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=475c41fb9ce99a66d24beb1341549f3f36c5af17;p=thirdparty%2Fpsycopg.git Fix mypy errors in test_errors.py Declare a couple a dynamic variables and check for None value before checking optional properties' values. --- diff --git a/pyproject.toml b/pyproject.toml index b38ceb66f..7bce34d6b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,6 +25,7 @@ files = [ "tests/scripts", "tests/test_conninfo.py", "tests/test_dns*", + "tests/test_errors.py", "tests/test_prepared*.py", "tests/test_psycopg_dbapi20.py", "tests/test_sql.py", diff --git a/tests/test_errors.py b/tests/test_errors.py index b6065c601..892b1f686 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -1,4 +1,5 @@ import pickle +from typing import List from weakref import ref import pytest @@ -34,7 +35,8 @@ def test_diag_right_attr(pgconn, monkeypatch): res = pgconn.make_empty_result(pq.ExecStatus.NONFATAL_ERROR) diag = e.Diagnostic(res) - checked = [] + to_check: pq.DiagnosticField + checked: List[pq.DiagnosticField] = [] def check_val(self, v): nonlocal to_check @@ -62,7 +64,7 @@ def test_diag_attr_values(conn): cur.execute("insert into test_exc values(2)") diag = exc.value.diag assert diag.sqlstate == "23514" - assert diag.schema_name[:7] == "pg_temp" + assert diag.schema_name and diag.schema_name[:7] == "pg_temp" assert diag.table_name == "test_exc" assert diag.constraint_name == "chk_eq1" if conn.pgconn.server_version >= 90600: @@ -97,7 +99,7 @@ def test_error_encoding(conn, enc): ) diag = excinfo.value.diag - assert f'"{eur}"' in diag.message_primary + assert diag.message_primary and f'"{eur}"' in diag.message_primary assert diag.sqlstate == "42P01" @@ -235,6 +237,7 @@ def test_query_context(conn): s = str(exc.value) assert "from wat" in s, s + assert exc.value.diag.message_primary assert exc.value.diag.message_primary in s assert "ERROR" not in s assert not s.endswith("\n")