def test_differ_compare_test_name_without_path(): image1 = LivePillowImage(Image.new('RGBA', (10, 20))) differ = LiveImageDiffer() with pytest.raises(ValueError, match=r'Used file_prefix without diffs_path\.'): differ.compare(image1, image1, 'test_name')
def test_differ_duplicate_file_prefix(tmp_path): image = LivePillowImage(Image.new('RGBA', (10, 20))) differ = LiveImageDiffer(tmp_path) differ.compare(image, image, 'first_test') differ.compare(image, image, 'other_test') with pytest.raises(ValueError, match=r"Duplicate file_prefix: 'first_test'\."): differ.compare(image, image, 'first_test')
def test_differ_compare_writes_no_files_without_file_prefix(tmp_path): image1 = LivePillowImage(Image.new('RGBA', (10, 20))) image1.set_pixel((5, 10), (0, 255, 0, 255)) image2 = LivePillowImage(Image.new('RGBA', (10, 20))) diffs_path = tmp_path / 'image_diffs' differ = LiveImageDiffer(diffs_path) differ.compare(image1, image2) assert list(diffs_path.iterdir()) == []
def test_differ_compare_uses_test_name(tmp_path, request): image1 = LivePillowImage(Image.new('RGBA', (10, 20))) image1.set_pixel((5, 10), (0, 0, 123, 255)) image2 = LivePillowImage(Image.new('RGBA', (10, 20))) diffs_path = tmp_path / 'image_diffs' actual_path = (diffs_path / 'test-PySrc-tests-test_live_image-py--' 'test_differ_compare_uses_test_name-actual.png') differ = LiveImageDiffer(diffs_path, request) differ.compare(image1, image2) assert actual_path.exists()
def test_differ_compare_display(patched_turtle): expected_report = """\ create_text -1 20 anchor='sw' fill='black' font=('Arial', 10, 'normal') text='Actual' create_image 0 20 image='...' create_text -1 60 anchor='sw' fill='black' font=('Arial', 10, 'normal') text='Diff (0 pixels)' create_image 0 60 image='...' create_text -1 100 anchor='sw' fill='black' font=('Arial', 10, 'normal') text='Expected' create_image 0 100 image='...' """ t = MockTurtle() image1 = LivePillowImage(Image.new('RGBA', (10, 20))) image2 = LivePillowImage(Image.new('RGBA', (10, 20))) differ = LiveImageDiffer() differ.compare(image1, image2) report = t.report assert replace_image(report) == expected_report
def test_differ_compare_two_sets(tmp_path): image1 = LivePillowImage(Image.new('RGBA', (10, 20))) image1.set_pixel((5, 10), (0, 0, 100, 255)) image2 = LivePillowImage(Image.new('RGBA', (10, 20))) diffs_path = tmp_path / 'image_diffs' actual_path1 = diffs_path / 'test_name-actual.png' actual_path2 = diffs_path / 'other_name-actual.png' differ = LiveImageDiffer(diffs_path) differ.compare(image1, image2, 'test_name') differ.compare(image1, image2, 'other_name') assert actual_path1.exists() assert actual_path2.exists()
def test_differ_compare_display_disabled(patched_turtle): expected_report = '\n' t = MockTurtle() image1 = LivePillowImage(Image.new('RGBA', (10, 20))) image2 = LivePillowImage(Image.new('RGBA', (10, 20))) differ = LiveImageDiffer(is_displayed=False) differ.compare(image1, image2) report = t.report assert replace_image(report) == expected_report
def test_differ_remove_no_prefix(tmp_path): image1 = LivePillowImage(Image.new('RGBA', (10, 20))) image1.set_pixel((5, 10), (0, 0, 101, 255)) image2 = LivePillowImage(Image.new('RGBA', (10, 20))) diffs_path = tmp_path / 'image_diffs' actual_path1 = diffs_path / 'apple-actual.png' actual_path2 = diffs_path / 'banana-actual.png' differ = LiveImageDiffer(diffs_path) differ.compare(image1, image2, 'apple') differ.compare(image1, image2, 'banana') differ.remove_common_prefix() assert actual_path1.exists() assert actual_path2.exists()
def test_differ_compare_writes_file(tmp_path): image1 = LivePillowImage(Image.new('RGBA', (10, 20))) image1.set_pixel((5, 10), (0, 0, 255, 255)) image2 = LivePillowImage(Image.new('RGBA', (10, 20))) diffs_path = tmp_path / 'image_diffs' actual_path = diffs_path / 'test_name-actual.png' diff_path = diffs_path / 'test_name-diff.png' expected_path = diffs_path / 'test_name-expected.png' differ = LiveImageDiffer(diffs_path) differ.compare(image1, image2, 'test_name') assert actual_path.exists() assert diff_path.exists() assert expected_path.exists()
def test_differ_compare_two_sizes(): blue = (0, 0, 255, 255) green = (0, 255, 0, 255) missing_blue = (255, 0, 51, 255) missing_green = (255, 51, 0, 255) image1 = LivePillowImage(Image.new('RGBA', (2, 3))) image1.set_pixel((0, 2), blue) image2 = LivePillowImage(Image.new('RGBA', (3, 2))) image2.set_pixel((2, 0), green) differ = LiveImageDiffer() diff = differ.compare(image1, image2).convert_to_painter() diff_pixel1 = diff.get_pixel((0, 2)) diff_pixel2 = diff.get_pixel((2, 0)) assert diff_pixel1 == missing_blue assert diff_pixel2 == missing_green assert differ.diff_count == 5
def test_differ_compare(): blue = (0, 0, 255, 255) white = (255, 255, 255, 255) expected_match = (0, 0, 255, 255 // 3) expected_diff = (255, 255 // 5, 255 * 2 // 5, 255) image1 = LivePillowImage(Image.new('RGBA', (10, 20))) image1.set_pixel((5, 10), blue) image1.set_pixel((6, 10), blue) image2 = LivePillowImage(Image.new('RGBA', (10, 20))) image2.set_pixel((5, 10), blue) image2.set_pixel((6, 10), white) differ = LiveImageDiffer() diff = differ.compare(image1, image2).convert_to_painter() diff_pixel1 = diff.get_pixel((5, 10)) diff_pixel2 = diff.get_pixel((6, 10)) assert diff_pixel1 == expected_match assert diff_pixel2 == expected_diff assert differ.diff_count == 1