From: Daniele Varrazzo Date: Thu, 29 Apr 2021 17:22:27 +0000 (+0200) Subject: Add typing test for cursor iteration X-Git-Tag: 3.0.dev0~63^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5d3cc4425089098e28d88379e43c792759044ad;p=thirdparty%2Fpsycopg.git Add typing test for cursor iteration --- diff --git a/tests/test_typing.py b/tests/test_typing.py index 03c0f366a..c2df4c050 100644 --- a/tests/test_typing.py +++ b/tests/test_typing.py @@ -175,6 +175,44 @@ obj = {await_} curs.fetchone() _test_reveal(stmts, type, mypy, tmpdir) +@pytest.mark.slow +@pytest.mark.parametrize( + "curs, type", + [ + ( + "conn.cursor()", + "Tuple[Any, ...]", + ), + ( + "conn.cursor(row_factory=rows.dict_row)", + "Dict[str, Any]", + ), + ( + "conn.cursor(row_factory=thing_row)", + "Thing", + ), + ], +) +@pytest.mark.parametrize("server_side", [False, True]) +@pytest.mark.parametrize("conn_class", ["Connection", "AsyncConnection"]) +def test_iter_type(conn_class, server_side, curs, type, mypy, tmpdir): + if "Async" in conn_class: + async_ = "async " + await_ = "await " + else: + async_ = await_ = "" + + if server_side: + curs = curs.replace("(", "(name='foo',", 1) + stmts = f"""\ +conn = {await_}psycopg3.{conn_class}.connect() +curs = {curs} +{async_}for obj in curs: + pass +""" + _test_reveal(stmts, type, mypy, tmpdir) + + @pytest.mark.slow @pytest.mark.parametrize("method", ["fetchmany", "fetchall"]) @pytest.mark.parametrize(