Skip to content

Commit 36cf741

Browse files
committed
Fix test annotations on unit tests
1 parent 7f7ee7d commit 36cf741

13 files changed

+85
-59
lines changed

pyproject.toml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ ignorelist = [
285285
# Review and update builtin shadowing below this line
286286
"filter",
287287
"format",
288-
"input",
289288
"list",
290289
"property",
291290
]
@@ -350,18 +349,6 @@ max-complexity = 17
350349
"tests/unit/sdk/test_diff_summary.py" = ["ANN001"] # 9 errors
351350
"tests/unit/sdk/test_object_store.py" = ["ANN001"] # 7 errors
352351
"tests/unit/sdk/graphql/test_query.py" = ["ANN001"] # 7 errors
353-
"tests/unit/sdk/test_timestamp.py" = ["ANN001"] # 6 errors
354-
"tests/unit/sdk/test_repository.py" = ["ANN001"] # 6 errors
355-
"tests/unit/sdk/test_utils.py" = ["ANN001"] # 4 errors
356-
"tests/unit/sdk/test_store_branch.py" = ["ANN001"] # 4 errors
357-
"tests/unit/sdk/test_query_analyzer.py" = ["ANN001"] # 4 errors
358-
"tests/unit/sdk/test_group_context.py" = ["ANN001"] # 4 errors
359-
"tests/unit/sdk/test_branch.py" = ["ANN001"] # 4 errors
360-
"tests/unit/sdk/test_batch.py" = ["ANN001"] # 4 errors
361-
"tests/unit/sdk/graphql/test_renderer.py" = ["ANN001"] # 4 errors
362-
"tests/unit/sdk/checks/test_checks.py" = ["ANN001"] # 2 errors
363-
"tests/unit/sdk/test_schema_sorter.py" = ["ANN001"] # 1 error
364-
"tests/unit/sdk/test_protocols_generator.py" = ["ANN001"] # 1 error
365352

366353
# tests/integration/ - 60 errors total
367354
"tests/integration/test_infrahub_client.py" = ["ANN001"] # 32 errors

tests/unit/sdk/checks/test_checks.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
from pathlib import Path
2+
from typing import TYPE_CHECKING
23

34
import pytest
45

56
from infrahub_sdk import InfrahubClient
67
from infrahub_sdk.checks import InfrahubCheck
78

9+
if TYPE_CHECKING:
10+
from pytest_httpx import HTTPXMock
11+
812
pytestmark = pytest.mark.httpx_mock(can_send_already_matched_responses=True)
913

1014

@@ -36,15 +40,15 @@ class IFCheckNoName(InfrahubCheck):
3640
assert check.root_directory == str(tmp_path)
3741

3842

39-
async def test_async_init(client) -> None:
43+
async def test_async_init(client: InfrahubClient) -> None:
4044
class IFCheck(InfrahubCheck):
4145
query = "my_query"
4246

4347
check = await IFCheck.init()
4448
assert isinstance(check.client, InfrahubClient)
4549

4650

47-
async def test_validate_sync_async(mock_gql_query_my_query) -> None:
51+
async def test_validate_sync_async(mock_gql_query_my_query: "HTTPXMock") -> None:
4852
class IFCheckAsync(InfrahubCheck):
4953
query = "my_query"
5054

tests/unit/sdk/graphql/test_renderer.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
from typing import Any
2+
13
from infrahub_sdk.graphql.renderers import render_input_block, render_query_block
24

35

4-
def test_render_query_block(query_data_no_filter) -> None:
6+
def test_render_query_block(query_data_no_filter: dict[str, Any]) -> None:
57
lines = render_query_block(data=query_data_no_filter)
68

79
expected_lines = [
@@ -44,7 +46,7 @@ def test_render_query_block(query_data_no_filter) -> None:
4446
assert lines == expected_lines
4547

4648

47-
def test_render_query_block_alias(query_data_alias) -> None:
49+
def test_render_query_block_alias(query_data_alias: dict[str, Any]) -> None:
4850
lines = render_query_block(data=query_data_alias)
4951

5052
expected_lines = [
@@ -66,7 +68,7 @@ def test_render_query_block_alias(query_data_alias) -> None:
6668
assert lines == expected_lines
6769

6870

69-
def test_render_query_block_fragment(query_data_fragment) -> None:
71+
def test_render_query_block_fragment(query_data_fragment: dict[str, Any]) -> None:
7072
lines = render_query_block(data=query_data_fragment)
7173

7274
expected_lines = [
@@ -90,7 +92,7 @@ def test_render_query_block_fragment(query_data_fragment) -> None:
9092
assert lines == expected_lines
9193

9294

93-
def test_render_input_block(input_data_01) -> None:
95+
def test_render_input_block(input_data_01: dict[str, Any]) -> None:
9496
lines = render_input_block(data=input_data_01)
9597

9698
expected_lines = [

tests/unit/sdk/test_batch.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def test_func() -> int:
5050
@pytest.mark.parametrize("client_type", client_types)
5151
async def test_batch_return_exception(
5252
httpx_mock: HTTPXMock,
53-
mock_query_mutation_location_create_failed,
54-
mock_schema_query_01,
53+
mock_query_mutation_location_create_failed: HTTPXMock,
54+
mock_schema_query_01: HTTPXMock,
5555
clients: BothClients,
5656
client_type: str,
5757
) -> None:
@@ -96,8 +96,8 @@ async def test_batch_return_exception(
9696
@pytest.mark.parametrize("client_type", client_types)
9797
async def test_batch_exception(
9898
httpx_mock: HTTPXMock,
99-
mock_query_mutation_location_create_failed,
100-
mock_schema_query_01,
99+
mock_query_mutation_location_create_failed: HTTPXMock,
100+
mock_schema_query_01: HTTPXMock,
101101
clients: BothClients,
102102
client_type: str,
103103
) -> None:

tests/unit/sdk/test_branch.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
from __future__ import annotations
2+
13
import inspect
4+
from typing import TYPE_CHECKING
25

36
import pytest
47

@@ -8,6 +11,11 @@
811
InfrahubBranchManagerSync,
912
)
1013

14+
if TYPE_CHECKING:
15+
from pytest_httpx import HTTPXMock
16+
17+
from tests.unit.sdk.conftest import BothClients
18+
1119
async_branch_methods = [method for method in dir(InfrahubBranchManager) if not method.startswith("_")]
1220
sync_branch_methods = [method for method in dir(InfrahubBranchManagerSync) if not method.startswith("_")]
1321

@@ -21,7 +29,7 @@ def test_method_sanity() -> None:
2129

2230

2331
@pytest.mark.parametrize("method", async_branch_methods)
24-
def test_validate_method_signature(method) -> None:
32+
def test_validate_method_signature(method: str) -> None:
2533
async_method = getattr(InfrahubBranchManager, method)
2634
sync_method = getattr(InfrahubBranchManagerSync, method)
2735
async_sig = inspect.signature(async_method)
@@ -31,7 +39,7 @@ def test_validate_method_signature(method) -> None:
3139

3240

3341
@pytest.mark.parametrize("client_type", client_types)
34-
async def test_get_branches(clients, mock_branches_list_query, client_type) -> None:
42+
async def test_get_branches(clients: BothClients, mock_branches_list_query: HTTPXMock, client_type: str) -> None:
3543
if client_type == "standard":
3644
branches = await clients.standard.branch.all()
3745
else:

tests/unit/sdk/test_group_context.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import inspect
2+
from collections.abc import Callable
23

34
import pytest
45

56
from infrahub_sdk.query_groups import InfrahubGroupContext, InfrahubGroupContextBase, InfrahubGroupContextSync
7+
from infrahub_sdk.schema import NodeSchemaAPI
68

79
async_methods = [method for method in dir(InfrahubGroupContext) if not method.startswith("_")]
810
sync_methods = [method for method in dir(InfrahubGroupContextSync) if not method.startswith("_")]
@@ -18,7 +20,9 @@ async def test_method_sanity() -> None:
1820

1921
@pytest.mark.parametrize("method", async_methods)
2022
async def test_validate_method_signature(
21-
method, replace_sync_return_annotation, replace_async_return_annotation
23+
method: str,
24+
replace_sync_return_annotation: Callable[[str], str],
25+
replace_async_return_annotation: Callable[[str], str],
2226
) -> None:
2327
async_method = getattr(InfrahubGroupContext, method)
2428
sync_method = getattr(InfrahubGroupContextSync, method)
@@ -65,7 +69,7 @@ def test_generate_group_name() -> None:
6569
assert context._generate_group_name(suffix="xxx") == "MYID-xxx-11aaec5206c3dca37cbbcaaabf121550"
6670

6771

68-
def test_generate_group_description(std_group_schema) -> None:
72+
def test_generate_group_description(std_group_schema: NodeSchemaAPI) -> None:
6973
context = InfrahubGroupContextBase()
7074
context.set_properties(identifier="MYID")
7175
assert not context._generate_group_description(schema=std_group_schema)

tests/unit/sdk/test_protocols_generator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
from dataclasses import dataclass
2+
from typing import TYPE_CHECKING
23

34
import pytest
45

56
from infrahub_sdk import InfrahubClient
67
from infrahub_sdk.protocols_generator.generator import CodeGenerator
78

9+
if TYPE_CHECKING:
10+
from pytest_httpx import HTTPXMock
11+
812

913
@dataclass
1014
class SyncifyTestCase:
@@ -41,7 +45,7 @@ async def test_filter_syncify(test_case: SyncifyTestCase) -> None:
4145
assert CodeGenerator._jinja2_filter_syncify(value=test_case.input, sync=test_case.sync) == test_case.output
4246

4347

44-
async def test_generator(client: InfrahubClient, mock_schema_query_05) -> None:
48+
async def test_generator(client: InfrahubClient, mock_schema_query_05: "HTTPXMock") -> None:
4549
schemas = await client.schema.fetch(branch="main")
4650

4751
code_generator = CodeGenerator(schema=schemas)

tests/unit/sdk/test_query_analyzer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from infrahub_sdk.analyzer import GraphQLOperation, GraphQLQueryAnalyzer
66

77

8-
async def test_analyzer_init_query_only(query_01, bad_query_01) -> None:
8+
async def test_analyzer_init_query_only(query_01: str, bad_query_01: str) -> None:
99
gqa = GraphQLQueryAnalyzer(query=query_01)
1010
assert isinstance(gqa.document, DocumentNode)
1111

@@ -151,7 +151,7 @@ async def test_get_variables(query_01: str, query_04: str, query_05: str, query_
151151
"var_type,var_required",
152152
[("[ID]", False), ("[ID]!", True), ("[ID!]", False), ("[ID!]!", True)],
153153
)
154-
async def test_get_nested_variables(var_type, var_required) -> None:
154+
async def test_get_nested_variables(var_type: str, var_required: bool) -> None:
155155
query = (
156156
"""
157157
query ($ids: %s){

tests/unit/sdk/test_repository.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def temp_dir() -> Generator[str]:
1717
yield tmp_dir
1818

1919

20-
def test_initialize_repo_creates_new_repo(temp_dir) -> None:
20+
def test_initialize_repo_creates_new_repo(temp_dir: str) -> None:
2121
"""Test that a new Git repository is created if none exists."""
2222
manager = GitRepoManager(root_directory=temp_dir, branch="main")
2323

@@ -29,7 +29,7 @@ def test_initialize_repo_creates_new_repo(temp_dir) -> None:
2929
assert isinstance(manager.git, Repo)
3030

3131

32-
def test_initialize_repo_uses_existing_repo(temp_dir) -> None:
32+
def test_initialize_repo_uses_existing_repo(temp_dir: str) -> None:
3333
"""Test that the GitRepoManager uses an existing repository without an active branch."""
3434
# Manually initialize a repo
3535
Repo.init(temp_dir, default_branch=b"main")
@@ -40,15 +40,15 @@ def test_initialize_repo_uses_existing_repo(temp_dir) -> None:
4040
assert (Path(temp_dir) / ".git").is_dir()
4141

4242

43-
def test_active_branch_returns_correct_branch(temp_dir) -> None:
43+
def test_active_branch_returns_correct_branch(temp_dir: str) -> None:
4444
"""Test that the active branch is correctly returned."""
4545
manager = GitRepoManager(temp_dir, branch="develop")
4646

4747
# Verify the active branch is "develop"
4848
assert manager.active_branch == "develop"
4949

5050

51-
def test_initialize_repo_raises_error_on_failure(monkeypatch, temp_dir) -> None:
51+
def test_initialize_repo_raises_error_on_failure(monkeypatch: pytest.MonkeyPatch, temp_dir: str) -> None:
5252
"""Test that an error is raised if the repository cannot be initialized."""
5353

5454
def mock_init(*args, **kwargs) -> None: # noqa: ANN002, ANN003
@@ -60,7 +60,7 @@ def mock_init(*args, **kwargs) -> None: # noqa: ANN002, ANN003
6060
GitRepoManager(temp_dir)
6161

6262

63-
def test_gitrepo_init(temp_dir) -> None:
63+
def test_gitrepo_init(temp_dir: str) -> None:
6464
src_directory = get_fixtures_dir() / "integration/mock_repo"
6565
repo = GitRepo(name="mock_repo", src_directory=src_directory, dst_directory=Path(temp_dir))
6666
assert len(list(repo._repo.git.get_walker())) == 1

tests/unit/sdk/test_schema_sorter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
from typing import TYPE_CHECKING
2+
13
from infrahub_sdk import InfrahubClient
24
from infrahub_sdk.transfer.schema_sorter import InfrahubSchemaTopologicalSorter
35

6+
if TYPE_CHECKING:
7+
from pytest_httpx import HTTPXMock
8+
49

5-
async def test_schema_sorter(client: InfrahubClient, mock_schema_query_01) -> None:
10+
async def test_schema_sorter(client: InfrahubClient, mock_schema_query_01: "HTTPXMock") -> None:
611
schemas = await client.schema.all()
712
topological_sorter = InfrahubSchemaTopologicalSorter()
813

0 commit comments

Comments
 (0)