Skip to content

Commit 4b4f02f

Browse files
committed
test: pyright in tests
This commit changes some of our tests to work with stricter pyright settings. I made the checks for tests a little less strict than the real `dbtsl` tests since our tests sometimes inject wrong types into the API to purposefully induce errors, or mocks stuff that's really hard to type.
1 parent bb1c970 commit 4b4f02f

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

.github/workflows/code-quality.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
run: "hatch run dev:basedpyright dbtsl tests"
3333

3434
- name: mypy
35-
run: "hatch run dev:python -m mypy dbtsl tests"
35+
run: "hatch run dev:python -m mypy dbtsl"
3636

3737
- name: fetch server schema
3838
run: "hatch run dev:fetch-schema"

lefthook.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pre-commit:
99
pyright:
1010
run: "hatch run dev:basedpyright dbtsl tests"
1111
mypy:
12-
run: "hatch run dev:python -m mypy dbtsl tests"
12+
run: "hatch run dev:python -m mypy dbtsl"
1313

1414
commit-msg:
1515
scripts:

pyproject.toml

+12-2
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,21 @@ PIP_EXTRA_INDEX_URL = "https://pypi.org/simple/"
128128
asyncio_mode = "auto"
129129

130130
[tool.pyright]
131-
# TODO: we'd love to enable "strict" typechecking, but
132-
# pyarrow not having type stubs makes that really hard
133131
typeCheckingMode = "strict"
134132
venv = ".venv/"
135133

134+
[[tool.pyright.executionEnvironments]]
135+
root = "tests"
136+
# Tests use private methods and assign inappropriate values to some
137+
# properties to check our error handling capabilities etc. To avoid
138+
# having to ignore everything, we disable some checks
139+
reportPrivateUsage = false
140+
reportAssignmentType = false
141+
reportAny = false
142+
reportCallIssue = false
143+
reportArgumentType = false
144+
reportUnknownMemberType = false
145+
136146
[tool.mypy]
137147
strict = true
138148

tests/api/graphql/test_client.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import base64
22
import io
3+
from typing import Any
34
from unittest.mock import AsyncMock, MagicMock, call
45

56
import pyarrow as pa
@@ -43,7 +44,7 @@ async def gqr_behavior(query_id: QueryId, page_num: int) -> QueryResult:
4344
arrow_result=base64.b64encode(byte_stream.getvalue()).decode("utf-8"),
4445
)
4546

46-
async def run_behavior(op: ProtocolOperation, query_id: QueryId, page_num: int) -> QueryResult:
47+
async def run_behavior(_op: ProtocolOperation[Any, Any], query_id: QueryId, page_num: int) -> QueryResult:
4748
return await gqr_behavior(query_id, page_num)
4849

4950
cq_mock = mocker.patch.object(client, "create_query", return_value=query_id, new_callable=AsyncMock)
@@ -59,7 +60,7 @@ async def run_behavior(op: ProtocolOperation, query_id: QueryId, page_num: int)
5960

6061
kwargs = {"metrics": ["m1", "m2"], "group_by": ["gb"], "limit": 1}
6162
async with client.session():
62-
result_table = await client.query(**kwargs)
63+
result_table = await client.query(**kwargs) # pyright: ignore[reportUnknownVariableType]
6364

6465
cq_mock.assert_awaited_once_with(**kwargs)
6566

@@ -108,7 +109,7 @@ def gqr_behavior(query_id: QueryId, page_num: int) -> QueryResult:
108109
arrow_result=base64.b64encode(byte_stream.getvalue()).decode("utf-8"),
109110
)
110111

111-
def run_behavior(op: ProtocolOperation, query_id: QueryId, page_num: int) -> QueryResult:
112+
def run_behavior(op: ProtocolOperation[Any, Any], query_id: QueryId, page_num: int) -> QueryResult:
112113
return gqr_behavior(query_id, page_num)
113114

114115
cq_mock = mocker.patch.object(client, "create_query", return_value=query_id)
@@ -125,7 +126,7 @@ def run_behavior(op: ProtocolOperation, query_id: QueryId, page_num: int) -> Que
125126
kwargs = {"metrics": ["m1", "m2"], "group_by": ["gb"], "limit": 1}
126127

127128
with client.session():
128-
result_table = client.query(**kwargs)
129+
result_table = client.query(**kwargs) # pyright: ignore[reportUnknownVariableType]
129130

130131
cq_mock.assert_called_once_with(**kwargs)
131132

tests/api/graphql/test_protocol.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ...conftest import QueryValidator
88
from ...query_test_cases import TEST_QUERIES
99

10-
VARIABLES = {
10+
VARIABLES: dict[str, list[dict[str, Any]]] = {
1111
"metrics": [{}],
1212
"dimensions": [{"metrics": ["m"]}],
1313
"measures": [{"metrics": ["m"]}],

tests/integration/test_sl_client.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,13 @@ async def test_client_metadata(subtests: SubTests, client: BothClients) -> None:
8282
@pytest.mark.parametrize("query", TEST_QUERIES)
8383
async def test_client_query(api: str, query: QueryParameters, client: BothClients) -> None:
8484
client._method_map["query"] = api # type: ignore
85-
# TODO: fix typing on client.query
8685
table = await maybe_await(client.query(**query)) # type: ignore
87-
assert len(table) > 0
86+
assert len(table) > 0 # type: ignore
8887

8988

9089
@pytest.mark.parametrize("query", TEST_QUERIES)
9190
async def test_client_compile_sql_adhoc_query(query: QueryParameters, client: BothClients) -> None:
9291
# TODO: fix typing on client.compile_sql
9392
sql = await maybe_await(client.compile_sql(**query)) # type: ignore
94-
assert len(sql) > 0
93+
assert len(sql) > 0 # type: ignore
9594
assert "SELECT" in sql

0 commit comments

Comments
 (0)