Skip to content

Commit 0471c99

Browse files
committed
add tests
1 parent 07d4a1b commit 0471c99

File tree

1 file changed

+67
-3
lines changed

1 file changed

+67
-3
lines changed

mypyc/test-data/run-weakref.test

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ from mypy_extensions import mypyc_attr
77
@mypyc_attr(native_class=False)
88
class Object:
99
"""some random weakreffable object"""
10-
pass
1110

1211
def test_weakref_ref():
1312
obj = Object()
@@ -16,6 +15,20 @@ def test_weakref_ref():
1615
obj = None
1716
assert r() is None, r()
1817

18+
[file driver.py]
19+
from native import test_weakref_ref
20+
21+
test_weakref_ref()
22+
23+
24+
[case testWeakrefRefWithCallback]
25+
from weakref import ref
26+
from mypy_extensions import mypyc_attr
27+
28+
@mypyc_attr(native_class=False)
29+
class Object:
30+
"""some random weakreffable object"""
31+
1932
def test_weakref_ref_with_callback():
2033
obj = Object()
2134
r = ref(obj, lambda x: x)
@@ -24,7 +37,58 @@ def test_weakref_ref_with_callback():
2437
assert r() is None, r()
2538

2639
[file driver.py]
27-
from native import test_weakref_ref, test_weakref_ref_with_callback
40+
from native import test_weakref_ref_with_callback
2841

29-
test_weakref_ref()
3042
test_weakref_ref_with_callback()
43+
44+
45+
[case testWeakrefProxy]
46+
import pytest # type: ignore [import-not-found]
47+
from weakref import proxy
48+
from mypy_extensions import mypyc_attr
49+
50+
@mypyc_attr(native_class=False)
51+
class Object:
52+
"""some random weakreffable object"""
53+
def some_meth(self) -> int:
54+
return 1
55+
56+
def test_weakref_proxy():
57+
obj = Object()
58+
p = proxy(obj)
59+
assert obj.some_meth() == 1
60+
assert p.some_meth() == 1
61+
obj = None
62+
with pytest.raises(ReferenceError):
63+
p.some_meth()
64+
65+
[file driver.py]
66+
from native import test_weakref_proxy
67+
68+
test_weakref_proxy()
69+
70+
71+
[case testWeakrefProxyWithCallback]
72+
import pytest # type: ignore [import-not-found]
73+
from weakref import proxy
74+
from mypy_extensions import mypyc_attr
75+
76+
@mypyc_attr(native_class=False)
77+
class Object:
78+
"""some random weakreffable object"""
79+
def some_meth(self) -> int:
80+
return 1
81+
82+
def test_weakref_proxy_with_callback():
83+
obj = Object()
84+
p = proxy(obj, lambda x: x)
85+
assert obj.some_meth() == 1
86+
assert p.some_meth() == 1
87+
obj = None
88+
with pytest.raises(ReferenceError):
89+
p.some_meth()
90+
91+
[file driver.py]
92+
from native import test_weakref_proxy_with_callback
93+
94+
test_weakref_proxy_with_callback()

0 commit comments

Comments
 (0)