Skip to content

Commit b2e0c9b

Browse files
committed
add a test
1 parent 9db2dc4 commit b2e0c9b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

mlir/test/python/ir/module.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# RUN: %PYTHON %s | FileCheck %s
22

33
import gc
4+
from pathlib import Path
5+
from tempfile import NamedTemporaryFile
46
from mlir.ir import *
57

68

@@ -27,6 +29,24 @@ def testParseSuccess():
2729
print(str(module))
2830

2931

32+
# Verify successful parse from file.
33+
# CHECK-LABEL: TEST: testParseFromFileSuccess
34+
# CHECK: module @successfulParse
35+
@run
36+
def testParseFromFileSuccess():
37+
ctx = Context()
38+
with NamedTemporaryFile(mode="w") as tmp_file:
39+
tmp_file.write(r"""module @successfulParse {}""")
40+
tmp_file.flush()
41+
module = Module.parse(Path(tmp_file.name), ctx)
42+
assert module.context is ctx
43+
print("CLEAR CONTEXT")
44+
ctx = None # Ensure that module captures the context.
45+
gc.collect()
46+
module.dump() # Just outputs to stderr. Verifies that it functions.
47+
print(str(module))
48+
49+
3050
# Verify parse error.
3151
# CHECK-LABEL: TEST: testParseError
3252
# CHECK: testParseError: <

0 commit comments

Comments
 (0)