Skip to content
Merged
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
17 changes: 5 additions & 12 deletions python/tvm/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2065,22 +2065,15 @@ def _is_method(func):
def test_compare(self, before, expected, transform):
"""Unit test to compare the expected TIR PrimFunc to actual"""

def pprint(name, obj):
script = obj.script()
if isinstance(obj, tvm.IRModule):
return script.replace("class Module", f"class {name}")
else:
return script.replace("def func", f"def {name}")

if inspect.isclass(expected) and issubclass(expected, Exception):
with pytest.raises(expected):
after = transform(before)

# This portion through pytest.fail isn't strictly
# necessary, but gives a better error message that
# includes the before/after.
before_str = pprint("before", before)
after_str = pprint("after", after)
before_str = before.script(name="before")
after_str = after.script(name="after")

pytest.fail(
msg=(
Expand All @@ -2095,9 +2088,9 @@ def pprint(name, obj):
try:
tvm.ir.assert_structural_equal(after, expected)
except ValueError as err:
before_str = pprint("before", before)
after_str = pprint("after", after)
expected_str = pprint("expected", expected)
before_str = before.script(name="before")
after_str = after.script(name="after")
expected_str = expected.script(name="expected")
raise ValueError(
f"TIR after transformation did not match expected:\n"
f"{before_str}\n{after_str}\n{expected_str}"
Expand Down