aboutsummaryrefslogtreecommitdiff
path: root/mlir/test/Bindings/Python/ir_operation.py
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/test/Bindings/Python/ir_operation.py')
-rw-r--r--mlir/test/Bindings/Python/ir_operation.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/mlir/test/Bindings/Python/ir_operation.py b/mlir/test/Bindings/Python/ir_operation.py
index d23e0b6c0b4e..1f6df8626a0a 100644
--- a/mlir/test/Bindings/Python/ir_operation.py
+++ b/mlir/test/Bindings/Python/ir_operation.py
@@ -551,3 +551,30 @@ def testPrintInvalidOperation():
# CHECK: "module"() ( {
# CHECK: }) : () -> ()
run(testPrintInvalidOperation)
+
+
+# CHECK-LABEL: TEST: testCreateWithInvalidAttributes
+def testCreateWithInvalidAttributes():
+ ctx = Context()
+ with Location.unknown(ctx):
+ try:
+ Operation.create("module", attributes={None:StringAttr.get("name")})
+ except Exception as e:
+ # CHECK: Invalid attribute key (not a string) when attempting to create the operation "module" (Unable to cast Python instance of type <class 'NoneType'> to C++ type
+ print(e)
+ try:
+ Operation.create("module", attributes={42:StringAttr.get("name")})
+ except Exception as e:
+ # CHECK: Invalid attribute key (not a string) when attempting to create the operation "module" (Unable to cast Python instance of type <class 'int'> to C++ type
+ print(e)
+ try:
+ Operation.create("module", attributes={"some_key":ctx})
+ except Exception as e:
+ # CHECK: Invalid attribute value for the key "some_key" when attempting to create the operation "module" (Unable to cast Python instance of type <class '_mlir.ir.Context'> to C++ type 'mlir::python::PyAttribute')
+ print(e)
+ try:
+ Operation.create("module", attributes={"some_key":None})
+ except Exception as e:
+ # CHECK: Found an invalid (`None`?) attribute value for the key "some_key" when attempting to create the operation "module"
+ print(e)
+run(testCreateWithInvalidAttributes)