mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-29 16:51:30 +00:00
refactor(tests/ui): properly propagate model css class
This commit is contained in:
parent
2523597c2a
commit
a4f8d2b877
@ -186,7 +186,8 @@ def _get_test_name_and_group(node_id: str) -> tuple[str, str]:
|
|||||||
return shortened_name, group_name
|
return shortened_name, group_name
|
||||||
|
|
||||||
|
|
||||||
def get_screen_path(test_name: str) -> Path | None:
|
def get_screen_path(test_case: TestCase) -> Path | None:
|
||||||
|
test_name = test_case.id
|
||||||
path = SCREENS_DIR / test_name / "actual"
|
path = SCREENS_DIR / test_name / "actual"
|
||||||
if path.exists():
|
if path.exists():
|
||||||
return path
|
return path
|
||||||
|
@ -36,7 +36,7 @@ LEGACY_MODEL_NAMES = {
|
|||||||
|
|
||||||
|
|
||||||
def generate_master_diff_report(
|
def generate_master_diff_report(
|
||||||
diff_tests: dict[str, tuple[str, str]], base_dir: Path
|
diff_tests: dict[TestCase, tuple[str, str]], base_dir: Path
|
||||||
) -> None:
|
) -> None:
|
||||||
unique_differing_screens = _get_unique_differing_screens(diff_tests, base_dir)
|
unique_differing_screens = _get_unique_differing_screens(diff_tests, base_dir)
|
||||||
_differing_screens_report(unique_differing_screens, base_dir)
|
_differing_screens_report(unique_differing_screens, base_dir)
|
||||||
@ -46,7 +46,7 @@ def get_diff(
|
|||||||
current: FixturesType,
|
current: FixturesType,
|
||||||
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[TestCase, str], dict[TestCase, str], dict[TestCase, tuple[str, str]]]:
|
||||||
master = _preprocess_master_compat(download.fetch_fixtures_master())
|
master = _preprocess_master_compat(download.fetch_fixtures_master())
|
||||||
|
|
||||||
removed = {}
|
removed = {}
|
||||||
@ -63,30 +63,28 @@ def get_diff(
|
|||||||
master_tests = master_groups.get(group, {})
|
master_tests = master_groups.get(group, {})
|
||||||
current_tests = current_groups.get(group, {})
|
current_tests = current_groups.get(group, {})
|
||||||
|
|
||||||
def testname(test: str) -> str:
|
def testkey(test: str) -> TestCase:
|
||||||
case = TestCase.from_fixtures(test, group)
|
return TestCase.from_fixtures(test, group)
|
||||||
model = LEGACY_MODEL_NAMES.get(case.model, case.model)
|
|
||||||
return case.replace(model=model).id
|
|
||||||
|
|
||||||
# removed items
|
# removed items
|
||||||
removed_here = {
|
removed_here = {
|
||||||
testname(test): master_tests[test]
|
testkey(test): master_tests[test]
|
||||||
for test in (master_tests.keys() - current_tests.keys())
|
for test in (master_tests.keys() - current_tests.keys())
|
||||||
}
|
}
|
||||||
# added items
|
# added items
|
||||||
added_here = {
|
added_here = {
|
||||||
testname(test): current_tests[test]
|
testkey(test): current_tests[test]
|
||||||
for test in (current_tests.keys() - master_tests.keys())
|
for test in (current_tests.keys() - master_tests.keys())
|
||||||
}
|
}
|
||||||
# create the diff from items in both branches
|
# create the diff from items in both branches
|
||||||
diff_here = {}
|
diff_here = {}
|
||||||
for master_test, master_hash in master_tests.items():
|
for master_test, master_hash in master_tests.items():
|
||||||
full_test_name = testname(master_test)
|
key = testkey(master_test)
|
||||||
if full_test_name in removed_here:
|
if key in removed_here:
|
||||||
continue
|
continue
|
||||||
if current_tests.get(master_test) == master_hash:
|
if current_tests.get(master_test) == master_hash:
|
||||||
continue
|
continue
|
||||||
diff_here[full_test_name] = (
|
diff_here[key] = (
|
||||||
master_tests[master_test],
|
master_tests[master_test],
|
||||||
current_tests[master_test],
|
current_tests[master_test],
|
||||||
)
|
)
|
||||||
@ -152,12 +150,13 @@ def _preprocess_master_compat(master_fixtures: dict[str, Any]) -> FixturesType:
|
|||||||
|
|
||||||
def _create_testcase_html_diff_file(
|
def _create_testcase_html_diff_file(
|
||||||
zipped_screens: list[tuple[str | None, str | None]],
|
zipped_screens: list[tuple[str | None, str | None]],
|
||||||
test_name: str,
|
test_case: TestCase,
|
||||||
master_hash: str,
|
master_hash: str,
|
||||||
current_hash: str,
|
current_hash: str,
|
||||||
base_dir: Path,
|
base_dir: Path,
|
||||||
) -> Path:
|
) -> Path:
|
||||||
doc = document(title=test_name, model=test_name[:2])
|
test_name = test_case.id
|
||||||
|
doc = document(title=test_name, model=test_case.model)
|
||||||
with doc:
|
with doc:
|
||||||
h1(test_name)
|
h1(test_name)
|
||||||
p("This UI test differs from master.", style="color: grey; font-weight: bold;")
|
p("This UI test differs from master.", style="color: grey; font-weight: bold;")
|
||||||
@ -181,10 +180,11 @@ def _create_testcase_html_diff_file(
|
|||||||
|
|
||||||
|
|
||||||
def _differing_screens_report(
|
def _differing_screens_report(
|
||||||
unique_differing_screens: dict[tuple[str | None, str | None], str], base_dir: Path
|
unique_differing_screens: dict[tuple[str | None, str | None], TestCase],
|
||||||
|
base_dir: Path,
|
||||||
) -> None:
|
) -> None:
|
||||||
try:
|
try:
|
||||||
model = next(iter(unique_differing_screens.values()))[:2]
|
model = next(iter(unique_differing_screens.values())).model
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
model = ""
|
model = ""
|
||||||
|
|
||||||
@ -207,21 +207,21 @@ def _differing_screens_report(
|
|||||||
html.image_column(current, base_dir)
|
html.image_column(current, base_dir)
|
||||||
html.diff_column()
|
html.diff_column()
|
||||||
with td():
|
with td():
|
||||||
with a(href=f"diff/{testcase}.html"):
|
with a(href=f"diff/{testcase.id}.html"):
|
||||||
i(testcase)
|
i(testcase.id)
|
||||||
|
|
||||||
html.write(base_dir, doc, "master_diff.html")
|
html.write(base_dir, doc, "master_diff.html")
|
||||||
|
|
||||||
|
|
||||||
def _get_unique_differing_screens(
|
def _get_unique_differing_screens(
|
||||||
diff_tests: dict[str, tuple[str, str]], base_dir: Path
|
diff_tests: dict[TestCase, tuple[str, str]], base_dir: Path
|
||||||
) -> dict[tuple[str | None, str | None], str]:
|
) -> dict[tuple[str | None, str | None], TestCase]:
|
||||||
|
|
||||||
# Holding unique screen differences, connected with a certain testcase
|
# Holding unique screen differences, connected with a certain testcase
|
||||||
# Used for diff report
|
# Used for diff report
|
||||||
unique_differing_screens: dict[tuple[str | None, str | None], str] = {}
|
unique_differing_screens: dict[tuple[str | None, str | None], TestCase] = {}
|
||||||
|
|
||||||
for test_name, (master_hash, current_hash) in diff_tests.items():
|
for test_case, (master_hash, current_hash) in diff_tests.items():
|
||||||
# Downloading master recordings only if we do not have them already
|
# Downloading master recordings only if we do not have them already
|
||||||
master_screens_path = MASTER_CACHE_DIR / master_hash
|
master_screens_path = MASTER_CACHE_DIR / master_hash
|
||||||
if not master_screens_path.exists():
|
if not master_screens_path.exists():
|
||||||
@ -233,7 +233,7 @@ def _get_unique_differing_screens(
|
|||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
print("WARNING:", e)
|
print("WARNING:", e)
|
||||||
|
|
||||||
current_screens_path = get_screen_path(test_name)
|
current_screens_path = get_screen_path(test_case)
|
||||||
if not current_screens_path:
|
if not current_screens_path:
|
||||||
current_screens_path = MASTER_CACHE_DIR / "empty_current_screens"
|
current_screens_path = MASTER_CACHE_DIR / "empty_current_screens"
|
||||||
current_screens_path.mkdir(exist_ok=True)
|
current_screens_path.mkdir(exist_ok=True)
|
||||||
@ -254,12 +254,12 @@ def _get_unique_differing_screens(
|
|||||||
|
|
||||||
# Create testcase HTML report
|
# Create testcase HTML report
|
||||||
_create_testcase_html_diff_file(
|
_create_testcase_html_diff_file(
|
||||||
zipped_screens, test_name, master_hash, current_hash, base_dir
|
zipped_screens, test_case, master_hash, current_hash, base_dir
|
||||||
)
|
)
|
||||||
|
|
||||||
# Save differing screens for differing screens report
|
# Save differing screens for differing screens report
|
||||||
for master, current in zipped_screens:
|
for master, current in zipped_screens:
|
||||||
if master != current:
|
if master != current:
|
||||||
unique_differing_screens[(master, current)] = test_name
|
unique_differing_screens[(master, current)] = test_case
|
||||||
|
|
||||||
return unique_differing_screens
|
return unique_differing_screens
|
||||||
|
@ -115,20 +115,20 @@ def create_reports(models: list[str] | None = None) -> None:
|
|||||||
with tempfile.TemporaryDirectory(prefix="trezor-records-") as temp_dir:
|
with tempfile.TemporaryDirectory(prefix="trezor-records-") as temp_dir:
|
||||||
yield Path(temp_dir)
|
yield Path(temp_dir)
|
||||||
|
|
||||||
for test_name, test_hash in removed_tests.items():
|
for test_case, test_hash in removed_tests.items():
|
||||||
with tmpdir() as temp_dir:
|
with tmpdir() as temp_dir:
|
||||||
try:
|
try:
|
||||||
download.fetch_recorded(test_hash, temp_dir)
|
download.fetch_recorded(test_hash, temp_dir)
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
print("Could not download recorded files for", test_name)
|
print("Could not download recorded files for", test_case.id)
|
||||||
continue
|
continue
|
||||||
removed(temp_dir, test_name)
|
removed(temp_dir, test_case.id)
|
||||||
|
|
||||||
for test_name, test_hash in added_tests.items():
|
for test_case, test_hash in added_tests.items():
|
||||||
screen_path = get_screen_path(test_name)
|
screen_path = get_screen_path(test_case)
|
||||||
if not screen_path:
|
if not screen_path:
|
||||||
continue
|
continue
|
||||||
added(screen_path, test_name)
|
added(screen_path, test_case.id)
|
||||||
|
|
||||||
generate_master_diff_report(diff_tests, MASTERDIFF_PATH)
|
generate_master_diff_report(diff_tests, MASTERDIFF_PATH)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user