diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/tools/wpt/create.py | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/tools/wpt/create.py')
-rw-r--r-- | testing/web-platform/tests/tools/wpt/create.py | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/testing/web-platform/tests/tools/wpt/create.py b/testing/web-platform/tests/tools/wpt/create.py new file mode 100644 index 0000000000..27a23ca901 --- /dev/null +++ b/testing/web-platform/tests/tools/wpt/create.py @@ -0,0 +1,133 @@ +# mypy: allow-untyped-defs + +import subprocess +import os + +here = os.path.dirname(__file__) + +template_prefix = """<!doctype html> +%(documentElement)s<meta charset=utf-8> +""" +template_long_timeout = "<meta name=timeout content=long>\n" + +template_body_th = """<title></title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script> + +</script> +""" + +template_body_reftest = """<title></title> +<link rel=%(match)s href=%(ref)s> +""" + +template_body_reftest_wait = """<script src="/common/reftest-wait.js"></script> +""" + +def get_parser(): + import argparse + p = argparse.ArgumentParser() + p.add_argument("--no-editor", action="store_true", + help="Don't try to open the test in an editor") + p.add_argument("-e", "--editor", action="store", help="Editor to use") + p.add_argument("--long-timeout", action="store_true", + help="Test should be given a long timeout (typically 60s rather than 10s, but varies depending on environment)") + p.add_argument("--overwrite", action="store_true", + help="Allow overwriting an existing test file") + p.add_argument("-r", "--reftest", action="store_true", + help="Create a reftest rather than a testharness (js) test"), + p.add_argument("-m", "--reference", dest="ref", help="Path to the reference file") + p.add_argument("--mismatch", action="store_true", + help="Create a mismatch reftest") + p.add_argument("--wait", action="store_true", + help="Create a reftest that waits until takeScreenshot() is called") + p.add_argument("--tests-root", action="store", default=os.path.join(here, "..", ".."), + help="Path to the root of the wpt directory") + p.add_argument("path", action="store", help="Path to the test file") + return p + + + +def rel_path(path, tests_root): + if path is None: + return + + abs_path = os.path.normpath(os.path.abspath(path)) + return os.path.relpath(abs_path, tests_root) + + +def run(_venv, **kwargs): + path = rel_path(kwargs["path"], kwargs["tests_root"]) + ref_path = rel_path(kwargs["ref"], kwargs["tests_root"]) + + if kwargs["ref"]: + kwargs["reftest"] = True + + if ".." in path: + print("""Test path %s is not under wpt root.""" % path) + return 1 + + if ref_path and ".." in ref_path: + print("""Reference path %s is not under wpt root""" % ref_path) + return 1 + + + if os.path.exists(path) and not kwargs["overwrite"]: + print("Test path already exists, pass --overwrite to replace") + return 1 + + if kwargs["mismatch"] and not kwargs["reftest"]: + print("--mismatch only makes sense for a reftest") + return 1 + + if kwargs["wait"] and not kwargs["reftest"]: + print("--wait only makes sense for a reftest") + return 1 + + args = {"documentElement": "<html class=reftest-wait>\n" if kwargs["wait"] else ""} + template = template_prefix % args + if kwargs["long_timeout"]: + template += template_long_timeout + + if kwargs["reftest"]: + args = {"match": "match" if not kwargs["mismatch"] else "mismatch", + "ref": os.path.relpath(ref_path, path) if kwargs["ref"] else '""'} + template += template_body_reftest % args + if kwargs["wait"]: + template += template_body_reftest_wait + else: + template += template_body_th + try: + os.makedirs(os.path.dirname(path)) + except OSError: + pass + with open(path, "w") as f: + f.write(template) + + ref_path = kwargs["ref"] + if ref_path and not os.path.exists(ref_path): + with open(ref_path, "w") as f: + f.write(template_prefix % {"documentElement": ""}) + + if kwargs["no_editor"]: + editor = None + elif kwargs["editor"]: + editor = kwargs["editor"] + elif "VISUAL" in os.environ: + editor = os.environ["VISUAL"] + elif "EDITOR" in os.environ: + editor = os.environ["EDITOR"] + else: + editor = None + + proc = None + if editor: + if ref_path: + path = f"{path} {ref_path}" + proc = subprocess.Popen(f"{editor} {path}", shell=True) + else: + print("Created test %s" % path) + + if proc: + proc.wait() |