@@ -42,11 +42,11 @@ def test_issue_68204_debian_bookworm_format():
42
42
# Mock pkg.latest_version to return Debian Bookworm format
43
43
mock_latest_version = MagicMock (return_value = "6.1.147-1" )
44
44
mock_latest_installed = MagicMock (return_value = "6.1.0-38-cloud-amd64" )
45
-
45
+
46
46
with patch .dict (kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }):
47
47
with patch .object (kernelpkg , "latest_installed" , mock_latest_installed ):
48
48
result = kernelpkg .latest_available ()
49
-
49
+
50
50
# Should not crash and should return a properly formatted version
51
51
assert isinstance (result , str )
52
52
assert "6.1.147" in result
@@ -62,13 +62,15 @@ def test_issue_68204_ubuntu_noble_format():
62
62
# Mock pkg.latest_version to return Ubuntu Noble format
63
63
mock_latest_version = MagicMock (return_value = "6.8.0-45-generic" )
64
64
mock_latest_installed = MagicMock (return_value = "6.1.0-38-generic" )
65
-
65
+
66
66
# Mock kernel type to return "generic" for this test
67
67
with patch .object (kernelpkg , "_kernel_type" , return_value = "generic" ):
68
- with patch .dict (kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }):
68
+ with patch .dict (
69
+ kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }
70
+ ):
69
71
with patch .object (kernelpkg , "latest_installed" , mock_latest_installed ):
70
72
result = kernelpkg .latest_available ()
71
-
73
+
72
74
# Should not crash and should return a properly formatted version
73
75
assert isinstance (result , str )
74
76
assert "6.8.0" in result
@@ -83,12 +85,14 @@ def test_issue_68204_debian_bullseye_format():
83
85
"""
84
86
mock_latest_version = MagicMock (return_value = "5.10.0-18-amd64" )
85
87
mock_latest_installed = MagicMock (return_value = "5.10.0-17-amd64" )
86
-
88
+
87
89
with patch .object (kernelpkg , "_kernel_type" , return_value = "amd64" ):
88
- with patch .dict (kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }):
90
+ with patch .dict (
91
+ kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }
92
+ ):
89
93
with patch .object (kernelpkg , "latest_installed" , mock_latest_installed ):
90
94
result = kernelpkg .latest_available ()
91
-
95
+
92
96
assert isinstance (result , str )
93
97
assert "5.10.0" in result
94
98
assert "18" in result
@@ -102,12 +106,14 @@ def test_issue_68204_ubuntu_jammy_format():
102
106
"""
103
107
mock_latest_version = MagicMock (return_value = "5.15.0-91-generic" )
104
108
mock_latest_installed = MagicMock (return_value = "5.15.0-90-generic" )
105
-
109
+
106
110
with patch .object (kernelpkg , "_kernel_type" , return_value = "generic" ):
107
- with patch .dict (kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }):
111
+ with patch .dict (
112
+ kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }
113
+ ):
108
114
with patch .object (kernelpkg , "latest_installed" , mock_latest_installed ):
109
115
result = kernelpkg .latest_available ()
110
-
116
+
111
117
assert isinstance (result , str )
112
118
assert "5.15.0" in result
113
119
assert "91" in result
@@ -121,11 +127,11 @@ def test_issue_68204_debian_security_update_format():
121
127
"""
122
128
mock_latest_version = MagicMock (return_value = "6.1.147-1+deb12u1" )
123
129
mock_latest_installed = MagicMock (return_value = "6.1.0-38-cloud-amd64" )
124
-
130
+
125
131
with patch .dict (kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }):
126
132
with patch .object (kernelpkg , "latest_installed" , mock_latest_installed ):
127
133
result = kernelpkg .latest_available ()
128
-
134
+
129
135
assert isinstance (result , str )
130
136
assert "6.1.147" in result
131
137
# The security update suffix should be handled gracefully
@@ -138,12 +144,14 @@ def test_issue_68204_ubuntu_complex_format():
138
144
"""
139
145
mock_latest_version = MagicMock (return_value = "5.15.0-91.101-generic" )
140
146
mock_latest_installed = MagicMock (return_value = "5.15.0-90-generic" )
141
-
147
+
142
148
with patch .object (kernelpkg , "_kernel_type" , return_value = "generic" ):
143
- with patch .dict (kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }):
149
+ with patch .dict (
150
+ kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }
151
+ ):
144
152
with patch .object (kernelpkg , "latest_installed" , mock_latest_installed ):
145
153
result = kernelpkg .latest_available ()
146
-
154
+
147
155
assert isinstance (result , str )
148
156
assert "5.15.0" in result
149
157
assert "91" in result
@@ -157,12 +165,14 @@ def test_issue_68204_backport_format():
157
165
"""
158
166
mock_latest_version = MagicMock (return_value = "6.1.147-1~bpo11+1" )
159
167
mock_latest_installed = MagicMock (return_value = "5.10.0-18-amd64" )
160
-
168
+
161
169
with patch .object (kernelpkg , "_kernel_type" , return_value = "amd64" ):
162
- with patch .dict (kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }):
170
+ with patch .dict (
171
+ kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }
172
+ ):
163
173
with patch .object (kernelpkg , "latest_installed" , mock_latest_installed ):
164
174
result = kernelpkg .latest_available ()
165
-
175
+
166
176
assert isinstance (result , str )
167
177
assert "6.1.147" in result
168
178
# Backport suffix should be handled gracefully
@@ -175,11 +185,11 @@ def test_issue_68204_empty_result_fallback():
175
185
"""
176
186
mock_latest_version = MagicMock (return_value = "" )
177
187
mock_latest_installed = MagicMock (return_value = "6.1.0-38-cloud-amd64" )
178
-
188
+
179
189
with patch .dict (kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }):
180
190
with patch .object (kernelpkg , "latest_installed" , mock_latest_installed ):
181
191
result = kernelpkg .latest_available ()
182
-
192
+
183
193
assert result == "6.1.0-38-cloud-amd64"
184
194
185
195
@@ -190,11 +200,11 @@ def test_issue_68204_malformed_version_fallback():
190
200
"""
191
201
mock_latest_version = MagicMock (return_value = "not-a-version-at-all" )
192
202
mock_latest_installed = MagicMock (return_value = "6.1.0-38-cloud-amd64" )
193
-
203
+
194
204
with patch .dict (kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }):
195
205
with patch .object (kernelpkg , "latest_installed" , mock_latest_installed ):
196
206
result = kernelpkg .latest_available ()
197
-
207
+
198
208
assert result == "6.1.0-38-cloud-amd64"
199
209
200
210
@@ -206,15 +216,17 @@ def test_issue_68204_original_error_reproduction():
206
216
"""
207
217
# These are the exact version formats that caused the original issue
208
218
failing_versions = [
209
- "6.1.147-1" , # Debian Bullseye/Bookworm
219
+ "6.1.147-1" , # Debian Bullseye/Bookworm
210
220
"6.8.0-45-generic" , # Ubuntu Noble
211
221
]
212
-
222
+
213
223
for version in failing_versions :
214
224
mock_latest_version = MagicMock (return_value = version )
215
225
mock_latest_installed = MagicMock (return_value = "6.1.0-38-cloud-amd64" )
216
-
217
- with patch .dict (kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }):
226
+
227
+ with patch .dict (
228
+ kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }
229
+ ):
218
230
with patch .object (kernelpkg , "latest_installed" , mock_latest_installed ):
219
231
# This line would have caused AttributeError with the old regex
220
232
# Now it should work without any exception
@@ -224,36 +236,45 @@ def test_issue_68204_original_error_reproduction():
224
236
assert isinstance (result , str )
225
237
except AttributeError as e :
226
238
if "'NoneType' object has no attribute 'group'" in str (e ):
227
- pytest .fail (f"Original bug still present for version { version } : { e } " )
239
+ pytest .fail (
240
+ f"Original bug still present for version { version } : { e } "
241
+ )
228
242
else :
229
243
# Some other AttributeError, re-raise
230
244
raise
231
245
232
246
233
247
@pytest .mark .skipif (not HAS_MODULES , reason = "Salt modules could not be loaded" )
234
- @pytest .mark .parametrize ("version_string,description" , [
235
- ("6.1.147-1" , "Debian 12 Bookworm" ),
236
- ("6.8.0-45-generic" , "Ubuntu 24.04 Noble" ),
237
- ("6.1.0-18-amd64" , "Debian 11 Bullseye" ),
238
- ("6.2.0-37-generic" , "Ubuntu 23.04 Lunar" ),
239
- ("5.15.0-91-generic" , "Ubuntu 22.04 Jammy" ),
240
- ("6.1.147-1+deb12u1" , "Debian security update" ),
241
- ])
248
+ @pytest .mark .parametrize (
249
+ "version_string,description" ,
250
+ [
251
+ ("6.1.147-1" , "Debian 12 Bookworm" ),
252
+ ("6.8.0-45-generic" , "Ubuntu 24.04 Noble" ),
253
+ ("6.1.0-18-amd64" , "Debian 11 Bullseye" ),
254
+ ("6.2.0-37-generic" , "Ubuntu 23.04 Lunar" ),
255
+ ("5.15.0-91-generic" , "Ubuntu 22.04 Jammy" ),
256
+ ("6.1.147-1+deb12u1" , "Debian security update" ),
257
+ ],
258
+ )
242
259
def test_issue_68204_comprehensive_format_validation (version_string , description ):
243
260
"""
244
261
Test - Comprehensive validation that all reported problematic formats now work
245
262
This test validates the complete fix using the actual problematic version strings
246
263
"""
247
264
mock_latest_version = MagicMock (return_value = version_string )
248
265
mock_latest_installed = MagicMock (return_value = "6.1.0-38-cloud-amd64" )
249
-
266
+
250
267
with patch .dict (kernelpkg .__salt__ , {"pkg.latest_version" : mock_latest_version }):
251
268
with patch .object (kernelpkg , "latest_installed" , mock_latest_installed ):
252
269
# This should NOT raise an AttributeError anymore
253
270
result = kernelpkg .latest_available ()
254
-
271
+
255
272
# Validate that we get a string result (no crash)
256
- assert isinstance (result , str ), f"Failed for { description } format: { version_string } "
257
-
273
+ assert isinstance (
274
+ result , str
275
+ ), f"Failed for { description } format: { version_string } "
276
+
258
277
# Validate that result is not empty
259
- assert len (result ) > 0 , f"Empty result for { description } format: { version_string } "
278
+ assert (
279
+ len (result ) > 0
280
+ ), f"Empty result for { description } format: { version_string } "
0 commit comments