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

fix(tests/ui): fix failing master diffs

This commit is contained in:
matejcik 2024-04-30 13:36:04 +02:00 committed by Ioan Bizău
parent 421b2d8db1
commit 2523597c2a
2 changed files with 36 additions and 18 deletions

View File

@ -7,7 +7,7 @@ import shutil
import typing as t import typing as t
import warnings import warnings
from copy import deepcopy from copy import deepcopy
from dataclasses import asdict, dataclass, field from dataclasses import asdict, dataclass, field, replace
from difflib import SequenceMatcher from difflib import SequenceMatcher
from functools import cached_property from functools import cached_property
from itertools import zip_longest from itertools import zip_longest
@ -256,6 +256,11 @@ class TestCase:
def fixtures_name(self) -> str: def fixtures_name(self) -> str:
return f"{self.model}_{self.language}_{self.name}" return f"{self.model}_{self.language}_{self.name}"
@classmethod
def from_fixtures(cls, fixtures_name: str, group: str) -> Self:
model, lang, name = fixtures_name.split("_", maxsplit=2)
return cls(model=model, group=group, name=name, language=lang)
@property @property
def dir(self) -> Path: def dir(self) -> Path:
return SCREENS_DIR / self.id return SCREENS_DIR / self.id
@ -292,6 +297,9 @@ class TestCase:
result.save_metadata() result.save_metadata()
return result return result
def replace(self, **kwargs) -> Self:
return replace(self, **kwargs)
@dataclass @dataclass
class TestResult: class TestResult:

View File

@ -8,6 +8,7 @@ from dominate.tags import a, h1, hr, i, p, script, table, td, th, tr
from ..common import ( from ..common import (
UI_TESTS_DIR, UI_TESTS_DIR,
FixturesType, FixturesType,
TestCase,
get_screen_path, get_screen_path,
screens_and_hashes, screens_and_hashes,
screens_diff, screens_diff,
@ -27,6 +28,12 @@ MASTER_CACHE_DIR = HERE / "master_cache"
if not MASTER_CACHE_DIR.exists(): if not MASTER_CACHE_DIR.exists():
MASTER_CACHE_DIR.mkdir() MASTER_CACHE_DIR.mkdir()
LEGACY_MODEL_NAMES = {
"T1": "T1B1",
"TT": "T2T1",
"TR": "T2B1",
}
def generate_master_diff_report( def generate_master_diff_report(
diff_tests: dict[str, tuple[str, str]], base_dir: Path diff_tests: dict[str, tuple[str, str]], base_dir: Path
@ -40,7 +47,7 @@ def get_diff(
print_to_console: bool = False, print_to_console: bool = False,
models: list[str] | None = None, models: list[str] | None = None,
) -> tuple[dict[str, str], dict[str, str], dict[str, tuple[str, str]]]: ) -> tuple[dict[str, str], dict[str, str], dict[str, tuple[str, str]]]:
master = _get_preprocessed_master_fixtures() master = _preprocess_master_compat(download.fetch_fixtures_master())
removed = {} removed = {}
added = {} added = {}
@ -57,9 +64,9 @@ def get_diff(
current_tests = current_groups.get(group, {}) current_tests = current_groups.get(group, {})
def testname(test: str) -> str: def testname(test: str) -> str:
assert test.startswith(model + "_") case = TestCase.from_fixtures(test, group)
test = test[len(model) + 1 :] model = LEGACY_MODEL_NAMES.get(case.model, case.model)
return f"{model}-{group}-{test}" return case.replace(model=model).id
# removed items # removed items
removed_here = { removed_here = {
@ -123,21 +130,24 @@ def document(
def _preprocess_master_compat(master_fixtures: dict[str, Any]) -> FixturesType: def _preprocess_master_compat(master_fixtures: dict[str, Any]) -> FixturesType:
if all(isinstance(v, str) for v in master_fixtures.values()):
# old format, convert to new format
new_fixtures = {} new_fixtures = {}
for key, val in master_fixtures.items(): for model, groups_by_model in master_fixtures.items():
model, _test = key.split("_", maxsplit=1) if model not in LEGACY_MODEL_NAMES:
groups_by_model = new_fixtures.setdefault(model, {}) new_fixtures[model] = groups_by_model
default_group = groups_by_model.setdefault("device_tests", {}) continue
default_group[key] = val
# (a) replace model group name
model = LEGACY_MODEL_NAMES.get(model)
new_groups_by_model = new_fixtures.setdefault(model, {})
for group, tests_by_group in groups_by_model.items():
new_tests_by_group = new_groups_by_model.setdefault(group, {})
for key, val in tests_by_group.items():
case = TestCase.from_fixtures(key, group)
# (b) in individual testcases, replace model name prefix
new_case = case.replace(model=model)
new_tests_by_group[new_case.fixtures_name] = val
return FixturesType(new_fixtures) return FixturesType(new_fixtures)
else:
return FixturesType(master_fixtures)
def _get_preprocessed_master_fixtures() -> FixturesType:
return _preprocess_master_compat(download.fetch_fixtures_master())
def _create_testcase_html_diff_file( def _create_testcase_html_diff_file(