From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../tests/tools/metadata/meta/__init__.py | 0 .../tests/tools/metadata/meta/schema.py | 31 +++++++++ .../tests/tools/metadata/meta/tests/__init__.py | 0 .../tests/tools/metadata/meta/tests/test_schema.py | 77 ++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 testing/web-platform/tests/tools/metadata/meta/__init__.py create mode 100644 testing/web-platform/tests/tools/metadata/meta/schema.py create mode 100644 testing/web-platform/tests/tools/metadata/meta/tests/__init__.py create mode 100644 testing/web-platform/tests/tools/metadata/meta/tests/test_schema.py (limited to 'testing/web-platform/tests/tools/metadata/meta') diff --git a/testing/web-platform/tests/tools/metadata/meta/__init__.py b/testing/web-platform/tests/tools/metadata/meta/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/testing/web-platform/tests/tools/metadata/meta/schema.py b/testing/web-platform/tests/tools/metadata/meta/schema.py new file mode 100644 index 0000000000..b3c5673619 --- /dev/null +++ b/testing/web-platform/tests/tools/metadata/meta/schema.py @@ -0,0 +1,31 @@ +from dataclasses import dataclass +from typing import Any, ClassVar, Dict, List, Optional, Set + +from ..schema import SchemaValue, validate_dict + +""" +YAML filename for meta files +""" +META_YML_FILENAME = "META.yml" + +@dataclass +class MetaFile(): + """documented structure of META files. + Reference: https://github.com/web-platform-tests/wpt/pull/18434 + """ + + """a link to the specification covered by the tests in the directory""" + spec: Optional[str] = None + """a list of GitHub account username belonging to people who are notified when pull requests + modify files in the directory + """ + suggested_reviewers: Optional[List[str]] = None + + _optional_keys: ClassVar[Set[str]] = {"spec", "suggested_reviewers"} + + def __init__(self, obj: Dict[str, Any]): + validate_dict(obj, optional_keys=MetaFile._optional_keys) + self.spec = SchemaValue.from_union([SchemaValue.from_str, SchemaValue.from_none], obj.get("spec")) + self.suggested_reviewers = SchemaValue.from_union( + [lambda x: SchemaValue.from_list(SchemaValue.from_str, x), SchemaValue.from_none], + obj.get("suggested_reviewers")) diff --git a/testing/web-platform/tests/tools/metadata/meta/tests/__init__.py b/testing/web-platform/tests/tools/metadata/meta/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/testing/web-platform/tests/tools/metadata/meta/tests/test_schema.py b/testing/web-platform/tests/tools/metadata/meta/tests/test_schema.py new file mode 100644 index 0000000000..31e13f356b --- /dev/null +++ b/testing/web-platform/tests/tools/metadata/meta/tests/test_schema.py @@ -0,0 +1,77 @@ +# mypy: allow-untyped-defs + +from dataclasses import asdict +from ..schema import MetaFile + +import pytest +import re + +@pytest.mark.parametrize( + "input,expected_result,expected_exception_type,exception_message", + [ + ( + { + "spec": "spec-value", + "suggested_reviewers": ["reviewer_1", "reviewer_2"] + }, + { + "spec": "spec-value", + "suggested_reviewers": ["reviewer_1", "reviewer_2"] + }, + None, + None + ), + ( + { + "spec": "spec-value", + }, + { + "spec": "spec-value", + "suggested_reviewers": None, + }, + None, + None + ), + ( + { + "suggested_reviewers": ["reviewer_1", "reviewer_2"] + }, + { + "spec": None, + "suggested_reviewers": ["reviewer_1", "reviewer_2"], + }, + None, + None + ), + ( + {}, + {"spec": None, "suggested_reviewers": None}, + None, + None + ), + ( + { + "spec": "spec-value", + "suggested_reviewers": ["reviewer_1", 3] + }, + None, + ValueError, + "Input value ['reviewer_1', 3] does not fit one of the expected values for the union" + ), + ( + { + "spec": "spec-value", + "suggested_reviewers": ["reviewer_1", "reviewer_2"], + "extra": "test" + }, + None, + ValueError, + "Object contains invalid keys: ['extra']" + ), + ]) +def test_meta_file(input, expected_result, expected_exception_type, exception_message): + if expected_exception_type: + with pytest.raises(expected_exception_type, match=re.escape(exception_message)): + MetaFile(input) + else: + assert expected_result == asdict(MetaFile(input)) -- cgit v1.2.3