11from types import SimpleNamespace
2- from typing import List
2+ from typing import List , Tuple
33
44import pytest
5- from apt_repo import BinaryPackage
65
76import gardenlinux .apt .package_repo_info as repoinfo
87
98
109class 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+
2938def 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
137146def 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 ) == []
0 commit comments