From: Denis Laxalde Date: Tue, 2 Mar 2021 11:18:32 +0000 (+0100) Subject: Make cursor tests mypy-clean X-Git-Tag: 3.0.3~3^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a18ad43081266cac6c9fb52038a57bcf962798a;p=thirdparty%2Fpsycopg.git Make cursor tests mypy-clean Add a type annotation to 'rns' in test_rownumber(); assert that cursor._query is not None. --- diff --git a/pyproject.toml b/pyproject.toml index 149c32cde..837794df5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ files = [ "tests/test_prepared*.py", "tests/test_psycopg_dbapi20.py", "tests/test_sql.py", + "tests/test_*cursor*.py", "tests/types", ] warn_unused_ignores = true diff --git a/tests/test_cursor.py b/tests/test_cursor.py index f6d01136b..4f8219bdd 100644 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -2,6 +2,7 @@ import gc import pickle import weakref import datetime as dt +from typing import List import pytest @@ -343,8 +344,9 @@ def test_rownumber(conn): assert cur.rownumber == 2 cur.fetchmany(10) assert cur.rownumber == 12 - rns = [] + rns: List[int] = [] for i in cur: + assert cur.rownumber rns.append(cur.rownumber) if len(rns) >= 3: break @@ -470,6 +472,7 @@ def test_query_params_execute(conn): assert cur._query is None cur.execute("select %t, %s::text", [1, None]) + assert cur._query is not None assert cur._query.query == b"select $1, $2::text" assert cur._query.params == [b"1", None] diff --git a/tests/test_cursor_async.py b/tests/test_cursor_async.py index 5ff9ea770..70bd3fc57 100644 --- a/tests/test_cursor_async.py +++ b/tests/test_cursor_async.py @@ -2,6 +2,7 @@ import gc import pytest import weakref import datetime as dt +from typing import List import psycopg from psycopg import pq, sql, rows @@ -345,8 +346,9 @@ async def test_rownumber(aconn): assert cur.rownumber == 2 await cur.fetchmany(10) assert cur.rownumber == 12 - rns = [] + rns: List[int] = [] async for i in cur: + assert cur.rownumber rns.append(cur.rownumber) if len(rns) >= 3: break @@ -472,6 +474,7 @@ async def test_query_params_execute(aconn): assert cur._query is None await cur.execute("select %t, %s::text", [1, None]) + assert cur._query is not None assert cur._query.query == b"select $1, $2::text" assert cur._query.params == [b"1", None] diff --git a/tests/test_server_cursor.py b/tests/test_server_cursor.py index a35aad107..196c703f2 100644 --- a/tests/test_server_cursor.py +++ b/tests/test_server_cursor.py @@ -45,6 +45,7 @@ def test_query_params(conn): with conn.cursor("foo") as cur: assert cur._query is None cur.execute("select generate_series(1, %s) as bar", (3,)) + assert cur._query assert b"declare" in cur._query.query.lower() assert b"(1, $1)" in cur._query.query.lower() assert cur._query.params == [bytes([0, 3])] # 3 as binary int2 diff --git a/tests/test_server_cursor_async.py b/tests/test_server_cursor_async.py index fc01db25b..6da867351 100644 --- a/tests/test_server_cursor_async.py +++ b/tests/test_server_cursor_async.py @@ -47,6 +47,7 @@ async def test_query_params(aconn): async with aconn.cursor("foo") as cur: assert cur._query is None await cur.execute("select generate_series(1, %s) as bar", (3,)) + assert cur._query is not None assert b"declare" in cur._query.query.lower() assert b"(1, $1)" in cur._query.query.lower() assert cur._query.params == [bytes([0, 3])] # 3 as binary int2