From b88aaa3bee990eb32851930093be29a969590bff Mon Sep 17 00:00:00 2001 From: Nazar Goshko Date: Thu, 10 Jan 2019 20:21:18 +0200 Subject: [PATCH 1/6] Fix problem with space in paths --- needle/engines/imagemagick_engine.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/needle/engines/imagemagick_engine.py b/needle/engines/imagemagick_engine.py index 39669be..dd48d72 100644 --- a/needle/engines/imagemagick_engine.py +++ b/needle/engines/imagemagick_engine.py @@ -5,23 +5,23 @@ class Engine(EngineBase): + compare_path = "compare" - compare_command = ("{compare} -metric RMSE -subimage-search -dissimilarity-threshold 1.0 {baseline} " - "{new} {diff}") def assertSameFiles(self, output_file, baseline_file, threshold=0): diff_file = output_file.replace('.png', '.diff.png') - compare_cmd = self.compare_command.format( - compare=self.compare_path, - baseline=baseline_file, - new=output_file, - diff=diff_file) - process = subprocess.Popen(compare_cmd, shell=True, + compare_command = [self.compare_path, + "-metric","RMSE", + "-subimage-search", + "-dissimilarity-threshold","1.0", + baseline_file, output_file, diff_file] + + process = subprocess.Popen(compare_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) compare_stdout, compare_stderr = process.communicate() - + print(compare_stderr) difference = float(compare_stderr.split()[1][1:-1]) if difference <= threshold: os.remove(diff_file) From 881d66418581a39ada23d6f76caa0d32debf4a7c Mon Sep 17 00:00:00 2001 From: Nazar Goshko Date: Thu, 10 Jan 2019 20:26:50 +0200 Subject: [PATCH 2/6] Delete debug prints --- needle/engines/imagemagick_engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/needle/engines/imagemagick_engine.py b/needle/engines/imagemagick_engine.py index dd48d72..288b6af 100644 --- a/needle/engines/imagemagick_engine.py +++ b/needle/engines/imagemagick_engine.py @@ -21,7 +21,7 @@ def assertSameFiles(self, output_file, baseline_file, threshold=0): stdout=subprocess.PIPE, stderr=subprocess.PIPE) compare_stdout, compare_stderr = process.communicate() - print(compare_stderr) + difference = float(compare_stderr.split()[1][1:-1]) if difference <= threshold: os.remove(diff_file) From 471913c7b50ddd65e88d82b2b36115751f3473ad Mon Sep 17 00:00:00 2001 From: Nazar Goshko Date: Thu, 17 Jan 2019 19:47:32 +0200 Subject: [PATCH 3/6] Add new engine, based on Wand library --- needle/engines/wand_engine.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 needle/engines/wand_engine.py diff --git a/needle/engines/wand_engine.py b/needle/engines/wand_engine.py new file mode 100644 index 0000000..625543f --- /dev/null +++ b/needle/engines/wand_engine.py @@ -0,0 +1,29 @@ +from wand.image import Image +from needle.engines.base import EngineBase + + +class Engine(EngineBase): + + + def assertSameFiles(self, output_file, baseline_file, threshold=0): + + diff_file = output_file.replace('.png', '.diff.png') + + img_base = Image(filename=os.path.abspath(baseline_file)) + img_out = Image(filename=os.path.abspath(output_file)) + + img_base.normalize() + img_out.normalize() + + comparison, difference = img_base.compare(img_out, metric='root_mean_square') + + if difference <= threshold: + return + else: + comparison.save(diff_file) + + raise AssertionError("The new screenshot '{new}' did not match " + "the baseline '{baseline}' (See {diff}):\n" + .format(new=output_file, + baseline=baseline_file, + diff=diff_file)) \ No newline at end of file From af99f9ac13fbe5d496d46c1bc0de13a004268f36 Mon Sep 17 00:00:00 2001 From: Nazar Goshko Date: Thu, 17 Jan 2019 19:54:33 +0200 Subject: [PATCH 4/6] Add wand dependence to setup script --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 811a002..b2990c6 100644 --- a/setup.py +++ b/setup.py @@ -17,6 +17,7 @@ def read(*parts): 'nose>=1.0.0', 'selenium>=2,<4', 'pillow', + 'wand>=0.5.0' ] if sys.version_info < (2, 7, 0): From 66771b7612266f577d1f97ac4e833f69f41934d6 Mon Sep 17 00:00:00 2001 From: Nazar Goshko Date: Fri, 18 Jan 2019 12:11:39 +0200 Subject: [PATCH 5/6] fix import --- needle/engines/wand_engine.py | 1 + 1 file changed, 1 insertion(+) diff --git a/needle/engines/wand_engine.py b/needle/engines/wand_engine.py index 625543f..cfb0fc1 100644 --- a/needle/engines/wand_engine.py +++ b/needle/engines/wand_engine.py @@ -1,4 +1,5 @@ from wand.image import Image +import os from needle.engines.base import EngineBase From 356e46affeca63aa907c6f89c48da417275fe627 Mon Sep 17 00:00:00 2001 From: Nazar Goshko Date: Fri, 18 Jan 2019 12:19:43 +0200 Subject: [PATCH 6/6] fix save diff file --- needle/engines/wand_engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/needle/engines/wand_engine.py b/needle/engines/wand_engine.py index cfb0fc1..2436403 100644 --- a/needle/engines/wand_engine.py +++ b/needle/engines/wand_engine.py @@ -21,7 +21,7 @@ def assertSameFiles(self, output_file, baseline_file, threshold=0): if difference <= threshold: return else: - comparison.save(diff_file) + comparison.save(filename=diff_file) raise AssertionError("The new screenshot '{new}' did not match " "the baseline '{baseline}' (See {diff}):\n"