2023-01-27 14:13:12 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2020-03-03 14:50:57 +00:00
|
|
|
import urllib.error
|
|
|
|
import urllib.request
|
|
|
|
import zipfile
|
2022-01-28 15:02:17 +00:00
|
|
|
from pathlib import Path
|
2023-01-27 14:13:12 +00:00
|
|
|
from typing import Any
|
2020-03-03 14:50:57 +00:00
|
|
|
|
|
|
|
import requests
|
|
|
|
|
2022-03-22 11:12:11 +00:00
|
|
|
RECORDS_WEBSITE = "https://data.trezor.io/dev/firmware/ui_tests/"
|
2020-03-03 14:50:57 +00:00
|
|
|
FIXTURES_MASTER = "https://raw.githubusercontent.com/trezor/trezor-firmware/master/tests/ui_tests/fixtures.json"
|
2022-01-28 15:02:17 +00:00
|
|
|
FIXTURES_CURRENT = Path(__file__).resolve().parent.parent / "fixtures.json"
|
2020-03-03 14:50:57 +00:00
|
|
|
|
|
|
|
|
2022-01-28 18:26:03 +00:00
|
|
|
def fetch_recorded(hash: str, path: Path) -> None:
|
2020-03-03 14:50:57 +00:00
|
|
|
zip_src = RECORDS_WEBSITE + hash + ".zip"
|
|
|
|
|
|
|
|
try:
|
2024-09-20 13:37:43 +00:00
|
|
|
dest, _ = urllib.request.urlretrieve(zip_src)
|
2020-03-03 14:50:57 +00:00
|
|
|
except urllib.error.HTTPError:
|
2021-09-27 10:13:51 +00:00
|
|
|
raise RuntimeError(f"No such recorded collection was found on '{zip_src}'.")
|
2020-03-03 14:50:57 +00:00
|
|
|
|
2024-09-20 13:37:43 +00:00
|
|
|
with zipfile.ZipFile(dest, "r") as z:
|
2020-03-03 14:50:57 +00:00
|
|
|
z.extractall(path)
|
|
|
|
|
2024-09-20 13:37:43 +00:00
|
|
|
Path(dest).unlink()
|
2020-03-03 14:50:57 +00:00
|
|
|
|
|
|
|
|
2023-01-27 14:13:12 +00:00
|
|
|
def fetch_fixtures_master() -> dict[str, Any]:
|
2020-03-03 14:50:57 +00:00
|
|
|
r = requests.get(FIXTURES_MASTER)
|
|
|
|
r.raise_for_status()
|
|
|
|
return r.json()
|