Commit 5908c597 authored by Maria Glukhova's avatar Maria Glukhova

Tests for visual comparison.

parent a7452e87
......@@ -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)
@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'
@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
......@@ -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
@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'
......@@ -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
@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'
......@@ -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)
@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'
......@@ -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')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment