Skip to content

Commit

Permalink
python 2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
fdintino committed Jul 7, 2024
1 parent 9a71726 commit a75bdf0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/thumbor_video_engine/engines/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __getattribute__(self, attr):
# or video_engine class, when appropriate, for self.__class__
if attr == "__class__" and self.__dict__.get("engine"):
return self.__dict__["engine"].__class__
return super().__getattribute__(attr)
return object.__getattribute__(self, attr)

def __getattr__(self, attr):
if not self.__dict__.get('engine'):
Expand Down
2 changes: 1 addition & 1 deletion tests/engines/test_video_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

def assert_colors_similar(rgb1, rgb2, message):
delta_e = color_diff(rgb1, rgb2)
assert delta_e < 0.05, f"{message}: {repr_rgb(rgb1)} != {repr_rgb(rgb2)}"
assert delta_e < 0.05, "%s: %s != %s" % (message, repr_rgb(rgb1), repr_rgb(rgb2))


@pytest.fixture
Expand Down
14 changes: 7 additions & 7 deletions tests/result_storages/test_file_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from thumbor_video_engine.engines.video import Engine as VideoEngine
from thumbor_video_engine.engines.ffmpeg import Engine as FFMpegEngine


@pytest.fixture
Expand Down Expand Up @@ -55,12 +55,12 @@ def test_file_result_storage_retrieve(config, mocker, http_client, base_url, tmp
src_file,
"%s/%s/ba/68/88258f0b20357d15380b611a7b31da32f19b" % (tmp_path, subdir))

mocker.spy(VideoEngine, "load")
mocker.spy(FFMpegEngine, "load")

response = yield http_client.fetch("%s/unsafe/hotdog.gif" % base_url,
headers={'Accept': mime_type})
assert response.code == 200
assert VideoEngine.load.call_count == 0
assert FFMpegEngine.load.call_count == 0
assert response.headers.get('content-type') == mime_type
if auto_gif:
assert response.headers.get('vary') == 'Accept'
Expand All @@ -71,7 +71,7 @@ def test_file_result_storage_retrieve(config, mocker, http_client, base_url, tmp
"%s/unsafe/pbj-time.gif" % base_url,
headers={'Accept': mime_type})
assert response.code == 200
assert VideoEngine.load.call_count == 1
assert FFMpegEngine.load.call_count == 1


@pytest.mark.gen_test
Expand All @@ -92,15 +92,15 @@ def test_file_result_storage_legacy_retrieve(
src_file,
"%s/v2%s/un/sa/unsafe/hotdog.gif" % (tmp_path, subdir))

mocker.spy(VideoEngine, "load")
mocker.spy(FFMpegEngine, "load")

response = yield http_client.fetch("%s/unsafe/hotdog.gif" % base_url,
headers={'Accept': accept})
assert response.code == 200
assert VideoEngine.load.call_count == 0
assert FFMpegEngine.load.call_count == 0

response = yield http_client.fetch(
"%s/unsafe/pbj-time.gif" % base_url,
headers={'Accept': accept})
assert response.code == 200
assert VideoEngine.load.call_count == 1
assert FFMpegEngine.load.call_count == 1
6 changes: 3 additions & 3 deletions tests/result_storages/test_s3_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
asyncio = None

from thumbor.engines import BaseEngine
from thumbor_video_engine.engines.video import Engine as VideoEngine
from thumbor_video_engine.engines.ffmpeg import Engine as FFMpegEngine


# Subclassed Popen that gets around mirakuru not capturing stderr
Expand Down Expand Up @@ -106,7 +106,7 @@ def test_s3_result_storage_load(mocker, config, http_client, base_url, auto_gif,
if mime_type == 'image/gif':
config.FFMPEG_GIF_AUTO_H264 = False

mocker.spy(VideoEngine, "load")
mocker.spy(FFMpegEngine, "load")

if not auto_gif and mime_type != 'image/png':
bucket_key = 'unsafe/hotdog.gif'
Expand Down Expand Up @@ -134,7 +134,7 @@ def test_s3_result_storage_load(mocker, config, http_client, base_url, auto_gif,
assert response.headers.get("vary") == "Accept"
else:
assert response.headers.get("vary") is None
assert VideoEngine.load.call_count == 0
assert FFMpegEngine.load.call_count == 0


@pytest.mark.skipif(Bucket is None, reason="tc_aws unavailable")
Expand Down
1 change: 1 addition & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import math


Expand Down

0 comments on commit a75bdf0

Please sign in to comment.