test-kivy-app/kivy_venv/lib/python3.11/site-packages/kivy/tests/test_weakmethod.py

45 lines
989 B
Python
Raw Normal View History

2024-09-15 12:12:16 +00:00
import gc
def test_weak_method_on_obj():
from kivy.weakmethod import WeakMethod
class SomeClass:
def do_something(self):
pass
obj = SomeClass()
weak_method = WeakMethod(obj.do_something)
assert not weak_method.is_dead()
assert weak_method() == obj.do_something
assert weak_method == WeakMethod(obj.do_something)
assert weak_method != WeakMethod(SomeClass().do_something)
del obj
gc.collect()
assert weak_method.is_dead()
assert weak_method() is None
assert weak_method != WeakMethod(SomeClass().do_something)
def test_weak_method_func():
from kivy.weakmethod import WeakMethod
def do_something():
pass
weak_method = WeakMethod(do_something)
assert not weak_method.is_dead()
assert weak_method() == do_something
assert weak_method == WeakMethod(do_something)
del do_something
gc.collect()
assert not weak_method.is_dead()
assert weak_method() is not None