summaryrefslogtreecommitdiffstats
path: root/tests/crdb/test_typing.py
blob: 2cff0a735a3e2024d201575c7e09717f245dc8b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import pytest

from ..test_typing import _test_reveal


@pytest.mark.parametrize(
    "conn, type",
    [
        (
            "psycopg.crdb.connect()",
            "psycopg.crdb.CrdbConnection[Tuple[Any, ...]]",
        ),
        (
            "psycopg.crdb.connect(row_factory=rows.dict_row)",
            "psycopg.crdb.CrdbConnection[Dict[str, Any]]",
        ),
        (
            "psycopg.crdb.CrdbConnection.connect()",
            "psycopg.crdb.CrdbConnection[Tuple[Any, ...]]",
        ),
        (
            "psycopg.crdb.CrdbConnection.connect(row_factory=rows.tuple_row)",
            "psycopg.crdb.CrdbConnection[Tuple[Any, ...]]",
        ),
        (
            "psycopg.crdb.CrdbConnection.connect(row_factory=rows.dict_row)",
            "psycopg.crdb.CrdbConnection[Dict[str, Any]]",
        ),
        (
            "await psycopg.crdb.AsyncCrdbConnection.connect()",
            "psycopg.crdb.AsyncCrdbConnection[Tuple[Any, ...]]",
        ),
        (
            "await psycopg.crdb.AsyncCrdbConnection.connect(row_factory=rows.dict_row)",
            "psycopg.crdb.AsyncCrdbConnection[Dict[str, Any]]",
        ),
    ],
)
def test_connection_type(conn, type, mypy):
    stmts = f"obj = {conn}"
    _test_reveal_crdb(stmts, type, mypy)


def _test_reveal_crdb(stmts, type, mypy):
    stmts = f"""\
import psycopg.crdb
{stmts}
"""
    _test_reveal(stmts, type, mypy)