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"
|
|
|
|
zip_dest = path / "recorded.zip"
|
|
|
|
|
|
|
|
try:
|
|
|
|
urllib.request.urlretrieve(zip_src, zip_dest)
|
|
|
|
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
|
|
|
|
|
|
|
with zipfile.ZipFile(zip_dest, "r") as z:
|
|
|
|
z.extractall(path)
|
|
|
|
|
|
|
|
zip_dest.unlink()
|
|
|
|
|
|
|
|
|
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()
|