Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion mlir/extras/testing/testing.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import difflib
import inspect
import platform
import re
import shutil
import sys
import tempfile
from pathlib import Path
from subprocess import PIPE, Popen
from textwrap import dedent
from textwrap import dedent, indent

import pytest

Expand All @@ -16,6 +17,25 @@
from ...ir import Module


def replace_correct_str_with_comments(fun, correct_with_checks):
# fun = inspect.currentframe().f_back.f_code
lines, lnum = inspect.findsource(fun)
fun_src = inspect.getsource(fun)
fun_src = re.sub(
r'dedent\(\s+""".*"""\s+\)',
"#####"
+ indent(correct_with_checks, " ")
+ "\n filecheck_with_comments(ctx.module)\n#####",
fun_src,
flags=re.DOTALL,
)
fun_src = fun_src.splitlines(keepends=True)
lines[lnum : lnum + len(fun_src)] = fun_src

with open(inspect.getfile(fun), "w") as f:
f.writelines(lines)


def filecheck(correct: str, module):
if isinstance(module, Module):
assert module.operation.verify()
Expand Down
Loading