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

tests/ui: download recorded fixtures from server

This commit is contained in:
Tomas Susanka 2019-12-31 10:28:39 +00:00
parent 3dfbe7aa98
commit ce00fa667a
4 changed files with 47 additions and 13 deletions

View File

@ -1,2 +1,3 @@
*.png
*.html
*.zip

View File

@ -7,7 +7,7 @@ from pathlib import Path
import pytest
from .html import create_diff_doc
from . import html
def _get_test_dirname(node):
@ -74,10 +74,13 @@ def _process_tested(fixture_test_path, test_name):
actual_hash = _hash_files(records)
if actual_hash != expected_hash:
create_diff_doc(fixture_test_path, test_name, actual_hash, expected_hash)
diff_file = html.diff_file(
fixture_test_path, test_name, actual_hash, expected_hash
)
pytest.fail(
"Hash of {} differs.\nExpected: {}\nActual: {}".format(
test_name, expected_hash, actual_hash
"Hash of {} differs.\nExpected: {}\nActual: {}\nDiff file: {}".format(
test_name, expected_hash, actual_hash, diff_file
)
)
else:

View File

@ -0,0 +1,24 @@
import urllib.error
import urllib.request
import zipfile
RECORDS_WEBSITE = "https://firmware.corp.sldev.cz/ui_tests/"
def fetch_recorded(recorded_hash, recorded_path):
zip_src = RECORDS_WEBSITE + recorded_hash + ".zip"
zip_dest = recorded_path / "recorded.zip"
try:
urllib.request.urlretrieve(zip_src, zip_dest)
except urllib.error.HTTPError:
raise RuntimeError("No such recorded collection was found on '%s'." % zip_src)
except urllib.error.URLError:
raise RuntimeError(
"Server firmware.corp.sldev.cz could not be found. Are you on VPN?"
)
with zipfile.ZipFile(zip_dest, "r") as z:
z.extractall(recorded_path)
zip_dest.unlink()

View File

@ -4,14 +4,26 @@ from itertools import zip_longest
import dominate
from dominate.tags import div, h1, hr, i, img, p, table, td, th, tr
from . import download
def create_diff_doc(fixture_test_path, test_name, actual_hash, expected_hash):
def _image(src, fixture_test_path):
with td():
if src:
img(src=src.relative_to(fixture_test_path))
else:
i("missing")
def diff_file(fixture_test_path, test_name, actual_hash, expected_hash):
doc = dominate.document(title=test_name)
recorded_path = fixture_test_path / "recorded"
actual_path = fixture_test_path / "actual"
if not recorded_path.exists():
return
recorded_path.mkdir()
download.fetch_recorded(expected_hash, recorded_path)
recorded = sorted(recorded_path.iterdir())
actual = sorted(actual_path.iterdir())
@ -45,10 +57,4 @@ def create_diff_doc(fixture_test_path, test_name, actual_hash, expected_hash):
f.write(doc.render())
f.close()
def _image(src, fixture_test_path):
with td():
if src:
img(src=src.relative_to(fixture_test_path))
else:
i("missing")
return fixture_test_path / "diff.html"