feat(tests): prepare UI testing for T1

pull/2131/head
grdddj 2 years ago committed by matejcik
parent 58fb6c77a7
commit 9e654abdb3

@ -15,7 +15,7 @@
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
import os
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Generator
import pytest
@ -62,7 +62,9 @@ def _raw_client(request: pytest.FixtureRequest) -> Client:
@pytest.fixture(scope="function")
def client(request: pytest.FixtureRequest, _raw_client: Client) -> Client:
def client(
request: pytest.FixtureRequest, _raw_client: Client
) -> Generator[Client, None, None]:
"""Client fixture.
Every test function that requires a client instance will get it from here.

@ -22,6 +22,10 @@ FILE_HASHES: Dict[str, str] = {}
ACTUAL_HASHES: Dict[str, str] = {}
PROCESSED: Set[str] = set()
# T1/TT, to be set in screen_recording(), as we do not know it beforehand
# TODO: it is not the cleanest, we could create a class out of this file
MODEL = ""
def get_test_name(node_id: str) -> str:
# Test item name is usually function name, but when parametrization is used,
@ -103,6 +107,13 @@ def screen_recording(
) -> Generator[None, None, None]:
test_ui = request.config.getoption("ui")
test_name = get_test_name(request.node.nodeid)
# Differentiating test names between T1 and TT
# Making the model global for other functions
global MODEL
MODEL = f"T{client.features.model}"
test_name = f"{MODEL}_{test_name}"
screens_test_path = SCREENS_DIR / test_name
if test_ui == "record":
@ -133,7 +144,11 @@ def screen_recording(
def list_missing() -> Set[str]:
return set(FILE_HASHES.keys()) - PROCESSED
# Only listing the ones for the current model
relevant_cases = {
case for case in FILE_HASHES.keys() if case.startswith(f"{MODEL}_")
}
return relevant_cases - PROCESSED
def read_fixtures() -> None:
@ -153,7 +168,12 @@ def write_fixtures_suggestion(remove_missing: bool) -> None:
def _get_fixtures_content(fixtures: Dict[str, str], remove_missing: bool) -> str:
if remove_missing:
fixtures = {i: fixtures[i] for i in PROCESSED}
# Not removing the ones for different model
nonrelevant_cases = {
f: h for f, h in FILE_HASHES.items() if not f.startswith(f"{MODEL}_")
}
processed_fixtures = {i: fixtures[i] for i in PROCESSED}
fixtures = {**nonrelevant_cases, **processed_fixtures}
else:
fixtures = fixtures

Loading…
Cancel
Save