Skip to content

Commit 3a72208

Browse files
committed
Refactor tests to increase coverage
1 parent daddf94 commit 3a72208

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

stdimage/management/commands/rendervariations.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ def add_arguments(self, parser):
2525
help='Replace existing files.')
2626

2727
def handle(self, *args, **options):
28-
replace = options.get('replace')
29-
if len(options['field_path']):
30-
routes = options['field_path']
31-
else:
32-
routes = [options['field_path']]
28+
replace = options.get('replace', False)
29+
routes = options.get('field_path', [])
3330
for route in routes:
3431
try:
3532
app_label, model_name, field_name = route.rsplit('.')
@@ -73,7 +70,7 @@ def render(field, images, count, replace, do_render):
7370
' ', progressbar.Bar(),
7471
)) as bar:
7572
with ProcessPoolExecutor() as executor:
76-
while next(executor.map(render_field_variations, kwargs_list)):
73+
for _ in executor.map(render_field_variations, kwargs_list):
7774
bar += 1
7875

7976

tests/test_commands.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import hashlib
22
import os
33
import time
4+
from concurrent.futures import ThreadPoolExecutor
45

56
import pytest
67
from django.core.management import CommandError, call_command
@@ -11,7 +12,16 @@
1112

1213

1314
@pytest.mark.django_db
14-
class TestRenderVariations(object):
15+
class TestRenderVariations:
16+
17+
@pytest.fixture(autouse=True)
18+
def _swap_concurrent_executor(self, monkeypatch):
19+
"""Use ThreadPoolExecutor for coverage reports."""
20+
monkeypatch.setattr(
21+
'concurrent.futures.ProcessPoolExecutor',
22+
ThreadPoolExecutor,
23+
)
24+
1525
def test_no_options(self, image_upload_file):
1626
obj = ThumbnailModel.objects.create(
1727
image=image_upload_file

tests/test_models.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from django.core.files.uploadedfile import SimpleUploadedFile
1313

1414

15-
class UUID4Monkey(object):
15+
class UUID4Monkey:
1616
hex = '653d1c6863404b9689b75fa930c9d0a0'
1717

1818

@@ -38,7 +38,7 @@ class UUID4Monkey(object):
3838
]
3939

4040

41-
class TestStdImage(object):
41+
class TestStdImage:
4242
fixtures = {}
4343

4444
@pytest.fixture(autouse=True)

tests/test_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
@pytest.mark.django_db
12-
class TestRenderVariations(object):
12+
class TestRenderVariations:
1313
def test_render_variations(self, image_upload_file):
1414
instance = ManualVariationsModel.customer_manager.create(
1515
image=image_upload_file
@@ -31,7 +31,7 @@ def test_render_variations(self, image_upload_file):
3131
assert os.path.exists(path)
3232

3333

34-
class TestUploadTo(object):
34+
class TestUploadTo:
3535
def test_file_name(self):
3636
file_name = UploadTo()(object(), '/path/to/file.jpeg')
3737
assert file_name == '/path/to/file.jpeg'

0 commit comments

Comments
 (0)