Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add tests
  • Loading branch information
BobTheBuidler committed Aug 2, 2025
commit 0471c999402bfacfb134af433548e015f6b86d77
70 changes: 67 additions & 3 deletions mypyc/test-data/run-weakref.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ from mypy_extensions import mypyc_attr
@mypyc_attr(native_class=False)
class Object:
"""some random weakreffable object"""
pass

def test_weakref_ref():
obj = Object()
Expand All @@ -16,6 +15,20 @@ def test_weakref_ref():
obj = None
assert r() is None, r()

[file driver.py]
from native import test_weakref_ref

test_weakref_ref()


[case testWeakrefRefWithCallback]
from weakref import ref
from mypy_extensions import mypyc_attr

@mypyc_attr(native_class=False)
class Object:
"""some random weakreffable object"""

def test_weakref_ref_with_callback():
obj = Object()
r = ref(obj, lambda x: x)
Expand All @@ -24,7 +37,58 @@ def test_weakref_ref_with_callback():
assert r() is None, r()

[file driver.py]
from native import test_weakref_ref, test_weakref_ref_with_callback
from native import test_weakref_ref_with_callback

test_weakref_ref()
test_weakref_ref_with_callback()


[case testWeakrefProxy]
import pytest # type: ignore [import-not-found]
from weakref import proxy
from mypy_extensions import mypyc_attr

@mypyc_attr(native_class=False)
class Object:
"""some random weakreffable object"""
def some_meth(self) -> int:
return 1

def test_weakref_proxy():
obj = Object()
p = proxy(obj)
assert obj.some_meth() == 1
assert p.some_meth() == 1
obj = None
with pytest.raises(ReferenceError):
p.some_meth()

[file driver.py]
from native import test_weakref_proxy

test_weakref_proxy()


[case testWeakrefProxyWithCallback]
import pytest # type: ignore [import-not-found]
from weakref import proxy
from mypy_extensions import mypyc_attr

@mypyc_attr(native_class=False)
class Object:
"""some random weakreffable object"""
def some_meth(self) -> int:
return 1

def test_weakref_proxy_with_callback():
obj = Object()
p = proxy(obj, lambda x: x)
assert obj.some_meth() == 1
assert p.some_meth() == 1
obj = None
with pytest.raises(ReferenceError):
p.some_meth()

[file driver.py]
from native import test_weakref_proxy_with_callback

test_weakref_proxy_with_callback()