From: Denis Laxalde Date: Tue, 2 Nov 2021 10:07:34 +0000 (+0100) Subject: Make dbapi20 tests mypy-clean X-Git-Tag: 3.0.2~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c0ba2d22a9a95fd018728dcf22b63322dc04509;p=thirdparty%2Fpsycopg.git Make dbapi20 tests mypy-clean --- diff --git a/pyproject.toml b/pyproject.toml index 89a930226..bb1f9b9ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,9 @@ files = [ "psycopg/psycopg", "psycopg_pool/psycopg_pool", "psycopg_c/psycopg_c", + "tests/dbapi20.py", "tests/pq", + "tests/test_psycopg_dbapi20.py", "tests/test_sql.py", "tests/types", ] diff --git a/tests/dbapi20.py b/tests/dbapi20.py index 8d013facf..b47cc05e5 100644 --- a/tests/dbapi20.py +++ b/tests/dbapi20.py @@ -20,6 +20,7 @@ __author__ = 'Stuart Bishop ' import unittest import time import sys +from typing import Any, Dict # Revision 1.12 2009/02/06 03:35:11 kf7xm @@ -98,9 +99,9 @@ class DatabaseAPI20Test(unittest.TestCase): # The self.driver module. This should be the module where the 'connect' # method is to be found - driver = None + driver: Any = None connect_args = () # List of arguments to pass to connect - connect_kw_args = {} # Keyword arguments for connect + connect_kw_args: Dict[str, Any] = {} # Keyword arguments for connect table_prefix = 'dbapi20test_' # If you need to specify a prefix for tables ddl1 = 'create table %sbooze (name varchar(20))' % table_prefix @@ -191,8 +192,8 @@ class DatabaseAPI20Test(unittest.TestCase): self.failUnless(issubclass(self.driver.Warning,Exception)) self.failUnless(issubclass(self.driver.Error,Exception)) else: - self.failUnless(issubclass(self.driver.Warning,StandardError)) - self.failUnless(issubclass(self.driver.Error,StandardError)) + self.failUnless(issubclass(self.driver.Warning,StandardError)) # type: ignore[name-defined] + self.failUnless(issubclass(self.driver.Error,StandardError)) # type: ignore[name-defined] self.failUnless( issubclass(self.driver.InterfaceError,self.driver.Error) diff --git a/tests/test_psycopg_dbapi20.py b/tests/test_psycopg_dbapi20.py index dbf6670ce..d3da1304c 100644 --- a/tests/test_psycopg_dbapi20.py +++ b/tests/test_psycopg_dbapi20.py @@ -1,5 +1,6 @@ import pytest import datetime as dt +from typing import Any, Dict import psycopg from psycopg.conninfo import conninfo_to_dict @@ -16,7 +17,7 @@ def with_dsn(request, dsn): class PsycopgTests(dbapi20.DatabaseAPI20Test): driver = psycopg # connect_args = () # set by the fixture - connect_kw_args = {} + connect_kw_args: Dict[str, Any] = {} def test_nextset(self): # tested elsewhere @@ -28,7 +29,7 @@ class PsycopgTests(dbapi20.DatabaseAPI20Test): # Shut up warnings -PsycopgTests.failUnless = PsycopgTests.assertTrue +PsycopgTests.failUnless = PsycopgTests.assertTrue # type: ignore[assignment] @pytest.mark.parametrize( @@ -120,7 +121,7 @@ def test_time_from_ticks(ticks, want): ], ) def test_connect_args(monkeypatch, pgconn, args, kwargs, want): - the_conninfo = None + the_conninfo: str def fake_connect(conninfo): nonlocal the_conninfo