mirror of
https://github.com/django/django.git
synced 2025-06-05 19:49:13 +00:00
Used skipIf decorator to skip image tests when PIL is not available
This commit is contained in:
parent
8fdc56d2a6
commit
86eb606b88
@ -6,18 +6,23 @@ import shutil
|
||||
from django.core.files import File
|
||||
from django.core.files.images import ImageFile
|
||||
from django.test import TestCase
|
||||
from django.utils.unittest import skipIf
|
||||
|
||||
from .models import (Image, Person, PersonWithHeight, PersonWithHeightAndWidth,
|
||||
PersonDimensionsFirst, PersonTwoImages, TestImageFieldFile)
|
||||
from .models import Image
|
||||
|
||||
|
||||
# If PIL available, do these tests.
|
||||
if Image:
|
||||
|
||||
from .models import (Person, PersonWithHeight, PersonWithHeightAndWidth,
|
||||
PersonDimensionsFirst, PersonTwoImages, TestImageFieldFile)
|
||||
from .models import temp_storage_dir
|
||||
else:
|
||||
# PIL not available, create dummy classes (tests will be skipped anyway)
|
||||
class Person():
|
||||
pass
|
||||
PersonWithHeight = PersonWithHeightAndWidth = PersonDimensionsFirst = Person
|
||||
PersonTwoImages = Person
|
||||
|
||||
|
||||
class ImageFieldTestMixin(object):
|
||||
class ImageFieldTestMixin(object):
|
||||
"""
|
||||
Mixin class to provide common functionality to ImageField test classes.
|
||||
"""
|
||||
@ -83,7 +88,8 @@ if Image:
|
||||
self.assertEqual(getattr(instance, height_field_name), height)
|
||||
|
||||
|
||||
class ImageFieldTests(ImageFieldTestMixin, TestCase):
|
||||
@skipIf(Image is None, "PIL is required to test ImageField")
|
||||
class ImageFieldTests(ImageFieldTestMixin, TestCase):
|
||||
"""
|
||||
Tests for ImageField that don't need to be run with each of the
|
||||
different test model classes.
|
||||
@ -169,7 +175,8 @@ if Image:
|
||||
self.assertEqual(p.mugshot, loaded_p.mugshot)
|
||||
|
||||
|
||||
class ImageFieldTwoDimensionsTests(ImageFieldTestMixin, TestCase):
|
||||
@skipIf(Image is None, "PIL is required to test ImageField")
|
||||
class ImageFieldTwoDimensionsTests(ImageFieldTestMixin, TestCase):
|
||||
"""
|
||||
Tests behavior of an ImageField and its dimensions fields.
|
||||
"""
|
||||
@ -282,7 +289,8 @@ if Image:
|
||||
self.assertEqual(p.mugshot.was_opened, True)
|
||||
|
||||
|
||||
class ImageFieldNoDimensionsTests(ImageFieldTwoDimensionsTests):
|
||||
@skipIf(Image is None, "PIL is required to test ImageField")
|
||||
class ImageFieldNoDimensionsTests(ImageFieldTwoDimensionsTests):
|
||||
"""
|
||||
Tests behavior of an ImageField with no dimension fields.
|
||||
"""
|
||||
@ -290,7 +298,8 @@ if Image:
|
||||
PersonModel = Person
|
||||
|
||||
|
||||
class ImageFieldOneDimensionTests(ImageFieldTwoDimensionsTests):
|
||||
@skipIf(Image is None, "PIL is required to test ImageField")
|
||||
class ImageFieldOneDimensionTests(ImageFieldTwoDimensionsTests):
|
||||
"""
|
||||
Tests behavior of an ImageField with one dimensions field.
|
||||
"""
|
||||
@ -298,7 +307,8 @@ if Image:
|
||||
PersonModel = PersonWithHeight
|
||||
|
||||
|
||||
class ImageFieldDimensionsFirstTests(ImageFieldTwoDimensionsTests):
|
||||
@skipIf(Image is None, "PIL is required to test ImageField")
|
||||
class ImageFieldDimensionsFirstTests(ImageFieldTwoDimensionsTests):
|
||||
"""
|
||||
Tests behavior of an ImageField where the dimensions fields are
|
||||
defined before the ImageField.
|
||||
@ -307,7 +317,8 @@ if Image:
|
||||
PersonModel = PersonDimensionsFirst
|
||||
|
||||
|
||||
class ImageFieldUsingFileTests(ImageFieldTwoDimensionsTests):
|
||||
@skipIf(Image is None, "PIL is required to test ImageField")
|
||||
class ImageFieldUsingFileTests(ImageFieldTwoDimensionsTests):
|
||||
"""
|
||||
Tests behavior of an ImageField when assigning it a File instance
|
||||
rather than an ImageFile instance.
|
||||
@ -317,7 +328,8 @@ if Image:
|
||||
File = File
|
||||
|
||||
|
||||
class TwoImageFieldTests(ImageFieldTestMixin, TestCase):
|
||||
@skipIf(Image is None, "PIL is required to test ImageField")
|
||||
class TwoImageFieldTests(ImageFieldTestMixin, TestCase):
|
||||
"""
|
||||
Tests a model with two ImageFields.
|
||||
"""
|
||||
|
@ -13,9 +13,7 @@ from django.utils import unittest
|
||||
from .models import (Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post,
|
||||
NullBooleanModel, BooleanModel, Document, RenamedField)
|
||||
|
||||
# If PIL available, do these tests.
|
||||
if Image:
|
||||
from .imagefield import (ImageFieldTests, ImageFieldTwoDimensionsTests,
|
||||
from .imagefield import (ImageFieldTests, ImageFieldTwoDimensionsTests,
|
||||
TwoImageFieldTests, ImageFieldNoDimensionsTests,
|
||||
ImageFieldOneDimensionTests, ImageFieldDimensionsFirstTests,
|
||||
ImageFieldUsingFileTests)
|
||||
|
Loading…
x
Reference in New Issue
Block a user