Issue #4885: Add weakref support to mmap objects. Patch by Valerie Lambert.

This commit is contained in:
Antoine Pitrou 2013-08-05 23:17:30 +02:00
parent 914061ab15
commit c53204b947
4 changed files with 23 additions and 3 deletions

View file

@ -1,11 +1,12 @@
from test.support import (TESTFN, run_unittest, import_module, unlink,
requires, _2G, _4G)
requires, _2G, _4G, gc_collect)
import unittest
import os
import re
import itertools
import socket
import sys
import weakref
# Skip test if we can't import mmap.
mmap = import_module('mmap')
@ -692,6 +693,15 @@ class MmapTests(unittest.TestCase):
"wrong exception raised in context manager")
self.assertTrue(m.closed, "context manager failed")
def test_weakref(self):
# Check mmap objects are weakrefable
mm = mmap.mmap(-1, 16)
wr = weakref.ref(mm)
self.assertIs(wr(), mm)
del mm
gc_collect()
self.assertIs(wr(), None)
class LargeMmapTests(unittest.TestCase):
def setUp(self):