Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Display differences #2862

Merged
merged 2 commits into from
Dec 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 31 additions & 5 deletions Tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@

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
Expand Down Expand Up @@ -84,6 +94,13 @@ def assert_image_equal(self, a, b, msg=None):
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):
Expand All @@ -103,11 +120,20 @@ def assert_image_similar(self, a, b, epsilon, msg=None):
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
Expand Down
18 changes: 18 additions & 0 deletions Tests/test_uploader.py
Original file line number Diff line number Diff line change
@@ -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()