xref: /trunk/test/aoo-test/src/aootest/checkers/report.py (revision 2cb6d6f119bbe2f78742f1c5c8538cb0d4e72ede)
1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22# usage: report.py <val.json> <kinds.json> [12|14|12x]   -- groups errors by normalized message
23import sys, re, json, collections
24
25
26def norm(m):
27    m = re.sub(r'; expected .*', '', m)
28    m = re.sub(r' \(with xmlns.*', '', m)
29    return re.sub(r'value of attribute "([^"]+)" is invalid.*', r'value of attribute "\1" is invalid', m)
30
31
32def kinds_of(d, ver="12"):
33    """Groups the errors of one validate.check() result for version `ver` by normalized message."""
34    kinds = collections.defaultdict(lambda: {"errors": 0, "packages": set()})
35    for f, line, col, msg in d["errors"][ver]:
36        k = kinds[norm(msg) if f != "?" else "UNPARSED: " + msg]
37        k["errors"] += 1; k["packages"].add(f.split("/")[0])
38    return {k: {"errors": v["errors"], "packages": sorted(v["packages"])} for k, v in kinds.items()}
39
40
41def main(argv=None):
42    val, out, *rest = sys.argv[1:] if argv is None else argv
43    ver = rest[0] if rest else "12"
44    res = kinds_of(json.load(open(val)), ver)
45    json.dump(res, open(out, "w"), indent=1, sort_keys=True)
46    tot = sum(v["errors"] for v in res.values())
47    print(f"ODF {ver[0]}.{ver[1]}{' extended, foreign content removed' if ver.endswith('x') else ''}: {len(res)} kinds, {tot} errors, {len({p for v in res.values() for p in v['packages']})} packages with errors")
48    for k, v in sorted(res.items(), key=lambda kv: -kv[1]["errors"]):
49        print(f"  {v['errors']:5d} {len(v['packages']):4d}  {k[:120]}")
50
51
52if __name__ == "__main__":
53    main()
54