diff --git a/needle/engines/imagemagick_engine.py b/needle/engines/imagemagick_engine.py index 39669be..288b6af 100644 --- a/needle/engines/imagemagick_engine.py +++ b/needle/engines/imagemagick_engine.py @@ -5,19 +5,19 @@ 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() diff --git a/needle/engines/wand_engine.py b/needle/engines/wand_engine.py new file mode 100644 index 0000000..2436403 --- /dev/null +++ b/needle/engines/wand_engine.py @@ -0,0 +1,30 @@ +from wand.image import Image +import os +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(filename=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 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):