コード例 #1
0
def test_differ_assert_passes():
    image1 = LivePillowImage(Image.new('RGBA', (10, 20)))
    image2 = LivePillowImage(Image.new('RGBA', (10, 20)))

    differ = LiveImageDiffer()

    differ.assert_equal(image1, image2)
コード例 #2
0
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')
コード例 #3
0
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()) == []
コード例 #4
0
def test_differ_assert_fails():
    blue = (0, 0, 255, 255)

    image1 = LivePillowImage(Image.new('RGBA', (10, 20)))
    image1.set_pixel((5, 10), blue)
    image2 = LivePillowImage(Image.new('RGBA', (10, 20)))

    differ = LiveImageDiffer()

    with pytest.raises(AssertionError, match=r'Images differ by 1 pixel.'):
        differ.assert_equal(image1, image2)
コード例 #5
0
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()
コード例 #6
0
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
コード例 #7
0
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
コード例 #8
0
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()
コード例 #9
0
def test_live_png_as_painter(tmp_path):
    blue = (0, 0, 255, 255)
    white = (255, 255, 255, 255)

    image1 = LivePillowImage(Image.new('RGBA', (10, 20)))
    image1.set_pixel((5, 10), blue)
    image1.set_pixel((6, 10), white)

    image2 = LivePillowImage(Image.new('RGBA', (10, 20)))
    image2.set_pixel((5, 10), blue)
    bytes2 = image2.convert_to_png()
    image3 = LivePng(bytes2)
    painter3 = image3.convert_to_painter()
    painter3.set_pixel((6, 10), white)

    differ = LiveImageDiffer(tmp_path)

    differ.assert_equal(image1, painter3, 'live_png_as_painter')
コード例 #10
0
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
コード例 #11
0
def test_differ_cleans_diffs_path(tmp_path):
    diffs_path = tmp_path / 'image_diffs'
    diffs_path.mkdir()
    leftover_path = diffs_path / 'leftover-actual.png'
    leftover_path.write_text('garbage')
    unrelated_path = diffs_path / 'leftover-unrelated.png'
    unrelated_path.write_text('garbage')

    LiveImageDiffer(diffs_path)

    assert unrelated_path.exists()
    assert not leftover_path.exists()
コード例 #12
0
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()
コード例 #13
0
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
コード例 #14
0
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')
コード例 #15
0
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()