Skip to content

Commit 1ac6ee3

Browse files
fix type warnings
1 parent 805a35a commit 1ac6ee3

10 files changed

Lines changed: 52 additions & 49 deletions

File tree

score_pytest/attribute_plugin.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def decorator(func: TestFunction) -> TestFunction:
9090
def pytest_runtest_makereport(item: pytest.Item, call: pytest.CallInfo[None]):
9191
"""Attach file and line info to the report for use in junitxml output."""
9292

93-
outcome = yield
94-
report = outcome.get_result()
93+
outcome = yield # pyright: ignore[reportUnknownVariableType]
94+
report = outcome.get_result() # pyright: ignore[reportUnknownVariableType]
9595

9696
if report.when != "call":
9797
return
@@ -115,7 +115,7 @@ def pytest_runtest_makereport(item: pytest.Item, call: pytest.CallInfo[None]):
115115
)
116116

117117
if isinstance(marker.args[0], dict):
118-
for k, v in marker.args[0].items():
118+
for k, v in marker.args[0].items(): # pyright: ignore[reportUnknownVariableType]
119119
item.user_properties.append((k, str(v)))
120120

121121

@@ -124,11 +124,11 @@ def add_file_and_line_attr(
124124
record_xml_attribute: Callable[[str, str], None], request: pytest.FixtureRequest
125125
) -> None:
126126
"""Adding line & file to the <testcase> attribute in the XML"""
127-
node = request.node
128-
raw_file_path, line_number, _ = node.location
127+
node = request.node # pyright: ignore[reportUnknownVariableType]
128+
raw_file_path, line_number, _ = node.location # pyright: ignore[reportUnknownVariableType]
129129

130130
# turning `../../../_main/<file_path>` into => <filepath>
131-
clean_file_path = raw_file_path.split("_main/")[-1]
131+
clean_file_path = raw_file_path.split("_main/")[-1] # pyright: ignore[reportUnknownVariableType]
132132
record_xml_attribute("file", str(clean_file_path))
133133
# Convert pytest's 0-based source line number to 1-based numbering for XML output.
134134
record_xml_attribute("line", str(line_number + 1))

score_pytest/tests/test_rules_are_working_correctly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
#
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
13-
def test_local_fixture_has_correct_value(fixture42):
13+
def test_score_pytest_loads_conftest(fixture42): # pyright: ignore[reportMissingParameterType]
1414
assert fixture42 == 42

scripts_bazel/tests/traceability_gate_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def test_gate_fail_on_broken_test_refs(
210210
monkeypatch: pytest.MonkeyPatch,
211211
capsys: pytest.CaptureFixture[str],
212212
) -> None:
213-
metrics_by_type = {
213+
metrics_by_type: dict[str, object] = {
214214
"tool_req": {
215215
"include_not_implemented": False,
216216
"include_external": False,
@@ -223,7 +223,7 @@ def test_gate_fail_on_broken_test_refs(
223223
"fully_linked_pct": 100.0,
224224
}
225225
}
226-
tests = {
226+
tests: dict[str, object] = {
227227
"total": 2,
228228
"linked_to_requirements": 2,
229229
"linked_to_requirements_pct": 100.0,
@@ -248,7 +248,7 @@ def test_gate_specific_need_type_only(
248248
monkeypatch: pytest.MonkeyPatch,
249249
capsys: pytest.CaptureFixture[str],
250250
) -> None:
251-
metrics_by_type = {
251+
metrics_by_type: dict[str, object] = {
252252
"tool_req": {
253253
"include_not_implemented": False,
254254
"include_external": False,
@@ -272,7 +272,7 @@ def test_gate_specific_need_type_only(
272272
"fully_linked_pct": 0.0,
273273
},
274274
}
275-
tests = {
275+
tests: dict[str, object] = {
276276
"total": 1,
277277
"linked_to_requirements": 1,
278278
"linked_to_requirements_pct": 100.0,
@@ -349,7 +349,7 @@ def test_gate_missing_metrics_by_type_returns_error(
349349
monkeypatch: pytest.MonkeyPatch,
350350
capsys: pytest.CaptureFixture[str],
351351
) -> None:
352-
payload = {
352+
payload: dict[str, object] = {
353353
"schema_version": "2",
354354
"generated_by": "sphinx_build",
355355
"overall_metrics": {
@@ -383,7 +383,7 @@ def test_gate_missing_tests_section_returns_error(
383383
monkeypatch: pytest.MonkeyPatch,
384384
capsys: pytest.CaptureFixture[str],
385385
) -> None:
386-
metrics_by_type = {
386+
metrics_by_type: dict[str, object] = {
387387
"tool_req": {
388388
"include_not_implemented": False,
389389
"include_external": False,
@@ -396,7 +396,7 @@ def test_gate_missing_tests_section_returns_error(
396396
"fully_linked_pct": 100.0,
397397
}
398398
}
399-
payload = {
399+
payload: dict[str, object] = {
400400
"schema_version": "2",
401401
"generated_by": "sphinx_build",
402402
"overall_metrics": _derive_overall_metrics(metrics_by_type),

src/extensions/score_metamodel/checks/check_options.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ def check_extra_options(
243243
"mandatory_links",
244244
"optional_links",
245245
):
246-
assert need_options[o] is not None
247-
allowed_options.update(need_options[o].keys())
246+
val = need_options[o]
247+
assert val is not None
248+
allowed_options.update(val.keys())
248249

249250
extra_options = [
250251
option

src/extensions/score_metamodel/tests/test_graph_checks.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,6 @@ def filter_is_external(self, is_external: bool) -> DummyNeedsView:
4141
)
4242

4343

44-
class NeedObject(dict):
45-
"""Need object that supports both mapping and attribute style access used by code."""
46-
47-
@property
48-
def id(self) -> str:
49-
"""Return need identifier."""
50-
return self["id"]
51-
52-
@property
53-
def _links(self) -> dict[str, list[NeedObject]]:
54-
"""Return links map."""
55-
return self["links"]
56-
57-
5844
def test_eval_need_check_invalid_check_parts_raises_value_error() -> None:
5945
"""Raise error when a check does not contain exactly three parts."""
6046
log = fake_check_logger()

src/extensions/score_metrics/tests/test_sphinx_filters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_generic_pie_items_by_tag_matches_source_by_id_prefix() -> None:
6969
assert results == [1, 1]
7070

7171

72-
EXAMPLE_METRICS = {
72+
EXAMPLE_METRICS: dict[str, object] = {
7373
"schema_version": "1",
7474
"generated_by": "sphinx_build",
7575
"overall_metrics": {
@@ -110,15 +110,15 @@ def test_get_key_values_raises_key_error_when_global_is_empty() -> None:
110110
"""It raises KeyError if CALCULATED_METRICS is still empty."""
111111
results: list[int] = []
112112
with pytest.raises(KeyError):
113-
sphinx_filters._get_key_values(results, ["overall_metrics:total"])
113+
sphinx_filters._get_key_values(results, ["overall_metrics:total"]) # pyright: ignore[reportPrivateUsage]
114114

115115

116116
def test_get_key_values_appends_values_when_metrics_loaded() -> None:
117117
"""It appends resolved integer values once metrics data is loaded."""
118118
sphinx_filters.CALCULATED_METRICS = EXAMPLE_METRICS
119119
results: list[int] = []
120120

121-
sphinx_filters._get_key_values(
121+
sphinx_filters._get_key_values( # pyright: ignore[reportPrivateUsage]
122122
results,
123123
[
124124
"overall_metrics:total",

src/extensions/score_metrics/tests/test_traceability_metrics.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def test_get_need_types_by_tags_returns_matching_directives_only() -> None:
4343
},
4444
"optional_options": {},
4545
"mandatory_links": {},
46+
"mandatory_links_str": {},
4647
"optional_links": {},
48+
"optional_links_str": {},
4749
},
4850
{
4951
"title": "Test Type Verification",
@@ -57,7 +59,9 @@ def test_get_need_types_by_tags_returns_matching_directives_only() -> None:
5759
},
5860
"optional_options": {},
5961
"mandatory_links": {},
62+
"mandatory_links_str": {},
6063
"optional_links": {},
64+
"optional_links_str": {},
6165
},
6266
{
6367
"title": "Test Type Extra",
@@ -71,7 +75,9 @@ def test_get_need_types_by_tags_returns_matching_directives_only() -> None:
7175
},
7276
"optional_options": {},
7377
"mandatory_links": {},
78+
"mandatory_links_str": {},
7479
"optional_links": {},
80+
"optional_links_str": {},
7581
},
7682
]
7783
result = metrics.get_need_types_by_tags(needs, {"verification", "requirement"})
@@ -98,7 +104,9 @@ def test_get_need_types_by_tags_returns_empty_on_non_match() -> None:
98104
},
99105
"optional_options": {},
100106
"mandatory_links": {},
107+
"mandatory_links_str": {},
101108
"optional_links": {},
109+
"optional_links_str": {},
102110
},
103111
]
104112
result = metrics.get_need_types_by_tags(needs, {"requirements_without_proccess"})

src/extensions/score_metrics/traceability_metrics.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from sphinx_needs.data import NeedsView, SphinxNeedsData
2929
from sphinx_needs.need_item import NeedItem
3030

31-
CALCULATED_METRICS = {}
31+
CALCULATED_METRICS: dict[str, object] = {}
3232

3333

3434
def get_need_types_by_tags(needs: list[ScoreNeedType], tags: set[str]) -> list[str]:
@@ -44,7 +44,7 @@ def get_need_types_by_tags(needs: list[ScoreNeedType], tags: set[str]) -> list[s
4444
return found_need_types
4545

4646

47-
def is_non_empty(value: Any) -> bool:
47+
def is_non_empty(value: object) -> bool:
4848
"""Return True if value should be treated as present for traceability checks."""
4949
if isinstance(value, str):
5050
return bool(value.strip())
@@ -60,7 +60,7 @@ def safe_percent(numerator: int, denominator: int) -> float:
6060

6161
def calculate_requirement_metrics(
6262
current_requirement_needs: list[NeedItem],
63-
) -> dict[str, Any]:
63+
) -> dict[str, int | float]:
6464
"""Calculate requirement traceability statistics for links and completeness."""
6565
total = len(current_requirement_needs)
6666
reqs_with_code_link = 0
@@ -94,7 +94,7 @@ def calculate_requirement_metrics(
9494

9595
def calculate_test_metrics(
9696
test_needs: list[NeedItem], all_needs: NeedsView
97-
) -> dict[str, Any]:
97+
) -> dict[str, object]:
9898
"""Calculate testcase linkage and broken testcase-reference statistics."""
9999
tests_total = len(test_needs)
100100
tests_linked = 0
@@ -144,7 +144,7 @@ def calculate_full_need_metrics(app: Sphinx, include_external: bool):
144144
test_needs = list(all_needs.filter_types(["testcase"]).values())
145145
test_metrics = calculate_test_metrics(test_needs, all_needs)
146146

147-
metrics_by_type: dict[str, Any] = {}
147+
metrics_by_type: dict[str, dict[str, int | float]] = {}
148148

149149
# Metrics accumulated over all requirements types
150150
overall_metrics: dict[str, Any] = {
@@ -182,7 +182,7 @@ def calculate_full_need_metrics(app: Sphinx, include_external: bool):
182182
overall_metrics["fully_linked"], overall_metrics["total"]
183183
)
184184

185-
output: dict[str, Any] = {
185+
output: dict[str, object] = {
186186
"schema_version": "2",
187187
"generated_by": "sphinx_build",
188188
"overall_metrics": overall_metrics,

src/incremental_dirty_build_test.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515

1616
from pathlib import Path
1717

18+
from pyfakefs.fake_filesystem import FakeFilesystem as FFS
19+
1820
from incremental import clean_builddir_if_stale, update_module_hash
1921

2022
_BUILD = Path("/build")
2123
_MODULE = Path("/MODULE.bazel")
2224
_LOCK = Path("/MODULE.bazel.lock")
2325

2426

25-
def _simulate_old_state(fs, warnings: str | None) -> None:
27+
def _simulate_old_state(fs: FFS, warnings: str | None) -> None:
2628
"""Helper function to set up a build directory with an old hash and warnings."""
2729

2830
fs.create_dir(_BUILD)
@@ -33,7 +35,9 @@ def _simulate_old_state(fs, warnings: str | None) -> None:
3335
fs.create_file(_BUILD / "warnings.txt", contents=warnings)
3436

3537

36-
def test_clean_removes_build_dir_when_previous_build_had_warnings(fs) -> None:
38+
def test_clean_removes_build_dir_when_previous_build_had_warnings(
39+
fs: FFS,
40+
) -> None:
3741
"""If warnings.txt exists and is not empty, the build dir is removed."""
3842

3943
_simulate_old_state(fs, warnings="WARNING: something went wrong")
@@ -43,7 +47,7 @@ def test_clean_removes_build_dir_when_previous_build_had_warnings(fs) -> None:
4347
assert not _BUILD.exists()
4448

4549

46-
def test_clean_keeps_build_dir_when_warnings_txt_is_empty(fs) -> None:
50+
def test_clean_keeps_build_dir_when_warnings_txt_is_empty(fs: FFS) -> None:
4751
"""If warnings.txt exists and is empty, the build dir is kept."""
4852

4953
_simulate_old_state(fs, warnings="")
@@ -53,7 +57,7 @@ def test_clean_keeps_build_dir_when_warnings_txt_is_empty(fs) -> None:
5357
assert _BUILD.exists()
5458

5559

56-
def test_clean_is_noop_when_warnings_txt_is_absent(fs) -> None:
60+
def test_clean_is_noop_when_warnings_txt_is_absent(fs: FFS) -> None:
5761
"""If warnings.txt does not exist, the build dir is kept (no error)."""
5862

5963
_simulate_old_state(fs, warnings=None)
@@ -63,13 +67,15 @@ def test_clean_is_noop_when_warnings_txt_is_absent(fs) -> None:
6367
assert _BUILD.exists()
6468

6569

66-
def test_clean_is_noop_when_build_dir_is_absent(fs) -> None:
70+
def test_clean_is_noop_when_build_dir_is_absent(fs: FFS) -> None:
6771
fs.create_file(_MODULE, contents="stable")
6872

6973
clean_builddir_if_stale(_BUILD, [_MODULE])
7074

7175

72-
def test_module_changed_removes_build_dir_when_one_sentinel_file_changed(fs) -> None:
76+
def test_module_changed_removes_build_dir_when_one_sentinel_file_changed(
77+
fs: FFS,
78+
) -> None:
7379
_simulate_old_state(fs, warnings=None)
7480

7581
_LOCK.write_bytes(b"new lock")
@@ -78,15 +84,17 @@ def test_module_changed_removes_build_dir_when_one_sentinel_file_changed(fs) ->
7884
assert not _BUILD.exists()
7985

8086

81-
def test_module_changed_keeps_build_dir_when_all_sentinel_files_unchanged(fs) -> None:
87+
def test_module_changed_keeps_build_dir_when_all_sentinel_files_unchanged(
88+
fs: FFS,
89+
) -> None:
8290
_simulate_old_state(fs, warnings=None)
8391

8492
clean_builddir_if_stale(_BUILD, [_MODULE, _LOCK])
8593

8694
assert _BUILD.exists()
8795

8896

89-
def test_module_change_after_successful_build_forces_clean(fs) -> None:
97+
def test_module_change_after_successful_build_forces_clean(fs: FFS) -> None:
9098
_simulate_old_state(fs, warnings=None)
9199

92100
_MODULE.write_bytes(b"version 2")
@@ -95,7 +103,7 @@ def test_module_change_after_successful_build_forces_clean(fs) -> None:
95103
assert not _BUILD.exists()
96104

97105

98-
def test_missing_hash_file_triggers_clean(fs) -> None:
106+
def test_missing_hash_file_triggers_clean(fs: FFS) -> None:
99107
"""If _build/ exists but hash file is absent, treat as stale (e.g. upgrade from old version)."""
100108
fs.create_dir(_BUILD)
101109
fs.create_file(_MODULE, contents="stable")

src/tests/test_consumer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def _make_params() -> list[pytest.param]: # type: ignore[type-arg]
348348
id=f"{repo.name}-{override}-{_cmd_id(cmd)}",
349349
)
350350
)
351-
return params
351+
return params # pyright: ignore[reportUnknownVariableType]
352352

353353

354354
@pytest.mark.parametrize("repo, override_type, cmd", _make_params())

0 commit comments

Comments
 (0)