Skip to content
This repository has been archived by the owner on Sep 22, 2020. It is now read-only.

Commit

Permalink
Fix skipping of engine testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
relekang committed Apr 2, 2015
1 parent f8aa50d commit 3c98e02
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ engine.

.. code-block:: python
@unittest.skipIf(not has_pillow(), 'Pillow not installed')
@unittest.skipIf(not has_installed('pillow'), 'Pillow not installed')
class PillowEngineTestCase(EngineTestMixin, unittest.TestCase):
ENGINE = PillowEngine
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cache_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from thumbnails.images import Thumbnail

from .compat import mock
from .utils import has_django, has_redis
from .utils import has_installed


class CacheBackendTestMixin(object):
Expand Down Expand Up @@ -48,12 +48,12 @@ class SimpleCacheBackendTestCase(CacheBackendTestMixin, unittest.TestCase):
BACKEND = SimpleCacheBackend


@unittest.skipIf(not has_django(), 'Django is not installed')
@unittest.skipIf(not has_installed('django'), 'Django is not installed')
class DjangoCacheBackendTestCase(CacheBackendTestMixin, unittest.TestCase):
BACKEND = DjangoCacheBackend


@unittest.skipIf(not has_redis(), 'Redis not installed')
@unittest.skipIf(not has_installed('redis'), 'Redis not installed')
class RedisCacheBackendTestCase(CacheBackendTestMixin, unittest.TestCase):
BACKEND = RedisCacheBackend

Expand Down
4 changes: 2 additions & 2 deletions tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from thumbnails.conf.wrapper import SettingsWrapper

from .compat import mock
from .utils import has_django
from .utils import has_installed


class SettingsWrapperTestCase(unittest.TestCase):
Expand All @@ -26,7 +26,7 @@ def test_override_by_thumbnail_settings_module(self):
settings = SettingsWrapper()
self.assertEqual(settings.THUMBNAIL_ENGINE, 'thumbnails.engines.PillowEngine')

@unittest.skipIf(not has_django(), 'Django not installed')
@unittest.skipIf(not has_installed('django'), 'Django not installed')
def test_django_defaults(self):
settings = SettingsWrapper()
self.assertEqual(
Expand Down
8 changes: 4 additions & 4 deletions tests/test_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from thumbnails.images import SourceFile, Thumbnail

from .compat import mock
from .utils import has_installed
from .utils import is_tox_env


class EngineTestMixin(object):
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_create_from_url(self):
self.assertEqual(thumbnail.url, 'http://puppies.lkng.me/200x300')


@unittest.skipIf(not has_installed('PIL'), 'Pillow not installed')
@unittest.skipIf(not is_tox_env('pillow'), 'not pillow environment')
class PillowEngineTestCase(EngineTestMixin, unittest.TestCase):
ENGINE = PillowEngine
RAW_DATA_HASH = 'cd63a4ccd85070c76db822ca5ccb11ba59966256'
Expand All @@ -211,13 +211,13 @@ def test_load_with_os_error(self, mock_image_load):
mock_image_load.assert_called_once()


@unittest.skipIf(not has_installed('wand.image'), 'Wand not installed')
@unittest.skipIf(not is_tox_env('wand'), 'not wand environment')
class WandEngineTestCase(EngineTestMixin, unittest.TestCase):
ENGINE = WandEngine
RAW_DATA_HASH = '8eb021308a7fb04cb0e87ce9026828f42e8a4a81'


@unittest.skipIf(not has_installed('pgmagick'), 'pgmagick not installed')
@unittest.skipIf(not is_tox_env('pgmagick'), 'not pgmagick environment')
class PgmagickEngineTestCase(EngineTestMixin, unittest.TestCase):
ENGINE = PgmagickEngine
RAW_DATA_HASH = '47be661ff0e19f6e78eaa38b68db74d10f3f4c96'
Expand Down
4 changes: 2 additions & 2 deletions tests/test_storage_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shutil
import unittest

from tests.utils import has_django
from tests.utils import has_installed
from thumbnails.storage_backends import (BaseStorageBackend, DjangoStorageBackend,
FilesystemStorageBackend)

Expand Down Expand Up @@ -43,6 +43,6 @@ def test_create_location_in_init(self):
os.path.exists(instance.location)


@unittest.skipIf(not has_django(), 'Django not installed')
@unittest.skipIf(not has_installed('django'), 'Django not installed')
class DjangoStorageBackendTestCase(StorageBackendTestMixin, unittest.TestCase):
BACKEND = DjangoStorageBackend
5 changes: 5 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ def has_installed(dependency):
return False


def is_tox_env(env):
if 'VIRTUAL_ENV' in os.environ:
return env in os.environ['VIRTUAL_ENV']


def has_django():
return has_installed('django')

Expand Down
8 changes: 4 additions & 4 deletions thumbnails/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from thumbnails import helpers
from thumbnails.conf import settings
from thumbnails.engines import DummyEngine
from thumbnails.helpers import get_engine, generate_filename, get_cache_backend
from thumbnails.images import SourceFile, Thumbnail


Expand Down Expand Up @@ -29,11 +29,11 @@ def get_thumbnail(original, size, **options):
detected file type as well as the one specified in ``THUMBNAIL_FALLBACK_FORMAT``.
:return: A Thumbnail object
"""
engine = helpers.get_engine()
cache = helpers.get_cache_backend()
engine = get_engine()
cache = get_cache_backend()
original = SourceFile(original)
crop = options.get('crop', None)
thumbnail_name = helpers.generate_filename(original, size, crop, options)
thumbnail_name = generate_filename(original, size, crop, options)

if settings.THUMBNAIL_DUMMY:
engine = DummyEngine()
Expand Down
4 changes: 1 addition & 3 deletions thumbnails/conf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# -*- coding: utf-8 -*-
from . import wrapper

settings = wrapper.SettingsWrapper()
from thumbnails.conf.wrapper import settings # noqa
2 changes: 2 additions & 0 deletions thumbnails/conf/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ def _load_from_module(self, _module, target):
for setting in dir(_module):
if not setting.startswith('_'):
target[setting] = getattr(_module, setting)

settings = SettingsWrapper()
12 changes: 9 additions & 3 deletions thumbnails/engines/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# -*- coding: utf-8 -*-
from thumbnails.engines.base import BaseThumbnailEngine # noqa
from thumbnails.engines.pillow import PillowEngine # noqa
from thumbnails.engines.dummy import DummyEngine # noqa


try:
from thumbnails.engines.pillow_engine import PillowEngine # noqa
except ImportError:
PillowEngine = None


try:
from thumbnails.engines.wand import WandEngine # noqa
from thumbnails.engines.wand_engine import WandEngine # noqa
except ImportError:
WandEngine = None


try:
from thumbnails.engines.pgmagick import PgmagickEngine # noqa
from thumbnails.engines.pgmagick_engine import PgmagickEngine # noqa
except ImportError:
PgmagickEngine = None
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

from base64 import b64decode

from pgmagick import Blob, Geometry, Image, ImageType
Expand All @@ -10,7 +8,7 @@

class PgmagickEngine(BaseThumbnailEngine):
"""
Image backend for pgmagick, requires the pgpmagick package.
Image backend for pgmagick, requires the pgmagick package.
"""

def engine_load_image(self, original):
Expand Down Expand Up @@ -61,4 +59,3 @@ def engine_get_format(self, image):
if _format == 'CompuServe graphics interchange format':
return 'GIF'
return _format

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

from wand.image import Image

from .base import BaseThumbnailEngine
Expand Down

0 comments on commit 3c98e02

Please sign in to comment.