Skip to content

Commit 9a413db

Browse files
authored
Merge pull request #848 from LalatenduMohanty/add_return_annotaions_to_tests
test: add return type annotations to all test functions
2 parents d3ca6c0 + ab7d86f commit 9a413db

22 files changed

Lines changed: 253 additions & 227 deletions

tests/test_bootstrap.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
from fromager.commands import bootstrap
1313

1414

15-
def test_get_requirements_single_arg():
15+
def test_get_requirements_single_arg() -> None:
1616
requirements = bootstrap._get_requirements_from_args(["a"], [])
1717
assert [Requirement("a")] == requirements
1818

1919

20-
def test_get_requirements_multiple_args():
20+
def test_get_requirements_multiple_args() -> None:
2121
requirements = bootstrap._get_requirements_from_args(["a", "b"], [])
2222
assert [Requirement("a"), Requirement("b")] == requirements
2323

2424

25-
def test_get_requirements_args_and_file(tmp_path: pathlib.Path):
25+
def test_get_requirements_args_and_file(tmp_path: pathlib.Path) -> None:
2626
requirements_file = tmp_path / "requirements.txt"
2727
requirements_file.write_text("c\n")
2828
requirements = bootstrap._get_requirements_from_args(
@@ -35,14 +35,14 @@ def test_get_requirements_args_and_file(tmp_path: pathlib.Path):
3535
] == requirements
3636

3737

38-
def test_ignore_based_on_marker():
38+
def test_ignore_based_on_marker() -> None:
3939
requirements = bootstrap._get_requirements_from_args(
4040
['foo; python_version<"3.9"'], []
4141
)
4242
assert [] == requirements
4343

4444

45-
def test_write_constraints_file_simple():
45+
def test_write_constraints_file_simple() -> None:
4646
buffer = io.StringIO()
4747
raw_graph = {
4848
"": {
@@ -87,7 +87,7 @@ def test_write_constraints_file_simple():
8787
assert expected == buffer.getvalue()
8888

8989

90-
def test_write_constraints_file_resolvable_duplicate():
90+
def test_write_constraints_file_resolvable_duplicate() -> None:
9191
buffer = io.StringIO()
9292
raw_graph = {
9393
"": {
@@ -140,7 +140,7 @@ def test_write_constraints_file_resolvable_duplicate():
140140
assert expected == buffer.getvalue()
141141

142142

143-
def test_write_constraints_file_unresolvable_duplicate():
143+
def test_write_constraints_file_unresolvable_duplicate() -> None:
144144
"""Test that unresolvable duplicates cause the function to return False and not write conflicting constraints.
145145
146146
This test has conflicting requirements for package 'c':
@@ -203,7 +203,7 @@ def test_write_constraints_file_unresolvable_duplicate():
203203
assert "c==" not in output # No conflicting c versions should be written
204204

205205

206-
def test_write_constraints_file_duplicates():
206+
def test_write_constraints_file_duplicates() -> None:
207207
buffer = io.StringIO()
208208
raw_graph = {
209209
"": {
@@ -283,7 +283,7 @@ def test_write_constraints_file_duplicates():
283283
assert "b==" not in output_content
284284

285285

286-
def test_write_constraints_file_multiples():
286+
def test_write_constraints_file_multiples() -> None:
287287
buffer = io.StringIO()
288288
raw_graph = {
289289
"": {
@@ -342,7 +342,7 @@ def test_write_constraints_file_multiples():
342342
assert expected == buffer.getvalue()
343343

344344

345-
def test_write_constraints_file_prevents_false_resolution():
345+
def test_write_constraints_file_prevents_false_resolution() -> None:
346346
"""Test that packages marked as unresolvable in early iterations stay unresolvable.
347347
348348
This test validates the fix for the bug where a package could appear unresolvable
@@ -452,7 +452,7 @@ def test_write_constraints_file_prevents_false_resolution():
452452
assert "conflicted==" not in output_content
453453

454454

455-
def test_to_constraints_command_no_file_on_failure(tmp_path):
455+
def test_to_constraints_command_no_file_on_failure(tmp_path: pathlib.Path) -> None:
456456
"""Test that the to-constraints logic doesn't create output files when there are constraint conflicts.
457457
458458
This is a regression test for the bug where constraint resolution would write partial
@@ -531,7 +531,7 @@ def test_to_constraints_command_no_file_on_failure(tmp_path):
531531
)
532532

533533

534-
def test_skip_constraints_cli_option():
534+
def test_skip_constraints_cli_option() -> None:
535535
"""Test that the --skip-constraints option is available in the CLI"""
536536
runner = CliRunner()
537537
result = runner.invoke(bootstrap.bootstrap, ["--help"])
@@ -545,7 +545,7 @@ def test_skip_constraints_cli_option():
545545
def test_resolve_version_from_git_url_with_submodules_enabled(
546546
mock_git_clone: Mock,
547547
tmp_context: context.WorkContext,
548-
):
548+
) -> None:
549549
"""Test that git_clone is called with submodules=True when configured."""
550550
req = Requirement("test-pkg @ git+https://github.com/example/repo.git")
551551

@@ -582,7 +582,7 @@ def test_resolve_version_from_git_url_with_submodules_enabled(
582582
def test_resolve_version_from_git_url_with_specific_submodule_paths(
583583
mock_git_clone: Mock,
584584
tmp_context: context.WorkContext,
585-
):
585+
) -> None:
586586
"""Test that git_clone is called with specific submodule paths when configured."""
587587
req = Requirement("test-pkg @ git+https://github.com/example/repo.git")
588588

@@ -618,7 +618,7 @@ def test_resolve_version_from_git_url_with_specific_submodule_paths(
618618
def test_resolve_version_from_git_url_with_submodules_disabled(
619619
mock_git_clone: Mock,
620620
tmp_context: context.WorkContext,
621-
):
621+
) -> None:
622622
"""Test that git_clone is called with submodules=False by default."""
623623
req = Requirement("test-pkg @ git+https://github.com/example/repo.git")
624624

@@ -645,7 +645,7 @@ def test_resolve_version_from_git_url_with_submodules_disabled(
645645
def test_resolve_version_from_git_url_with_git_ref(
646646
mock_git_clone: Mock,
647647
tmp_context: context.WorkContext,
648-
):
648+
) -> None:
649649
"""Test that git_clone is called with the correct ref when URL includes @ref."""
650650
req = Requirement("test-pkg @ git+https://github.com/example/repo.git@v1.2.3")
651651

@@ -677,7 +677,9 @@ def test_resolve_version_from_git_url_with_git_ref(
677677
assert call_args.kwargs["ref"] == "v1.2.3"
678678

679679

680-
def test_resolve_version_from_git_url_invalid_scheme(tmp_context: context.WorkContext):
680+
def test_resolve_version_from_git_url_invalid_scheme(
681+
tmp_context: context.WorkContext,
682+
) -> None:
681683
"""Test that non-git URLs raise ValueError."""
682684
req = Requirement("test-pkg @ https://github.com/example/repo.git")
683685

tests/test_bootstrapper.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
)
6161

6262

63-
def test_resolve_from_graph_no_changes(tmp_context: WorkContext):
63+
def test_resolve_from_graph_no_changes(tmp_context: WorkContext) -> None:
6464
bt = bootstrapper.Bootstrapper(tmp_context, None, old_graph)
6565
bt.why = [(RequirementType.TOP_LEVEL, Requirement("foo"), Version("1.0.0"))]
6666

@@ -98,7 +98,7 @@ def test_resolve_from_graph_no_changes(tmp_context: WorkContext):
9898
) == ("", Version("5"))
9999

100100

101-
def test_resolve_from_graph_install_dep_upgrade(tmp_context: WorkContext):
101+
def test_resolve_from_graph_install_dep_upgrade(tmp_context: WorkContext) -> None:
102102
bt = bootstrapper.Bootstrapper(tmp_context, None, old_graph)
103103

104104
# simulating new bootstrap with a toplevel requirement of pbr==8
@@ -135,7 +135,7 @@ def test_resolve_from_graph_install_dep_upgrade(tmp_context: WorkContext):
135135
) == ("", Version("5"))
136136

137137

138-
def test_resolve_from_graph_install_dep_downgrade(tmp_context: WorkContext):
138+
def test_resolve_from_graph_install_dep_downgrade(tmp_context: WorkContext) -> None:
139139
bt = bootstrapper.Bootstrapper(tmp_context, None, old_graph)
140140

141141
# simulating new bootstrap with a toplevel requirement of pbr<=6
@@ -172,7 +172,7 @@ def test_resolve_from_graph_install_dep_downgrade(tmp_context: WorkContext):
172172
) == ("", Version("5"))
173173

174174

175-
def test_resolve_from_graph_toplevel_dep(tmp_context: WorkContext):
175+
def test_resolve_from_graph_toplevel_dep(tmp_context: WorkContext) -> None:
176176
bt = bootstrapper.Bootstrapper(tmp_context, None, old_graph)
177177

178178
# simulating new bootstrap with a toplevel requirement for foo
@@ -226,19 +226,19 @@ def test_resolve_from_graph_toplevel_dep(tmp_context: WorkContext):
226226
) == ("", Version("6"))
227227

228228

229-
def test_seen(tmp_context):
229+
def test_seen(tmp_context: WorkContext) -> None:
230230
bt = bootstrapper.Bootstrapper(tmp_context)
231231
req = Requirement("testdist")
232-
version = "1.2"
232+
version = Version("1.2")
233233
assert not bt._has_been_seen(req, version)
234234
bt._mark_as_seen(req, version)
235235
assert bt._has_been_seen(req, version)
236236

237237

238-
def test_seen_extras(tmp_context):
238+
def test_seen_extras(tmp_context: WorkContext) -> None:
239239
req1 = Requirement("testdist")
240240
req2 = Requirement("testdist[extra]")
241-
version = "1.2"
241+
version = Version("1.2")
242242
bt = bootstrapper.Bootstrapper(tmp_context)
243243
assert not bt._has_been_seen(req1, version)
244244
bt._mark_as_seen(req1, version)
@@ -249,19 +249,19 @@ def test_seen_extras(tmp_context):
249249
assert bt._has_been_seen(req2, version)
250250

251251

252-
def test_seen_name_canonicalization(tmp_context):
252+
def test_seen_name_canonicalization(tmp_context: WorkContext) -> None:
253253
req = Requirement("flit_core")
254-
version = "1.2"
254+
version = Version("1.2")
255255
bt = bootstrapper.Bootstrapper(tmp_context)
256256
assert not bt._has_been_seen(req, version)
257257
bt._mark_as_seen(req, version)
258258
assert bt._has_been_seen(req, version)
259259

260260

261-
def test_seen_requirements_sdist(tmp_context):
261+
def test_seen_requirements_sdist(tmp_context: WorkContext) -> None:
262262
bt = bootstrapper.Bootstrapper(tmp_context)
263263
req = Requirement("testdist")
264-
version = "1.2"
264+
version = Version("1.2")
265265
assert not bt._has_been_seen(req, version, sdist_only=False)
266266
assert not bt._has_been_seen(req, version, sdist_only=True)
267267
# sdist only does not affect wheel status
@@ -282,17 +282,17 @@ def test_seen_requirements_sdist(tmp_context):
282282
assert bt._has_been_seen(req2, version, sdist_only=False)
283283

284284

285-
def test_build_order(tmp_context):
285+
def test_build_order(tmp_context: WorkContext) -> None:
286286
bt = bootstrapper.Bootstrapper(tmp_context)
287287
bt._add_to_build_order(
288288
req=Requirement("buildme>1.0"),
289-
version="6.0",
289+
version=Version("6.0"),
290290
source_url="url",
291291
source_url_type="sdist",
292292
)
293293
bt._add_to_build_order(
294294
req=Requirement("testdist>1.0"),
295-
version="1.2",
295+
version=Version("1.2"),
296296
source_url="url",
297297
source_url_type="sdist",
298298
)
@@ -321,23 +321,23 @@ def test_build_order(tmp_context):
321321
assert expected == contents
322322

323323

324-
def test_build_order_repeats(tmp_context):
324+
def test_build_order_repeats(tmp_context: WorkContext) -> None:
325325
bt = bootstrapper.Bootstrapper(tmp_context)
326326
bt._add_to_build_order(
327327
Requirement("buildme>1.0"),
328-
"6.0",
328+
Version("6.0"),
329329
"url",
330330
"sdist",
331331
)
332332
bt._add_to_build_order(
333333
Requirement("buildme>1.0"),
334-
"6.0",
334+
Version("6.0"),
335335
"url",
336336
"sdist",
337337
)
338338
bt._add_to_build_order(
339339
Requirement("buildme[extra]>1.0"),
340-
"6.0",
340+
Version("6.0"),
341341
"url",
342342
"sdist",
343343
)
@@ -357,17 +357,17 @@ def test_build_order_repeats(tmp_context):
357357
assert expected == contents
358358

359359

360-
def test_build_order_name_canonicalization(tmp_context):
360+
def test_build_order_name_canonicalization(tmp_context: WorkContext) -> None:
361361
bt = bootstrapper.Bootstrapper(tmp_context)
362362
bt._add_to_build_order(
363363
Requirement("flit-core>1.0"),
364-
"3.9.0",
364+
Version("3.9.0"),
365365
"url",
366366
"sdist",
367367
)
368368
bt._add_to_build_order(
369369
Requirement("flit_core>1.0"),
370-
"3.9.0",
370+
Version("3.9.0"),
371371
"url",
372372
"sdist",
373373
)
@@ -387,7 +387,7 @@ def test_build_order_name_canonicalization(tmp_context):
387387
assert expected == contents
388388

389389

390-
def test_explain(tmp_context: WorkContext):
390+
def test_explain(tmp_context: WorkContext) -> None:
391391
bt = bootstrapper.Bootstrapper(tmp_context, None, old_graph)
392392
bt.why = [(RequirementType.TOP_LEVEL, Requirement("foo"), Version("1.0.0"))]
393393
assert bt._explain == f"{RequirementType.TOP_LEVEL} dependency foo (1.0.0)"
@@ -405,7 +405,7 @@ def test_explain(tmp_context: WorkContext):
405405
)
406406

407407

408-
def test_is_build_requirement(tmp_context: WorkContext):
408+
def test_is_build_requirement(tmp_context: WorkContext) -> None:
409409
bt = bootstrapper.Bootstrapper(tmp_context, None, old_graph)
410410
bt.why = []
411411
assert not bt._processing_build_requirement(RequirementType.TOP_LEVEL)

tests/test_build_environment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def test_missing_dependency_format(
1414
resolve_dist: Mock,
1515
tmp_context: WorkContext,
16-
):
16+
) -> None:
1717
resolutions = {
1818
"flit_core": "3.9.0",
1919
"setuptools": "69.5.1",
@@ -40,7 +40,7 @@ def test_missing_dependency_format(
4040
assert "flit_core -> 3.9.0" in s
4141

4242

43-
def test_missing_dependency_pattern():
43+
def test_missing_dependency_pattern() -> None:
4444
msg = textwrap.dedent("""
4545
DEBUG uv 0.8.4
4646
DEBUG Searching for default Python interpreter in virtual environments
@@ -62,7 +62,7 @@ def test_missing_dependency_pattern():
6262
assert match is not None
6363

6464

65-
def test_missing_dependency_pattern_resolution_impossible():
65+
def test_missing_dependency_pattern_resolution_impossible() -> None:
6666
msg = textwrap.dedent("""
6767
DEBUG uv 0.8.4
6868
DEBUG Searching for default Python interpreter in virtual environments

tests/test_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def get_option_names(cmd: click.Command) -> typing.Iterable[str]:
99
return [o.name for o in cmd.params if o.name]
1010

1111

12-
def test_bootstrap_pallel_options() -> None:
12+
def test_bootstrap_parallel_options() -> None:
1313
expected: set[str] = set()
1414
expected.update(get_option_names(bootstrap.bootstrap))
1515
expected.update(get_option_names(build.build_parallel))

0 commit comments

Comments
 (0)