summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_deque.py21
-rw-r--r--Lib/test/test_dict.py14
-rw-r--r--Lib/test/test_file.py13
-rw-r--r--Lib/test/test_fileio.py1
-rw-r--r--Lib/test/test_set.py17
-rw-r--r--Lib/test/test_struct.py7
6 files changed, 69 insertions, 4 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index 0f0d09847e..4e2de3d005 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -1,7 +1,8 @@
from collections import deque
import unittest
from test import test_support, seq_tests
-from weakref import proxy
+import gc
+import weakref
import copy
import cPickle as pickle
import random
@@ -418,6 +419,22 @@ class TestBasic(unittest.TestCase):
d.append(1)
gc.collect()
+ def test_container_iterator(self):
+ # Bug # XXX: tp_traverse was not implemented for deque iterator objects
+ class C(object):
+ pass
+ for i in range(2):
+ obj = C()
+ ref = weakref.ref(obj)
+ if i == 0:
+ container = deque([obj, 1])
+ else:
+ container = reversed(deque([obj, 1]))
+ obj.x = iter(container)
+ del obj, container
+ gc.collect()
+ self.assert_(ref() is None, "Cycle was not collected")
+
class TestVariousIteratorArgs(unittest.TestCase):
def test_constructor(self):
@@ -528,7 +545,7 @@ class TestSubclass(unittest.TestCase):
def test_weakref(self):
d = deque('gallahad')
- p = proxy(d)
+ p = weakref.proxy(d)
self.assertEqual(str(p), str(d))
d = None
self.assertRaises(ReferenceError, str, p)
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index f715657d36..14d62f5024 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -2,6 +2,7 @@ import unittest
from test import test_support
import UserDict, random, string
+import gc, weakref
class DictTest(unittest.TestCase):
@@ -554,6 +555,19 @@ class DictTest(unittest.TestCase):
pass
d = {}
+ def test_container_iterator(self):
+ # Bug # XXX: tp_traverse was not implemented for dictiter objects
+ class C(object):
+ pass
+ iterators = (dict.iteritems, dict.itervalues, dict.iterkeys)
+ for i in iterators:
+ obj = C()
+ ref = weakref.ref(obj)
+ container = {obj: 1}
+ obj.x = i(container)
+ del obj, container
+ gc.collect()
+ self.assert_(ref() is None, "Cycle was not collected")
from test import mapping_tests
diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py
index 96f6da2023..b4f494ba96 100644
--- a/Lib/test/test_file.py
+++ b/Lib/test/test_file.py
@@ -125,6 +125,19 @@ class AutoFileTests(unittest.TestCase):
class OtherFileTests(unittest.TestCase):
+ def testOpenDir(self):
+ this_dir = os.path.dirname(__file__)
+ for mode in (None, "w"):
+ try:
+ if mode:
+ f = open(this_dir, mode)
+ else:
+ f = open(this_dir)
+ except IOError as e:
+ self.assertEqual(e.filename, this_dir)
+ else:
+ self.fail("opening a directory didn't raise an IOError")
+
def testModeStrings(self):
# check invalid mode strings
for mode in ("", "aU", "wU+"):
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py
index c9787795e3..d8cf415ed8 100644
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -109,6 +109,7 @@ class AutoFileTests(unittest.TestCase):
_fileio._FileIO('.', 'r')
except IOError as e:
self.assertNotEqual(e.errno, 0)
+ self.assertEqual(e.filename, ".")
else:
self.fail("Should have raised IOError")
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index d38a675907..8d05712365 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -1,6 +1,7 @@
import unittest
from test import test_support
-from weakref import proxy
+import gc
+import weakref
import operator
import copy
import pickle
@@ -322,6 +323,18 @@ class TestJointOps(unittest.TestCase):
self.assertEqual(sum(elem.hash_count for elem in d), n)
self.assertEqual(d3, dict.fromkeys(d, 123))
+ def test_container_iterator(self):
+ # Bug # XXX: tp_traverse was not implemented for set iterator object
+ class C(object):
+ pass
+ obj = C()
+ ref = weakref.ref(obj)
+ container = set([obj, 1])
+ obj.x = iter(container)
+ del obj, container
+ gc.collect()
+ self.assert_(ref() is None, "Cycle was not collected")
+
class TestSet(TestJointOps):
thetype = set
@@ -538,7 +551,7 @@ class TestSet(TestJointOps):
def test_weakref(self):
s = self.thetype('gallahad')
- p = proxy(s)
+ p = weakref.proxy(s)
self.assertEqual(str(p), str(s))
s = None
self.assertRaises(ReferenceError, str, p)
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index 232bffc275..7f5f08b4c6 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -2,6 +2,8 @@ import array
import unittest
import struct
import warnings
+warnings.filterwarnings("ignore", "struct integer overflow masking is deprecated",
+ DeprecationWarning)
from functools import wraps
from test.test_support import TestFailed, verbose, run_unittest
@@ -461,6 +463,11 @@ class StructTest(unittest.TestCase):
self.check_float_coerce(endian + fmt, 1.0)
self.check_float_coerce(endian + fmt, 1.5)
+ def test_issue4228(self):
+ # Packing a long may yield either 32 or 64 bits
+ x = struct.pack('L', -1)[:4]
+ self.assertEqual(x, '\xff'*4)
+
def test_unpack_from(self):
test_string = 'abcd01234'
fmt = '4s'