Skip to content

Commit d198aa1

Browse files
committed
test_host_behavior_interop.py add test_interop_assertions test
1 parent c2f26ac commit d198aa1

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_host_behavior_interop.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,37 @@
4848

4949
class TestPyStructNumericSequenceTypes(object):
5050

51+
@skipIf(True, "not supported in native mode")
52+
def test_interop_assertions(self):
53+
class MyType(object):
54+
data = 100000000000
55+
56+
t = MyType()
57+
import java
58+
BigInteger = java.type("java.math.BigInteger")
59+
60+
polyglot.register_interop_behavior(MyType,
61+
is_number=False,
62+
as_long=lambda x: x.data)
63+
try:
64+
# since is number is false, this should throw a TypeError
65+
print(BigInteger.valueOf(t))
66+
except TypeError:
67+
assert True
68+
else:
69+
assert False
70+
71+
polyglot.register_interop_behavior(MyType,
72+
is_number=True,
73+
fits_in_long=lambda x: True)
74+
try:
75+
# since as_long is not defined, this should throw a TypeError
76+
print(BigInteger.valueOf(t))
77+
except TypeError:
78+
assert True
79+
else:
80+
assert False
81+
5182
@skipIf(is_native, "not supported in native mode")
5283
def test_host_interop_extension(self):
5384
MyNativeType = CPyExtType("MyNativeType",
@@ -72,7 +103,6 @@ def test_host_interop_extension(self):
72103
instance = MyNativeType()
73104
assert instance.get_data() == 10
74105

75-
import polyglot
76106
import java
77107
BigInteger = java.type("java.math.BigInteger")
78108

0 commit comments

Comments
 (0)