diff Lib/test/test_module.py @ 84950:cdddd3ed2ae1

Add a test for module weakrefability
author Antoine Pitrou <solipsis@pitrou.net>
date Thu, 01 Aug 2013 19:20:31 +0200
parents 79e2f5bbc30c
children 07229c6104b1
line wrap: on
line diff
--- a/Lib/test/test_module.py	Thu Aug 01 18:31:06 2013 +0200
+++ b/Lib/test/test_module.py	Thu Aug 01 19:20:31 2013 +0200
@@ -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 @@
         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')