|
| 1 | +import json |
| 2 | +import os |
| 3 | + |
| 4 | + |
| 5 | +def suite_conformance(suite): |
| 6 | + global function_suite |
| 7 | + res = { |
| 8 | + "t": 0, |
| 9 | + "o": 0, |
| 10 | + "i": 0, |
| 11 | + "p": 0 |
| 12 | + } |
| 13 | + |
| 14 | + if "s" in suite.keys(): |
| 15 | + for subSuite in suite["s"].values(): |
| 16 | + conformance = suite_conformance(subSuite) |
| 17 | + res["t"] += conformance["t"] |
| 18 | + res["o"] += conformance["o"] |
| 19 | + res["i"] += conformance["i"] |
| 20 | + res["p"] += conformance["p"] |
| 21 | + |
| 22 | + if "t" in suite.keys(): |
| 23 | + for testName in suite["t"].keys(): |
| 24 | + test = suite["t"][testName] |
| 25 | + |
| 26 | + res["t"] += 1 |
| 27 | + if "s" in test.keys() and "r" in test.keys(): |
| 28 | + if test["s"] == "O" and test["r"] == "O": |
| 29 | + res["o"] += 1 |
| 30 | + elif test["s"] == "I" and test["r"] == "I": |
| 31 | + res["i"] += 1 |
| 32 | + elif test["s"] == "P" or test["r"] == "P": |
| 33 | + res["p"] += 1 |
| 34 | + elif "s" in test.keys(): |
| 35 | + if test["s"] == "O": |
| 36 | + res["o"] += 1 |
| 37 | + elif test["s"] == "I": |
| 38 | + res["i"] += 1 |
| 39 | + elif test["s"] == "P": |
| 40 | + res["p"] += 1 |
| 41 | + else: |
| 42 | + if test["r"] == "O": |
| 43 | + res["o"] += 1 |
| 44 | + elif test["r"] == "I": |
| 45 | + res["i"] += 1 |
| 46 | + elif test["r"] == "P": |
| 47 | + res["p"] += 1 |
| 48 | + |
| 49 | + return res |
| 50 | + |
| 51 | + |
| 52 | +def version_conformance(suite): |
| 53 | + res = {} |
| 54 | + |
| 55 | + if "s" in suite.keys(): |
| 56 | + for subSuite in suite["s"].values(): |
| 57 | + versions = version_conformance(subSuite) |
| 58 | + for key in versions.keys(): |
| 59 | + if key not in res.keys(): |
| 60 | + res[key] = { |
| 61 | + "t": 0, |
| 62 | + "o": 0, |
| 63 | + "i": 0, |
| 64 | + "p": 0 |
| 65 | + } |
| 66 | + |
| 67 | + res[key]["t"] += versions[key]["t"] |
| 68 | + res[key]["o"] += versions[key]["o"] |
| 69 | + res[key]["i"] += versions[key]["i"] |
| 70 | + res[key]["p"] += versions[key]["p"] |
| 71 | + |
| 72 | + if "t" in suite.keys(): |
| 73 | + for testName in suite["t"].keys(): |
| 74 | + test = suite["t"][testName] |
| 75 | + |
| 76 | + if "v" in test.keys(): |
| 77 | + version = test["v"] |
| 78 | + if version != 255: |
| 79 | + key = str(version) |
| 80 | + if key not in res.keys(): |
| 81 | + res[key] = { |
| 82 | + "t": 0, |
| 83 | + "o": 0, |
| 84 | + "i": 0, |
| 85 | + "p": 0 |
| 86 | + } |
| 87 | + |
| 88 | + res[key]["t"] += 1 |
| 89 | + if "s" in test.keys() and "r" in test.keys(): |
| 90 | + if test["s"] == "O" and test["r"] == "O": |
| 91 | + res[key]["o"] += 1 |
| 92 | + elif test["s"] == "I" and test["r"] == "I": |
| 93 | + res[key]["i"] += 1 |
| 94 | + elif test["s"] == "P" or test["r"] == "P": |
| 95 | + res[key]["p"] += 1 |
| 96 | + elif "s" in test.keys(): |
| 97 | + if test["s"] == "O": |
| 98 | + res[key]["o"] += 1 |
| 99 | + elif test["s"] == "I": |
| 100 | + res[key]["i"] += 1 |
| 101 | + elif test["s"] == "P": |
| 102 | + res[key]["p"] += 1 |
| 103 | + else: |
| 104 | + if test["r"] == "O": |
| 105 | + res[key]["o"] += 1 |
| 106 | + elif test["r"] == "I": |
| 107 | + res[key]["i"] += 1 |
| 108 | + elif test["r"] == "P": |
| 109 | + res[key]["p"] += 1 |
| 110 | + |
| 111 | + return res |
| 112 | + |
| 113 | + |
| 114 | +def fix_tests(tests): |
| 115 | + fixed = {} |
| 116 | + |
| 117 | + for test in tests: |
| 118 | + name = test["n"] |
| 119 | + if test["n"] in fixed: |
| 120 | + if test["s"]: |
| 121 | + fixed[name]["s"] = test["r"] |
| 122 | + else: |
| 123 | + fixed[name]["r"] = test["r"] |
| 124 | + else: |
| 125 | + fixed[name] = {} |
| 126 | + |
| 127 | + if "v" in test.keys(): |
| 128 | + fixed[name]["v"] = test["v"] |
| 129 | + |
| 130 | + if "s" in test.keys(): |
| 131 | + if test["s"]: |
| 132 | + fixed[name]["s"] = test["r"] |
| 133 | + else: |
| 134 | + fixed[name]["r"] = test["r"] |
| 135 | + else: |
| 136 | + fixed[name]["r"] = test["r"] |
| 137 | + |
| 138 | + return fixed |
| 139 | + |
| 140 | + |
| 141 | +def fix_suite(suites): |
| 142 | + fixed = {} |
| 143 | + for suite in suites: |
| 144 | + name = suite["n"] |
| 145 | + fixed[name] = {} |
| 146 | + |
| 147 | + if "s" in suite.keys(): |
| 148 | + fixed[name]["s"] = fix_suite(suite["s"]) |
| 149 | + |
| 150 | + if "t" in suite.keys(): |
| 151 | + fixed[name]["t"] = fix_tests(suite["t"]) |
| 152 | + |
| 153 | + fixed[name]["a"] = suite_conformance(fixed[name]) |
| 154 | + fixed[name]["v"] = version_conformance(fixed[name]) |
| 155 | + |
| 156 | + return fixed |
| 157 | + |
| 158 | + |
| 159 | +def fix_all(latest): |
| 160 | + fixed = { |
| 161 | + "c": latest["c"], |
| 162 | + "u": latest["u"], |
| 163 | + "r": fix_suite(latest["r"]["s"]), |
| 164 | + "a": { |
| 165 | + "t": 0, |
| 166 | + "o": 0, |
| 167 | + "i": 0, |
| 168 | + "p": 0 |
| 169 | + }, |
| 170 | + "v": {}, |
| 171 | + } |
| 172 | + |
| 173 | + for suite in fixed["r"].values(): |
| 174 | + fixed["a"]["t"] += suite["a"]["t"] |
| 175 | + fixed["a"]["o"] += suite["a"]["o"] |
| 176 | + fixed["a"]["i"] += suite["a"]["i"] |
| 177 | + fixed["a"]["p"] += suite["a"]["p"] |
| 178 | + |
| 179 | + for key in suite["v"].keys(): |
| 180 | + if key not in fixed["v"].keys(): |
| 181 | + fixed["v"][key] = { |
| 182 | + "t": 0, |
| 183 | + "o": 0, |
| 184 | + "i": 0, |
| 185 | + "p": 0 |
| 186 | + } |
| 187 | + |
| 188 | + fixed["v"][key]["t"] += suite["v"][key]["t"] |
| 189 | + fixed["v"][key]["o"] += suite["v"][key]["o"] |
| 190 | + fixed["v"][key]["i"] += suite["v"][key]["i"] |
| 191 | + fixed["v"][key]["p"] += suite["v"][key]["p"] |
| 192 | + |
| 193 | + return fixed |
| 194 | + |
| 195 | + |
| 196 | +def fix_file(file_name): |
| 197 | + with open(file_name) as latest_f: |
| 198 | + latest = json.load(latest_f) |
| 199 | + fixed_latest = fix_all(latest) |
| 200 | + |
| 201 | + with open(file_name, 'w') as latest_of: |
| 202 | + json.dump(fixed_latest, latest_of, separators=( |
| 203 | + ',', ':'), ensure_ascii=False) |
| 204 | + |
| 205 | + return fixed_latest |
| 206 | + |
| 207 | + |
| 208 | +def clean_main(latest): |
| 209 | + with open("./refs/heads/main/results.json") as results_f: |
| 210 | + results = json.load(results_f) |
| 211 | + fixed_results = [] |
| 212 | + for result in results: |
| 213 | + fixed_results.append({ |
| 214 | + "c": result["c"], |
| 215 | + "u": result["u"], |
| 216 | + "a": result["a"], |
| 217 | + }) |
| 218 | + |
| 219 | + fixed_results[-1] = { |
| 220 | + "c": latest["c"], |
| 221 | + "u": latest["u"], |
| 222 | + "a": latest["a"], |
| 223 | + } |
| 224 | + |
| 225 | + with open("./refs/heads/main/results.json", 'w') as results_of: |
| 226 | + json.dump(fixed_results, results_of, separators=( |
| 227 | + ',', ':'), ensure_ascii=False) |
| 228 | + |
| 229 | + |
| 230 | +def clean_old(file_name, results): |
| 231 | + fixed_results = [{ |
| 232 | + "c": results["c"], |
| 233 | + "u": results["u"], |
| 234 | + "a": results["a"], |
| 235 | + }] |
| 236 | + |
| 237 | + with open(file_name, 'w') as results_of: |
| 238 | + json.dump(fixed_results, results_of, separators=( |
| 239 | + ',', ':'), ensure_ascii=False) |
| 240 | + |
| 241 | + |
| 242 | +for top, dirs, files in os.walk("./refs/tags"): |
| 243 | + for dir in dirs: |
| 244 | + print("Fixing " + dir) |
| 245 | + results = fix_file("./refs/tags/" + dir + "/latest.json") |
| 246 | + clean_old("./refs/tags/" + dir + "/results.json", results) |
| 247 | + |
| 248 | + if os.path.exists("./refs/tags/" + dir + "/features.json"): |
| 249 | + os.remove("./refs/tags/" + dir + "/features.json") |
| 250 | + |
| 251 | +print("Fixing main branch") |
| 252 | +results = fix_file("./refs/heads/main/latest.json") |
| 253 | +clean_main(results) |
| 254 | +if os.path.exists("./refs/heads/main/features.json"): |
| 255 | + os.remove("./refs/heads/main/features.json") |
0 commit comments