1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 14:28:07 +00:00

feat(tests): master diff creating different_screens.html report

This commit is contained in:
grdddj 2023-04-12 12:23:55 +02:00 committed by Jiří Musil
parent aa9f848b70
commit 2b71a44fd3

View File

@ -6,7 +6,7 @@ from contextlib import contextmanager
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
from dominate.tags import br, h1, h2, hr, i, p, table, td, th, tr from dominate.tags import a, br, h1, h2, hr, i, p, table, td, th, tr
from ..common import ( from ..common import (
SCREENS_DIR, SCREENS_DIR,
@ -138,19 +138,13 @@ def added(screens_path: Path, test_name: str) -> Path:
return html.write(MASTERDIFF_PATH / "added", doc, test_name + ".html") return html.write(MASTERDIFF_PATH / "added", doc, test_name + ".html")
def diff( def create_testcase_html_diff_file(
master_screens_path: Path, zipped_screens: list[tuple[str | None, str | None]],
current_screens_path: Path,
test_name: str, test_name: str,
master_hash: str, master_hash: str,
current_hash: str, current_hash: str,
) -> Path: ) -> Path:
doc = document(title=test_name, model=test_name[:2]) doc = document(title=test_name, model=test_name[:2])
master_screens, master_hashes = screens_and_hashes(master_screens_path)
current_screens, current_hashes = screens_and_hashes(current_screens_path)
html.store_images(master_screens, master_hashes)
html.store_images(current_screens, current_hashes)
with doc: with doc:
h1(test_name) h1(test_name)
p("This UI test differs from master.", style="color: grey; font-weight: bold;") p("This UI test differs from master.", style="color: grey; font-weight: bold;")
@ -168,9 +162,7 @@ def diff(
th("Master") th("Master")
th("Current branch") th("Current branch")
html.diff_table( html.diff_table(zipped_screens, MASTERDIFF_PATH / "diff")
screens_diff(master_hashes, current_hashes), MASTERDIFF_PATH / "diff"
)
return html.write(MASTERDIFF_PATH / "diff", doc, test_name + ".html") return html.write(MASTERDIFF_PATH / "diff", doc, test_name + ".html")
@ -249,28 +241,72 @@ def create_reports() -> None:
continue continue
added(screen_path, test_name) added(screen_path, test_name)
# Holding unique screen differences, connected with a certain testcase
# Used for diff report
unique_differing_screens: dict[tuple[str | None, str | None], str] = {}
for test_name, (master_hash, current_hash) in diff_tests.items(): for test_name, (master_hash, current_hash) in diff_tests.items():
with tmpdir() as master_root: with tmpdir() as master_root:
master_screens = master_root / "downloaded" master_screens_path = master_root / "downloaded"
master_screens.mkdir() master_screens_path.mkdir()
try: try:
download.fetch_recorded(master_hash, master_screens) download.fetch_recorded(master_hash, master_screens_path)
except RuntimeError as e: except RuntimeError as e:
print("WARNING:", e) print("WARNING:", e)
current_screens = _get_screen_path(test_name) current_screens_path = _get_screen_path(test_name)
if not current_screens: if not current_screens_path:
current_screens = master_root / "empty_current_screens" current_screens_path = master_root / "empty_current_screens"
current_screens.mkdir() current_screens_path.mkdir()
diff( # Saving all the images to a common directory
master_screens, # They will be referenced from the HTML files
current_screens, master_screens, master_hashes = screens_and_hashes(master_screens_path)
current_screens, current_hashes = screens_and_hashes(current_screens_path)
html.store_images(master_screens, master_hashes)
html.store_images(current_screens, current_hashes)
# List of tuples of master and current screens
# Useful for both testcase HTML report and the differing screen report
zipped_screens = list(screens_diff(master_hashes, current_hashes))
# Create testcase HTML report
create_testcase_html_diff_file(
zipped_screens,
test_name, test_name,
master_hash, master_hash,
current_hash, current_hash,
) )
# Save differing screens for differing screens report
for master, current in zipped_screens:
if master != current:
unique_differing_screens[(master, current)] = test_name
differing_screens_report(unique_differing_screens)
def differing_screens_report(
unique_differing_screens: dict[tuple[str | None, str | None], str]
) -> None:
doc = document(title="Master differing screens")
with doc:
with table(border=1, width=600):
with tr():
th("Expected")
th("Actual")
th("Testcase (link)")
for (master, current), testcase in unique_differing_screens.items():
with tr(bgcolor="red"):
html.image_column(master, MASTERDIFF_PATH)
html.image_column(current, MASTERDIFF_PATH)
with td():
with a(href=f"diff/{testcase}.html"):
i(testcase)
html.write(MASTERDIFF_PATH, doc, "differing_screens.html")
def main() -> None: def main() -> None:
create_dirs() create_dirs()