|
| 1 | +import json, os |
| 2 | + |
| 3 | +def suite_conformance(suites): |
| 4 | + res = { |
| 5 | + "t": 0, |
| 6 | + "o": 0, |
| 7 | + "i": 0, |
| 8 | + "p": 0 |
| 9 | + } |
| 10 | + |
| 11 | + for suite in suites.values(): |
| 12 | + if "s" in suite.keys(): |
| 13 | + conformance = suite_conformance(suite["s"]) |
| 14 | + res["t"] += conformance["t"] |
| 15 | + res["o"] += conformance["o"] |
| 16 | + res["i"] += conformance["i"] |
| 17 | + res["p"] += conformance["p"] |
| 18 | + |
| 19 | + if "t" in suite.keys(): |
| 20 | + for test in suite["t"].values(): |
| 21 | + res["t"] += 1 |
| 22 | + if "s" in test.keys() and "r" in test.keys(): |
| 23 | + if test["s"] == "O" and test["r"] == "O": |
| 24 | + res["o"] += 1 |
| 25 | + elif test["s"] == "I" and test["r"] == "I": |
| 26 | + res["i"] += 1 |
| 27 | + elif test["s"] == "P" or test["r"] == "P": |
| 28 | + res["p"] += 1 |
| 29 | + elif "s" in test.keys(): |
| 30 | + if test["s"] == "O": |
| 31 | + res["o"] += 1 |
| 32 | + elif test["s"] == "I": |
| 33 | + res["i"] += 1 |
| 34 | + elif test["s"] == "P": |
| 35 | + res["p"] += 1 |
| 36 | + else: |
| 37 | + if test["r"] == "O": |
| 38 | + res["o"] += 1 |
| 39 | + elif test["r"] == "I": |
| 40 | + res["i"] += 1 |
| 41 | + elif test["r"] == "P": |
| 42 | + res["p"] += 1 |
| 43 | + |
| 44 | + return res |
| 45 | + |
| 46 | +def version_conformance(suites): |
| 47 | + res = {} |
| 48 | + |
| 49 | + for suite in suites.values(): |
| 50 | + if "s" in suite.keys(): |
| 51 | + versions = version_conformance(suite["s"]) |
| 52 | + for key in versions.keys(): |
| 53 | + if key not in res.keys(): |
| 54 | + res[key] = 0 |
| 55 | + |
| 56 | + res[key] += versions[key] |
| 57 | + |
| 58 | + if "t" in suite.keys(): |
| 59 | + for test in suite["t"].values(): |
| 60 | + if "v" in test.keys(): |
| 61 | + version = test["v"] |
| 62 | + if version != 255: |
| 63 | + key = str(version) |
| 64 | + if key not in res.keys(): |
| 65 | + res[key] = 0 |
| 66 | + |
| 67 | + res[key] += 1 |
| 68 | + |
| 69 | + return res |
| 70 | + |
| 71 | +def fix_tests(tests): |
| 72 | + fixed = {} |
| 73 | + |
| 74 | + for test in tests: |
| 75 | + name = test["n"] |
| 76 | + if test["n"] in fixed: |
| 77 | + if test["s"]: |
| 78 | + fixed[name]["s"] = test["r"] |
| 79 | + else: |
| 80 | + fixed[name]["r"] = test["r"] |
| 81 | + else: |
| 82 | + fixed[name] = {} |
| 83 | + |
| 84 | + if "v" in test.keys(): |
| 85 | + fixed[name]["v"] = test["v"] |
| 86 | + |
| 87 | + if "s" in test.keys(): |
| 88 | + if test["s"]: |
| 89 | + fixed[name]["s"] = test["r"] |
| 90 | + else: |
| 91 | + fixed[name]["r"] = test["r"] |
| 92 | + else: |
| 93 | + fixed[name]["r"] = test["r"] |
| 94 | + |
| 95 | + return fixed |
| 96 | + |
| 97 | +def fix_suite(suites): |
| 98 | + fixed = {} |
| 99 | + for suite in suites: |
| 100 | + name = suite["n"] |
| 101 | + fixed[name] = {} |
| 102 | + |
| 103 | + if "s" in suite.keys(): |
| 104 | + fixed[name]["s"] = fix_suite(suite["s"]) |
| 105 | + fixed[name]["a"] = suite_conformance(fixed[name]["s"]) |
| 106 | + fixed[name]["v"] = version_conformance(fixed[name]["s"]) |
| 107 | + |
| 108 | + if "t" in suite.keys(): |
| 109 | + fixed[name]["t"] = fix_tests(suite["t"]) |
| 110 | + |
| 111 | + return fixed |
| 112 | + |
| 113 | +def fix_all(latest): |
| 114 | + fixed = { |
| 115 | + "c": latest["c"], |
| 116 | + "u": latest["u"], |
| 117 | + "n": latest["r"]["n"], |
| 118 | + "r": fix_suite(latest["r"]["s"]), |
| 119 | + } |
| 120 | + |
| 121 | + fixed["a"] = suite_conformance(fixed["r"]) |
| 122 | + fixed["v"] = version_conformance(fixed["r"]) |
| 123 | + |
| 124 | + return fixed |
| 125 | + |
| 126 | +for top, dirs, files in os.walk("./refs/tags"): |
| 127 | + for dir in dirs: |
| 128 | + print("Fixing " + dir) |
| 129 | + with open("./refs/tags/" + dir + "/latest.json") as latest_f: |
| 130 | + latest = json.load(latest_f) |
| 131 | + |
| 132 | + latest_fixed = fix_all(latest) |
| 133 | + |
| 134 | + with open("./refs/tags/" + dir + "/latest.json", 'w') as latest_of: |
| 135 | + json.dump(latest_fixed, latest_of, separators=(',', ':'), ensure_ascii=False) |
| 136 | + |
| 137 | + |
0 commit comments