|
1 | 1 | import re |
2 | | -import warnings |
3 | 2 |
|
4 | 3 | import pytest |
5 | 4 |
|
6 | | -from ocp_resources.utils import ( |
7 | | - InvalidArgumentsError, |
8 | | - TimeoutExpiredError, |
9 | | - TimeoutSampler, |
10 | | -) |
| 5 | +from ocp_resources.utils import TimeoutExpiredError, TimeoutSampler |
11 | 6 |
|
12 | 7 |
|
13 | 8 | class TestTimeoutSampler: |
@@ -150,154 +145,3 @@ def test_timeout_sampler_raises_timeout(self, test_params, expected): |
150 | 145 | assert ( |
151 | 146 | exception_match |
152 | 147 | ), f"Expected Regex: {expected['exception_log_regex']!r} Exception Log: {exception_log!r}" |
153 | | - |
154 | | - @pytest.mark.parametrize( |
155 | | - "test_params, expected", |
156 | | - [ |
157 | | - pytest.param( |
158 | | - {}, |
159 | | - { |
160 | | - "exceptions": (Exception,), |
161 | | - "exceptions_dict": {Exception: []}, |
162 | | - }, |
163 | | - id="noargs", |
164 | | - ), |
165 | | - pytest.param( |
166 | | - { |
167 | | - "exceptions": ValueError, |
168 | | - }, |
169 | | - { |
170 | | - "exceptions": (ValueError,), |
171 | | - "exceptions_dict": {ValueError: []}, |
172 | | - "warning": { |
173 | | - "class": DeprecationWarning, |
174 | | - "text": "TimeoutSampler() exception and exception_msg are now deprecated.", |
175 | | - }, |
176 | | - }, |
177 | | - id="init_valueerror_expect_deprecation_warning", |
178 | | - ), |
179 | | - pytest.param( |
180 | | - { |
181 | | - "exceptions": ValueError, |
182 | | - "exceptions_msg": "test message", |
183 | | - }, |
184 | | - { |
185 | | - "exceptions": (ValueError,), |
186 | | - "exceptions_dict": {ValueError: ["test message"]}, |
187 | | - "warning": { |
188 | | - "class": DeprecationWarning, |
189 | | - "text": "TimeoutSampler() exception and exception_msg are now deprecated.", |
190 | | - }, |
191 | | - }, |
192 | | - id="init_valueerror_with_msg_expect_deprecation_warning", |
193 | | - ), |
194 | | - pytest.param( |
195 | | - { |
196 | | - "exceptions": (Exception, ValueError), |
197 | | - }, |
198 | | - { |
199 | | - "exceptions": (Exception, ValueError), |
200 | | - "exceptions_dict": { |
201 | | - Exception: [], |
202 | | - ValueError: [], |
203 | | - }, |
204 | | - "warning": { |
205 | | - "class": DeprecationWarning, |
206 | | - "text": "TimeoutSampler() exception and exception_msg are now deprecated.", |
207 | | - }, |
208 | | - }, |
209 | | - id="init_multi_exception_with_no_msg_expect_deprecation_warning", |
210 | | - ), |
211 | | - pytest.param( |
212 | | - { |
213 | | - "exceptions_dict": { |
214 | | - Exception: ["exception msg"], |
215 | | - ValueError: ["another exception msg"], |
216 | | - }, |
217 | | - }, |
218 | | - { |
219 | | - "exceptions": (Exception, ValueError), |
220 | | - "exceptions_dict": { |
221 | | - Exception: ["exception msg"], |
222 | | - ValueError: ["another exception msg"], |
223 | | - }, |
224 | | - }, |
225 | | - id="init_dict", |
226 | | - ), |
227 | | - pytest.param( |
228 | | - { |
229 | | - "exceptions_dict": { |
230 | | - Exception: [], |
231 | | - ValueError: [], |
232 | | - }, |
233 | | - }, |
234 | | - { |
235 | | - "exceptions": (Exception, ValueError), |
236 | | - "exceptions_dict": { |
237 | | - Exception: [], |
238 | | - ValueError: [], |
239 | | - }, |
240 | | - }, |
241 | | - id="init_dict_no_msgs", |
242 | | - ), |
243 | | - pytest.param( |
244 | | - { |
245 | | - "exceptions": TypeError, |
246 | | - "exceptions_dict": { |
247 | | - Exception: ["exception msg"], |
248 | | - KeyError: ["another exception msg"], |
249 | | - }, |
250 | | - }, |
251 | | - { |
252 | | - "raises": InvalidArgumentsError, |
253 | | - }, |
254 | | - id="init_deprecated_exceptions_and_new_dict_expect_raise_invalid_arguments", |
255 | | - ), |
256 | | - pytest.param( |
257 | | - { |
258 | | - "exceptions_msg": "test exception message", |
259 | | - "exceptions_dict": { |
260 | | - Exception: ["exception msg"], |
261 | | - KeyError: ["another exception msg"], |
262 | | - }, |
263 | | - }, |
264 | | - { |
265 | | - "raises": InvalidArgumentsError, |
266 | | - }, |
267 | | - id="init_deprecated_msg_and_new_dict_expect_raise_invalid_arguments", |
268 | | - ), |
269 | | - ], |
270 | | - ) |
271 | | - def test_timeout_sampler_pre_process_exceptions(self, test_params, expected): |
272 | | - # TODO: Remove this test when _pre_process_exceptions() is removed from TimeoutSampler |
273 | | - def _timeout_sampler(): |
274 | | - return TimeoutSampler( |
275 | | - wait_timeout=1, |
276 | | - sleep=1, |
277 | | - func=lambda: True, |
278 | | - exceptions=test_params.get("exceptions"), |
279 | | - exceptions_msg=test_params.get("exceptions_msg"), |
280 | | - exceptions_dict=test_params.get("exceptions_dict"), |
281 | | - print_log=False, |
282 | | - ) |
283 | | - |
284 | | - if expected.get("raises"): |
285 | | - with pytest.raises(expected["raises"]): |
286 | | - _timeout_sampler() |
287 | | - else: |
288 | | - with warnings.catch_warnings(record=True) as caught_warnings: |
289 | | - # Note: catch_warnings is not thread safe |
290 | | - timeout_sampler = _timeout_sampler() |
291 | | - if "warning" in expected: |
292 | | - assert len(caught_warnings) == 1 |
293 | | - assert issubclass( |
294 | | - caught_warnings[-1].category, expected["warning"]["class"] |
295 | | - ) |
296 | | - assert expected["warning"]["text"] in str( |
297 | | - caught_warnings[-1].message |
298 | | - ) |
299 | | - else: |
300 | | - assert len(caught_warnings) == 0 |
301 | | - |
302 | | - assert expected["exceptions"] == timeout_sampler._exceptions |
303 | | - assert expected["exceptions_dict"] == timeout_sampler.exceptions_dict |
0 commit comments