From c53204b9477a2e28b6b366fd271f61c73b805cee Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Mon, 5 Aug 2013 23:17:30 +0200 Subject: Issue #4885: Add weakref support to mmap objects. Patch by Valerie Lambert. --- Lib/test/test_mmap.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'Lib/test/test_mmap.py') diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index 505ffba74e..b1cc97371e 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -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): -- cgit v1.2.1