Skip to content

Commit a18ee3a

Browse files
committed
Add run tests
1 parent 36df24f commit a18ee3a

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

mypyc/test-data/run-classes.test

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,53 @@ def welp() -> int:
934934
from native import welp
935935
assert welp() == 35
936936

937+
[case testSubclassUnsupportedException]
938+
from mypy_extensions import mypyc_attr
939+
940+
@mypyc_attr(native_class=False)
941+
class MyError(ZeroDivisionError):
942+
pass
943+
944+
@mypyc_attr(native_class=False)
945+
class MyError2(ZeroDivisionError):
946+
def __init__(self, s: str) -> None:
947+
super().__init__(s + "!")
948+
self.x = s.upper()
949+
950+
def f() -> None:
951+
raise MyError("foobar")
952+
953+
def test_non_native_exception_subclass_basics() -> None:
954+
e = MyError()
955+
assert isinstance(e, MyError)
956+
assert isinstance(e, ZeroDivisionError)
957+
assert isinstance(e, Exception)
958+
959+
e = MyError("x")
960+
assert repr(e) == "MyError('x')"
961+
962+
e2 = MyError2("ab")
963+
assert repr(e2) == "MyError2('ab!')", repr(e2)
964+
assert e2.x == "AB"
965+
966+
def test_raise_non_native_exception_subclass_1() -> None:
967+
try:
968+
f()
969+
except MyError:
970+
x = True
971+
else:
972+
assert False
973+
assert x
974+
975+
def test_raise_non_native_exception_subclass_2() -> None:
976+
try:
977+
f()
978+
except ZeroDivisionError:
979+
x = True
980+
else:
981+
assert False
982+
assert x
983+
937984
[case testSubclassPy]
938985
from b import B, V
939986
class A(B):

0 commit comments

Comments
 (0)