mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
Add weakref support to array.array and file objects.
This commit is contained in:
parent
691d80532b
commit
cb87bc8e7e
5 changed files with 38 additions and 4 deletions
|
@ -5,6 +5,7 @@
|
|||
|
||||
import unittest
|
||||
from test import test_support
|
||||
from weakref import proxy
|
||||
import array, cStringIO, math
|
||||
|
||||
tests = [] # list to accumulate all tests
|
||||
|
@ -614,6 +615,13 @@ class BaseTest(unittest.TestCase):
|
|||
b = buffer(a)
|
||||
self.assertEqual(b[0], a.tostring()[0])
|
||||
|
||||
def test_weakref(self):
|
||||
s = array.array(self.typecode, self.example)
|
||||
p = proxy(s)
|
||||
self.assertEqual(p.tostring(), s.tostring())
|
||||
s = None
|
||||
self.assertRaises(ReferenceError, len, p)
|
||||
|
||||
def test_bug_782369(self):
|
||||
import sys
|
||||
if hasattr(sys, "getrefcount"):
|
||||
|
@ -624,6 +632,8 @@ class BaseTest(unittest.TestCase):
|
|||
b = array.array('B', range(64))
|
||||
self.assertEqual(rc, sys.getrefcount(10))
|
||||
|
||||
|
||||
|
||||
class StringTest(BaseTest):
|
||||
|
||||
def test_setitem(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue