This is an automated email from the ASF dual-hosted git repository. jimjag pushed a commit to branch odf-devel in repository https://gitbox.apache.org/repos/asf/openoffice.git
commit b9065085114f6b2ef9d33f5189a658085609dd34 Author: Jim Jagielski <[email protected]> AuthorDate: Mon Oct 26 11:55:09 2026 -0400 test/odf-validate: check the ODF 1.2 Part 3 package rules --- test/odf-validate/.gitignore | 1 + test/odf-validate/README.md | 6 ++ test/odf-validate/fetch-schemas.sh | 1 + test/odf-validate/idcheck.py | 5 +- test/odf-validate/make-controls.py | 2 + test/odf-validate/make-pkg-controls.py | 101 ++++++++++++++++++ test/odf-validate/pkgcheck.py | 186 +++++++++++++++++++++++++++++++++ test/odf-validate/selftest.py | 12 ++- 8 files changed, 311 insertions(+), 3 deletions(-) diff --git a/test/odf-validate/.gitignore b/test/odf-validate/.gitignore index de3c5403a4..241fe5c692 100644 --- a/test/odf-validate/.gitignore +++ b/test/odf-validate/.gitignore @@ -4,3 +4,4 @@ schema/ baseline/ __pycache__/ fixtures/control/ +fixtures/control-pkg/ diff --git a/test/odf-validate/README.md b/test/odf-validate/README.md index 6411dc92cd..93562e111b 100644 --- a/test/odf-validate/README.md +++ b/test/odf-validate/README.md @@ -46,6 +46,12 @@ The steps: Embedded objects whose `content.xml` is MathML are skipped (ODF 1.2 Part 1 §2.2.1 B.4). - `report.py` groups the errors by normalized message. +- `pkgcheck.py <outdir> <pkg.json>` checks the ODF 1.2 Part 3 package rules + (§2.2.1, 3.2, 3.3, 3.4.1): zip methods, `mimetype` first / stored / no extra + field / equal to the `/` media type, one manifest entry per file, META-INF + contents, `manifest:size` and STORED on encrypted entries, and signature + files (well-formed, root, `OpenDocument-v1.2-os-dsig-schema.rng`). Findings + are `shall:` or `should:`; only `shall` findings are non-conformances. - `idcheck.py <outdir> <ids.json>` parses every stream namespace-aware and checks `xml:id` syntax and uniqueness per stream (ODF 1.2 Part 1 §2.2.1 D.1, D.2). `jing -i` does not check ID uniqueness. diff --git a/test/odf-validate/fetch-schemas.sh b/test/odf-validate/fetch-schemas.sh index fd069f90e7..c0d0302eb8 100755 --- a/test/odf-validate/fetch-schemas.sh +++ b/test/odf-validate/fetch-schemas.sh @@ -28,6 +28,7 @@ typeset -A SUMS SUMS=( https://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-schema.rng ca5d2510858c6f922b20cd27dc76d34959c1a976b9dfc6b5caeadbebfc83dbbb https://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-manifest-schema.rng 75f972902bc785c15e51fb4e112e2f1b24e2327829eb54786cf8687ee39c7631 + https://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-dsig-schema.rng 52fbf196dc11fcaac41ff4b320f005daf419794c2f343a26ecab05778d7e7f6f https://docs.oasis-open.org/office/OpenDocument/v1.4/os/schemas/OpenDocument-v1.4-schema.rng 4034ec6be29205d5fc1ee5f42468ac6ef824287b3aba6d9289032af4fafbda7f https://docs.oasis-open.org/office/OpenDocument/v1.4/os/schemas/OpenDocument-v1.4-manifest-schema.rng f96e1fe95f4e3609717a307c28e2fe0654c890fe70ea03eb8a53caa20b684782 ) diff --git a/test/odf-validate/idcheck.py b/test/odf-validate/idcheck.py index 63e798c809..cb3953039c 100644 --- a/test/odf-validate/idcheck.py +++ b/test/odf-validate/idcheck.py @@ -20,7 +20,7 @@ #************************************************************** # usage: idcheck.py <outdir> <ids.json> -# ODF 1.2 Part 1 2.2.1 D.1 and D.2, which `jing -i` does not check: each XML stream is +# ODF 1.2 Part 1 2.2.1 D.1 and D.2, and Part 3 2.2.1 F, which `jing -i` does not check: each XML stream is # parsed namespace-aware, and its xml:id values must be NCNames, unique within the stream. import sys, os, re, zipfile, json from xml.parsers import expat @@ -70,7 +70,8 @@ def main(): except Exception: bad_zip.append(pkg); continue for name in z.namelist(): - if name.rsplit("/", 1)[-1] not in STREAMS: + base = name.rsplit("/", 1)[-1] + if base not in STREAMS and not (name.startswith("META-INF/") and "signatures" in base): continue nstreams += 1 for line, col, msg in check_stream(z.read(name)): diff --git a/test/odf-validate/make-controls.py b/test/odf-validate/make-controls.py index d1ec181447..f29e54d065 100644 --- a/test/odf-validate/make-controls.py +++ b/test/odf-validate/make-controls.py @@ -53,3 +53,5 @@ mk("dupid", "1.2", '<text:p xml:id="a1">x</text:p><text:p xml:id=" a1 ">y</text: mk("badid", "1.2", '<text:p xml:id="1abc">x</text:p>') mk("badid2", "1.2", '<text:p xml:id="a b">x</text:p>') mk("badns", "1.2", "<text:p><zz:span/></text:p>") +# Part 3 2.2.1 F: signature files are held to the same rules (validate.py does not look at them) +mk("badsig", "1.2", "<text:p>hi</text:p>", {"META-INF/documentsignatures.xml": '<a><b xml:id="x"/><b xml:id="x"/></a>'}) diff --git a/test/odf-validate/make-pkg-controls.py b/test/odf-validate/make-pkg-controls.py new file mode 100644 index 0000000000..2234983c73 --- /dev/null +++ b/test/odf-validate/make-pkg-controls.py @@ -0,0 +1,101 @@ +#************************************************************** +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +#************************************************************** + +# usage: make-pkg-controls.py -- (re)generate pkgcheck.py's negative-control packages in fixtures/control-pkg/ +# .expected.json maps each package to the (level, rule) pairs pkgcheck.py must report, exactly. +import json, os, shutil, warnings, zipfile + +C = os.path.join(os.path.dirname(os.path.abspath(__file__)), "fixtures", "control-pkg") +MIME = "application/vnd.oasis.opendocument.text" +S, Z = zipfile.ZIP_STORED, zipfile.ZIP_DEFLATED +SIG = ('<?xml version="1.0" encoding="UTF-8"?>\n<dsig:document-signatures xmlns:dsig="urn:oasis:names:tc:opendocument:xmlns:digitalsignature:1.0" ' + 'dsig:version="%s" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:Signature Id="s1"/></dsig:document-signatures>\n') +ENC = ('<manifest:encryption-data manifest:checksum-type="SHA1/1K" manifest:checksum="AAAA">' + '<manifest:algorithm manifest:algorithm-name="Blowfish CFB" manifest:initialisation-vector="AAAA"/>' + '<manifest:key-derivation manifest:key-derivation-name="PBKDF2" manifest:key-size="16" manifest:iteration-count="1024" manifest:salt="AAAA"/>' + '</manifest:encryption-data>') + + +def entry(path, mt="text/xml", inner="", **attrs): + a = "".join(' manifest:%s="%s"' % kv for kv in attrs.items()) + return '<manifest:file-entry manifest:full-path="%s" manifest:media-type="%s"%s>%s</manifest:file-entry>' % (path, mt, a, inner) + + +def manifest(*entries, root="manifest:manifest"): + return ('<?xml version="1.0" encoding="UTF-8"?>\n<%s xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2">%s</%s>\n' + % (root, "".join(entries), root)) + + +ROOT = entry("/", MIME, version="1.2") +CONTENT = entry("content.xml") +GOOD_MANI = manifest(ROOT, CONTENT) +EXPECTED = {} + + +def build(name, files, expect=()): + """files: (zip name, data, method[, extra]) in physical order.""" + with zipfile.ZipFile(os.path.join(C, name + ".odt"), "w") as z, warnings.catch_warnings(): + warnings.simplefilter("ignore") + for f in files: + zi = zipfile.ZipInfo(f[0]) + if len(f) > 3: + zi.extra = f[3] + z.writestr(zi, f[1], compress_type=f[2]) + EXPECTED[name + ".odt"] = sorted(expect) + + +def std(mani=GOOD_MANI, mime=MIME, extra=()): + return [("mimetype", mime, S), ("content.xml", "<c/>", Z)] + list(extra) + [("META-INF/manifest.xml", mani, Z)] + + +shutil.rmtree(C, ignore_errors=True) +os.makedirs(C) +build("good", std()) +sub = [("Object 1/content.xml", "<c/>", Z), ("Pictures/a.png", "x", S), ("secret.xml", "0123456789", S), + ("META-INF/documentsignatures.xml", SIG % "1.2", Z)] +build("good-full", std(manifest(ROOT, CONTENT, entry("Object 1/", MIME, version="1.2"), entry("Object 1/content.xml"), + entry("Pictures/a.png", "image/png"), entry("secret.xml", inner=ENC, size="10")), extra=sub)) +build("mime-deflated", [("mimetype", MIME, Z), ("content.xml", "<c/>", Z), ("META-INF/manifest.xml", GOOD_MANI, Z)], [("shall", "mimetype-compressed")]) +build("mime-extra", [("mimetype", MIME, S, b"\xfe\xca\x00\x00"), ("content.xml", "<c/>", Z), ("META-INF/manifest.xml", GOOD_MANI, Z)], [("shall", "mimetype-extra")]) +build("mime-notfirst", [("content.xml", "<c/>", Z), ("mimetype", MIME, S), ("META-INF/manifest.xml", GOOD_MANI, Z)], [("shall", "mimetype-first")]) +build("mime-mismatch", std(mime="application/x-bogus"), [("shall", "mimetype-mismatch")]) +build("mime-nonascii", std(mime=MIME + "é"), [("shall", "mimetype-ascii")]) +build("mime-missing", std()[1:], [("should", "mimetype-missing"), ("shall", "mimetype-missing")]) +build("mime-missing-noroot", std(manifest(CONTENT))[1:], [("should", "mimetype-missing")]) +build("no-root-entry", std(manifest(CONTENT)), [("shall", "manifest-root-entry")]) +build("uncovered", std(extra=[("extra.xml", "<e/>", Z)]), [("shall", "manifest-coverage")]) +build("dup-entry", std(manifest(ROOT, CONTENT, CONTENT)), [("shall", "manifest-duplicate")]) +build("self-entry", std(manifest(ROOT, CONTENT, entry("mimetype", "text/plain"))), [("shall", "manifest-self")]) +build("dangling", std(manifest(ROOT, CONTENT, entry("gone.xml"))), [("should", "manifest-dangling")]) +build("dir-entry-manifest", std(manifest(ROOT, CONTENT, entry("Configurations2/", "application/vnd.sun.xml.ui.configuration"))), [("should", "manifest-dir-entry")]) +build("stray-meta-inf", std(extra=[("META-INF/foo.xml", "<f/>", Z)]), [("shall", "meta-inf-file")]) +build("no-manifest", [("mimetype", MIME, S), ("content.xml", "<c/>", Z)], [("shall", "manifest-missing")]) +build("manifest-malformed", std("<manifest:manifest"), [("shall", "manifest-malformed")]) +build("manifest-wrongroot", std(manifest(root="manifest:other")), [("shall", "manifest-root")]) +build("zip-bzip2", std(extra=[("b.xml", "<b/>", zipfile.ZIP_BZIP2)], mani=manifest(ROOT, CONTENT, entry("b.xml"))), [("shall", "zip-method")]) +build("zip-dup-name", std(extra=[("content.xml", "<d/>", Z)]), [("shall", "zip-duplicate")]) +build("zip-dir-entry", std(extra=[("Pictures/", "", S)]), [("should", "zip-dir-entry")]) +build("enc-nosize", std(manifest(ROOT, CONTENT, entry("secret.xml", inner=ENC)), extra=[("secret.xml", "0123456789", S)]), [("shall", "encrypted-size")]) +build("enc-deflated", std(manifest(ROOT, CONTENT, entry("secret.xml", inner=ENC, size="10")), extra=[("secret.xml", "0123456789", Z)]), [("shall", "encrypted-method")]) +build("sig-malformed", std(extra=[("META-INF/documentsignatures.xml", "<dsig", Z)]), [("shall", "signature-malformed")]) +build("sig-wrongroot", std(extra=[("META-INF/documentsignatures.xml", "<a/>", Z)]), [("shall", "signature-root")]) +build("sig-badversion", std(extra=[("META-INF/documentsignatures.xml", SIG % "1.1", Z)]), [("shall", "signature-schema")]) +json.dump(EXPECTED, open(os.path.join(C, ".expected.json"), "w"), indent=1) diff --git a/test/odf-validate/pkgcheck.py b/test/odf-validate/pkgcheck.py new file mode 100644 index 0000000000..c59e9a087b --- /dev/null +++ b/test/odf-validate/pkgcheck.py @@ -0,0 +1,186 @@ +#************************************************************** +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +#************************************************************** + +# usage: pkgcheck.py <outdir> <pkg.json> +# ODF 1.2 Part 3 2.2.1, 3.2, 3.3 and 3.4.1 on every package in <outdir>. Each finding is +# "shall: [rule] ..." or "should: [rule] ...". Schema validity of the manifest is validate.py's job. +import sys, os, re, zipfile, json, struct, subprocess, shutil, warnings +from xml.etree import ElementTree as ET + +D = os.path.dirname(os.path.abspath(__file__)) +JING = ["java", "-jar", os.environ.get("ODFV_JING", "/Applications/XMLauthor/lib/jing.jar"), "-i"] +DSIG_SCHEMA = D + "/schema/OpenDocument-v1.2-os-dsig-schema.rng" +MANI = "{urn:oasis:names:tc:opendocument:xmlns:manifest:1.0}" +DSIG = "{urn:oasis:names:tc:opendocument:xmlns:digitalsignature:1.0}" +ERR = re.compile(r"^(.*?):(\d+):(\d+): (error|fatal|warning): (.*)$") + + +def check_package(path, work): + """Returns [(entry, level, rule, message)] for one package.""" + out = [] + + def add(entry, level, rule, msg): + out.append((entry, level, rule, msg)) + z = zipfile.ZipFile(path) + infos = z.infolist() + names = [i.filename for i in infos] + for n in sorted({n for n in names if names.count(n) > 1}): + add(n, "shall", "zip-duplicate", "zip entry name occurs more than once") + for i in infos: + if i.compress_type not in (zipfile.ZIP_STORED, zipfile.ZIP_DEFLATED): + add(i.filename, "shall", "zip-method", "compression method %d is neither STORED nor DEFLATED (2.2.1 A)" % i.compress_type) + if i.filename.endswith("/"): + add(i.filename, "should", "zip-dir-entry", "directories have no zip entries (4.3)") + files = {n for n in names if not n.endswith("/")} + + # mimetype (3.3) + mime = None + if "mimetype" not in files: + add("mimetype", "should", "mimetype-missing", "no mimetype file (2.2.1 C)") + else: + mi = z.getinfo("mimetype") + first = min(infos, key=lambda i: i.header_offset) + if first.filename != "mimetype" or mi.header_offset != 0: + add("mimetype", "shall", "mimetype-first", "mimetype is not the first file of the zip (3.3)") + with open(path, "rb") as f: + f.seek(mi.header_offset) + hdr = f.read(30) + if len(hdr) == 30 and hdr[:4] == b"PK\x03\x04": + method, extralen = struct.unpack("<H", hdr[8:10])[0], struct.unpack("<H", hdr[28:30])[0] + if method != zipfile.ZIP_STORED: + add("mimetype", "shall", "mimetype-compressed", "mimetype is compressed, local header method %d (3.3)" % method) + if extralen: + add("mimetype", "shall", "mimetype-extra", "mimetype has a %d byte extra field in its local header (3.3)" % extralen) + else: + add("mimetype", "shall", "mimetype-first", "no local file header at the recorded offset") + if mi.compress_type != zipfile.ZIP_STORED: + add("mimetype", "shall", "mimetype-compressed", "mimetype is compressed, central directory method %d (3.3)" % mi.compress_type) + raw = z.read("mimetype") + try: + mime = raw.decode("ascii") + except UnicodeDecodeError: + add("mimetype", "shall", "mimetype-ascii", "mimetype content is not ASCII (3.3)") + + # META-INF contents (2.2.1 D, E) + for n in sorted(files): + if n.startswith("META-INF/") and n != "META-INF/manifest.xml" and "signatures" not in n.rsplit("/", 1)[-1]: + add(n, "shall", "meta-inf-file", "file other than manifest.xml and signature files in META-INF (2.2.1 E)") + + # manifest (2.2.1 B, 3.2) + entries = None + if "META-INF/manifest.xml" not in files: + add("META-INF/manifest.xml", "shall", "manifest-missing", "no META-INF/manifest.xml (2.2.1 B)") + else: + try: + root = ET.fromstring(z.read("META-INF/manifest.xml")) + if root.tag != MANI + "manifest": + add("META-INF/manifest.xml", "shall", "manifest-root", "root element is not manifest:manifest (2.2.1 B.2)") + else: + entries = [e for e in root if e.tag == MANI + "file-entry"] + except ET.ParseError as e: + add("META-INF/manifest.xml", "shall", "manifest-malformed", "not well-formed: %s (2.2.1 B.1)" % e) + if entries is not None: + paths = [e.get(MANI + "full-path") for e in entries] + for p in sorted({p for p in paths if paths.count(p) > 1}, key=str): + add("META-INF/manifest.xml", "shall", "manifest-duplicate", "more than one file-entry for %s (3.2)" % p) + for p in paths: + if p in ("META-INF/manifest.xml", "mimetype"): + add("META-INF/manifest.xml", "shall", "manifest-self", "file-entry for %s (3.2)" % p) + elif p and p.endswith("/") and p != "/": + if p + "content.xml" not in files and p + "styles.xml" not in files: + add("META-INF/manifest.xml", "should", "manifest-dir-entry", "file-entry for %s, a directory without a document (4.3)" % p) + elif p not in files and p != "/": + add("META-INF/manifest.xml", "should", "manifest-dangling", "file-entry for %s, which is not in the package (3.2)" % p) + for n in sorted(files): + if n != "mimetype" and not n.startswith("META-INF/") and n not in paths: + add(n, "shall", "manifest-coverage", "no file-entry in the manifest (3.2)") + root_entry = [e for e in entries if e.get(MANI + "full-path") == "/"] + if "mimetype" in files and not root_entry: + add("META-INF/manifest.xml", "shall", "manifest-root-entry", 'no file-entry for "/" although the package has a mimetype file (3.2)') + for e in root_entry: + mt = e.get(MANI + "media-type") + if "mimetype" not in files: + add("mimetype", "shall", "mimetype-missing", 'file-entry for "/" but no mimetype file (3.3)') + elif mime is not None and mt != mime: + add("mimetype", "shall", "mimetype-mismatch", 'mimetype is "%s" but the "/" media-type is "%s" (3.3)' % (mime, mt)) + # encrypted entries (3.4.1) + for e in entries: + if e.find(MANI + "encryption-data") is None: + continue + p = e.get(MANI + "full-path") + size = e.get(MANI + "size") + if size is None or not re.fullmatch(r"[0-9]+", size): + add(p, "shall", "encrypted-size", "encrypted entry without a valid manifest:size (3.4.1, 4.8.13)") + if p in files and z.getinfo(p).compress_type != zipfile.ZIP_STORED: + add(p, "shall", "encrypted-method", "encrypted entry is not flagged STORED in the zip (3.4.1)") + + # signature files (2.2.1 D) + sigs = sorted(n for n in files if n.startswith("META-INF/") and "signatures" in n.rsplit("/", 1)[-1]) + for n in sigs: + try: + root = ET.fromstring(z.read(n)) + except ET.ParseError as e: + add(n, "shall", "signature-malformed", "not well-formed: %s (2.2.1 D.1)" % e) + continue + if root.tag != DSIG + "document-signatures": + add(n, "shall", "signature-root", "root element is not dsig:document-signatures (2.2.1 D.2)") + continue + p = os.path.join(work, os.path.basename(path), n) + os.makedirs(os.path.dirname(p), exist_ok=True) + open(p, "wb").write(z.read(n)) + r = subprocess.run(JING + [DSIG_SCHEMA, p], capture_output=True, text=True) + for line in (r.stdout + r.stderr).splitlines(): + m = ERR.match(line) + if m: + add(n, "shall", "signature-schema", "%s:%s %s (2.2.1 D.3)" % (m.group(2), m.group(3), m.group(5))) + elif line.strip(): + add(n, "shall", "signature-schema", line.strip()) + return out + + +def main(): + outdir, pkgjson = sys.argv[1], sys.argv[2] + if not os.path.abspath(pkgjson).startswith(os.path.join(D, "runs") + os.sep): + sys.exit("pkgcheck.py: <pkg.json> must live under " + os.path.join(D, "runs")) + work = os.path.abspath(pkgjson[:-5] + ".xml") + shutil.rmtree(work, ignore_errors=True) + errors, bad_zip = [], [] + pkgs = sorted(p for p in os.listdir(outdir) if not p.startswith(".")) + for pkg in pkgs: + try: + found = check_package(os.path.join(outdir, pkg), work) + except zipfile.BadZipFile: + bad_zip.append(pkg); continue + for entry, level, rule, msg in found: + errors.append([pkg + "/" + entry, 0, 0, "%s: [%s] %s" % (level, rule, msg)]) + json.dump({"packages": pkgs, "bad_zip": bad_zip, "errors": errors}, open(pkgjson, "w")) + shall = [e for e in errors if e[3].startswith("shall:")] + print(f"package check: {len(shall)} shall and {len(errors) - len(shall)} should findings in " + f"{len({e[0].split('/')[0] for e in errors})} of {len(pkgs)} packages, bad zips: {bad_zip}") + rules = {} + for e in errors: + k = e[3].split("]")[0] + "]" + rules[k] = rules.get(k, 0) + 1 + for k in sorted(rules): + print(f" {rules[k]:6d} {k}") + + +main() diff --git a/test/odf-validate/selftest.py b/test/odf-validate/selftest.py index 0058afe95a..61e6091695 100644 --- a/test/odf-validate/selftest.py +++ b/test/odf-validate/selftest.py @@ -44,8 +44,18 @@ checks.update({ "idcheck: dupid.odt flags the duplicate after normalization": any("duplicates" in m for m in ierrs("dupid.odt")), "idcheck: badid.odt, badid2.odt flag non-NCName ids": all(any("not an NCName" in m for m in ierrs(p)) for p in ("badid.odt", "badid2.odt")), "idcheck: badns.odt flags the unbound prefix": any("unbound prefix" in m for m in ierrs("badns.odt")), - "idcheck: no errors in other packages": {e[0].split("/")[0] for e in i["errors"]} == {"dupid.odt", "badid.odt", "badid2.odt", "badns.odt"}, + "idcheck: badsig.odt flags a duplicate id in a signature file": any("duplicates" in m for m in ierrs("badsig.odt")), + "idcheck: no errors in other packages": {e[0].split("/")[0] for e in i["errors"]} == {"dupid.odt", "badid.odt", "badid2.odt", "badns.odt", "badsig.odt"}, }) +subprocess.run([sys.executable, "-I", os.path.join(D, "make-pkg-controls.py")], check=True) +pk = os.path.join(D, "runs", "control", "pkg.json") +pdir = os.path.join(D, "fixtures", "control-pkg") +subprocess.run([sys.executable, "-I", os.path.join(D, "pkgcheck.py"), pdir, pk], check=True, capture_output=True) +pe = json.load(open(pk))["errors"] +expected = json.load(open(os.path.join(pdir, ".expected.json"))) +def found(pkg): return sorted({tuple(m.split("]")[0].split(": [")) for m in (e[3] for e in pe if e[0].startswith(pkg + "/"))}) +for pkg in sorted(expected): + checks["pkgcheck: " + pkg + " reports exactly " + (", ".join(r for _, r in map(tuple, expected[pkg])) or "nothing")] = found(pkg) == [tuple(x) for x in expected[pkg]] for k, ok in checks.items(): print(("PASS " if ok else "FAIL ") + k) sys.exit(0 if all(checks.values()) else 1)
