Skip to content

Commit 7c35990

Browse files
committed
working phash lib
1 parent 2b48aff commit 7c35990

File tree

4 files changed

+16
-23
lines changed

4 files changed

+16
-23
lines changed

pytest_mpl/kernels.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from PIL import Image
1010

1111
#: The default hamming distance bit tolerance for "similar" imagehash hashes.
12-
DEFAULT_HAMMING_TOLERANCE = 2
12+
DEFAULT_HAMMING_TOLERANCE = 4
1313

1414
#: The default imagehash hash size (N), resulting in a hash of N**2 bits.
1515
DEFAULT_HASH_SIZE = 16

tests/baseline/hashes/test_phash.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"test.test_gen": "8fe8c01f7a45b01f6645ac1fe9572b2a807e2ae0d41a7ab085967aac87997eab",
3+
"pytest-mpl-kernel": "phash"
4+
}

tests/test_kernels.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
# --XX-----------X
2626
HASH_4BIT = "0100456789abcdee"
2727

28+
#: baseline with 8-bit delta (64-bit)
29+
# -X------------XX
30+
HASH_8BIT = "0023456789abcd00"
31+
2832

2933
#: Absolute path to test baseline image
3034
baseline_image = Path(__file__).parent / "baseline" / "2.0.x" / "test_base_style.png"
@@ -97,7 +101,8 @@ def test_phash_option():
97101
[
98102
(HASH_BASE, True, 0),
99103
(HASH_2BIT, True, 2),
100-
(HASH_4BIT, False, 4),
104+
(HASH_4BIT, True, 4),
105+
(HASH_8BIT, False, 8),
101106
(HASH_BASE_32, False, None),
102107
],
103108
)

tests/test_pytest_mpl.py

+5-21
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
fail_hash_library = Path(__file__).parent / "baseline" / "test_hash_lib.json"
3333
baseline_dir_abs = Path(__file__).parent / "baseline" / baseline_subdir
3434
hash_baseline_dir_abs = Path(__file__).parent / "baseline" / "hybrid"
35+
phash_library = Path(__file__).parent / "baseline" / "hashes" / "test_phash.json"
3536

3637

3738
WIN = sys.platform.startswith('win')
@@ -491,31 +492,14 @@ def test_results_always(tmpdir):
491492
assert json_res[json_image_key] is None
492493

493494

494-
def test_phash(tmpdir, capsys):
495+
def test_phash(tmpdir):
495496
test_file = tmpdir.join("test.py").strpath
496497
with open(test_file, "w") as fo:
497498
fo.write(TEST_GENERATE)
498499

499-
results_dir = tmpdir.mkdir("foo").strpath
500-
gen_dir = tmpdir.mkdir("bar").strpath
501-
hash_file = "test_phash.json"
502-
503-
code = call_pytest([f"--mpl-generate-path={gen_dir}", test_file])
504-
assert code == 0
505-
assert os.path.exists(os.path.join(gen_dir, "test_gen.png"))
506-
507-
command = [f"--mpl-generate-hash-library={hash_file}",
508-
"--mpl-results-always",
509-
f"--mpl-results-path={results_dir}",
500+
command = ["--mpl",
510501
"--mpl-kernel=phash",
502+
f"--mpl-hash-library={phash_library}",
511503
test_file]
512504
code = call_pytest(command)
513-
hash_file = os.path.join(results_dir, hash_file)
514-
assert os.path.exists(os.path.join(hash_file))
515-
516-
with open(hash_file) as fi:
517-
hash_lib = json.load(fi)
518-
519-
with capsys.disabled():
520-
from pprint import pprint
521-
pprint(hash_lib)
505+
assert code == 0

0 commit comments

Comments
 (0)