mirror of
https://github.com/python/cpython.git
synced 2025-10-18 04:38:07 +00:00
Add a test for module weakrefability
This commit is contained in:
parent
5284f80268
commit
4ed328c4d7
1 changed files with 9 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
# Test the module type
|
# Test the module type
|
||||||
import unittest
|
import unittest
|
||||||
|
import weakref
|
||||||
from test.support import run_unittest, gc_collect
|
from test.support import run_unittest, gc_collect
|
||||||
from test.script_helper import assert_python_ok
|
from test.script_helper import assert_python_ok
|
||||||
|
|
||||||
|
@ -95,6 +96,14 @@ a = A(destroyed)"""
|
||||||
gc_collect()
|
gc_collect()
|
||||||
self.assertEqual(destroyed, [1])
|
self.assertEqual(destroyed, [1])
|
||||||
|
|
||||||
|
def test_weakref(self):
|
||||||
|
m = ModuleType("foo")
|
||||||
|
wr = weakref.ref(m)
|
||||||
|
self.assertIs(wr(), m)
|
||||||
|
del m
|
||||||
|
gc_collect()
|
||||||
|
self.assertIs(wr(), None)
|
||||||
|
|
||||||
def test_module_repr_minimal(self):
|
def test_module_repr_minimal(self):
|
||||||
# reprs when modules have no __file__, __name__, or __loader__
|
# reprs when modules have no __file__, __name__, or __loader__
|
||||||
m = ModuleType('foo')
|
m = ModuleType('foo')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue