Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions stdimage/management/commands/rendervariations.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ def add_arguments(self, parser):
help='Replace existing files.')

def handle(self, *args, **options):
replace = options.get('replace')
if len(options['field_path']):
routes = options['field_path']
else:
routes = [options['field_path']]
replace = options.get('replace', False)
routes = options.get('field_path', [])
for route in routes:
try:
app_label, model_name, field_name = route.rsplit('.')
Expand Down Expand Up @@ -73,7 +70,7 @@ def render(field, images, count, replace, do_render):
' ', progressbar.Bar(),
)) as bar:
with ProcessPoolExecutor() as executor:
while next(executor.map(render_field_variations, kwargs_list)):
for _ in executor.map(render_field_variations, kwargs_list):
bar += 1


Expand Down
12 changes: 11 additions & 1 deletion tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import hashlib
import os
import time
from concurrent.futures import ThreadPoolExecutor

import pytest
from django.core.management import CommandError, call_command
Expand All @@ -11,7 +12,16 @@


@pytest.mark.django_db
class TestRenderVariations(object):
class TestRenderVariations:

@pytest.fixture(autouse=True)
def _swap_concurrent_executor(self, monkeypatch):
"""Use ThreadPoolExecutor for coverage reports."""
monkeypatch.setattr(
'concurrent.futures.ProcessPoolExecutor',
ThreadPoolExecutor,
)

def test_no_options(self, image_upload_file):
obj = ThumbnailModel.objects.create(
image=image_upload_file
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.core.files.uploadedfile import SimpleUploadedFile


class UUID4Monkey(object):
class UUID4Monkey:
hex = '653d1c6863404b9689b75fa930c9d0a0'


Expand All @@ -38,7 +38,7 @@ class UUID4Monkey(object):
]


class TestStdImage(object):
class TestStdImage:
fixtures = {}

@pytest.fixture(autouse=True)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@pytest.mark.django_db
class TestRenderVariations(object):
class TestRenderVariations:
def test_render_variations(self, image_upload_file):
instance = ManualVariationsModel.customer_manager.create(
image=image_upload_file
Expand All @@ -31,7 +31,7 @@ def test_render_variations(self, image_upload_file):
assert os.path.exists(path)


class TestUploadTo(object):
class TestUploadTo:
def test_file_name(self):
file_name = UploadTo()(object(), '/path/to/file.jpeg')
assert file_name == '/path/to/file.jpeg'
Expand Down