From 511312c2528084b061f23b72755cc0511d65d7a6 Mon Sep 17 00:00:00 2001 From: yengliong Date: Tue, 29 Oct 2024 20:15:19 +0800 Subject: [PATCH] Fix unit test --- inbm-lib/tests/unit/inbm_common_lib/test_utility.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/inbm-lib/tests/unit/inbm_common_lib/test_utility.py b/inbm-lib/tests/unit/inbm_common_lib/test_utility.py index d15ad39b5..b9da8d709 100644 --- a/inbm-lib/tests/unit/inbm_common_lib/test_utility.py +++ b/inbm-lib/tests/unit/inbm_common_lib/test_utility.py @@ -113,7 +113,8 @@ def test_create_file_with_contents_successfully(self) -> None: self.fail(f"Unexpected exception raised during test: {e}") @patch('builtins.open', new_callable=mock_open, read_data='IMAGE_BUILD_DATE="20241026100955"') - def test_get_image_build_date_successfully(self, mock_open: Mock) -> None: + @patch('os.path.exists', return_value=True) + def test_get_image_build_date_successfully(self, mock_exist: Mock, mock_open: Mock) -> None: try: self.assertEqual(get_image_build_date(), "20241026100955") except IOError as e: @@ -121,7 +122,8 @@ def test_get_image_build_date_successfully(self, mock_open: Mock) -> None: mock_open.assert_called_once_with('/etc/image-id', 'r') @patch('builtins.open', new_callable=mock_open, read_data='') - def test_get_image_build_date_with_no_version_found(self, mock_open: Mock) -> None: + @patch('os.path.exists', return_value=True) + def test_get_image_build_date_with_no_version_found(self, mock_exist: Mock, mock_open: Mock) -> None: try: self.assertEqual(get_image_build_date(), UNKNOWN) except IOError as e: