mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
Merge pull request #2862 from wiredfool/difference-upload
Display differences for test failures
This commit is contained in:
commit
dcb8d6f0b8
|
@ -13,6 +13,7 @@ pip install check-manifest
|
||||||
pip install olefile
|
pip install olefile
|
||||||
pip install pyroma
|
pip install pyroma
|
||||||
pip install coverage
|
pip install coverage
|
||||||
|
pip install test-image-results
|
||||||
|
|
||||||
# docs only on Python 2.7
|
# docs only on Python 2.7
|
||||||
if [ "$TRAVIS_PYTHON_VERSION" == "2.7" ]; then pip install -r requirements.txt ; fi
|
if [ "$TRAVIS_PYTHON_VERSION" == "2.7" ]; then pip install -r requirements.txt ; fi
|
||||||
|
|
|
@ -9,6 +9,16 @@ import unittest
|
||||||
|
|
||||||
from PIL import Image, ImageMath
|
from PIL import Image, ImageMath
|
||||||
|
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
HAS_UPLOADER = False
|
||||||
|
try:
|
||||||
|
import test_image_results
|
||||||
|
HAS_UPLOADER = True
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
def convert_to_comparable(a, b):
|
def convert_to_comparable(a, b):
|
||||||
new_a, new_b = a, b
|
new_a, new_b = a, b
|
||||||
|
@ -84,6 +94,13 @@ class PillowTestCase(unittest.TestCase):
|
||||||
a.size, b.size,
|
a.size, b.size,
|
||||||
msg or "got size %r, expected %r" % (a.size, b.size))
|
msg or "got size %r, expected %r" % (a.size, b.size))
|
||||||
if a.tobytes() != b.tobytes():
|
if a.tobytes() != b.tobytes():
|
||||||
|
if HAS_UPLOADER:
|
||||||
|
try:
|
||||||
|
url = test_image_results.upload(a, b)
|
||||||
|
logger.error("Url for test images: %s" %url)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
self.fail(msg or "got different content")
|
self.fail(msg or "got different content")
|
||||||
|
|
||||||
def assert_image_similar(self, a, b, epsilon, msg=None):
|
def assert_image_similar(self, a, b, epsilon, msg=None):
|
||||||
|
@ -103,11 +120,20 @@ class PillowTestCase(unittest.TestCase):
|
||||||
diff += sum(i * num for i, num in enumerate(chdiff.histogram()))
|
diff += sum(i * num for i, num in enumerate(chdiff.histogram()))
|
||||||
|
|
||||||
ave_diff = float(diff)/(a.size[0]*a.size[1])
|
ave_diff = float(diff)/(a.size[0]*a.size[1])
|
||||||
self.assertGreaterEqual(
|
try:
|
||||||
epsilon, ave_diff,
|
self.assertGreaterEqual(
|
||||||
(msg or '') +
|
epsilon, ave_diff,
|
||||||
" average pixel value difference %.4f > epsilon %.4f" % (
|
(msg or '') +
|
||||||
ave_diff, epsilon))
|
" average pixel value difference %.4f > epsilon %.4f" % (
|
||||||
|
ave_diff, epsilon))
|
||||||
|
except Exception as e:
|
||||||
|
if HAS_UPLOADER:
|
||||||
|
try:
|
||||||
|
url = test_image_results.upload(a, b)
|
||||||
|
logger.error("Url for test images: %s" %url)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
raise e
|
||||||
|
|
||||||
def assert_warning(self, warn_class, func, *args, **kwargs):
|
def assert_warning(self, warn_class, func, *args, **kwargs):
|
||||||
import warnings
|
import warnings
|
||||||
|
|
18
Tests/test_uploader.py
Normal file
18
Tests/test_uploader.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
from helper import unittest, PillowTestCase, hopper
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
|
class TestUploader(PillowTestCase):
|
||||||
|
def check_upload_equal(self):
|
||||||
|
result = hopper('P').convert('RGB')
|
||||||
|
target = hopper('RGB')
|
||||||
|
self.assert_image_equal(result, target)
|
||||||
|
|
||||||
|
def check_upload_similar(self):
|
||||||
|
result = hopper('P').convert('RGB')
|
||||||
|
target = hopper('RGB')
|
||||||
|
self.assert_image_similar(result, target, 0)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user