Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/type conversion in encode image #58

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions fiat_toolbox/infographics/risk_infographics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand Down
4 changes: 2 additions & 2 deletions tests/infographics/test_risk_infographics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading