1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 09:28:13 +00:00

fix(tests): do not load every image to learn its width

This commit is contained in:
matejcik 2023-02-01 15:52:04 +01:00 committed by matejcik
parent ed16fefae7
commit c7b787a2ec
4 changed files with 30 additions and 24 deletions

View File

@ -6,7 +6,6 @@ from typing import Iterable
from dominate import document
from dominate.tags import a, i, img, table, td, th, tr
from PIL import Image
from ..common import UI_TESTS_DIR
@ -74,14 +73,8 @@ def _relative_path(cur_dir: Path, path_to: Path) -> str:
def image_link(hash: str, cur_dir: Path, title: str = "") -> None:
"""Put image into table as one cell."""
path = _IMAGE_DIR / f"{hash}.png"
im = Image.open(path)
width = im.width
if width < 240:
width *= 2
img(
src=_relative_path(cur_dir, path),
style=f"width: {width}px; image-rendering: pixelated;",
title=title,
loading="lazy",
)

View File

@ -6,7 +6,6 @@ from contextlib import contextmanager
from pathlib import Path
from typing import Any
import dominate
from dominate.tags import br, h1, h2, hr, i, p, table, td, th, tr
from ..common import (
@ -17,7 +16,7 @@ from ..common import (
screens_diff,
)
from . import download, html
from .testreport import REPORTS_PATH
from .testreport import REPORTS_PATH, document
MASTERDIFF_PATH = REPORTS_PATH / "master_diff"
IMAGES_PATH = MASTERDIFF_PATH / "images"
@ -52,8 +51,6 @@ def get_diff() -> tuple[dict[str, str], dict[str, str], dict[str, tuple[str, str
master_tests = master_groups.get(group, {})
current_tests = current_groups.get(group, {})
print(f"checking model {model}, group {group}...")
def testname(test: str) -> str:
assert test.startswith(model + "_")
test = test[len(model) + 1 :]
@ -92,7 +89,7 @@ def get_diff() -> tuple[dict[str, str], dict[str, str], dict[str, tuple[str, str
def removed(screens_path: Path, test_name: str) -> Path:
doc = dominate.document(title=test_name)
doc = document(title=test_name, model=test_name[:2])
screens, hashes = screens_and_hashes(screens_path)
html.store_images(screens, hashes)
@ -116,7 +113,7 @@ def removed(screens_path: Path, test_name: str) -> Path:
def added(screens_path: Path, test_name: str) -> Path:
doc = dominate.document(title=test_name)
doc = document(title=test_name, model=test_name[:2])
screens, hashes = screens_and_hashes(screens_path)
html.store_images(screens, hashes)
@ -146,7 +143,7 @@ def diff(
master_hash: str,
current_hash: str,
) -> Path:
doc = dominate.document(title=test_name)
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)
@ -182,7 +179,7 @@ def index() -> Path:
diff = list((MASTERDIFF_PATH / "diff").iterdir())
title = "UI changes from master"
doc = dominate.document(title=title)
doc = document(title=title)
with doc:
h1("UI changes from master")

View File

@ -60,3 +60,8 @@ tr.bad a, tr.bad a:visited {
.script-hidden {
display: none;
}
.model-T1 img, .model-TR img {
image-rendering: pixelated;
width: 256px;
}

View File

@ -27,7 +27,10 @@ ALL_UNIQUE_SCREENS = "all_unique_screens.html"
def document(
title: str, actual_hash: str | None = None, index: bool = False
title: str,
actual_hash: str | None = None,
index: bool = False,
model: str | None = None,
) -> dominate.document:
doc = dominate.document(title=title)
style = t.style()
@ -42,6 +45,9 @@ def document(
if index:
doc.body["data-index"] = True
if model:
doc.body["class"] = f"model-{model}"
return doc
@ -72,7 +78,7 @@ def setup(main_runner: bool) -> None:
"""Delete and create the reports dir to clear previous entries."""
if main_runner:
shutil.rmtree(TESTREPORT_PATH, ignore_errors=True)
TESTREPORT_PATH.mkdir()
TESTREPORT_PATH.mkdir(parents=True)
(TESTREPORT_PATH / "failed").mkdir()
(TESTREPORT_PATH / "passed").mkdir()
(TESTREPORT_PATH / "new").mkdir()
@ -137,16 +143,18 @@ def all_screens() -> Path:
Shows all test-cases at one place.
"""
title = "All test cases"
doc = dominate.document(title=title)
recent_tests = list(TestResult.recent_tests())
model = recent_tests[0].test.model if recent_tests else None
title = "All test cases"
doc = document(title=title, model=model)
with doc:
h1("All test cases")
hr()
count = 0
result_count = 0
for result in TestResult.recent_tests():
for result in recent_tests:
result_count += 1
h2(result.test.id, id=result.test.id)
for image in result.images:
@ -164,17 +172,18 @@ def all_unique_screens() -> Path:
"""Generate an HTML file with all the unique screens from the current test run."""
results = TestResult.recent_tests()
result_count = 0
model = None
test_cases = defaultdict(list)
for result in results:
result_count += 1
model = result.test.model
for image in result.images:
test_cases[image].append(result.test.id)
test_case_pairs = sorted(test_cases.items(), key=lambda x: len(x[1]), reverse=True)
title = "All unique screens"
doc = dominate.document(title=title)
doc = document(title=title, model=model)
with doc:
h1("All unique screens")
hr()
@ -236,7 +245,9 @@ def failed(result: TestResult) -> Path:
_copy_deduplicated(result.test)
doc = document(title=result.test.id, actual_hash=result.actual_hash)
doc = document(
title=result.test.id, actual_hash=result.actual_hash, model=result.test.model
)
with doc:
_header(result.test.id, result.expected_hash, result.actual_hash)
@ -279,7 +290,7 @@ def recorded(result: TestResult, header: str = "Recorded") -> Path:
"""
_copy_deduplicated(result.test)
doc = document(title=result.test.id)
doc = document(title=result.test.id, model=result.test.model)
with doc:
_header(result.test.id, result.actual_hash, result.actual_hash)