Skip to content

Commit 286be4f

Browse files
authored
chore: remove pytest-tornado dependency (#37)
* chore: remove pytest-tornado dependency It is no longer maintained and was not providing much utility anyway. * remove auto-merge action It is currently broken. It can be added back once it is fixed.
1 parent a85afd0 commit 286be4f

16 files changed

Lines changed: 174 additions & 155 deletions

.github/workflows/dependabot-auto-merge-caller.yaml

Lines changed: 0 additions & 27 deletions
This file was deleted.

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ exclude_lines =
2828
[tool:pytest]
2929
python_files = tests.py test_*.py *_test.py
3030
norecursedirs = *.egg .eggs dist build docs .tox .git __pycache__
31+
asyncio_default_fixture_loop_scope = function
3132
filterwarnings =
3233
ignore:@return_future is deprecated:DeprecationWarning
3334
ignore:@asynchronous is deprecated:DeprecationWarning

tests/conftest.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
import asyncio
12
import os
3+
24
import pytest
5+
import pytest_asyncio
6+
7+
import tornado.httpclient
8+
import tornado.httpserver
9+
import tornado.testing
310

411
from thumbor.config import Config
512
from thumbor.context import Context, ServerParameters, RequestParameters
@@ -11,6 +18,11 @@
1118
except ImportError:
1219
from thumbor.utils import which
1320

21+
try:
22+
from thumbor.context import ThreadPool
23+
except ImportError: # pragma: no cover
24+
ThreadPool = None
25+
1426
try:
1527
from tests.mock_aio_server import s3_server, s3_client, session # noqa
1628
except: # noqa
@@ -27,6 +39,18 @@ def s3_client():
2739
CURR_DIR = os.path.abspath(os.path.dirname(__file__))
2840

2941

42+
@pytest.fixture(autouse=True)
43+
def reset_thumbor_threadpool():
44+
"""thumbor's ThreadPool is a process-wide singleton that can otherwise
45+
hold a reference to a previous test's (now closed) event loop."""
46+
if ThreadPool is not None and getattr(ThreadPool, "_instance", None):
47+
for thread_pool in ThreadPool._instance.values():
48+
thread_pool.cleanup()
49+
yield
50+
if ThreadPool is not None:
51+
ThreadPool._instance = None
52+
53+
3054
@pytest.fixture
3155
def storage_path():
3256
return os.path.join(CURR_DIR, "data")
@@ -89,3 +113,35 @@ def context(config):
89113
@pytest.fixture
90114
def app(context):
91115
return get_application(context)
116+
117+
118+
@pytest.fixture
119+
def _unused_port():
120+
return tornado.testing.bind_unused_port()
121+
122+
123+
@pytest.fixture
124+
def http_port(_unused_port):
125+
return _unused_port[1]
126+
127+
128+
@pytest.fixture
129+
def base_url(http_port):
130+
return "http://localhost:%d" % http_port
131+
132+
133+
@pytest_asyncio.fixture
134+
async def http_server(app, _unused_port):
135+
server = tornado.httpserver.HTTPServer(app)
136+
server.add_socket(_unused_port[0])
137+
await asyncio.sleep(0)
138+
yield server
139+
server.stop()
140+
await server.close_all_connections()
141+
142+
143+
@pytest_asyncio.fixture
144+
async def http_client(http_server):
145+
client = tornado.httpclient.AsyncHTTPClient()
146+
yield client
147+
client.close()

tests/engines/test_anim_gif_auto_mp4.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
VIDEO_HEADERS = {"Accept": 'video/*,*/*;q=0.8'}
77

88

9-
@pytest.mark.gen_test
9+
@pytest.mark.asyncio
1010
@pytest.mark.parametrize('accepts_video', (True, False))
1111
@pytest.mark.parametrize('setting_key,setting_val,format_box', [
1212
('FFMPEG_GIF_AUTO_H264', True, b'avcC'),
1313
('FFMPEG_GIF_AUTO_H265', True, b'hvcC'),
1414
('FFMPEG_GIF_AUTO_H264', False, None),
1515
])
16-
def test_auto_h26x_transcodes_anim_gif(http_client, base_url, accepts_video,
16+
async def test_auto_h26x_transcodes_anim_gif(http_client, base_url, accepts_video,
1717
config, setting_key, setting_val, format_box):
1818
setattr(config, setting_key, setting_val)
1919

20-
response = yield http_client.fetch("%s/unsafe/hotdog.gif" % base_url,
20+
response = await http_client.fetch("%s/unsafe/hotdog.gif" % base_url,
2121
headers=(VIDEO_HEADERS if accepts_video else {}))
2222

2323
mime_type = 'video/mp4' if accepts_video and setting_val else 'image/gif'

tests/engines/test_anim_gif_auto_webp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ def config(config):
1717
return config
1818

1919

20-
@pytest.mark.gen_test
20+
@pytest.mark.asyncio
2121
@pytest.mark.parametrize('accepts_webp', (True, False))
2222
@pytest.mark.parametrize('ffmpeg_conf_gif_auto_webp', (True, False))
23-
def test_auto_webp_transcodes_anim_gif(http_client, base_url, accepts_webp,
23+
async def test_auto_webp_transcodes_anim_gif(http_client, base_url, accepts_webp,
2424
config, ffmpeg_conf_gif_auto_webp):
2525
config.FFMPEG_GIF_AUTO_WEBP = ffmpeg_conf_gif_auto_webp
2626

27-
response = yield http_client.fetch("%s/unsafe/hotdog.gif" % base_url,
27+
response = await http_client.fetch("%s/unsafe/hotdog.gif" % base_url,
2828
headers=(WEBP_HEADERS if accepts_webp else {}))
2929

3030
img_format = 'webp' if accepts_webp and ffmpeg_conf_gif_auto_webp else 'gif'

tests/engines/test_ffmpeg_engine.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ def test_source_height(context):
2727
assert engine.source_height == 150
2828

2929

30-
@pytest.mark.gen_test
31-
def test_error_handling(mocker, http_client, base_url):
30+
@pytest.mark.asyncio
31+
async def test_error_handling(mocker, http_client, base_url):
3232
with pytest.raises(HTTPClientError) as exc_info:
33-
yield http_client.fetch("%s/unsafe/corrupt.mp4" % base_url)
33+
await http_client.fetch("%s/unsafe/corrupt.mp4" % base_url)
3434
assert exc_info.value.code == 500
3535

3636

37-
@pytest.mark.gen_test
37+
@pytest.mark.asyncio
3838
@pytest.mark.parametrize('has_ctx_request', [True, False])
39-
def test_error_handling_run_cmd(storage_path, mocker, context, has_ctx_request):
39+
async def test_error_handling_run_cmd(storage_path, mocker, context, has_ctx_request):
4040
if not has_ctx_request:
4141
context.request = None
4242
with open("%s/corrupt.mp4" % storage_path, mode='rb') as f:

tests/engines/test_ffmpeg_operations.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ def config(config):
1313
return config
1414

1515

16-
@pytest.mark.gen_test
17-
def test_crop(mocker, http_client, base_url):
16+
@pytest.mark.asyncio
17+
async def test_crop(mocker, http_client, base_url):
1818
mocker.spy(FFmpegEngine, 'crop')
1919
mocker.spy(FFmpegEngine, 'run_cmd')
2020

21-
response = yield http_client.fetch("%s/unsafe/50x25:150x125/hotdog.mp4" % base_url)
21+
response = await http_client.fetch("%s/unsafe/50x25:150x125/hotdog.mp4" % base_url)
2222

2323
assert response.code == 200
2424
assert response.headers.get('content-type') == 'video/mp4'
@@ -35,12 +35,12 @@ def test_crop(mocker, http_client, base_url):
3535
assert (file_info['width'], file_info['height']) == (100, 100)
3636

3737

38-
@pytest.mark.gen_test
39-
def test_flip_horizontally(mocker, http_client, base_url):
38+
@pytest.mark.asyncio
39+
async def test_flip_horizontally(mocker, http_client, base_url):
4040
mocker.spy(FFmpegEngine, 'flip_horizontally')
4141
mocker.spy(FFmpegEngine, 'run_cmd')
4242

43-
response = yield http_client.fetch("%s/unsafe/-200x150/hotdog.mp4" % base_url)
43+
response = await http_client.fetch("%s/unsafe/-200x150/hotdog.mp4" % base_url)
4444

4545
assert response.code == 200
4646
assert response.headers.get('content-type') == 'video/mp4'
@@ -57,12 +57,12 @@ def test_flip_horizontally(mocker, http_client, base_url):
5757
assert (file_info['width'], file_info['height']) == (200, 150)
5858

5959

60-
@pytest.mark.gen_test
61-
def test_flip_vertically(mocker, http_client, base_url):
60+
@pytest.mark.asyncio
61+
async def test_flip_vertically(mocker, http_client, base_url):
6262
mocker.spy(FFmpegEngine, 'flip_vertically')
6363
mocker.spy(FFmpegEngine, 'run_cmd')
6464

65-
response = yield http_client.fetch("%s/unsafe/200x-150/hotdog.mp4" % base_url)
65+
response = await http_client.fetch("%s/unsafe/200x-150/hotdog.mp4" % base_url)
6666

6767
assert response.code == 200
6868
assert response.headers.get('content-type') == 'video/mp4'
@@ -79,12 +79,12 @@ def test_flip_vertically(mocker, http_client, base_url):
7979
assert (file_info['width'], file_info['height']) == (200, 150)
8080

8181

82-
@pytest.mark.gen_test
83-
def test_filter_grayscale(mocker, http_client, base_url):
82+
@pytest.mark.asyncio
83+
async def test_filter_grayscale(mocker, http_client, base_url):
8484
mocker.spy(FFmpegEngine, 'convert_to_grayscale')
8585
mocker.spy(FFmpegEngine, 'run_cmd')
8686

87-
response = yield http_client.fetch("%s/unsafe/filters:grayscale()/hotdog.mp4" % base_url)
87+
response = await http_client.fetch("%s/unsafe/filters:grayscale()/hotdog.mp4" % base_url)
8888

8989
assert response.code == 200
9090
assert response.headers.get('content-type') == 'video/mp4'
@@ -101,12 +101,12 @@ def test_filter_grayscale(mocker, http_client, base_url):
101101
assert (file_info['width'], file_info['height']) == (200, 150)
102102

103103

104-
@pytest.mark.gen_test
105-
def test_filter_rotate(mocker, http_client, base_url):
104+
@pytest.mark.asyncio
105+
async def test_filter_rotate(mocker, http_client, base_url):
106106
mocker.spy(FFmpegEngine, 'rotate')
107107
mocker.spy(FFmpegEngine, 'run_cmd')
108108

109-
response = yield http_client.fetch("%s/unsafe/filters:rotate(90)/hotdog.mp4" % base_url)
109+
response = await http_client.fetch("%s/unsafe/filters:rotate(90)/hotdog.mp4" % base_url)
110110

111111
assert response.code == 200
112112
assert response.headers.get('content-type') == 'video/mp4'
@@ -123,14 +123,14 @@ def test_filter_rotate(mocker, http_client, base_url):
123123
assert (file_info['width'], file_info['height']) == (200, 150)
124124

125125

126-
@pytest.mark.gen_test
127-
def test_reorientate(mocker, config, http_client, base_url):
126+
@pytest.mark.asyncio
127+
async def test_reorientate(mocker, config, http_client, base_url):
128128
config.RESPECT_ORIENTATION = True
129129

130130
mocker.spy(FFmpegEngine, 'reorientate')
131131
mocker.spy(FFmpegEngine, 'run_cmd')
132132

133-
response = yield http_client.fetch("%s/unsafe/hotdog.mp4" % base_url)
133+
response = await http_client.fetch("%s/unsafe/hotdog.mp4" % base_url)
134134

135135
assert response.code == 200
136136
assert response.headers.get('content-type') == 'video/mp4'

0 commit comments

Comments
 (0)