Skip to content

Commit c499c31

Browse files
authored
use comments (#146)
1 parent 3b6adc9 commit c499c31

18 files changed

+2751
-3412
lines changed

mlir/extras/testing/testing.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import difflib
22
import inspect
33
import platform
4+
import re
45
import shutil
56
import sys
67
import tempfile
78
from pathlib import Path
89
from subprocess import PIPE, Popen
9-
from textwrap import dedent
10+
from textwrap import dedent, indent
1011

1112
import pytest
1213

@@ -16,6 +17,25 @@
1617
from ...ir import Module
1718

1819

20+
def replace_correct_str_with_comments(fun, correct_with_checks):
21+
# fun = inspect.currentframe().f_back.f_code
22+
lines, lnum = inspect.findsource(fun)
23+
fun_src = inspect.getsource(fun)
24+
fun_src = re.sub(
25+
r'dedent\(\s+""".*"""\s+\)',
26+
"#####"
27+
+ indent(correct_with_checks, " ")
28+
+ "\n filecheck_with_comments(ctx.module)\n#####",
29+
fun_src,
30+
flags=re.DOTALL,
31+
)
32+
fun_src = fun_src.splitlines(keepends=True)
33+
lines[lnum : lnum + len(fun_src)] = fun_src
34+
35+
with open(inspect.getfile(fun), "w") as f:
36+
f.writelines(lines)
37+
38+
1939
def filecheck(correct: str, module):
2040
if isinstance(module, Module):
2141
assert module.operation.verify()

0 commit comments

Comments
 (0)