diff --git a/fiat_toolbox/infographics/risk_infographics.py b/fiat_toolbox/infographics/risk_infographics.py index 5a2961c..ea29d05 100644 --- a/fiat_toolbox/infographics/risk_infographics.py +++ b/fiat_toolbox/infographics/risk_infographics.py @@ -97,10 +97,11 @@ def _encode_image_from_path(image_path: str) -> str: str The base64 encoded image string """ - if not Path.exists(image_path): - RiskInfographicsParser.logger.error(f"Image not found at {image_path}") + path = Path(image_path) + if not Path.exists(path): + RiskInfographicsParser.logger.error(f"Image not found at {path}") return - with open(image_path, "rb") as image_file: + with open(path, "rb") as image_file: encoded_string = base64.b64encode(image_file.read()).decode() return f'data:image/png;base64,{encoded_string}' diff --git a/tests/infographics/test_risk_infographics.py b/tests/infographics/test_risk_infographics.py index 4280d1d..010f4f4 100644 --- a/tests/infographics/test_risk_infographics.py +++ b/tests/infographics/test_risk_infographics.py @@ -99,8 +99,8 @@ def test_encode_image_from_path(self, mock_open, mock_path_exists): # Assert expected_encoded_string = f'data:image/png;base64,{base64.b64encode(self.money_bin).decode()}' assert encoded_image == expected_encoded_string - mock_open.assert_called_once_with(self.money_path, "rb") - mock_path_exists.assert_called_once_with(self.money_path) + mock_open.assert_called_once_with(Path(self.money_path), "rb") + mock_path_exists.assert_called_once_with(Path(self.money_path)) @patch("fiat_toolbox.infographics.infographics.Path.exists")