Skip to content

Commit

Permalink
Fixed test_get_image_exists
Browse files Browse the repository at this point in the history
Test was failing due to slight quality differences, pyplot passing a slightly blue filtered image to be saved, and return_value.content needing to be a byte string and not an ndarray.
  • Loading branch information
jasonkwok475 committed Nov 24, 2024
1 parent 7b86f86 commit b520620
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 84 deletions.
2 changes: 1 addition & 1 deletion main_window/competition/mapping/mapbox_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def getImage(self, overwrite: bool = False) -> np.ndarray:
if not os.path.isdir(scalefolder):
os.mkdir(scalefolder)

impath = os.path.join(scalefolder, str(self) + ".jpg")
impath = os.path.join(scalefolder, str(self) + ".png")

if ((not os.path.exists(impath)) or overwrite) and not (maps is None):
response = maps.tile(
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ dependencies = [
"sortedcontainers==2.4.0",
"pyqt5-qt5==5.15.2",
"digi-xbee",
"opencv-python-headless>=4.10.0.84",
"opencv-python>=4.10.0.84",
]

[tool.uv.sources]
Expand Down
12 changes: 7 additions & 5 deletions tests/test_mapbox_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import cv2

import numpy
import pytest
Expand Down Expand Up @@ -78,14 +79,15 @@ def test_get_image_fail(self, hennings_tile, mocker):
)

def test_get_image_exists(self, hennings_tile, mocker):
hennings_image = pyplot.imread(
os.path.join(LOCAL, "tests", "test_mapbox_utils", "41322_89729.jpg"), "jpeg"
)
impath = os.path.join(LOCAL, "tests", "test_mapbox_utils", "41322_89729.png")
hennings_image = pyplot.imread(impath, "jpeg")

mocked_tile = mocker.patch("main_window.competition.mapping.mapbox_utils.maps.tile")
mocked_tile.return_value.status_code = 200
mocked_tile.return_value.content = hennings_image
mocked_tile.return_value.content = cv2.imencode('.png', cv2.imread(impath))[1]

i = hennings_tile.getImage()
# Pass true to overwrite as image file may exist from previous tests
i = hennings_tile.getImage(True)

numpy.testing.assert_array_equal(i, hennings_image)

Expand Down
Binary file removed tests/test_mapbox_utils/41322_89729.jpg
Binary file not shown.
Binary file added tests/test_mapbox_utils/41322_89729.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b520620

Please sign in to comment.