Commit 59b423ee by David Baumgold

Decorate test functions that require Pillow JPEG support

parent 945314bf
...@@ -15,6 +15,8 @@ from path import path ...@@ -15,6 +15,8 @@ from path import path
from tempdir import mkdtemp_clean from tempdir import mkdtemp_clean
from textwrap import dedent from textwrap import dedent
from uuid import uuid4 from uuid import uuid4
from functools import wraps
from unittest import SkipTest
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
...@@ -60,6 +62,26 @@ TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4(). ...@@ -60,6 +62,26 @@ TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
def requires_pillow_jpeg(func):
"""
A decorator to indicate that the function requires JPEG support for Pillow,
otherwise it cannot be run
"""
@wraps(func)
def decorated_func(*args, **kwargs):
"""
Execute the function if we have JPEG support in Pillow.
"""
try:
from PIL import Image
except ImportError:
raise SkipTest("Pillow is not installed (or not found)")
if not getattr(Image.core, "jpeg_decoder", False):
raise SkipTest("Pillow cannot open JPEG files")
return func(*args, **kwargs)
return decorated_func
@override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE) @override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE)
class ContentStoreTestCase(CourseTestCase): class ContentStoreTestCase(CourseTestCase):
""" """
...@@ -102,6 +124,7 @@ class ImportRequiredTestCases(ContentStoreTestCase): ...@@ -102,6 +124,7 @@ class ImportRequiredTestCases(ContentStoreTestCase):
effort = self.store.get_item(course_key.make_usage_key('about', 'end_date')) effort = self.store.get_item(course_key.make_usage_key('about', 'end_date'))
self.assertEqual(effort.data, 'TBD') self.assertEqual(effort.data, 'TBD')
@requires_pillow_jpeg
def test_asset_import(self): def test_asset_import(self):
''' '''
This test validates that an image asset is imported and a thumbnail was generated for a .gif This test validates that an image asset is imported and a thumbnail was generated for a .gif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment