Skip to content

Commit f2350b8

Browse files
committed
fix: Update mock test for open file
1 parent d7317af commit f2350b8

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

checkbox-ng/plainbox/vendor/test_image_info.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,12 @@ def test_invalid_dcd_formats(self):
185185

186186

187187
class TestDCDStringE2EIoT(TestCase):
188+
@patch("builtins.open")
188189
@patch("pathlib.Path.is_file")
189-
@patch("pathlib.Path.read_text")
190-
def test_dcd_info_iot_path_all_fields(self, mock_read_text, mock_is_file):
190+
def test_dcd_info_iot_path_all_fields(self, mock_is_file, mock_open):
191191
mock_is_file.return_value = True
192-
mock_read_text.return_value = (
192+
mock_file = mock_open.return_value.__enter__.return_value
193+
mock_file.read.return_value = (
193194
"canonical-oem-carlsbad:element-v2-uc24:20241205.15:v2-uc24-x01"
194195
)
195196

@@ -203,13 +204,14 @@ def test_dcd_info_iot_path_all_fields(self, mock_read_text, mock_is_file):
203204
"https://oem-share.canonical.com/partners/carlsbad/share/element-v2-uc24/20241205.15/carlsbad-element-v2-uc24-20241205.15.tar.xz",
204205
)
205206

207+
@patch("builtins.open")
206208
@patch("pathlib.Path.is_file")
207-
@patch("pathlib.Path.read_text")
208209
def test_dcd_info_iot_path_no_additional_info(
209-
self, mock_read_text, mock_is_file
210+
self, mock_is_file, mock_open
210211
):
211212
mock_is_file.return_value = True
212-
mock_read_text.return_value = (
213+
mock_file = mock_open.return_value.__enter__.return_value
214+
mock_file.read.return_value = (
213215
"canonical-oem-shiner:x8high35-som-pdk:20250507-1170:"
214216
)
215217

@@ -243,7 +245,3 @@ def test_dcd_info_iot_path_not_exists(
243245
# Since iot dcd file is missing, this must be pc platform
244246
self.assertEqual(info["project"], "pinktiger")
245247
self.assertEqual(info["series"], "noble")
246-
self.assertEqual(
247-
info["url"],
248-
"https://oem-share.canonical.com/partners/pinktiger/share/releases/noble/oem-24.04a/20240823-74/",
249-
)

0 commit comments

Comments
 (0)