Skip to content

Commit 22a07cc

Browse files
committed
Update unittest
1 parent 4f2afcb commit 22a07cc

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_gst_v4l2_video_decoder_md5_checksum_comparison.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ def tearDownClass(cls):
174174
new_callable=mock_open,
175175
read_data="golden_md5_checksum",
176176
)
177+
@patch(
178+
"gst_v4l2_video_decoder_md5_checksum_comparison.manage_test_file_by_name"
179+
)
177180
def test_validate_video_decoder_md5_checksum_success(
178181
self,
182+
mock_manage_test_file_by_name,
179183
mock_open,
180184
mock_get_md5_checksum_from_command,
181185
mock_build_gst_command,
@@ -196,7 +200,7 @@ def test_validate_video_decoder_md5_checksum_success(
196200
mock_get_md5_checksum_from_command.return_value = "golden_md5_checksum"
197201
mock_build_gst_command.return_value = "my testing command"
198202

199-
validate_video_decoder_md5_checksum(args)
203+
validate_video_decoder_md5_checksum(args) # type: ignore
200204

201205
mock_os_path_exists.assert_has_calls(
202206
[call("golden_sample.mp4"), call("my_test.md5")]
@@ -214,8 +218,12 @@ def test_validate_video_decoder_md5_checksum_success(
214218
"get_md5_checksum_from_command"
215219
)
216220
@patch("builtins.open", new_callable=mock_open)
221+
@patch(
222+
"gst_v4l2_video_decoder_md5_checksum_comparison.manage_test_file_by_name"
223+
)
217224
def test_validate_video_decoder_md5_checksum_golden_sample_not_found(
218225
self,
226+
mock_manage_test_file_by_name,
219227
mock_open,
220228
mock_get_md5_checksum_from_command,
221229
mock_os_path_exists,
@@ -236,9 +244,9 @@ def test_validate_video_decoder_md5_checksum_golden_sample_not_found(
236244

237245
# Act and Assert
238246
with self.assertRaises(SystemExit) as cm:
239-
validate_video_decoder_md5_checksum(args)
247+
validate_video_decoder_md5_checksum(args) # type: ignore
240248
self.assertEqual(
241-
cm.exception.code,
249+
str(cm.exception),
242250
"Golden Sample 'non_exist_golden_sample.mp4' doesn't exist",
243251
)
244252
mock_os_path_exists.assert_has_calls(
@@ -253,8 +261,12 @@ def test_validate_video_decoder_md5_checksum_golden_sample_not_found(
253261
"get_md5_checksum_from_command"
254262
)
255263
@patch("builtins.open", new_callable=mock_open)
264+
@patch(
265+
"gst_v4l2_video_decoder_md5_checksum_comparison.manage_test_file_by_name"
266+
)
256267
def test_validate_video_decoder_md5_checksum_golden_md5_checksum_not_found(
257268
self,
269+
mock_manage_test_file_by_name,
258270
mock_open,
259271
mock_get_md5_checksum_from_command,
260272
mock_os_path_exists,
@@ -275,16 +287,16 @@ def test_validate_video_decoder_md5_checksum_golden_md5_checksum_not_found(
275287
mock_os_path_exists.side_effect = [True, False]
276288

277289
with self.assertRaises(SystemExit) as cm:
278-
validate_video_decoder_md5_checksum(args)
290+
validate_video_decoder_md5_checksum(args) # type: ignore
279291
self.assertEqual(
280-
cm.exception.code,
292+
str(cm.exception),
281293
(
282294
"Golden Sample's MD5 checksum 'non_exist_golden_sample.md5'"
283295
" doesn't exist"
284296
),
285297
)
286298
mock_os_path_exists.assert_has_calls(
287-
[call("golden_sample.mp4"), call("non_exist_golden_sample.md5")]
299+
[call("non_exist_golden_sample.md5")]
288300
)
289301
mock_get_md5_checksum_from_command.assert_not_called()
290302
mock_open.assert_not_called()
@@ -302,8 +314,12 @@ def test_validate_video_decoder_md5_checksum_golden_md5_checksum_not_found(
302314
new_callable=mock_open,
303315
read_data="different_golden_md5_checksum",
304316
)
317+
@patch(
318+
"gst_v4l2_video_decoder_md5_checksum_comparison.manage_test_file_by_name"
319+
)
305320
def test_validate_video_decoder_md5_checksum_failure(
306321
self,
322+
mock_manage_test_file_by_name,
307323
mock_open,
308324
mock_get_md5_checksum_from_command,
309325
mock_build_gst_command,
@@ -326,12 +342,12 @@ def test_validate_video_decoder_md5_checksum_failure(
326342

327343
# Act and Assert
328344
with self.assertRaises(SystemExit) as cm:
329-
validate_video_decoder_md5_checksum(args)
345+
validate_video_decoder_md5_checksum(args) # type: ignore
330346
self.assertEqual(
331347
cm.exception.code,
332348
"Failed. MD5 checksum is not same as Golden Sample",
333349
)
334-
mock_os_path_exists.assert_has_calls(
350+
mock_os_path_exists.assert_any_call(
335351
[call("golden_sample.mp4"), call("golden_sample.md5")]
336352
)
337353
mock_get_md5_checksum_from_command.assert_called_once_with(

0 commit comments

Comments
 (0)