From c7b787a2ec66340ab5acd53161e6c15d412c0f22 Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 1 Feb 2023 15:52:04 +0100 Subject: [PATCH] fix(tests): do not load every image to learn its width --- tests/ui_tests/reporting/html.py | 7 ------ tests/ui_tests/reporting/master_diff.py | 13 +++++------ tests/ui_tests/reporting/testreport.css | 5 +++++ tests/ui_tests/reporting/testreport.py | 29 +++++++++++++++++-------- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/tests/ui_tests/reporting/html.py b/tests/ui_tests/reporting/html.py index 793bd0fb99..20f8b2e46d 100644 --- a/tests/ui_tests/reporting/html.py +++ b/tests/ui_tests/reporting/html.py @@ -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", ) diff --git a/tests/ui_tests/reporting/master_diff.py b/tests/ui_tests/reporting/master_diff.py index 0c706d37d2..f889c6a5fd 100644 --- a/tests/ui_tests/reporting/master_diff.py +++ b/tests/ui_tests/reporting/master_diff.py @@ -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") diff --git a/tests/ui_tests/reporting/testreport.css b/tests/ui_tests/reporting/testreport.css index 6397b34318..db9f284f53 100644 --- a/tests/ui_tests/reporting/testreport.css +++ b/tests/ui_tests/reporting/testreport.css @@ -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; +} diff --git a/tests/ui_tests/reporting/testreport.py b/tests/ui_tests/reporting/testreport.py index 932bc718bb..95a4b1382e 100644 --- a/tests/ui_tests/reporting/testreport.py +++ b/tests/ui_tests/reporting/testreport.py @@ -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)