Skip to content

Commit 45b4892

Browse files
committed
Lint: Fix type annotations in tests
1 parent 13a7d0d commit 45b4892

21 files changed

+210
-142
lines changed

tests/apt/test_package_repo_info.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
from types import SimpleNamespace
2-
from typing import List
2+
from typing import List, Tuple
33

44
import pytest
5-
from apt_repo import BinaryPackage
65

76
import gardenlinux.apt.package_repo_info as repoinfo
87

98

109
class FakeAPTRepo:
1110
"""
12-
Fake replacement for apt_repo.APTTRepository.
11+
Fake replacement for apt_repo.APTRepository.
1312
14-
- stores the contructor args for assertions
13+
- stores the constructor args for assertions
1514
- exposes `.packages` and `get_packages_by_name(name)`
1615
"""
1716

@@ -20,12 +19,22 @@ def __init__(self, url: str, dist: str, components: List[str]) -> None:
2019
self.dist = dist
2120
self.components = components
2221
# list of objects with .package and .version attributes
23-
self.packages: List[BinaryPackage] = []
22+
self.packages: List[SimpleNamespace] = []
2423

25-
def get_packages_by_name(self, name: str) -> BinaryPackage:
24+
def get_packages_by_name(self, name: str) -> List[SimpleNamespace]:
2625
return [p for p in self.packages if p.package == name]
2726

2827

28+
# Fake GardenLinuxRepo subclass to avoid incomplete type issues in compare tests
29+
class FakeRepo(repoinfo.GardenLinuxRepo):
30+
def __init__(self, versions: List[Tuple[str, str]]) -> None:
31+
# Skip calling the real constructor
32+
self._versions = versions
33+
34+
def get_packages_versions(self) -> List[Tuple[str, str]]:
35+
return self._versions
36+
37+
2938
def test_gardenlinuxrepo_init(monkeypatch: pytest.MonkeyPatch) -> None:
3039
"""
3140
Test if GardenLinuxRepo creates an internal APTRepo
@@ -91,11 +100,11 @@ def test_compare_repo_union_returns_all() -> None:
91100
- names in both but with different versions
92101
"""
93102
# Arrange
94-
a = SimpleNamespace(get_packages_versions=lambda: [("a", "1"), ("b", "2")])
95-
b = SimpleNamespace(get_packages_versions=lambda: [("b", "3"), ("c", "4")])
103+
a = FakeRepo([("a", "1"), ("b", "2")])
104+
b = FakeRepo([("b", "3"), ("c", "4")])
96105

97106
# Act
98-
result = repoinfo.compare_repo(a, b, available_in_both=False) # type: ignore
107+
result = repoinfo.compare_repo(a, b, available_in_both=False)
99108

100109
# Assert
101110
expected = {
@@ -111,12 +120,12 @@ def test_compare_repo_intersection_only() -> None:
111120
When available_in_both=True, only intersection names are considered;
112121
differences are only returned if versions differ.
113122
"""
114-
# Arrange (both share 'b' with different versions)
115-
a = SimpleNamespace(get_packages_versions=lambda: [("a", "1"), ("b", "2")])
116-
b = SimpleNamespace(get_packages_versions=lambda: [("b", "3"), ("c", "4")])
123+
# Arrange
124+
a = FakeRepo([("a", "1"), ("b", "2")])
125+
b = FakeRepo([("b", "3"), ("c", "4")])
117126

118127
# Act
119-
result = repoinfo.compare_repo(a, b, available_in_both=True) # type: ignore
128+
result = repoinfo.compare_repo(a, b, available_in_both=True)
120129

121130
# Assert
122131
assert set(result) == {("b", "2", "3")}
@@ -127,20 +136,20 @@ def test_compare_same_returns_empty() -> None:
127136
When both sets are identical, compare_repo should return an empty set.
128137
"""
129138
# Arrange
130-
a = SimpleNamespace(get_packages_versions=lambda: [("a", "1"), ("b", "2")])
131-
b = SimpleNamespace(get_packages_versions=lambda: [("a", "1"), ("b", "2")])
139+
a = FakeRepo([("a", "1"), ("b", "2")])
140+
b = FakeRepo([("a", "1"), ("b", "2")])
132141

133142
# Act / Assert
134-
assert repoinfo.compare_repo(a, b, available_in_both=False) == [] # type: ignore
143+
assert repoinfo.compare_repo(a, b, available_in_both=False) == []
135144

136145

137146
def test_compare_empty_returns_empty() -> None:
138147
"""
139148
If both sets are empty, compare_repo should return an empty set.
140149
"""
141150
# Arrange
142-
a = SimpleNamespace(get_packages_versions=lambda: [])
143-
b = SimpleNamespace(get_packages_versions=lambda: [])
151+
a = FakeRepo([])
152+
b = FakeRepo([])
144153

145154
# Act / Assert
146-
assert repoinfo.compare_repo(a, b, available_in_both=True) == [] # type: ignore
155+
assert repoinfo.compare_repo(a, b, available_in_both=True) == []

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def write_zot_config(config_dict: Dict[str, Any], fd: int) -> None:
129129
json.dump(config_dict, fp, indent=4)
130130

131131

132-
@pytest.fixture(autouse=False, scope="function") # type: ignore[misc]
132+
@pytest.fixture(autouse=False, scope="function")
133133
def zot_session() -> Generator[subprocess.Popen[Any]]:
134134
load_dotenv()
135135
print("start zot session")

tests/distro_version/test_distro_version.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,39 @@
99
)
1010

1111

12-
def test_distro_version_unrecognizable_non_numeric_version():
12+
def test_distro_version_unrecognizable_non_numeric_version() -> None:
1313
with pytest.raises(UnsupportedDistroVersion):
1414
DistroVersion("garden.linux")
1515

1616

17-
def test_distro_version_unrecognizable_numeric_version():
17+
def test_distro_version_unrecognizable_numeric_version() -> None:
1818
with pytest.raises(UnsupportedDistroVersion):
1919
DistroVersion("1.2.3.4")
2020
with pytest.raises(UnsupportedDistroVersion):
2121
DistroVersion("1.100.-10")
2222

2323

24-
def test_distro_version_unrecognizable_too_short_version():
24+
def test_distro_version_unrecognizable_too_short_version() -> None:
2525
with pytest.raises(UnsupportedDistroVersion):
2626
DistroVersion("1")
2727

2828

29-
def test_distro_version_legacy_version_is_parsable():
29+
def test_distro_version_legacy_version_is_parsable() -> None:
3030
assert isinstance(DistroVersion("1.2"), LegacyDistroVersion)
3131

3232

33-
def test_distro_version_semver_version_is_parsable():
33+
def test_distro_version_semver_version_is_parsable() -> None:
3434
assert isinstance(DistroVersion("1.2.3"), SemverDistroVersion)
3535

3636

37-
def test_distro_version_patch_release_is_recognized():
37+
def test_distro_version_patch_release_is_recognized() -> None:
3838
assert DistroVersion("1.1").is_patch_release()
3939
assert DistroVersion("1.1.100").is_patch_release()
4040
assert not DistroVersion("1.0").is_patch_release()
4141
assert not DistroVersion("1.0.0").is_patch_release()
4242

4343

44-
def test_distro_version_previous_patch_release_is_recognized():
44+
def test_distro_version_previous_patch_release_is_recognized() -> None:
4545
assert DistroVersion("1.1").previous_patch_release().__str__() == "1.0"
4646
assert DistroVersion("1.1.100").previous_patch_release().__str__() == "1.1.99"
4747
with pytest.raises(NotAPatchRelease):

tests/features/test_cname.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from gardenlinux.features import CName
44

55

6-
@pytest.mark.parametrize( # type: ignore[misc]
6+
@pytest.mark.parametrize(
77
"input_cname, expected_output",
88
[
99
(

tests/features/test_cname_main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
def test_main_happy(
14-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
14+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
1515
) -> None:
1616
"""
1717
Test the "Happy Path" of the main() function.
@@ -49,7 +49,7 @@ def sort_graph_nodes(graph: networkx.Graph) -> List[str]:
4949

5050

5151
def test_main_version_from_file(
52-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
52+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
5353
) -> None:
5454
"""
5555
"Happy Path" test for grabbing the version and commit id from file in main().

tests/features/test_main.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_get_version_missing_file_raises(tmp_path: Path) -> None:
8888
# Tests for main()
8989
# -------------------------------
9090
def test_main_prints_arch(
91-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
91+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
9292
) -> None:
9393
# Arrange
9494
argv = ["prog", "--arch", "amd64", "--cname", "flav", "--version", "1.0", "arch"]
@@ -104,7 +104,7 @@ def test_main_prints_arch(
104104

105105

106106
def test_main_prints_container_name(
107-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
107+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
108108
) -> None:
109109
# Arrange
110110
argv = [
@@ -129,7 +129,7 @@ def test_main_prints_container_name(
129129

130130

131131
def test_main_prints_container_tag(
132-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
132+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
133133
) -> None:
134134
# Arrange
135135
argv = [
@@ -156,7 +156,7 @@ def test_main_prints_container_tag(
156156

157157

158158
def test_main_prints_commit_id(
159-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
159+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
160160
) -> None:
161161
# Arrange
162162
argv = ["prog", "--arch", "amd64", "--cname", "flav", "commit_id"]
@@ -179,7 +179,7 @@ def test_main_prints_commit_id(
179179

180180

181181
def test_main_prints_flags_elements_platforms(
182-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
182+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
183183
) -> None:
184184
# Arrange
185185
argv = [
@@ -210,7 +210,7 @@ def __init__(self, *a: Any, **k: Any):
210210

211211

212212
def test_main_prints_version(
213-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
213+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
214214
) -> None:
215215
# Arrange
216216
argv = ["prog", "--arch", "amd64", "--cname", "flav", "version"]
@@ -233,7 +233,7 @@ def test_main_prints_version(
233233

234234

235235
def test_main_prints_version_and_commit_id(
236-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
236+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
237237
) -> None:
238238
# Arrange
239239
argv = ["prog", "--arch", "amd64", "--cname", "flav", "version_and_commit_id"]
@@ -297,7 +297,7 @@ def test_main_raises_no_arch_no_default(monkeypatch: pytest.MonkeyPatch) -> None
297297

298298

299299
def test_main_raises_missing_commit_id(
300-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
300+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
301301
) -> None:
302302
# Arrange
303303
argv = [
@@ -319,7 +319,7 @@ def test_main_raises_missing_commit_id(
319319

320320

321321
def test_main_with_exclude_cname_print_elements(
322-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
322+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
323323
) -> None:
324324
# Arrange
325325
monkeypatch.setattr(
@@ -353,7 +353,7 @@ def test_main_with_exclude_cname_print_elements(
353353

354354

355355
def test_main_with_exclude_cname_print_features(
356-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
356+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
357357
) -> None:
358358
# Arrange
359359
monkeypatch.setattr(
@@ -390,7 +390,7 @@ def test_main_with_exclude_cname_print_features(
390390

391391

392392
def test_cname_release_file(
393-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
393+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
394394
) -> None:
395395
"""
396396
Test validation between release metadata and arguments given

tests/features/test_metadata_main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
def test_main_output(
13-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
13+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
1414
) -> None:
1515
"""
1616
Test successful "output-release-metadata"
@@ -37,7 +37,7 @@ def test_main_output(
3737

3838

3939
def test_main_write(
40-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
40+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
4141
) -> None:
4242
"""
4343
Test successful "write"

tests/features/test_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ..constants import GL_ROOT_DIR
88

99

10-
@pytest.mark.parametrize( # type: ignore[misc]
10+
@pytest.mark.parametrize(
1111
"input_cname, expected_output",
1212
[
1313
(

tests/flavors/test_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from gardenlinux.flavors.parser import Parser
77

88

9-
@pytest.fixture # type: ignore[misc]
9+
@pytest.fixture
1010
def valid_data() -> Dict[str, Any]:
1111
"""Minimal data for valid GL_FLAVORS_SCHEMA."""
1212
return {
@@ -97,7 +97,7 @@ def test_filter_category_and_exclude(valid_data: str) -> None:
9797
assert all("android" in name for _, name in android_combos)
9898

9999

100-
@pytest.mark.parametrize("flag", ["only_build", "only_test", "only_publish"]) # type: ignore[misc]
100+
@pytest.mark.parametrize("flag", ["only_build", "only_test", "only_publish"])
101101
def test_filter_with_flags(valid_data: str, flag: str) -> None:
102102
# Arrange
103103
parser = make_parser(valid_data)

0 commit comments

Comments
 (0)