# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # flake8: noqa: E501
try: import cPickle as pickle except ImportError: import pickle
import json import os import re from collections import defaultdict
import manifestupdate import mozpack.path as mozpath import mozunit import pytest from mozbuild.frontend.reader import BuildReader from mozbuild.test.common import MockConfig from moztest.resolve import (
TEST_SUITES,
BuildBackendLoader,
TestManifestLoader,
TestResolver,
)
here = os.path.abspath(os.path.dirname(__file__))
data_path = os.path.join(here, "data")
# Normalize paths to ensure that the fixture matches reality. for k in [ "ancestor_manifest", "manifest", "manifest_relpath", "path", "relpath",
]:
p = test.get(k) if p:
test[k] = p.replace("/", os.path.sep)
tests[path].append(test)
# dump tests to stdout for easier debugging on failure
print("The 'create_tests' fixture returned:")
print(json.dumps(dict(tests), indent=2, sort_keys=True)) return tests
# This matches the format of "test-defaults.pkl", which is generated by # testing/mozbase/manifestparser/manifestparser/manifestparser.py and # test_test_defaults_metadata_with_include_and_ancestor_manifest in # python/mozbuild/mozbuild/test/backend/test_test_manifest.py verifies that # the format is as expected. return {
(to_abspath("dragonfruit/elderberry/xpcshell_updater.toml")): { "support-files": "data/**\nxpcshell_updater.toml"
},
(
to_ancestor_manifest_path("carrot/xpcshell-one.toml"),
to_abspath("carrot/xpcshell-shared.toml"),
): { "head": "head_one.js",
},
(
to_ancestor_manifest_path("carrot/xpcshell-two.toml"),
to_abspath("carrot/xpcshell-shared.toml"),
): { "head": "head_two.js",
},
}
class WPTManifestNamespace: """Stand-in object for various WPT classes."""
def fake_wpt_manifestupdate(topsrcdir, *args, **kwargs): with open(os.path.join(topsrcdir, "wpt_manifest_data.json")) as fh:
data = json.load(fh)
items = {} for tests_root, test_data in data.items():
kwargs = {"tests_path": os.path.join(topsrcdir, tests_root)}
for test_type, tests in test_data.items(): for test in tests:
obj = WPTManifestNamespace() if"mozilla"in tests_root:
obj.id = "/_mozilla/" + test else:
obj.id = "/" + test
if loader_cls == BuildBackendLoader: with open(os.path.join(topobjdir, "all-tests.pkl"), "wb") as fh:
pickle.dump(all_tests, fh) with open(os.path.join(topobjdir, "test-defaults.pkl"), "wb") as fh:
pickle.dump(defaults, fh)
# The mock data already exists, so prevent BuildBackendLoader from regenerating # the build information from the whole gecko tree... class BuildBackendLoaderNeverOutOfDate(BuildBackendLoader): def backend_out_of_date(self, backend_file): returnFalse
loader_cls = BuildBackendLoaderNeverOutOfDate
# Patch WPT's manifestupdate.run to return tests based on the contents of # 'data/srcdir/wpt_manifest_data.json'.
monkeypatch.setattr(manifestupdate, "run", fake_wpt_manifestupdate)
# Simulate a prior full build by creating the harness install manifest.
manifests_dir = os.path.join(topobjdir, "_build_manifests", "install")
os.makedirs(manifests_dir) with open(os.path.join(manifests_dir, "_tests"), "w") as fh:
fh.write("")
# No _build_manifests/install/_tests was created; install must be skipped # to avoid leaving a half-populated _tests/ tree. assert list(loader()) assert calls == ["gen"]
for test in tests: if test["manifest"].endswith("xpcshell_updater.toml"): assert test["support-files"] == expected_support_files else: assert"support-files"notin test
def test_cwd_children_only(resolver): """If cwd is defined, only resolve tests under the specified cwd.""" # Pretend we're under '/services' and ask for 'common'. This should # pick up all tests from '/services/common'
tests = list(
resolver.resolve_tests(
paths=["currant"], cwd=os.path.join(resolver.topsrcdir, "banana")
)
)
assert len(tests) == 2
# Tests should be rewritten to objdir. for t in tests: assert t["here"] == mozpath.join(
resolver.topobjdir, "_tests/xpcshell/banana/currant"
)
def test_various_cwd(resolver): """Test various cwd conditions are all equal."""
expected = list(resolver.resolve_tests(paths=["banana"]))
actual = list(resolver.resolve_tests(paths=["banana"], cwd="/")) assert actual == expected
actual = list(resolver.resolve_tests(paths=["banana"], cwd=resolver.topsrcdir)) assert actual == expected
actual = list(resolver.resolve_tests(paths=["banana"], cwd=resolver.topobjdir)) assert actual == expected
def test_wildcard_patterns(resolver): """Test matching paths by wildcard."""
tests = list(resolver.resolve_tests(paths=["fig/**"])) assert len(tests) == 2 for t in tests: assert t["file_relpath"].startswith("fig")
tests = list(resolver.resolve_tests(paths=["**/**.js", "apple/**"])) assert len(tests) == 9 for t in tests:
path = t["file_relpath"] assert path.startswith("apple") or path.endswith(".js")
suites, tests = resolver.resolve_metadata([ "mochitest-a11y", "/browser", "xpcshell",
]) assert suites == {"mochitest-a11y", "xpcshell"} assert sorted(t["file_relpath"] for t in tests) == [ "juniper/browser_chrome.js", "kiwi/browser_devtools.js",
]
def test_resolve_metadata_root_path(resolver): """Test that a suite's root_path resolves as a suite dispatch."""
suites, tests = resolver.resolve_metadata(["mobile/android/fenix"]) assert suites == {"fenix"} assert tests == []
def test_resolve_metadata_subdir_not_suite(resolver): """Test that a subdirectory within a suite root resolves individual tests."""
suites, tests = resolver.resolve_metadata(["banana/currant"]) assert suites == set() assert len(tests) == 2 for t in tests: assert t["file_relpath"].startswith("banana/currant")
def test_resolve_metadata_file_not_suite(resolver): """Test that a specific file within a suite root resolves as a test."""
suites, tests = resolver.resolve_metadata(["apple/test_a11y.html"]) assert suites == set() assert len(tests) == 1 assert tests[0]["file_relpath"] == "apple/test_a11y.html"
def test_ancestor_manifest_defaults(resolver, topsrcdir, defaults): """Test that defaults from ancestor manifests are found."""
tests = list(resolver._resolve(paths=["carrot/test_included.js"])) assert len(tests) == 2
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.