Skip to content

Commit 2d66565

Browse files
committed
tool_tester: make a very simple pngcmp tester
1 parent 13f5a7e commit 2d66565

File tree

6 files changed

+57
-6
lines changed

6 files changed

+57
-6
lines changed

regtests/assets/png/black320x240.png

128 Bytes
Loading

regtests/assets/png/white320x240.png

150 Bytes
Loading

regtests/tool_tester/test_tools.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
import sys
77
from os.path import join, dirname, realpath
88
import logging
9-
from tool_tester.unidasm import (
10-
UnidasmTests
11-
)
9+
from tool_tester.pngcmp import PngCmpTests
10+
from tool_tester.unidasm import UnidasmTests
1211

1312
if __name__ == "__main__":
1413
# TODO: add colorized messages
@@ -23,7 +22,7 @@
2322
chained_results = []
2423
# TODO: point to $(regtests)\assets, configure if necessary
2524
assets_folder = join(dirname(dirname(realpath(__file__))), "assets")
26-
for test_cls in [UnidasmTests]:
25+
for test_cls in [PngCmpTests, UnidasmTests]:
2726
test_fn = test_cls(assets_folder)
2827
logging.info("Start test suite: %s", test_fn.identifier)
2928
chained_results.append(test_fn.execute_tests(test_fn.compose_tests()))

regtests/tool_tester/tool_tester/_selfexe.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def execute_tests(self, test_pool: Dict) -> bool:
5656
__launch_fullpath,
5757
encoding="utf-8",
5858
capture_output=True,
59-
check=True,
59+
# TODO: we need to disable check here cause pngcmp has a returncode of 1 when diverging snapshots occurs (wtf)
60+
#check=True,
61+
check=False,
6062
text=True,
6163
shell=False
6264
)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
##
2+
## license:BSD-3-Clause
3+
## copyright-holders:Angelo Salese
4+
##
5+
6+
import os
7+
from subprocess import CompletedProcess
8+
#from dataclasses import dataclass
9+
#import logging
10+
from tool_tester._selfexe import SelfExeTests
11+
from typing import List
12+
13+
class PngCmpTests(SelfExeTests):
14+
"""A very bread and butter test suite against PngCmp tool
15+
16+
* same_* tests if file A is equal, by checking if A == A
17+
* divergent_* tests if A != B, and B != A
18+
19+
We don't need to actually save the output to anywhere else,
20+
this tool will most likely be reused in other areas anyway. ;)
21+
22+
Args:
23+
SelfExeTests ([type]): [description]
24+
"""
25+
26+
def __init__(self, assets_path: str):
27+
super().__init__("pngcmp", assets_path)
28+
self._png_test_folder = os.path.join(assets_path, "png")
29+
30+
def _collect_tests(self):
31+
return {
32+
"same_black": ["black320x240", "black320x240"],
33+
"same_white": ["white320x240", "white320x240"],
34+
"divergent_black_on_white": ["black320x240", "white320x240"],
35+
"divergent_white_on_black": ["white320x240", "black320x240"]
36+
}
37+
38+
def _subprocess_args(self, test_handle: str, test_params: List):
39+
return [
40+
os.path.join(self._png_test_folder, test_params[0] + ".png"),
41+
os.path.join(self._png_test_folder, test_params[1] + ".png"),
42+
os.devnull
43+
]
44+
45+
def _assert_test_result(self, launch_result: CompletedProcess, test_handle: str, test_params: List):
46+
assert launch_result.returncode == int(test_handle.startswith("divergent")), f"{test_handle} return code == {launch_result.returncode}"
47+
assert launch_result.stderr == "", f"{test_handle} non-empty stderr {launch_result.stderr}"
48+
assert launch_result.stdout == "", f"{test_handle} non-empty stdout {launch_result.stdout}"

regtests/tool_tester/tool_tester/unidasm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class UnidasmTests(SelfExeTests):
3535
(otherwise you get a diff error later on).
3636
3. now run make tests or python $(modulepath)/test_tools.py and check if the new test gets captured.
3737
38+
Args:
39+
SelfExeTests ([type]): [description]
3840
"""
3941

4042
def __init__(self, assets_path: str):
@@ -45,7 +47,7 @@ def __init__(self, assets_path: str):
4547
logging.debug(self._bin_test_folder)
4648

4749
def _collect_tests(self):
48-
__static_tests = zip( os.listdir(self._asm_test_folder), os.listdir(self._bin_test_folder))
50+
__static_tests = zip(os.listdir(self._asm_test_folder), os.listdir(self._bin_test_folder))
4951
return {
5052
__asm.split(".")[0]: UnidasmMapper(asm_filename=__asm, bin_filename=__bin) for __asm, __bin in __static_tests
5153
}

0 commit comments

Comments
 (0)