]> granicus.if.org Git - python/commitdiff
Add a test for module weakrefability
authorAntoine Pitrou <solipsis@pitrou.net>
Thu, 1 Aug 2013 17:20:31 +0000 (19:20 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Thu, 1 Aug 2013 17:20:31 +0000 (19:20 +0200)
Lib/test/test_module.py

index 3000cec55f523f18c44c7f88b003d2e5e28c0599..5a9b503485245333d91881e7215c4222a9696ecd 100644 (file)
@@ -1,5 +1,6 @@
 # Test the module type
 import unittest
+import weakref
 from test.support import run_unittest, gc_collect
 from test.script_helper import assert_python_ok
 
@@ -95,6 +96,14 @@ a = A(destroyed)"""
         gc_collect()
         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):
         # reprs when modules have no __file__, __name__, or __loader__
         m = ModuleType('foo')