class Creator(object): def __init__(self, topsrcdir, test, suite, doc, **kwargs):
self.topsrcdir = topsrcdir
self.test = test
self.suite = suite
self.doc = doc
self.kwargs = kwargs
def check_args(self): """Perform any validation required for suite-specific arguments""" returnTrue
def __iter__(self): """Iterate over a list of (path, data) tuples corresponding to the files
to be created""" yield (self.test, self._get_template_contents())
@classmethod def get_parser(cls, parser):
parser.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)",
)
parser.add_argument( "-m", "--reference", dest="ref", help="Path to the reference file"
)
parser.add_argument( "--mismatch", action="store_true", help="Create a mismatch reftest"
)
parser.add_argument( "--wait",
action="store_true",
help="Create a reftest that waits until takeScreenshot() is called",
)
def check_args(self): if self.wpt_type(self.test) isNone:
print( """Test path %s is not in wpt directories:
testing/web-platform/tests for tests that may be shared
testing/web-platform/mozilla/tests for Gecko-only tests"""
% self.test
) returnFalse
ifnot self.reftest: if self.kwargs["ref"]:
print("--ref only makes sense for a reftest") returnFalse
if self.kwargs["mismatch"]:
print("--mismatch only makes sense for a reftest") returnFalse
if self.kwargs["wait"]:
print("--wait only makes sense for a reftest") returnFalse else: # Set the ref to a url relative to the test if self.kwargs["ref"]: if self.ref_path(self.kwargs["ref"]) isNone:
print("--ref doesn't refer to a path inside web-platform-tests") returnFalse
def ref_path(self, path): # The ref parameter can be one of several things # 1. An absolute path to a reference file # 2. A path to a file relative to the topsrcdir # 3. A path relative to the test file # These are not unambiguous, so it's somewhat best effort
if os.path.isabs(path):
path = os.path.normpath(path) ifnot path.startswith(self.topsrcdir): # Path is an absolute URL relative to the tests root if path.startswith("/_mozilla/"):
base = self.local_path
path = path[len("/_mozilla/") :] else:
base = self.upstream_path
path = path[1:]
path = path.replace("/", os.sep) return os.path.join(base, path) else: return self.src_rel_path(path) else: if self.wpt_type(path) isnotNone: return path else:
test_rel_path = self.src_rel_path(
os.path.join(os.path.dirname(self.test), path)
) if self.wpt_type(test_rel_path) isnotNone: return test_rel_path # Returning None indicates that the path wasn't valid
if path[0] == "/"and len(path) < len(ref_path): # This is an absolute url return path
# Othewise it's a file path
wpt_type_ref = self.wpt_type(ref_path)
wpt_type_test = self.wpt_type(self.test) if wpt_type_ref == wpt_type_test: return os.path.relpath(ref_path, os.path.dirname(self.test))
# If we have a local test referencing an upstream ref, # or vice-versa use absolute paths if wpt_type_ref == "upstream":
rel_path = os.path.relpath(ref_path, self.upstream_path)
url_base = "/" elif wpt_type_ref == "local":
rel_path = os.path.relpath(ref_path, self.local_path)
url_base = "/_mozilla/" else: returnNone return url_base + rel_path.replace(os.path.sep, "/")
# Insert a new test in the right place def update_toml_or_ini(manifest_prefix, testpath):
basedir = os.path.dirname(testpath)
manifest_file = os.path.join(basedir, manifest_prefix + ".toml") ifnot os.path.isfile(manifest_file):
manifest_file = os.path.join(basedir, manifest_prefix + ".ini") ifnot os.path.isfile(manifest_file):
print("Could not open manifest file {}".format(manifest_file)) return
filename = os.path.basename(testpath)
write_to_manifest_file(manifest_file, filename)
# Insert a new test in the right place within a given manifest file def write_to_manifest_file(manifest_file, filename):
use_toml = manifest_file.endswith(".toml")
manifest = manifestparser.TestManifest(manifests=[manifest_file], use_toml=use_toml)
insert_before = None
if any(t["name"] == filename for t in manifest.tests):
print("{} is already in the manifest.".format(filename)) return
for test in manifest.tests: if test.get("name") > filename:
insert_before = test.get("name") break
with open(manifest_file, "r") as f:
contents = f.readlines()
ifnot insert_before:
contents.append(filename) else:
insert_before = entry_line.format(insert_before) for i in range(len(contents)): if contents[i].startswith(insert_before):
contents.insert(i, filename) break
with io.open(manifest_file, "w", newline="\n") as f:
f.write("".join(contents))
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 ist noch experimentell.