mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-17 01:52:02 +00:00
fix(tests): do not load every image to learn its width
This commit is contained in:
parent
ed16fefae7
commit
c7b787a2ec
@ -6,7 +6,6 @@ from typing import Iterable
|
|||||||
|
|
||||||
from dominate import document
|
from dominate import document
|
||||||
from dominate.tags import a, i, img, table, td, th, tr
|
from dominate.tags import a, i, img, table, td, th, tr
|
||||||
from PIL import Image
|
|
||||||
|
|
||||||
from ..common import UI_TESTS_DIR
|
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:
|
def image_link(hash: str, cur_dir: Path, title: str = "") -> None:
|
||||||
"""Put image into table as one cell."""
|
"""Put image into table as one cell."""
|
||||||
path = _IMAGE_DIR / f"{hash}.png"
|
path = _IMAGE_DIR / f"{hash}.png"
|
||||||
im = Image.open(path)
|
|
||||||
width = im.width
|
|
||||||
if width < 240:
|
|
||||||
width *= 2
|
|
||||||
|
|
||||||
img(
|
img(
|
||||||
src=_relative_path(cur_dir, path),
|
src=_relative_path(cur_dir, path),
|
||||||
style=f"width: {width}px; image-rendering: pixelated;",
|
|
||||||
title=title,
|
title=title,
|
||||||
loading="lazy",
|
loading="lazy",
|
||||||
)
|
)
|
||||||
|
@ -6,7 +6,6 @@ from contextlib import contextmanager
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import dominate
|
|
||||||
from dominate.tags import br, h1, h2, hr, i, p, table, td, th, tr
|
from dominate.tags import br, h1, h2, hr, i, p, table, td, th, tr
|
||||||
|
|
||||||
from ..common import (
|
from ..common import (
|
||||||
@ -17,7 +16,7 @@ from ..common import (
|
|||||||
screens_diff,
|
screens_diff,
|
||||||
)
|
)
|
||||||
from . import download, html
|
from . import download, html
|
||||||
from .testreport import REPORTS_PATH
|
from .testreport import REPORTS_PATH, document
|
||||||
|
|
||||||
MASTERDIFF_PATH = REPORTS_PATH / "master_diff"
|
MASTERDIFF_PATH = REPORTS_PATH / "master_diff"
|
||||||
IMAGES_PATH = MASTERDIFF_PATH / "images"
|
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, {})
|
master_tests = master_groups.get(group, {})
|
||||||
current_tests = current_groups.get(group, {})
|
current_tests = current_groups.get(group, {})
|
||||||
|
|
||||||
print(f"checking model {model}, group {group}...")
|
|
||||||
|
|
||||||
def testname(test: str) -> str:
|
def testname(test: str) -> str:
|
||||||
assert test.startswith(model + "_")
|
assert test.startswith(model + "_")
|
||||||
test = test[len(model) + 1 :]
|
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:
|
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)
|
screens, hashes = screens_and_hashes(screens_path)
|
||||||
html.store_images(screens, hashes)
|
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:
|
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)
|
screens, hashes = screens_and_hashes(screens_path)
|
||||||
html.store_images(screens, hashes)
|
html.store_images(screens, hashes)
|
||||||
|
|
||||||
@ -146,7 +143,7 @@ def diff(
|
|||||||
master_hash: str,
|
master_hash: str,
|
||||||
current_hash: str,
|
current_hash: str,
|
||||||
) -> Path:
|
) -> 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)
|
master_screens, master_hashes = screens_and_hashes(master_screens_path)
|
||||||
current_screens, current_hashes = screens_and_hashes(current_screens_path)
|
current_screens, current_hashes = screens_and_hashes(current_screens_path)
|
||||||
html.store_images(master_screens, master_hashes)
|
html.store_images(master_screens, master_hashes)
|
||||||
@ -182,7 +179,7 @@ def index() -> Path:
|
|||||||
diff = list((MASTERDIFF_PATH / "diff").iterdir())
|
diff = list((MASTERDIFF_PATH / "diff").iterdir())
|
||||||
|
|
||||||
title = "UI changes from master"
|
title = "UI changes from master"
|
||||||
doc = dominate.document(title=title)
|
doc = document(title=title)
|
||||||
|
|
||||||
with doc:
|
with doc:
|
||||||
h1("UI changes from master")
|
h1("UI changes from master")
|
||||||
|
@ -60,3 +60,8 @@ tr.bad a, tr.bad a:visited {
|
|||||||
.script-hidden {
|
.script-hidden {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.model-T1 img, .model-TR img {
|
||||||
|
image-rendering: pixelated;
|
||||||
|
width: 256px;
|
||||||
|
}
|
||||||
|
@ -27,7 +27,10 @@ ALL_UNIQUE_SCREENS = "all_unique_screens.html"
|
|||||||
|
|
||||||
|
|
||||||
def document(
|
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:
|
) -> dominate.document:
|
||||||
doc = dominate.document(title=title)
|
doc = dominate.document(title=title)
|
||||||
style = t.style()
|
style = t.style()
|
||||||
@ -42,6 +45,9 @@ def document(
|
|||||||
if index:
|
if index:
|
||||||
doc.body["data-index"] = True
|
doc.body["data-index"] = True
|
||||||
|
|
||||||
|
if model:
|
||||||
|
doc.body["class"] = f"model-{model}"
|
||||||
|
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
|
||||||
@ -72,7 +78,7 @@ def setup(main_runner: bool) -> None:
|
|||||||
"""Delete and create the reports dir to clear previous entries."""
|
"""Delete and create the reports dir to clear previous entries."""
|
||||||
if main_runner:
|
if main_runner:
|
||||||
shutil.rmtree(TESTREPORT_PATH, ignore_errors=True)
|
shutil.rmtree(TESTREPORT_PATH, ignore_errors=True)
|
||||||
TESTREPORT_PATH.mkdir()
|
TESTREPORT_PATH.mkdir(parents=True)
|
||||||
(TESTREPORT_PATH / "failed").mkdir()
|
(TESTREPORT_PATH / "failed").mkdir()
|
||||||
(TESTREPORT_PATH / "passed").mkdir()
|
(TESTREPORT_PATH / "passed").mkdir()
|
||||||
(TESTREPORT_PATH / "new").mkdir()
|
(TESTREPORT_PATH / "new").mkdir()
|
||||||
@ -137,16 +143,18 @@ def all_screens() -> Path:
|
|||||||
|
|
||||||
Shows all test-cases at one place.
|
Shows all test-cases at one place.
|
||||||
"""
|
"""
|
||||||
title = "All test cases"
|
recent_tests = list(TestResult.recent_tests())
|
||||||
doc = dominate.document(title=title)
|
model = recent_tests[0].test.model if recent_tests else None
|
||||||
|
|
||||||
|
title = "All test cases"
|
||||||
|
doc = document(title=title, model=model)
|
||||||
with doc:
|
with doc:
|
||||||
h1("All test cases")
|
h1("All test cases")
|
||||||
hr()
|
hr()
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
result_count = 0
|
result_count = 0
|
||||||
for result in TestResult.recent_tests():
|
for result in recent_tests:
|
||||||
result_count += 1
|
result_count += 1
|
||||||
h2(result.test.id, id=result.test.id)
|
h2(result.test.id, id=result.test.id)
|
||||||
for image in result.images:
|
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."""
|
"""Generate an HTML file with all the unique screens from the current test run."""
|
||||||
results = TestResult.recent_tests()
|
results = TestResult.recent_tests()
|
||||||
result_count = 0
|
result_count = 0
|
||||||
|
model = None
|
||||||
test_cases = defaultdict(list)
|
test_cases = defaultdict(list)
|
||||||
for result in results:
|
for result in results:
|
||||||
result_count += 1
|
result_count += 1
|
||||||
|
model = result.test.model
|
||||||
for image in result.images:
|
for image in result.images:
|
||||||
test_cases[image].append(result.test.id)
|
test_cases[image].append(result.test.id)
|
||||||
|
|
||||||
test_case_pairs = sorted(test_cases.items(), key=lambda x: len(x[1]), reverse=True)
|
test_case_pairs = sorted(test_cases.items(), key=lambda x: len(x[1]), reverse=True)
|
||||||
|
|
||||||
title = "All unique screens"
|
title = "All unique screens"
|
||||||
doc = dominate.document(title=title)
|
doc = document(title=title, model=model)
|
||||||
|
|
||||||
with doc:
|
with doc:
|
||||||
h1("All unique screens")
|
h1("All unique screens")
|
||||||
hr()
|
hr()
|
||||||
@ -236,7 +245,9 @@ def failed(result: TestResult) -> Path:
|
|||||||
|
|
||||||
_copy_deduplicated(result.test)
|
_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:
|
with doc:
|
||||||
_header(result.test.id, result.expected_hash, result.actual_hash)
|
_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)
|
_copy_deduplicated(result.test)
|
||||||
|
|
||||||
doc = document(title=result.test.id)
|
doc = document(title=result.test.id, model=result.test.model)
|
||||||
|
|
||||||
with doc:
|
with doc:
|
||||||
_header(result.test.id, result.actual_hash, result.actual_hash)
|
_header(result.test.id, result.actual_hash, result.actual_hash)
|
||||||
|
Loading…
Reference in New Issue
Block a user