def test_make_plots(self): expected_depth_lines_fp = f"{self.gs_qc_dir}/2021-02-08-ARTIC-depth_lineplot.pdf" expected_depth_violin_fp = f"{self.gs_qc_dir}/2021-02-08-ARTIC-depth_violin.pdf" depth_fps = [str(p) for p in Path(self.test_samples_dir).rglob('*.depth.txt')] out_depth_lines_fp = f"{self.test_temp_dir}/temp_test_depth_lines.pdf" out_depth_violin_fp = f"{self.test_temp_dir}/temp_test_depth_violin.pdf" arg_list = ["samtools_depth_plots.py", out_depth_lines_fp, out_depth_violin_fp] arg_list.extend(depth_fps) try: make_plots(arg_list) # PDFs are vectorial, so we need to set a resolution when # converting to an image actual_lines = Image(filename=out_depth_lines_fp, resolution=150) with Image(filename=expected_depth_lines_fp, resolution=150) as expected_line: diff_lines = actual_lines.compare( expected_line, metric='root_mean_square') self.assertLess(diff_lines[1], 0.01) actual_violin = Image(filename=out_depth_violin_fp, resolution=150) with Image(filename=expected_depth_violin_fp, resolution=150) as expected_violin: diff_violin = actual_violin.compare( expected_violin, metric='root_mean_square') self.assertLess(diff_violin[1], 0.01) finally: for out_fp in [out_depth_lines_fp, out_depth_violin_fp]: try: os.remove(out_fp) except OSError: pass
def _run_expect_file(self, args, expected_data_file): r = subprocess.call(self.cmd + args, cwd=os.path.join(HERE, "data")) assert r == 0 expected = Image( filename=os.path.join(HERE, "data", expected_data_file)) actual = Image(filename=str(args[-1])) diff = actual.compare(expected, metric="root_mean_square") assert diff[1] < 0.01
def are_images_same(img1, img2): img = Image(filename=img1) im = Image(filename=img2) # return os.path.getsize(img1) == os.path.getsize(img2) comparison = img.compare(im, metric='root_mean_square')[1] print(str(comparison)) if comparison == 0: return True return False
def _run_expect_file(self, args, expected_pdf_base_name): r = subprocess.call(self.cmd + args, cwd=os.path.join(HERE, "data")) assert r == 0 expected_path = os.path.join( HERE, "data", expected_pdf_base_name + "-" + self.version + ".pdf") if not os.path.exists(expected_path): raise RuntimeError( "Expected output file {} not found".format(expected_path)) expected = Image(filename=expected_path) actual = Image(filename=str(args[-1])) diff = actual.compare(expected, metric="root_mean_square") assert diff[1] < 0.01
def comare_files(self, file_name_1, file_name_2): img_1 = Image( filename=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'screenshots', file_name_1)) img_2 = Image( filename=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'screenshots', file_name_2)) # Image(img_1.compare(img_2)).save(filename="asdasdasd.png") with (img_1.compare(img_2))[0].convert('png') as converted: converted.save(filename='converted.png')
def test_png_matchs_expectated(self): login = self.client.login(username=self.username, password=self.password) response = self.client.get( reverse("menu_gen:detail", kwargs={ "pk": self.menu.uuid, "export_format": "png" })) response_img = Image(blob=response, resolution=150) filename = os.path.join(os.path.dirname(__file__), "test_files/sample_png.png") with Image(filename=filename, resolution=150) as expected: diff = response_img.compare(expected, metric="root_mean_square") self.assertLess(diff[1], 0.01)
def process(self): self.parent = self.find_parent() if self.parent is None: self.state = Screenshot.STATE_NEW else: wand_current = Image(filename=self.image.path) wand_parent = Image(filename=self.parent.image.path) wand_diff, difference = wand_current.compare( wand_parent, metric='root_mean_square') self.image_diff_amount = difference if difference > self.DIFF_EPSILON: self.image_diff = ContentFile( wand_diff.make_blob('png'), name='{}_{}_diff.png'.format(self.parent.id, self.id), ) self.state = Screenshot.STATE_DIFFERENT else: self.state = Screenshot.STATE_MATCHING
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))
def diff(image1, image2): img1 = Image(filename=image1) img2 = Image(filename=image2) img3 = img1.compare(img2) img = img3[0] return img
import cv2 import argparse from wand.image import Image import PythonMagick # construct the argument parse and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-f", "--first", required=True, help="first input image") ap.add_argument("-s", "--second", required=True, help="second") ap.add_argument("-w", "--w", required=True) ap.add_argument("-he", "--h", required=True) args = vars(ap.parse_args()) imgA=cv2.imread(args["first"]) imgB=cv2.imread(args["second"]) w=int(args["w"]) h=int(args["h"]) dim=(w,h) path1="C:/Users/GOUAIED/OneDrive/Bureau/springbootrestdemo/springbootrestdemo1/screenshots/compare/imgA.png" path2="C:/Users/GOUAIED/OneDrive/Bureau/springbootrestdemo/springbootrestdemo1/screenshots/compare/imgB.png" path3="C:/Users/GOUAIED/OneDrive/Bureau/springbootrestdemo/springbootrestdemo1/screenshots/compare/diff.png" img1=cv2.resize(imgA, dim, interpolation = cv2.INTER_AREA) img2=cv2.resize(imgB, dim, interpolation = cv2.INTER_AREA) cv2.imwrite(path1,img1) cv2.imwrite(path2,img2) A=Image(filename=path1) B=Image(filename=path2) B.fuzz = B.quantum_range * 0.20 result_image, result_metric = B.compare(A) print(result_metric) result_image.save(filename=path3)
def compare_pdfs(expected_pdf_fp, real_pdf_fp): real_img = Image(filename=real_pdf_fp, resolution=150) with Image(filename=expected_pdf_fp, resolution=150) as expected_img: imgs_diff = real_img.compare(expected_img, metric='root_mean_square') return imgs_diff[1]