From db74b549e38af10c7ea008ade5db69504572127f Mon Sep 17 00:00:00 2001 From: WeizhongX <77710146+WeizhongX@users.noreply.github.com> Date: Mon, 22 Feb 2021 21:55:42 +0000 Subject: [PATCH] Bug 1692937 [wpt PR 27636] - new parameter --include-file for wptrunner, a=testonly Automatic update from web-platform-tests new parameter --include-file for wptrunner (#27636) * new parameter --include-file for wptrunner Add new command line parameter --include-file for wptrunner, so that we can load test cases from a file. -- wpt-commits: 1d2b75901ed1158d557695c58294ac5f78bd492e wpt-pr: 27636 --- .../tests/tools/wptrunner/wptrunner/testloader.py | 10 ++++++++++ .../wptrunner/wptrunner/tests/test_testloader.py | 23 ++++++++++++++++++++++ .../tools/wptrunner/wptrunner/wptcommandline.py | 2 ++ .../tests/tools/wptrunner/wptrunner/wptrunner.py | 2 ++ 4 files changed, 37 insertions(+) diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/testloader.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/testloader.py index 727149269a46..346fe2a27208 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/testloader.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/testloader.py @@ -50,6 +50,16 @@ class TestGroupsFile(object): def __getitem__(self, key): return self._data[key] +def read_include_from_file(file): + new_include = [] + with open(file) as f: + for line in f: + line = line.strip() + # Allow whole-line comments; + # fragments mean we can't have partial line #-based comments + if len(line) > 0 and not line.startswith("#"): + new_include.append(line) + return new_include def update_include_for_groups(test_groups, include): if include is None: diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_testloader.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_testloader.py index 394d2a00177b..f68bb5fb33a8 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_testloader.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_testloader.py @@ -8,6 +8,7 @@ import pytest from mozlog import structured from ..testloader import TestFilter as Filter, TestLoader as Loader +from ..testloader import read_include_from_file from .test_wpttest import make_mock_manifest here = os.path.dirname(__file__) @@ -58,6 +59,28 @@ def test_loader_h2_tests(): assert len(loader.disabled_tests["testharness"]) == 1 assert loader.disabled_tests["testharness"][0].url == "/a/bar.h2.html" +@pytest.mark.xfail(sys.platform == "win32", + reason="NamedTemporaryFile cannot be reopened on Win32") +def test_include_file(): + test_cases = """ +# This is a comment +/foo/bar-error.https.html +/foo/bar-success.https.html +/foo/idlharness.https.any.html +/foo/idlharness.https.any.worker.html + """ + + with tempfile.NamedTemporaryFile(mode="wt") as f: + f.write(test_cases) + f.flush() + + include = read_include_from_file(f.name) + + assert len(include) == 4 + assert "/foo/bar-error.https.html" in include + assert "/foo/bar-success.https.html" in include + assert "/foo/idlharness.https.any.html" in include + assert "/foo/idlharness.https.any.worker.html" in include @pytest.mark.xfail(sys.platform == "win32", reason="NamedTemporaryFile cannot be reopened on Win32") diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptcommandline.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptcommandline.py index 31250e916172..29d6fe5070f7 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptcommandline.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptcommandline.py @@ -131,6 +131,8 @@ scheme host and port.""") help="Test types to run") test_selection_group.add_argument("--include", action="append", help="URL prefix to include") + test_selection_group.add_argument("--include-file", action="store", + help="A file listing URL prefix for tests") test_selection_group.add_argument("--exclude", action="append", help="URL prefix to exclude") test_selection_group.add_argument("--include-manifest", type=abs_path, diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptrunner.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptrunner.py index 65c542b642b3..0294e8720ac2 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptrunner.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptrunner.py @@ -65,6 +65,8 @@ def get_loader(test_paths, product, debug=None, run_info_extras=None, chunker_kw manifest_filters = [] include = kwargs["include"] + if kwargs["include_file"]: + include.extend(testloader.read_include_from_file(kwargs["include_file"])) if test_groups: include = testloader.update_include_for_groups(test_groups, include) -- 2.11.4.GIT