diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/tools/wave/utils | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/tools/wave/utils')
4 files changed, 208 insertions, 0 deletions
diff --git a/testing/web-platform/tests/tools/wave/utils/__init__.py b/testing/web-platform/tests/tools/wave/utils/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testing/web-platform/tests/tools/wave/utils/__init__.py diff --git a/testing/web-platform/tests/tools/wave/utils/deserializer.py b/testing/web-platform/tests/tools/wave/utils/deserializer.py new file mode 100644 index 0000000000..28d1054f6b --- /dev/null +++ b/testing/web-platform/tests/tools/wave/utils/deserializer.py @@ -0,0 +1,118 @@ +# mypy: allow-untyped-defs + +from ..data.session import Session, UNKNOWN +from datetime import datetime +import dateutil.parser +from dateutil.tz import tzutc + + +def deserialize_sessions(session_dicts): + sessions = [] + for session_dict in session_dicts: + session = deserialize_session(session_dict) + sessions.append(session) + return sessions + + +def deserialize_session(session_dict): + token = "" + if "token" in session_dict: + token = session_dict["token"] + tests = {"include": [], "exclude": []} + if "tests" in session_dict: + tests = session_dict["tests"] + if "path" in session_dict: + test_paths = session_dict["path"].split(", ") + tests["include"] = tests["include"] + test_paths + test_types = [] + if "types" in session_dict: + test_types = session_dict["types"] + user_agent = "" + if "user_agent" in session_dict: + user_agent = session_dict["user_agent"] + labels = [] + if "labels" in session_dict: + labels = session_dict["labels"] + timeouts = {} + if "timeouts" in session_dict: + timeouts = session_dict["timeouts"] + pending_tests = None + if "pending_tests" in session_dict: + pending_tests = session_dict["pending_tests"] + running_tests = None + if "running_tests" in session_dict: + running_tests = session_dict["running_tests"] + status = UNKNOWN + if "status" in session_dict: + status = session_dict["status"] + test_state = None + if "test_state" in session_dict: + test_state = session_dict["test_state"] + last_completed_test = None + if "last_completed_test" in session_dict: + last_completed_test = session_dict["last_completed_test"] + date_created = None + if "date_created" in session_dict: + date_created = session_dict["date_created"] + date_created = iso_to_millis(date_created) + date_started = None + if "date_started" in session_dict: + date_started = session_dict["date_started"] + date_started = iso_to_millis(date_started) + date_finished = None + if "date_finished" in session_dict: + date_finished = session_dict["date_finished"] + date_finished = iso_to_millis(date_finished) + is_public = False + if "is_public" in session_dict: + is_public = session_dict["is_public"] + reference_tokens = [] + if "reference_tokens" in session_dict: + reference_tokens = session_dict["reference_tokens"] + browser = None + if "browser" in session_dict: + browser = session_dict["browser"] + expiration_date = None + if "expiration_date" in session_dict: + expiration_date = session_dict["expiration_date"] + expiration_date = iso_to_millis(expiration_date) + type = None + if "type" in session_dict: + type = session_dict["type"] + malfunctioning_tests = [] + if "malfunctioning_tests" in session_dict: + malfunctioning_tests = session_dict["malfunctioning_tests"] + + return Session( + token=token, + tests=tests, + test_types=test_types, + user_agent=user_agent, + labels=labels, + timeouts=timeouts, + pending_tests=pending_tests, + running_tests=running_tests, + status=status, + test_state=test_state, + last_completed_test=last_completed_test, + date_created=date_created, + date_started=date_started, + date_finished=date_finished, + is_public=is_public, + reference_tokens=reference_tokens, + browser=browser, + expiration_date=expiration_date, + type=type, + malfunctioning_tests=malfunctioning_tests + ) + +def iso_to_millis(iso_string): + if iso_string is None: + return None + try: + date = dateutil.parser.isoparse(iso_string) + date = date.replace(tzinfo=tzutc()) + epoch = datetime.utcfromtimestamp(0).replace(tzinfo=tzutc()) + return int((date - epoch).total_seconds() * 1000) + except Exception: + return iso_string diff --git a/testing/web-platform/tests/tools/wave/utils/serializer.py b/testing/web-platform/tests/tools/wave/utils/serializer.py new file mode 100644 index 0000000000..995365081d --- /dev/null +++ b/testing/web-platform/tests/tools/wave/utils/serializer.py @@ -0,0 +1,47 @@ +# mypy: allow-untyped-defs + +from datetime import datetime + + +def serialize_session(session): + return { + "token": session.token, + "types": session.test_types, + "user_agent": session.user_agent, + "labels": session.labels, + "timeouts": session.timeouts, + "test_state": session.test_state, + "last_completed_test": session.last_completed_test, + "tests": session.tests, + "pending_tests": session.pending_tests, + "running_tests": session.running_tests, + "status": session.status, + "browser": session.browser, + "date_created": millis_to_iso(session.date_created), + "date_started": millis_to_iso(session.date_started), + "date_finished": millis_to_iso(session.date_finished), + "is_public": session.is_public, + "reference_tokens": session.reference_tokens, + "expiration_date": millis_to_iso(session.expiration_date), + "type": session.type, + "malfunctioning_tests": session.malfunctioning_tests + } + +def serialize_sessions(sessions): + serialized_sessions = [] + for session in sessions: + serialized_sessions.append(serialize_session(session)) + return serialized_sessions + +def serialize_device(device): + return { + "token": device.token, + "user_agent": device.user_agent, + "name": device.name, + "last_active": millis_to_iso(device.last_active) + } + +def millis_to_iso(millis): + if millis is None: + return None + return datetime.utcfromtimestamp(millis/1000.0).isoformat() + "+00:00" diff --git a/testing/web-platform/tests/tools/wave/utils/user_agent_parser.py b/testing/web-platform/tests/tools/wave/utils/user_agent_parser.py new file mode 100644 index 0000000000..d1da820b53 --- /dev/null +++ b/testing/web-platform/tests/tools/wave/utils/user_agent_parser.py @@ -0,0 +1,43 @@ +# mypy: allow-untyped-defs + +from ua_parser import user_agent_parser + + +def parse_user_agent(user_agent_string): + user_agent = user_agent_parser.ParseUserAgent(user_agent_string) + + name = user_agent["family"] + version = "0" + + if user_agent["major"] is not None: + version = user_agent["major"] + + if user_agent["minor"] is not None: + version = version + "." + user_agent["minor"] + + if user_agent["patch"] is not None: + version = version + "." + user_agent["patch"] + + return { + "name": name, + "version": version + } + + +def abbreviate_browser_name(name): + short_names = { + "Chrome": "Ch", + "Chrome Mobile WebView": "Ch", + "Chromium": "Cm", + "WebKit": "Wk", + "Safari": "Sf", + "Firefox": "FF", + "IE": "IE", + "Edge": "Ed", + "Opera": "Op" + } + + if name in short_names: + return short_names[name] + else: + return "Xx" |