diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/tools/metadata/meta | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/tools/metadata/meta')
4 files changed, 108 insertions, 0 deletions
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 --- /dev/null +++ b/testing/web-platform/tests/tools/metadata/meta/__init__.py 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 --- /dev/null +++ b/testing/web-platform/tests/tools/metadata/meta/tests/__init__.py 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)) |