mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-20 05:28:14 +00:00

WIP - refactor and extend font generation for non-ascii characters WIP - add czech characters mapping between UTF8 value and index WIP - regenerate font files with czech characters WIP - shorten czech button text, it was causing SHUTDOWN for some reason WIP - support UTF8 characters in fonts.c WIP - account for translation in tests WIP - small fixes WIP - fix last test WIP - support UTF8 also in Rust font operations WIP - add a script to find non-translated english strings in micropython code WIP - add a validator script for checking missing micropython translations WIP - translate remaining altcoins and other apps in core (fido, sdcard, TT layouts, ...) WIP - generate czech glyphs for TT fonts WIP - modify gen_font.py to account for negative bearing czech characters WIP - extend translation validation scripts, move them into core/tools WIP - translate TT layouts in Rust WIP - fix tests WIP - fix inverse coloring of nonprintable glyph WIP - add build and test pipelines for Czech language WIP - merge both JSON files together WIP - run new isort WIP - unify all the translation in Rust, expose to micropython TEMP - leave en_merged.json file, so it is accessible by translators with old link WIP - fixes WIP - add french characters and translation via Google Translator WIP - skip rustfmt in mako-created files WIP - revert all the font height changes causing false-positive UI diff WIP - fixes after rebase WIP - fix broken translations WIP - revert some wording changes causing UI diff WIP - improve validation and translate scripts, translate missing strings WIP - sort all keys alphabetically WIP - remove any usage of translation in bootloader WIP - add newline at the end of JSON file WIP - fix bitcoin-only strings check WIP - fix python support check WIP - add some missing translations WIP - fix SD card device test WIP - fix pystyle WIP - fix rust unittests WIP - fix click tests WIP - flag errors in french translations WIP - add script transferring translations data into a byte blob WIP - regenerate fr.rs WIP - store and read language translations from flash WIP - storing language name in storage WIP - sending language_data in apply_settings protobuf message WIP - separate protobuf message for translations, fixes WIP - set up translations area for TT as well WIP - get rid of TREZOR_LANG env variable during build WIP - make the firmware buildable for TT WIP - add basic device tests WIP - set language for tests WIP - counting with language when writing fixtures WIP - add todos WIP - fix CI WIP - unify translations, make titles CAPITAL WIP - translate missing english WIP - skip translations messages for T1 WIP - not changing tests names for english WIP - fix flake8 WIP - no test language setting for T1 WIP - clippy lint about complex data type WIP - fix some english UI diff for TR WIP - fix cstyle WIP - minimize the usage of #[cfg(feature = "micropython")] outside translations module WIP - minimize TT's UI diff WIP - fix ruststyle WIP - fix TR build WIP - advanced Shamir text change WIP - storing the language name as the first item in the translation data WIP - modify and extend tests after storing language name WIP - modify checklist sentence WIP - add TEST_LANG into Makefile for all the emu tests WIP - default arguments WIP - reimplement default arguments remove unneeded pub from get_info function WIP - Rust handling of object attributes lookups from upy - thanks Matejcik! WIP - generate mock interface for attribute-based translations lookups WIP - change function calls to object attributes WIP - symbolic link for unix/translations.c WIP - fix and improve the reading of translations - thanks Matejcik! WIP - add support for multiple languages in removing missing tests WIP - fix multiple-accounts warning in tests WIP - fix encoding of newlines in translations WIP - fix czech tutorial text WIP - fix czech click tests WIP - do not translate wire error messages WIP - add language options to click tests as well WIP - setup czech device tests in CI WIP - setup czech click tests in CI WIP - record czech device tests for TR WIP - record czech click tests for TR WIP - record czech device tests for TT WIP - record czech click tests for TT WIP - pystyle WIP - cstyle WIP - fix Rust micropython import dependency WIP - fix czech recordings WIP - support french translations in tests WIP - shorten some french words to fix the tests WIP - fix micropython cfg compilation WIP - record french click tests for TR WIP - record french device tests for TR WIP - record french device tests for TT WIP - record french click tests for TT WIP - fix french translations - shorten them WIP - translate missing french words WIP - fix click tests WIP - add french tests into CI WIP - pystyle WIP - allow for czech/french tests in update script WIP - update czech fixtures WIP - update french fixtures WIP - ruststyle WIP - disallow MPU to run it on hardware WIP - cstyle WIP - change translations delimiter from * to \x00 WIP - change translations protobufs WIP - remove language handling from storage WIP - add header into JSON files WIP - count with header in translations blob WIP - yml style fixes WIP - fix proto gen WIP - verify version and data hash WIP - fix loading test translations feat(core): allow access to translations area in firmware [no changelog] WIP - fixes after rebase WIP - increase the TT's translations area to 3 sectors WIP - dynamically read the maximum translations size WIP - record non-english tests from CI WIP - loading font data from translations blob WIP - bump translations version WIP - include czech and french glyph data WIP - whitelist another negative-bearing glyph WIP - remove czech/french glyphs from common font files WIP - fix language tests WIP - specific fonts for specific models WIP - revert the non-ascii font hardcoding WIP - include missing BIG font into nonprintable logic WIP - minor Rust code improvements WIP - include newlines at the end of json files WIP - move glyph Rust function to librust_fonts.h WIP - add all fonts into translations file WIP - move fonts into its own dir WIP - reflect separate dir for fonts WIP - not putting translations trezorhal into bootloader WIP - write and read multiple fonts into translations data WIP - silence pyright issue/notissue WIP - delete no more used translations/*.py imports WIP - fix bootloader builds by introducing translations feature and TRANSLATIONS flag WIP - fix TT's bootloader Rust build WIP - fix tests in non-english languages WIP - not search for UTF-8 when there are no translations data WIP - add colons to strings where missing WIP - fix language loading in tests WIP - fix signmessage input flow to work in all languages WIP - create offset table for translation strings WIP - code improvements WIP - record foreign language fixtures + sync with main in english WIP - do alignment check before reading u16 data WIP - allocate blob in RAM for translations data WIP - add TODO for blob generation WIP - record non-english device tests WIP - use bytes.align_to instead of messing with pointers WIP - fixtures WIP - remove unused import WIP - add order.py WIP - add order.json WIP - take order.json into account in creating general.rs WIP - take order.json into account in generating the blob WIP - style WIP - sort the language files WIP - remove unused file WIP - code improvements WIP - add TODO for homescreen notification WIP - translate plural forms WIP - translate time intervals WIP - sign translations with dev keys, validate signatures, improve robustness WIP - improve tests for translations WIP - add `trezorctl utils sign-translations` for production signing of the blob WIP - pyright fix WIP - changing TR progress loader offset - it was colliding with title WIP - show indeterminate loader when loading translations data WIP - record new and updated language tests WIP - show the change language title/prompt in the target language WIP - sort keys WIP - add crowdin-cli into shell.nix WIP - add crowdin sync script
245 lines
8.2 KiB
Python
245 lines
8.2 KiB
Python
from pathlib import Path
|
|
from typing import Any
|
|
|
|
import dominate
|
|
import dominate.tags as t
|
|
from dominate.tags import a, h1, hr, i, p, table, td, th, tr
|
|
|
|
from ..common import (
|
|
UI_TESTS_DIR,
|
|
FixturesType,
|
|
get_screen_path,
|
|
screens_and_hashes,
|
|
screens_diff,
|
|
)
|
|
from . import download, html
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
|
|
STYLE = (HERE / "testreport.css").read_text()
|
|
SCRIPT = (HERE / "testreport.js").read_text()
|
|
GIF_SCRIPT = (HERE / "create-gif.js").read_text()
|
|
|
|
REPORTS_PATH = UI_TESTS_DIR / "reports"
|
|
|
|
# Saving the master screens on disk not to fetch them all the time
|
|
MASTER_CACHE_DIR = HERE / "master_cache"
|
|
if not MASTER_CACHE_DIR.exists():
|
|
MASTER_CACHE_DIR.mkdir()
|
|
|
|
|
|
def generate_master_diff_report(
|
|
diff_tests: dict[str, tuple[str, str]], base_dir: Path
|
|
) -> None:
|
|
unique_differing_screens = _get_unique_differing_screens(diff_tests, base_dir)
|
|
_differing_screens_report(unique_differing_screens, base_dir)
|
|
|
|
|
|
def get_diff(
|
|
current: FixturesType, print_to_console: bool = False
|
|
) -> tuple[dict[str, str], dict[str, str], dict[str, tuple[str, str]]]:
|
|
master = _get_preprocessed_master_fixtures()
|
|
|
|
removed = {}
|
|
added = {}
|
|
diff = {}
|
|
|
|
for model in master.keys() | current.keys():
|
|
master_groups = master.get(model, {})
|
|
current_groups = current.get(model, {})
|
|
for group in master_groups.keys() | current_groups.keys():
|
|
master_tests = master_groups.get(group, {})
|
|
current_tests = current_groups.get(group, {})
|
|
|
|
def testname(test: str) -> str:
|
|
assert test.startswith(model + "_")
|
|
test = test[len(model) + 1 :]
|
|
return f"{model}-{group}-{test}"
|
|
|
|
# removed items
|
|
removed_here = {
|
|
testname(test): master_tests[test]
|
|
for test in (master_tests.keys() - current_tests.keys())
|
|
}
|
|
# added items
|
|
added_here = {
|
|
testname(test): current_tests[test]
|
|
for test in (current_tests.keys() - master_tests.keys())
|
|
}
|
|
# create the diff from items in both branches
|
|
diff_here = {}
|
|
for master_test, master_hash in master_tests.items():
|
|
full_test_name = testname(master_test)
|
|
if full_test_name in removed_here:
|
|
continue
|
|
if current_tests.get(master_test) == master_hash:
|
|
continue
|
|
diff_here[full_test_name] = (
|
|
master_tests[master_test],
|
|
current_tests[master_test],
|
|
)
|
|
|
|
removed.update(removed_here)
|
|
added.update(added_here)
|
|
diff.update(diff_here)
|
|
if print_to_console:
|
|
print(f"{model} {group}")
|
|
print(f" removed: {len(removed_here)}")
|
|
print(f" added: {len(added_here)}")
|
|
print(f" diff: {len(diff_here)}")
|
|
|
|
return removed, added, diff
|
|
|
|
|
|
def document(
|
|
title: str,
|
|
actual_hash: str | None = None,
|
|
index: bool = False,
|
|
model: str | None = None,
|
|
) -> dominate.document:
|
|
doc = dominate.document(title=title)
|
|
style = t.style()
|
|
style.add_raw_string(STYLE)
|
|
script = t.script()
|
|
script.add_raw_string(GIF_SCRIPT)
|
|
script.add_raw_string(SCRIPT)
|
|
doc.head.add(style, script)
|
|
|
|
if actual_hash is not None:
|
|
doc.body["data-actual-hash"] = actual_hash
|
|
|
|
if index:
|
|
doc.body["data-index"] = True
|
|
|
|
if model:
|
|
doc.body["class"] = f"model-{model}"
|
|
|
|
return doc
|
|
|
|
|
|
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 = {}
|
|
for key, val in master_fixtures.items():
|
|
model, _test = key.split("_", maxsplit=1)
|
|
groups_by_model = new_fixtures.setdefault(model, {})
|
|
default_group = groups_by_model.setdefault("device_tests", {})
|
|
default_group[key] = val
|
|
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(
|
|
zipped_screens: list[tuple[str | None, str | None]],
|
|
test_name: str,
|
|
master_hash: str,
|
|
current_hash: str,
|
|
base_dir: Path,
|
|
) -> Path:
|
|
doc = document(title=test_name, model=test_name[:2])
|
|
with doc:
|
|
h1(test_name)
|
|
p("This UI test differs from master.", style="color: grey; font-weight: bold;")
|
|
with table():
|
|
with tr():
|
|
td("Master:")
|
|
td(master_hash, style="color: red;")
|
|
with tr():
|
|
td("Current:")
|
|
td(current_hash, style="color: green;")
|
|
hr()
|
|
|
|
with table(border=1, width=600):
|
|
with tr():
|
|
th("Master")
|
|
th("Current branch")
|
|
|
|
html.diff_table(zipped_screens, base_dir / "diff")
|
|
|
|
return html.write(base_dir / "diff", doc, test_name + ".html")
|
|
|
|
|
|
def _differing_screens_report(
|
|
unique_differing_screens: dict[tuple[str | None, str | None], str], base_dir: Path
|
|
) -> None:
|
|
try:
|
|
model = next(iter(unique_differing_screens.values()))[:2]
|
|
except StopIteration:
|
|
model = ""
|
|
|
|
doc = document(title="Master differing screens", model=model)
|
|
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, base_dir)
|
|
html.image_column(current, base_dir)
|
|
with td():
|
|
with a(href=f"diff/{testcase}.html"):
|
|
i(testcase)
|
|
|
|
html.write(base_dir, doc, "master_diff.html")
|
|
|
|
|
|
def _get_unique_differing_screens(
|
|
diff_tests: dict[str, tuple[str, str]], base_dir: Path
|
|
) -> dict[tuple[str | None, str | None], str]:
|
|
|
|
# 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():
|
|
# Downloading master recordings only if we do not have them already
|
|
master_screens_path = MASTER_CACHE_DIR / master_hash
|
|
if not master_screens_path.exists():
|
|
master_screens_path.mkdir()
|
|
# master_hash may be empty, in case of new test
|
|
if master_hash:
|
|
try:
|
|
download.fetch_recorded(master_hash, master_screens_path)
|
|
except RuntimeError as e:
|
|
print("WARNING:", e)
|
|
|
|
current_screens_path = get_screen_path(test_name)
|
|
if not current_screens_path:
|
|
current_screens_path = MASTER_CACHE_DIR / "empty_current_screens"
|
|
current_screens_path.mkdir(exist_ok=True)
|
|
|
|
# Saving all the images to a common directory
|
|
# They will be referenced from the HTML files
|
|
if master_hash:
|
|
master_screens, master_hashes = screens_and_hashes(master_screens_path)
|
|
else:
|
|
master_screens, master_hashes = [], []
|
|
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, master_hash, current_hash, base_dir
|
|
)
|
|
|
|
# Save differing screens for differing screens report
|
|
for master, current in zipped_screens:
|
|
if master != current:
|
|
unique_differing_screens[(master, current)] = test_name
|
|
|
|
return unique_differing_screens
|