Skip to content

Commit ed76689

Browse files
authored
Merge pull request #504 from opsmill/pog-test-annotations
Auto fix return type None for tests
2 parents 40f74f2 + bf2efc9 commit ed76689

37 files changed

+286
-270
lines changed

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def event_loop():
2020

2121

2222
@pytest.fixture(scope="session", autouse=True)
23-
def execute_before_any_test():
23+
def execute_before_any_test() -> None:
2424
config.SETTINGS.load_and_exit()
2525
config.SETTINGS.active.server_address = "http://mock"
2626

tests/integration/test_infrahub_client.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def base_dataset(
2929
cat_bella,
3030
dog_daisy,
3131
dog_rocky,
32-
):
32+
) -> None:
3333
await client.branch.create(branch_name="branch01")
3434

3535
@pytest.fixture
@@ -39,7 +39,7 @@ async def set_pagination_size3(self, client: InfrahubClient):
3939
yield
4040
client.pagination_size = original_pagination_size
4141

42-
async def test_query_branches(self, client: InfrahubClient, base_dataset):
42+
async def test_query_branches(self, client: InfrahubClient, base_dataset) -> None:
4343
branches = await client.branch.all()
4444
main = await client.branch.get(branch_name="main")
4545

@@ -50,7 +50,7 @@ async def test_query_branches(self, client: InfrahubClient, base_dataset):
5050
assert "main" in branches
5151
assert "branch01" in branches
5252

53-
async def test_branch_delete(self, client: InfrahubClient, base_dataset):
53+
async def test_branch_delete(self, client: InfrahubClient, base_dataset) -> None:
5454
async_branch = "async-delete-branch"
5555
await client.branch.create(branch_name=async_branch)
5656
pre_delete = await client.branch.all()
@@ -59,7 +59,7 @@ async def test_branch_delete(self, client: InfrahubClient, base_dataset):
5959
assert async_branch in pre_delete.keys()
6060
assert async_branch not in post_delete.keys()
6161

62-
async def test_get_all(self, client: InfrahubClient, base_dataset):
62+
async def test_get_all(self, client: InfrahubClient, base_dataset) -> None:
6363
nodes = await client.all(kind=TESTING_CAT)
6464
assert len(nodes) == 2
6565
assert isinstance(nodes[0], InfrahubNode)
@@ -80,7 +80,7 @@ async def test_get_all(self, client: InfrahubClient, base_dataset):
8080
# assert isinstance(nodes[0], InfrahubNode)
8181
# assert {node.name.value for node in nodes} == {"Bella", "Luna"}
8282

83-
async def test_get_one(self, client: InfrahubClient, base_dataset, cat_luna, person_sophia):
83+
async def test_get_one(self, client: InfrahubClient, base_dataset, cat_luna, person_sophia) -> None:
8484
node1 = await client.get(kind=TESTING_CAT, id=cat_luna.id)
8585
assert isinstance(node1, InfrahubNode)
8686
assert node1.name.value == "Luna"
@@ -89,7 +89,7 @@ async def test_get_one(self, client: InfrahubClient, base_dataset, cat_luna, per
8989
assert isinstance(node2, InfrahubNode)
9090
assert node2.name.value == "Sophia Walker"
9191

92-
async def test_filters_partial_match(self, client: InfrahubClient, base_dataset):
92+
async def test_filters_partial_match(self, client: InfrahubClient, base_dataset) -> None:
9393
nodes = await client.filters(kind=TESTING_PERSON, name__value="Walker")
9494
assert not nodes
9595

@@ -98,25 +98,25 @@ async def test_filters_partial_match(self, client: InfrahubClient, base_dataset)
9898
assert isinstance(nodes[0], InfrahubNode)
9999
assert sorted([node.name.value for node in nodes]) == ["Liam Walker", "Sophia Walker"]
100100

101-
async def test_get_generic(self, client: InfrahubClient, base_dataset):
101+
async def test_get_generic(self, client: InfrahubClient, base_dataset) -> None:
102102
nodes = await client.all(kind=TESTING_ANIMAL)
103103
assert len(nodes) == 4
104104

105-
async def test_get_generic_fragment(self, client: InfrahubClient, base_dataset):
105+
async def test_get_generic_fragment(self, client: InfrahubClient, base_dataset) -> None:
106106
nodes = await client.all(kind=TESTING_ANIMAL, fragment=True)
107107
assert len(nodes)
108108
assert nodes[0].typename in [TESTING_DOG, TESTING_CAT]
109109
assert nodes[0].breed.value is not None
110110

111-
async def test_get_related_nodes(self, client: InfrahubClient, base_dataset, person_ethan):
111+
async def test_get_related_nodes(self, client: InfrahubClient, base_dataset, person_ethan) -> None:
112112
ethan = await client.get(kind=TESTING_PERSON, id=person_ethan.id)
113113
assert ethan
114114

115115
assert ethan.animals.peers == []
116116
await ethan.animals.fetch()
117117
assert len(ethan.animals.peers) == 3
118118

119-
async def test_profile(self, client: InfrahubClient, base_dataset, person_liam):
119+
async def test_profile(self, client: InfrahubClient, base_dataset, person_liam) -> None:
120120
profile_schema_kind = f"Profile{TESTING_DOG}"
121121
profile_schema = await client.schema.get(kind=profile_schema_kind)
122122
assert isinstance(profile_schema, ProfileSchemaAPI)
@@ -137,30 +137,30 @@ async def test_profile(self, client: InfrahubClient, base_dataset, person_liam):
137137
obj1 = await client.get(kind=TESTING_DOG, id=obj.id)
138138
assert obj1.color.value == "#111111"
139139

140-
async def test_create_branch(self, client: InfrahubClient, base_dataset):
140+
async def test_create_branch(self, client: InfrahubClient, base_dataset) -> None:
141141
branch = await client.branch.create(branch_name="new-branch-1")
142142
assert isinstance(branch, BranchData)
143143
assert branch.id is not None
144144

145-
async def test_create_branch_async(self, client: InfrahubClient, base_dataset):
145+
async def test_create_branch_async(self, client: InfrahubClient, base_dataset) -> None:
146146
task_id = await client.branch.create(branch_name="new-branch-2", wait_until_completion=False)
147147
assert isinstance(task_id, str)
148148

149-
async def test_count(self, client: InfrahubClient, base_dataset):
149+
async def test_count(self, client: InfrahubClient, base_dataset) -> None:
150150
count = await client.count(kind=TESTING_PERSON)
151151
assert count == 3
152152

153-
async def test_count_with_filter(self, client: InfrahubClient, base_dataset):
153+
async def test_count_with_filter(self, client: InfrahubClient, base_dataset) -> None:
154154
count = await client.count(kind=TESTING_PERSON, name__values=["Liam Walker", "Ethan Carter"])
155155
assert count == 2
156156

157-
async def test_query_unexisting_branch(self, client: InfrahubClient):
157+
async def test_query_unexisting_branch(self, client: InfrahubClient) -> None:
158158
with pytest.raises(URLNotFoundError, match=r"/graphql/unexisting` not found."):
159159
await client.execute_graphql(query="unused", branch_name="unexisting")
160160

161161
async def test_create_generic_rel_with_hfid(
162162
self, client: InfrahubClient, base_dataset, cat_luna, person_sophia, schema_animal, schema_cat
163-
):
163+
) -> None:
164164
# See https://github.com/opsmill/infrahub-sdk-python/issues/277
165165
assert schema_animal.human_friendly_id != schema_cat.human_friendly_id, (
166166
"Inherited node schema should have a different hfid than generic one for this test to be relevant"
@@ -170,7 +170,7 @@ async def test_create_generic_rel_with_hfid(
170170
person_sophia = await client.get(kind=TESTING_PERSON, id=person_sophia.id, prefetch_relationships=True)
171171
assert person_sophia.favorite_animal.id == cat_luna.id
172172

173-
async def test_task_query(self, client: InfrahubClient, base_dataset, set_pagination_size3):
173+
async def test_task_query(self, client: InfrahubClient, base_dataset, set_pagination_size3) -> None:
174174
nbr_tasks = await client.task.count()
175175
assert nbr_tasks
176176

tests/integration/test_infrahubctl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def base_dataset(
4242
dog_daisy,
4343
dog_rocky,
4444
ctl_client_config,
45-
):
45+
) -> None:
4646
await client.branch.create(branch_name="branch01")
4747

4848
@pytest.fixture(scope="class")

tests/integration/test_node.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async def initial_schema(self, default_branch: str, client: InfrahubClient, sche
2020

2121
async def test_node_create(
2222
self, client: InfrahubClient, initial_schema: None, schema_manufacturer_base: NodeSchema
23-
):
23+
) -> None:
2424
schema_manufacturer = NodeSchemaAPI(**schema_manufacturer_base.model_dump(exclude_unset=True))
2525
data = {
2626
"name": "Fiat",
@@ -34,7 +34,7 @@ async def test_node_delete(
3434
self,
3535
client: InfrahubClient,
3636
initial_schema: None,
37-
):
37+
) -> None:
3838
obj = await client.create(kind=TESTING_MANUFACTURER, name="Dacia")
3939
await obj.save()
4040

@@ -52,7 +52,7 @@ async def test_node_create_with_relationships(
5252
initial_schema: None,
5353
manufacturer_mercedes,
5454
person_joe,
55-
):
55+
) -> None:
5656
node = await client.create(
5757
kind=TESTING_CAR, name="Tiguan", color="Black", manufacturer=manufacturer_mercedes.id, owner=person_joe.id
5858
)
@@ -71,7 +71,7 @@ async def test_node_create_with_relationships_using_related_node(
7171
manufacturer_mercedes,
7272
car_golf,
7373
person_joe,
74-
):
74+
) -> None:
7575
related_node = car_golf.owner
7676
node = await client.create(
7777
kind=TESTING_CAR, name="Tiguan", color="Black", manufacturer=manufacturer_mercedes, owner=related_node
@@ -90,7 +90,7 @@ async def test_node_update_with_original_data(
9090
default_branch: str,
9191
client: InfrahubClient,
9292
initial_schema: None,
93-
):
93+
) -> None:
9494
person_marina = await client.create(kind="TestingPerson", name="marina", age=20)
9595
await person_marina.save()
9696

@@ -183,7 +183,7 @@ async def test_node_update(
183183
tag_blue,
184184
tag_red,
185185
tag_green,
186-
):
186+
) -> None:
187187
car_golf.color.value = "White"
188188
await car_golf.tags.fetch()
189189
car_golf.tags.add(tag_blue.id)

tests/integration/test_repository.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
class TestInfrahubRepository(TestInfrahubDockerClient):
14-
async def test_add_repository(self, client: InfrahubClient, remote_repos_dir):
14+
async def test_add_repository(self, client: InfrahubClient, remote_repos_dir) -> None:
1515
src_directory = get_fixtures_dir() / "integration/mock_repo"
1616
repo = GitRepo(name="mock_repo", src_directory=src_directory, dst_directory=remote_repos_dir)
1717
commit = repo._repo.git[repo._repo.git.head()]

tests/integration/test_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#
1616
#
1717
class TestInfrahubSchema(TestInfrahubDockerClient):
18-
async def test_query_schema_for_branch_not_found(self, client: InfrahubClient):
18+
async def test_query_schema_for_branch_not_found(self, client: InfrahubClient) -> None:
1919
with pytest.raises(BranchNotFoundError) as exc:
2020
await client.all(kind="BuiltinTag", branch="I-do-not-exist")
2121

tests/integration/test_spec_object.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def load_menu_file(name: str) -> MenuFile:
2424
return files[0]
2525

2626

27-
def test_load_nested_folders_order():
27+
def test_load_nested_folders_order() -> None:
2828
files = YamlFile.load_from_disk(paths=[get_fixtures_dir() / "nested_spec_objects"])
2929
assert len(files) == 6
3030
assert Path(files[0].location).name == "3_file.yml"
@@ -53,10 +53,10 @@ async def initial_schema(self, default_branch: str, client: InfrahubClient, sche
5353
)
5454
assert resp.errors == {}
5555

56-
async def test_create_branch(self, client: InfrahubClient, initial_schema: None, branch_name: str):
56+
async def test_create_branch(self, client: InfrahubClient, initial_schema: None, branch_name: str) -> None:
5757
await client.branch.create(branch_name=branch_name, sync_with_git=False)
5858

59-
async def test_load_tags(self, client: InfrahubClient, branch_name: str, initial_schema: None):
59+
async def test_load_tags(self, client: InfrahubClient, branch_name: str, initial_schema: None) -> None:
6060
obj_file = load_object_file("animal_tags01.yml")
6161
await obj_file.validate_format(client=client, branch=branch_name)
6262

@@ -67,7 +67,7 @@ async def test_load_tags(self, client: InfrahubClient, branch_name: str, initial
6767

6868
assert len(await client.all(kind=obj_file.spec.kind, branch=branch_name)) == 3
6969

70-
async def test_update_tags(self, client: InfrahubClient, branch_name: str, initial_schema: None):
70+
async def test_update_tags(self, client: InfrahubClient, branch_name: str, initial_schema: None) -> None:
7171
obj_file = load_object_file("animal_tags02.yml")
7272
await obj_file.validate_format(client=client, branch=branch_name)
7373

@@ -81,7 +81,7 @@ async def test_update_tags(self, client: InfrahubClient, branch_name: str, initi
8181
assert len(tags_by_name) == 4
8282
assert tags_by_name["Veterinarian"].description.value == "Licensed animal healthcare professional"
8383

84-
async def test_load_persons(self, client: InfrahubClient, branch_name: str, initial_schema: None):
84+
async def test_load_persons(self, client: InfrahubClient, branch_name: str, initial_schema: None) -> None:
8585
obj_file = load_object_file("animal_person01.yml")
8686
await obj_file.validate_format(client=client, branch=branch_name)
8787

@@ -92,7 +92,7 @@ async def test_load_persons(self, client: InfrahubClient, branch_name: str, init
9292

9393
assert len(await client.all(kind=obj_file.spec.kind, branch=branch_name)) == 3
9494

95-
async def test_load_dogs(self, client: InfrahubClient, branch_name: str, initial_schema: None):
95+
async def test_load_dogs(self, client: InfrahubClient, branch_name: str, initial_schema: None) -> None:
9696
obj_file = load_object_file("animal_dog01.yml")
9797
await obj_file.validate_format(client=client, branch=branch_name)
9898

@@ -103,7 +103,7 @@ async def test_load_dogs(self, client: InfrahubClient, branch_name: str, initial
103103

104104
assert len(await client.all(kind=obj_file.spec.kind, branch=branch_name)) == 4
105105

106-
async def test_load_persons02(self, client: InfrahubClient, branch_name: str, initial_schema: None):
106+
async def test_load_persons02(self, client: InfrahubClient, branch_name: str, initial_schema: None) -> None:
107107
obj_file = load_object_file("animal_person02.yml")
108108
await obj_file.validate_format(client=client, branch=branch_name)
109109

@@ -135,7 +135,7 @@ async def test_load_persons02(self, client: InfrahubClient, branch_name: str, in
135135
animals_emily = [animal.display_label for animal in person_by_name["Emily Parker"].animals.peers]
136136
assert sorted(animals_emily) == sorted(["Max Golden Retriever", "Whiskers Siamese #FFD700"])
137137

138-
async def test_load_menu(self, client: InfrahubClient, branch_name: str, initial_schema: None):
138+
async def test_load_menu(self, client: InfrahubClient, branch_name: str, initial_schema: None) -> None:
139139
menu_file = load_menu_file("animal_menu01.yml")
140140
await menu_file.validate_format(client=client, branch=branch_name)
141141

tests/unit/ctl/test_branch_app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
runner = CliRunner()
77

88

9-
def test_branch_list(mock_branches_list_query):
9+
def test_branch_list(mock_branches_list_query) -> None:
1010
result = runner.invoke(app=app, args=["list"])
1111
assert result.exit_code == 0
1212
assert "cr1234" in result.stdout
1313

1414

15-
def test_branch_create_no_auth(httpx_mock: HTTPXMock, authentication_error_payload):
15+
def test_branch_create_no_auth(httpx_mock: HTTPXMock, authentication_error_payload) -> None:
1616
httpx_mock.add_response(
1717
status_code=401,
1818
method="POST",
@@ -24,7 +24,7 @@ def test_branch_create_no_auth(httpx_mock: HTTPXMock, authentication_error_paylo
2424
assert "Authentication is required" in result.stdout
2525

2626

27-
def test_branch_create_wrong_name(mock_branch_create_error):
27+
def test_branch_create_wrong_name(mock_branch_create_error) -> None:
2828
result = runner.invoke(app=app, args=["create", "branch2"])
2929

3030
assert result.exit_code == 1

tests/unit/ctl/test_cli.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,44 @@
88
pytestmark = pytest.mark.httpx_mock(can_send_already_matched_responses=True)
99

1010

11-
def test_main_app():
11+
def test_main_app() -> None:
1212
result = runner.invoke(app, ["--help"])
1313
assert result.exit_code == 0
1414
assert "[OPTIONS] COMMAND [ARGS]" in result.stdout
1515

1616

17-
def test_validate_all_commands_have_names():
17+
def test_validate_all_commands_have_names() -> None:
1818
assert app.registered_commands
1919
for command in app.registered_commands:
2020
assert command.name
2121

2222

23-
def test_validate_all_groups_have_names():
23+
def test_validate_all_groups_have_names() -> None:
2424
assert app.registered_groups
2525
for group in app.registered_groups:
2626
assert group.name
2727

2828

29-
def test_version_command():
29+
def test_version_command() -> None:
3030
result = runner.invoke(app, ["version"])
3131
assert result.exit_code == 0
3232
assert "Python SDK: v" in result.stdout
3333

3434

35-
def test_info_command_success(mock_query_infrahub_version, mock_query_infrahub_user):
35+
def test_info_command_success(mock_query_infrahub_version, mock_query_infrahub_user) -> None:
3636
result = runner.invoke(app, ["info"])
3737
assert result.exit_code == 0
3838
for expected in ["Connection Status", "Python Version", "SDK Version", "Infrahub Version"]:
3939
assert expected in result.stdout, f"'{expected}' not found in info command output"
4040

4141

42-
def test_info_command_failure():
42+
def test_info_command_failure() -> None:
4343
result = runner.invoke(app, ["info"])
4444
assert result.exit_code == 0
4545
assert "Connection Error" in result.stdout
4646

4747

48-
def test_info_detail_command_success(mock_query_infrahub_version, mock_query_infrahub_user):
48+
def test_info_detail_command_success(mock_query_infrahub_version, mock_query_infrahub_user) -> None:
4949
result = runner.invoke(app, ["info", "--detail"])
5050
assert result.exit_code == 0
5151
for expected in [
@@ -58,7 +58,7 @@ def test_info_detail_command_success(mock_query_infrahub_version, mock_query_inf
5858
assert expected in result.stdout, f"'{expected}' not found in detailed info command output"
5959

6060

61-
def test_info_detail_command_failure():
61+
def test_info_detail_command_failure() -> None:
6262
result = runner.invoke(app, ["info", "--detail"])
6363
assert result.exit_code == 0
6464
assert "Error Reason" in result.stdout

0 commit comments

Comments
 (0)