mirror of
https://github.com/home-assistant/core.git
synced 2025-12-26 14:08:21 +00:00
Ensure TurboJPEG is imported in the executor (#113504)
The import was too late and it eneded up being imported in the event loop
This commit is contained in:
@@ -38,25 +38,33 @@ def test_scale_jpeg_camera_image() -> None:
|
||||
camera_image = Image("image/jpeg", EMPTY_16_12_JPEG)
|
||||
|
||||
turbo_jpeg = mock_turbo_jpeg(first_width=16, first_height=12)
|
||||
with patch("turbojpeg.TurboJPEG", return_value=False):
|
||||
with patch(
|
||||
"homeassistant.components.camera.img_util.TurboJPEG", return_value=False
|
||||
):
|
||||
TurboJPEGSingleton()
|
||||
assert scale_jpeg_camera_image(camera_image, 16, 12) == camera_image.content
|
||||
|
||||
turbo_jpeg = mock_turbo_jpeg(first_width=16, first_height=12)
|
||||
turbo_jpeg.decode_header.side_effect = OSError
|
||||
with patch("turbojpeg.TurboJPEG", return_value=turbo_jpeg):
|
||||
with patch(
|
||||
"homeassistant.components.camera.img_util.TurboJPEG", return_value=turbo_jpeg
|
||||
):
|
||||
TurboJPEGSingleton()
|
||||
assert scale_jpeg_camera_image(camera_image, 16, 12) == camera_image.content
|
||||
|
||||
turbo_jpeg = mock_turbo_jpeg(first_width=16, first_height=12)
|
||||
with patch("turbojpeg.TurboJPEG", return_value=turbo_jpeg):
|
||||
with patch(
|
||||
"homeassistant.components.camera.img_util.TurboJPEG", return_value=turbo_jpeg
|
||||
):
|
||||
TurboJPEGSingleton()
|
||||
assert scale_jpeg_camera_image(camera_image, 16, 12) == EMPTY_16_12_JPEG
|
||||
|
||||
turbo_jpeg = mock_turbo_jpeg(
|
||||
first_width=16, first_height=12, second_width=8, second_height=6
|
||||
)
|
||||
with patch("turbojpeg.TurboJPEG", return_value=turbo_jpeg):
|
||||
with patch(
|
||||
"homeassistant.components.camera.img_util.TurboJPEG", return_value=turbo_jpeg
|
||||
):
|
||||
TurboJPEGSingleton()
|
||||
jpeg_bytes = scale_jpeg_camera_image(camera_image, 8, 6)
|
||||
|
||||
@@ -65,7 +73,9 @@ def test_scale_jpeg_camera_image() -> None:
|
||||
turbo_jpeg = mock_turbo_jpeg(
|
||||
first_width=640, first_height=480, second_width=640, second_height=480
|
||||
)
|
||||
with patch("turbojpeg.TurboJPEG", return_value=turbo_jpeg):
|
||||
with patch(
|
||||
"homeassistant.components.camera.img_util.TurboJPEG", return_value=turbo_jpeg
|
||||
):
|
||||
TurboJPEGSingleton()
|
||||
jpeg_bytes = scale_jpeg_camera_image(camera_image, 320, 480)
|
||||
|
||||
@@ -75,7 +85,9 @@ def test_scale_jpeg_camera_image() -> None:
|
||||
def test_turbojpeg_load_failure() -> None:
|
||||
"""Handle libjpegturbo not being installed."""
|
||||
_clear_turbojpeg_singleton()
|
||||
with patch("turbojpeg.TurboJPEG", side_effect=Exception):
|
||||
with patch(
|
||||
"homeassistant.components.camera.img_util.TurboJPEG", side_effect=Exception
|
||||
):
|
||||
TurboJPEGSingleton()
|
||||
assert TurboJPEGSingleton.instance() is False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user