[diffoscope] 03/03: Tests for visual comparison.

Maria Glukhova siamezzze-guest at moszumanska.debian.org
Mon Apr 17 22:55:04 CEST 2017


This is an automated email from the git hooks/post-receive script.

siamezzze-guest pushed a commit to branch siamezzze/image-visual-comparison
in repository diffoscope.

commit 43c2ed334af6ecffb4e11dc1bbb2cc9bdd371463
Author: Maria Glukhova <siamezzze at gmail.com>
Date:   Mon Apr 17 16:10:56 2017 +0300

    Tests for visual comparison.
---
 tests/comparators/test_gif.py        |  19 +++++++++++++++++++
 tests/comparators/test_ico_image.py  |  10 ++++++++++
 tests/comparators/test_jpeg_image.py |   9 +++++++++
 tests/comparators/test_png.py        |  10 ++++++++++
 tests/data/test3.gif                 | Bin 0 -> 854 bytes
 tests/data/test4.gif                 | Bin 0 -> 2094 bytes
 tests/test_presenters.py             |  27 +++++++++++++++++++++++++++
 7 files changed, 75 insertions(+)

diff --git a/tests/comparators/test_gif.py b/tests/comparators/test_gif.py
index bd1915e..bb898c7 100644
--- a/tests/comparators/test_gif.py
+++ b/tests/comparators/test_gif.py
@@ -20,6 +20,7 @@
 import pytest
 
 from diffoscope.comparators.gif import GifFile
+from diffoscope.config import Config
 
 from utils.data import load_fixture, get_data
 from utils.tools import skip_unless_tools_exist
@@ -27,6 +28,8 @@ from utils.nonexisting import assert_non_existing
 
 gif1 = load_fixture('test1.gif')
 gif2 = load_fixture('test2.gif')
+gif3 = load_fixture('test3.gif')
+gif4 = load_fixture('test4.gif')
 
 
 def test_identification(gif1):
@@ -48,3 +51,19 @@ def test_diff(differences):
 @skip_unless_tools_exist('gifbuild')
 def test_compare_non_existing(monkeypatch, gif1):
     assert_non_existing(monkeypatch, gif1, has_null_source=False)
+
+ at skip_unless_tools_exist('gifbuild', 'compose', 'convert', 'identify')
+def test_has_visuals(monkeypatch, gif3, gif4):
+    monkeypatch.setattr(Config(), 'html_output', True)
+    gif_diff = gif3.compare(gif4)
+    assert len(gif_diff.details) == 2
+    assert len(gif_diff.details[1].visuals) == 2
+    assert gif_diff.details[1].visuals[0].data_type == 'image/png;base64'
+    assert gif_diff.details[1].visuals[1].data_type == 'image/gif;base64'
+
+ at skip_unless_tools_exist('gifbuild', 'compose', 'convert', 'identify')
+def test_no_visuals_different_size(monkeypatch, gif1, gif2):
+    monkeypatch.setattr(Config(), 'html_output', True)
+    gif_diff = gif1.compare(gif2)
+    assert len(gif_diff.details) == 1
+    assert len(gif_diff.details[0].visuals) == 0
diff --git a/tests/comparators/test_ico_image.py b/tests/comparators/test_ico_image.py
index 7543adf..aa1eddb 100644
--- a/tests/comparators/test_ico_image.py
+++ b/tests/comparators/test_ico_image.py
@@ -20,6 +20,7 @@
 import pytest
 
 from diffoscope.comparators.image import ICOImageFile
+from diffoscope.config import Config
 
 from utils.data import load_fixture, get_data
 from utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
@@ -56,3 +57,12 @@ def differences_meta(image1_meta, image2_meta):
 def test_diff_meta(differences_meta):
     expected_diff = get_data('ico_image_meta_expected_diff')
     assert differences_meta[-1].unified_diff == expected_diff
+
+ at skip_unless_tools_exist('img2txt', 'compose', 'convert', 'identify')
+def test_has_visuals(monkeypatch, image1, image2):
+    monkeypatch.setattr(Config(), 'html_output', True)
+    ico_diff = image1.compare(image2)
+    assert len(ico_diff.details) == 2
+    assert len(ico_diff.details[0].visuals) == 2
+    assert ico_diff.details[0].visuals[0].data_type == 'image/png;base64'
+    assert ico_diff.details[0].visuals[1].data_type == 'image/gif;base64'
diff --git a/tests/comparators/test_jpeg_image.py b/tests/comparators/test_jpeg_image.py
index af405e4..8dd7e5d 100644
--- a/tests/comparators/test_jpeg_image.py
+++ b/tests/comparators/test_jpeg_image.py
@@ -73,3 +73,12 @@ def differences_meta(image1_meta, image2_meta):
 def test_diff_meta(differences_meta):
     expected_diff = get_data('jpeg_image_meta_expected_diff')
     assert differences_meta[-1].unified_diff == expected_diff
+
+ at skip_unless_tools_exist('img2txt', 'compose', 'convert', 'identify')
+def test_has_visuals(monkeypatch, image1, image2):
+    monkeypatch.setattr(Config(), 'html_output', True)
+    jpg_diff = image1.compare(image2)
+    assert len(jpg_diff.details) == 2
+    assert len(jpg_diff.details[0].visuals) == 2
+    assert jpg_diff.details[0].visuals[0].data_type == 'image/png;base64'
+    assert jpg_diff.details[0].visuals[1].data_type == 'image/gif;base64'
diff --git a/tests/comparators/test_png.py b/tests/comparators/test_png.py
index 8e8ee45..76378b7 100644
--- a/tests/comparators/test_png.py
+++ b/tests/comparators/test_png.py
@@ -20,6 +20,7 @@
 import pytest
 
 from diffoscope.comparators.png import PngFile
+from diffoscope.config import Config
 
 from utils.data import load_fixture, get_data
 from utils.tools import skip_unless_tools_exist
@@ -48,3 +49,12 @@ def test_diff(differences):
 @skip_unless_tools_exist('sng')
 def test_compare_non_existing(monkeypatch, png1):
     assert_non_existing(monkeypatch, png1, has_null_source=False)
+
+ at skip_unless_tools_exist('sng', 'compose', 'convert', 'identify')
+def test_has_visuals(monkeypatch, png1, png2):
+    monkeypatch.setattr(Config(), 'html_output', True)
+    png_diff = png1.compare(png2)
+    assert len(png_diff.details) == 2
+    assert len(png_diff.details[1].visuals) == 2
+    assert png_diff.details[1].visuals[0].data_type == 'image/png;base64'
+    assert png_diff.details[1].visuals[1].data_type == 'image/gif;base64'
diff --git a/tests/data/test3.gif b/tests/data/test3.gif
new file mode 100644
index 0000000..d10963d
Binary files /dev/null and b/tests/data/test3.gif differ
diff --git a/tests/data/test4.gif b/tests/data/test4.gif
new file mode 100644
index 0000000..b429d6a
Binary files /dev/null and b/tests/data/test4.gif differ
diff --git a/tests/test_presenters.py b/tests/test_presenters.py
index 5a0f874..e267eb8 100644
--- a/tests/test_presenters.py
+++ b/tests/test_presenters.py
@@ -44,6 +44,23 @@ def run(capsys, *args):
 
     return out
 
+def run_images(capsys, *args):
+    with pytest.raises(SystemExit) as exc:
+        prev = os.getcwd()
+        os.chdir(DATA_DIR)
+
+        try:
+            main(args + ('test1.png', 'test2.png'))
+        finally:
+            os.chdir(prev)
+
+    out, err = capsys.readouterr()
+
+    assert err == ''
+    assert exc.value.code == 1
+
+    return out
+
 def data(filename):
     with open(os.path.join(DATA_DIR, filename), encoding='utf-8') as f:
         return f.read()
@@ -115,6 +132,16 @@ def test_html_option_with_file(tmpdir, capsys):
     with open(report_path, 'r', encoding='utf-8') as f:
         assert extract_body(f.read()) == extract_body(data('output.html'))
 
+def test_html_visuals(tmpdir, capsys):
+    report_path = str(tmpdir.join('report.html'))
+
+    out = run_images(capsys, '--html', report_path)
+
+    assert out == ''
+    body = extract_body(open(report_path, 'r', encoding='utf-8').read())
+    assert '<img src="data:image/png;base64' in body
+    assert '<img src="data:image/gif;base64' in body
+
 def test_htmldir_option(tmpdir, capsys):
     html_dir = os.path.join(str(tmpdir), 'target')
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list