Skip to content

Commit

Permalink
working phash lib
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlittle committed May 26, 2022
1 parent 2b48aff commit 727910c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
4 changes: 4 additions & 0 deletions tests/baseline/hashes/test_phash.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"test.test_gen": "8fe8c01f7a05b01f6645ac1fe95f0b2a807e2ae2d41a7ab085967aac87997eab",
"pytest-mpl-kernel": "phash"
}
26 changes: 5 additions & 21 deletions tests/test_pytest_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
fail_hash_library = Path(__file__).parent / "baseline" / "test_hash_lib.json"
baseline_dir_abs = Path(__file__).parent / "baseline" / baseline_subdir
hash_baseline_dir_abs = Path(__file__).parent / "baseline" / "hybrid"
phash_library = Path(__file__).parent / "baseline" / "hashes" / "test_phash.json"


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


def test_phash(tmpdir, capsys):
def test_phash(tmpdir):
test_file = tmpdir.join("test.py").strpath
with open(test_file, "w") as fo:
fo.write(TEST_GENERATE)

results_dir = tmpdir.mkdir("foo").strpath
gen_dir = tmpdir.mkdir("bar").strpath
hash_file = "test_phash.json"

code = call_pytest([f"--mpl-generate-path={gen_dir}", test_file])
assert code == 0
assert os.path.exists(os.path.join(gen_dir, "test_gen.png"))

command = [f"--mpl-generate-hash-library={hash_file}",
"--mpl-results-always",
f"--mpl-results-path={results_dir}",
command = ["--mpl",
"--mpl-kernel=phash",
f"--mpl-hash-library={phash_library}",
test_file]
code = call_pytest(command)
hash_file = os.path.join(results_dir, hash_file)
assert os.path.exists(os.path.join(hash_file))

with open(hash_file) as fi:
hash_lib = json.load(fi)

with capsys.disabled():
from pprint import pprint
pprint(hash_lib)
assert code == 0

0 comments on commit 727910c

Please sign in to comment.