Last active
March 17, 2021 20:33
-
-
Save msullivan/0d3e3d52b9cca471ddcc29b31cc61def to your computer and use it in GitHub Desktop.
fixup test_edgeql_ir_scopetree.py from test output log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Run with: | |
# edb test tests/test_edgeql_ir_scopetree.py 2>&1 | python3 scopetree-test-fixup.py -i | |
import textwrap | |
import sys | |
from typing import * | |
MAX = 79 | |
def get_updates(data: str) -> Dict[str, str]: | |
cases = {} | |
for fail in data.split("FAIL: ")[1:]: | |
name = fail.split(" ")[0] | |
actual = fail.split("ACTUAL:\n")[1].split("\nDIFF:")[0] | |
cases[name] = textwrap.dedent(actual) | |
return cases | |
def reformat_expected(expected: str) -> List[str]: | |
new = textwrap.indent(expected, " "*8).split("\n") | |
for i, line in enumerate(new): | |
if len(line) > MAX: | |
for j in range(MAX-1, 0, -1): | |
if line[j] == '.': | |
new[i:i+1] = [line[:j]+'\\', line[j:]] | |
break | |
return new | |
def fixup(test_src: str, case: str, expected: str) -> str: | |
ls = test_src.split('\n') | |
i = ls.index(f' def {case}(self):') | |
i_ok = ls.index('% OK %', i) | |
i_end = ls.index(' """', i_ok) | |
ls[i_ok+1:i_end] = reformat_expected(expected) | |
return '\n'.join(ls) | |
def main(args: List[str]) -> None: | |
data = sys.stdin.read() | |
fname = "tests/test_edgeql_ir_scopetree.py" | |
upds = get_updates(data) | |
with open(fname) as f: | |
test_src = f.read() | |
for k, v in upds.items(): | |
test_src = fixup(test_src, k, v) | |
if args[1:] == ['-i']: | |
with open(fname, "w") as f: | |
f.write(test_src) | |
else: | |
sys.stdout.write(test_src) | |
if __name__ == '__main__': | |
main(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment