Merge pull request #2862 from wiredfool/difference-upload

Display differences for test failures
This commit is contained in:
wiredfool 2017-12-09 14:14:25 +00:00 committed by GitHub
commit dcb8d6f0b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 5 deletions

View File

@ -13,6 +13,7 @@ pip install check-manifest
pip install olefile
pip install pyroma
pip install coverage
pip install test-image-results
# docs only on Python 2.7
if [ "$TRAVIS_PYTHON_VERSION" == "2.7" ]; then pip install -r requirements.txt ; fi

View File

@ -9,6 +9,16 @@ import unittest
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):
new_a, new_b = a, b
@ -84,6 +94,13 @@ class PillowTestCase(unittest.TestCase):
a.size, b.size,
msg or "got size %r, expected %r" % (a.size, b.size))
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")
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()))
ave_diff = float(diff)/(a.size[0]*a.size[1])
self.assertGreaterEqual(
epsilon, ave_diff,
(msg or '') +
" average pixel value difference %.4f > epsilon %.4f" % (
ave_diff, epsilon))
try:
self.assertGreaterEqual(
epsilon, ave_diff,
(msg or '') +
" 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):
import warnings

18
Tests/test_uploader.py Normal file
View 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()