2004-09-30 10:46:00 -03:00
|
|
|
import unittest
|
|
|
|
from test import test_support
|
|
|
|
|
2008-02-23 13:40:11 -04:00
|
|
|
import UserDict, random, string
|
Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67952 | georg.brandl | 2008-12-27 18:42:40 +0100 (Sat, 27 Dec 2008) | 2 lines
#4752: actually use custom handler in example.
........
r67953 | georg.brandl | 2008-12-27 19:20:04 +0100 (Sat, 27 Dec 2008) | 3 lines
Patch #4739 by David Laban: add symbols to pydoc help topics,
so that ``help('@')`` works as expected.
........
r67955 | georg.brandl | 2008-12-27 19:27:53 +0100 (Sat, 27 Dec 2008) | 3 lines
Follow-up to r67746 in order to restore backwards-compatibility for
those who (monkey-)patch TextWrapper.wordsep_re with a custom RE.
........
r67957 | georg.brandl | 2008-12-27 19:49:19 +0100 (Sat, 27 Dec 2008) | 2 lines
#4754: improve winsound documentation.
........
r67958 | georg.brandl | 2008-12-27 20:02:59 +0100 (Sat, 27 Dec 2008) | 2 lines
#4682: 'b' is actually unsigned char.
........
r67960 | georg.brandl | 2008-12-27 20:04:44 +0100 (Sat, 27 Dec 2008) | 2 lines
#4695: fix backslashery.
........
r67961 | georg.brandl | 2008-12-27 20:06:04 +0100 (Sat, 27 Dec 2008) | 2 lines
Use :samp: role.
........
r67963 | georg.brandl | 2008-12-27 20:11:15 +0100 (Sat, 27 Dec 2008) | 2 lines
#4671: document that pydoc imports modules.
........
r67965 | antoine.pitrou | 2008-12-27 21:34:52 +0100 (Sat, 27 Dec 2008) | 3 lines
Issue #4677: add two list comprehension tests to pybench.
........
r67967 | benjamin.peterson | 2008-12-27 23:18:58 +0100 (Sat, 27 Dec 2008) | 1 line
fix markup
........
r67970 | alexandre.vassalotti | 2008-12-28 02:52:58 +0100 (Sun, 28 Dec 2008) | 2 lines
Fix name mangling of PyUnicode_ClearFreeList.
........
r67971 | alexandre.vassalotti | 2008-12-28 03:10:35 +0100 (Sun, 28 Dec 2008) | 2 lines
Sort UCS-2/UCS-4 name mangling list.
........
r67973 | alexandre.vassalotti | 2008-12-28 03:58:22 +0100 (Sun, 28 Dec 2008) | 2 lines
Document Py_VaBuildValue.
........
r67982 | benjamin.peterson | 2008-12-28 16:37:31 +0100 (Sun, 28 Dec 2008) | 1 line
fix WORD_BIGEDIAN declaration in Universal builds; fixes #4060 and #4728
........
r67988 | ronald.oussoren | 2008-12-28 20:40:56 +0100 (Sun, 28 Dec 2008) | 1 line
Issue4064: architecture string for universal builds on OSX
........
r67990 | ronald.oussoren | 2008-12-28 20:50:40 +0100 (Sun, 28 Dec 2008) | 3 lines
Update the fix for issue4064 to deal correctly with all three variants of
universal builds that are presented by the configure script.
........
r67995 | benjamin.peterson | 2008-12-28 22:16:07 +0100 (Sun, 28 Dec 2008) | 1 line
#4763 PyErr_ExceptionMatches won't blow up with NULL arguments
........
r68014 | benjamin.peterson | 2008-12-29 18:47:42 +0100 (Mon, 29 Dec 2008) | 1 line
#4764 set IOError.filename when trying to open a directory on POSIX platforms
........
r68016 | benjamin.peterson | 2008-12-29 18:56:58 +0100 (Mon, 29 Dec 2008) | 1 line
#4764 in io.open, set IOError.filename when trying to open a directory on POSIX platforms
........
r68030 | benjamin.peterson | 2008-12-29 22:38:14 +0100 (Mon, 29 Dec 2008) | 1 line
fix French
........
r68057 | vinay.sajip | 2008-12-30 08:01:25 +0100 (Tue, 30 Dec 2008) | 1 line
Minor documentation change relating to NullHandler.
........
r68061 | georg.brandl | 2008-12-30 11:15:49 +0100 (Tue, 30 Dec 2008) | 2 lines
#4778: attributes can't be called.
........
r68112 | benjamin.peterson | 2009-01-01 00:48:39 +0100 (Thu, 01 Jan 2009) | 1 line
#4795 inspect.isgeneratorfunction() should return False instead of None
........
r68115 | benjamin.peterson | 2009-01-01 05:04:41 +0100 (Thu, 01 Jan 2009) | 1 line
simplfy code
........
r68116 | georg.brandl | 2009-01-01 12:46:51 +0100 (Thu, 01 Jan 2009) | 2 lines
#4100: note that element children are not necessarily present on "start" events.
........
r68117 | georg.brandl | 2009-01-01 12:53:55 +0100 (Thu, 01 Jan 2009) | 2 lines
#4156: make clear that "protocol" is to be replaced with the protocol name.
........
r68118 | georg.brandl | 2009-01-01 13:00:19 +0100 (Thu, 01 Jan 2009) | 2 lines
#4185: clarify escape behavior of replacement strings.
........
r68120 | georg.brandl | 2009-01-01 13:15:31 +0100 (Thu, 01 Jan 2009) | 4 lines
#4228: Pack negative values the same way as 2.4
in struct's L format.
........
r68121 | georg.brandl | 2009-01-01 13:43:33 +0100 (Thu, 01 Jan 2009) | 2 lines
Point to types module in new module deprecation notice.
........
r68123 | georg.brandl | 2009-01-01 13:52:29 +0100 (Thu, 01 Jan 2009) | 2 lines
#4784: ... on three counts ...
........
r68124 | georg.brandl | 2009-01-01 13:53:19 +0100 (Thu, 01 Jan 2009) | 2 lines
#4782: Fix markup error that hid load() and loads().
........
r68125 | georg.brandl | 2009-01-01 14:02:09 +0100 (Thu, 01 Jan 2009) | 2 lines
#4776: add data_files and package_dir arguments.
........
r68126 | georg.brandl | 2009-01-01 14:05:13 +0100 (Thu, 01 Jan 2009) | 2 lines
Handlers are in the `logging.handlers` module.
........
r68127 | georg.brandl | 2009-01-01 14:14:49 +0100 (Thu, 01 Jan 2009) | 2 lines
#4767: Use correct submodules for all MIME classes.
........
r68128 | antoine.pitrou | 2009-01-01 15:11:22 +0100 (Thu, 01 Jan 2009) | 3 lines
Issue #3680: Reference cycles created through a dict, set or deque iterator did not get collected.
........
2009-01-01 11:46:10 -04:00
|
|
|
import gc, weakref
|
2004-09-30 10:46:00 -03:00
|
|
|
|
|
|
|
|
|
|
|
class DictTest(unittest.TestCase):
|
|
|
|
def test_constructor(self):
|
|
|
|
# calling built-in types without argument must return empty
|
|
|
|
self.assertEqual(dict(), {})
|
|
|
|
self.assert_(dict() is not {})
|
|
|
|
|
2007-12-18 20:21:06 -04:00
|
|
|
def test_literal_constructor(self):
|
|
|
|
# check literal constructor for different sized dicts (to exercise the BUILD_MAP oparg
|
2008-03-18 02:12:41 -03:00
|
|
|
for n in (0, 1, 6, 256, 400):
|
|
|
|
items = [(''.join([random.choice(string.letters)
|
|
|
|
for j in range(8)]),
|
|
|
|
i)
|
|
|
|
for i in range(n)]
|
|
|
|
random.shuffle(items)
|
2007-12-18 20:21:06 -04:00
|
|
|
dictliteral = '{' + ', '.join('%r: %d' % item for item in items) + '}'
|
|
|
|
self.assertEqual(eval(dictliteral), dict(items))
|
|
|
|
|
2004-09-30 10:46:00 -03:00
|
|
|
def test_bool(self):
|
|
|
|
self.assert_(not {})
|
|
|
|
self.assert_({1: 2})
|
|
|
|
self.assert_(bool({}) is False)
|
|
|
|
self.assert_(bool({1: 2}) is True)
|
|
|
|
|
|
|
|
def test_keys(self):
|
|
|
|
d = {}
|
|
|
|
self.assertEqual(d.keys(), [])
|
|
|
|
d = {'a': 1, 'b': 2}
|
|
|
|
k = d.keys()
|
|
|
|
self.assert_(d.has_key('a'))
|
|
|
|
self.assert_(d.has_key('b'))
|
|
|
|
|
|
|
|
self.assertRaises(TypeError, d.keys, None)
|
|
|
|
|
|
|
|
def test_values(self):
|
|
|
|
d = {}
|
|
|
|
self.assertEqual(d.values(), [])
|
|
|
|
d = {1:2}
|
|
|
|
self.assertEqual(d.values(), [2])
|
|
|
|
|
|
|
|
self.assertRaises(TypeError, d.values, None)
|
|
|
|
|
|
|
|
def test_items(self):
|
|
|
|
d = {}
|
|
|
|
self.assertEqual(d.items(), [])
|
|
|
|
|
|
|
|
d = {1:2}
|
|
|
|
self.assertEqual(d.items(), [(1, 2)])
|
|
|
|
|
|
|
|
self.assertRaises(TypeError, d.items, None)
|
|
|
|
|
|
|
|
def test_has_key(self):
|
|
|
|
d = {}
|
|
|
|
self.assert_(not d.has_key('a'))
|
|
|
|
d = {'a': 1, 'b': 2}
|
|
|
|
k = d.keys()
|
|
|
|
k.sort()
|
|
|
|
self.assertEqual(k, ['a', 'b'])
|
|
|
|
|
|
|
|
self.assertRaises(TypeError, d.has_key)
|
|
|
|
|
|
|
|
def test_contains(self):
|
|
|
|
d = {}
|
|
|
|
self.assert_(not ('a' in d))
|
|
|
|
self.assert_('a' not in d)
|
|
|
|
d = {'a': 1, 'b': 2}
|
|
|
|
self.assert_('a' in d)
|
|
|
|
self.assert_('b' in d)
|
|
|
|
self.assert_('c' not in d)
|
|
|
|
|
|
|
|
self.assertRaises(TypeError, d.__contains__)
|
|
|
|
|
|
|
|
def test_len(self):
|
|
|
|
d = {}
|
|
|
|
self.assertEqual(len(d), 0)
|
|
|
|
d = {'a': 1, 'b': 2}
|
|
|
|
self.assertEqual(len(d), 2)
|
|
|
|
|
|
|
|
def test_getitem(self):
|
|
|
|
d = {'a': 1, 'b': 2}
|
|
|
|
self.assertEqual(d['a'], 1)
|
|
|
|
self.assertEqual(d['b'], 2)
|
|
|
|
d['c'] = 3
|
|
|
|
d['a'] = 4
|
|
|
|
self.assertEqual(d['c'], 3)
|
|
|
|
self.assertEqual(d['a'], 4)
|
|
|
|
del d['b']
|
|
|
|
self.assertEqual(d, {'a': 4, 'c': 3})
|
|
|
|
|
|
|
|
self.assertRaises(TypeError, d.__getitem__)
|
|
|
|
|
|
|
|
class BadEq(object):
|
|
|
|
def __eq__(self, other):
|
|
|
|
raise Exc()
|
2007-11-21 20:55:51 -04:00
|
|
|
def __hash__(self):
|
|
|
|
return 24
|
2004-09-30 10:46:00 -03:00
|
|
|
|
|
|
|
d = {}
|
|
|
|
d[BadEq()] = 42
|
|
|
|
self.assertRaises(KeyError, d.__getitem__, 23)
|
|
|
|
|
|
|
|
class Exc(Exception): pass
|
|
|
|
|
|
|
|
class BadHash(object):
|
|
|
|
fail = False
|
|
|
|
def __hash__(self):
|
|
|
|
if self.fail:
|
|
|
|
raise Exc()
|
|
|
|
else:
|
|
|
|
return 42
|
|
|
|
|
|
|
|
x = BadHash()
|
|
|
|
d[x] = 42
|
|
|
|
x.fail = True
|
|
|
|
self.assertRaises(Exc, d.__getitem__, x)
|
|
|
|
|
|
|
|
def test_clear(self):
|
|
|
|
d = {1:1, 2:2, 3:3}
|
|
|
|
d.clear()
|
|
|
|
self.assertEqual(d, {})
|
|
|
|
|
|
|
|
self.assertRaises(TypeError, d.clear, None)
|
|
|
|
|
|
|
|
def test_update(self):
|
|
|
|
d = {}
|
|
|
|
d.update({1:100})
|
|
|
|
d.update({2:20})
|
|
|
|
d.update({1:1, 2:2, 3:3})
|
|
|
|
self.assertEqual(d, {1:1, 2:2, 3:3})
|
|
|
|
|
|
|
|
d.update()
|
|
|
|
self.assertEqual(d, {1:1, 2:2, 3:3})
|
|
|
|
|
|
|
|
self.assertRaises((TypeError, AttributeError), d.update, None)
|
|
|
|
|
|
|
|
class SimpleUserDict:
|
|
|
|
def __init__(self):
|
|
|
|
self.d = {1:1, 2:2, 3:3}
|
|
|
|
def keys(self):
|
|
|
|
return self.d.keys()
|
|
|
|
def __getitem__(self, i):
|
|
|
|
return self.d[i]
|
|
|
|
d.clear()
|
|
|
|
d.update(SimpleUserDict())
|
|
|
|
self.assertEqual(d, {1:1, 2:2, 3:3})
|
|
|
|
|
|
|
|
class Exc(Exception): pass
|
|
|
|
|
|
|
|
d.clear()
|
|
|
|
class FailingUserDict:
|
|
|
|
def keys(self):
|
|
|
|
raise Exc
|
|
|
|
self.assertRaises(Exc, d.update, FailingUserDict())
|
|
|
|
|
|
|
|
class FailingUserDict:
|
|
|
|
def keys(self):
|
|
|
|
class BogonIter:
|
|
|
|
def __init__(self):
|
|
|
|
self.i = 1
|
|
|
|
def __iter__(self):
|
|
|
|
return self
|
|
|
|
def next(self):
|
|
|
|
if self.i:
|
|
|
|
self.i = 0
|
|
|
|
return 'a'
|
|
|
|
raise Exc
|
|
|
|
return BogonIter()
|
|
|
|
def __getitem__(self, key):
|
|
|
|
return key
|
|
|
|
self.assertRaises(Exc, d.update, FailingUserDict())
|
|
|
|
|
|
|
|
class FailingUserDict:
|
|
|
|
def keys(self):
|
|
|
|
class BogonIter:
|
|
|
|
def __init__(self):
|
|
|
|
self.i = ord('a')
|
|
|
|
def __iter__(self):
|
|
|
|
return self
|
|
|
|
def next(self):
|
|
|
|
if self.i <= ord('z'):
|
|
|
|
rtn = chr(self.i)
|
|
|
|
self.i += 1
|
|
|
|
return rtn
|
|
|
|
raise StopIteration
|
|
|
|
return BogonIter()
|
|
|
|
def __getitem__(self, key):
|
|
|
|
raise Exc
|
|
|
|
self.assertRaises(Exc, d.update, FailingUserDict())
|
|
|
|
|
|
|
|
class badseq(object):
|
|
|
|
def __iter__(self):
|
|
|
|
return self
|
|
|
|
def next(self):
|
|
|
|
raise Exc()
|
|
|
|
|
|
|
|
self.assertRaises(Exc, {}.update, badseq())
|
|
|
|
|
|
|
|
self.assertRaises(ValueError, {}.update, [(1, 2, 3)])
|
|
|
|
|
|
|
|
def test_fromkeys(self):
|
|
|
|
self.assertEqual(dict.fromkeys('abc'), {'a':None, 'b':None, 'c':None})
|
|
|
|
d = {}
|
|
|
|
self.assert_(not(d.fromkeys('abc') is d))
|
|
|
|
self.assertEqual(d.fromkeys('abc'), {'a':None, 'b':None, 'c':None})
|
|
|
|
self.assertEqual(d.fromkeys((4,5),0), {4:0, 5:0})
|
|
|
|
self.assertEqual(d.fromkeys([]), {})
|
|
|
|
def g():
|
|
|
|
yield 1
|
|
|
|
self.assertEqual(d.fromkeys(g()), {1:None})
|
|
|
|
self.assertRaises(TypeError, {}.fromkeys, 3)
|
|
|
|
class dictlike(dict): pass
|
|
|
|
self.assertEqual(dictlike.fromkeys('a'), {'a':None})
|
|
|
|
self.assertEqual(dictlike().fromkeys('a'), {'a':None})
|
|
|
|
self.assert_(type(dictlike.fromkeys('a')) is dictlike)
|
|
|
|
self.assert_(type(dictlike().fromkeys('a')) is dictlike)
|
|
|
|
class mydict(dict):
|
|
|
|
def __new__(cls):
|
|
|
|
return UserDict.UserDict()
|
|
|
|
ud = mydict.fromkeys('ab')
|
|
|
|
self.assertEqual(ud, {'a':None, 'b':None})
|
|
|
|
self.assert_(isinstance(ud, UserDict.UserDict))
|
|
|
|
self.assertRaises(TypeError, dict.fromkeys)
|
|
|
|
|
|
|
|
class Exc(Exception): pass
|
|
|
|
|
|
|
|
class baddict1(dict):
|
|
|
|
def __init__(self):
|
|
|
|
raise Exc()
|
|
|
|
|
|
|
|
self.assertRaises(Exc, baddict1.fromkeys, [1])
|
|
|
|
|
|
|
|
class BadSeq(object):
|
|
|
|
def __iter__(self):
|
|
|
|
return self
|
|
|
|
def next(self):
|
|
|
|
raise Exc()
|
|
|
|
|
|
|
|
self.assertRaises(Exc, dict.fromkeys, BadSeq())
|
|
|
|
|
|
|
|
class baddict2(dict):
|
|
|
|
def __setitem__(self, key, value):
|
|
|
|
raise Exc()
|
|
|
|
|
|
|
|
self.assertRaises(Exc, baddict2.fromkeys, [1])
|
|
|
|
|
2007-11-06 22:26:17 -04:00
|
|
|
# test fast path for dictionary inputs
|
|
|
|
d = dict(zip(range(6), range(6)))
|
|
|
|
self.assertEqual(dict.fromkeys(d, 0), dict(zip(range(6), [0]*6)))
|
|
|
|
|
2004-09-30 10:46:00 -03:00
|
|
|
def test_copy(self):
|
|
|
|
d = {1:1, 2:2, 3:3}
|
|
|
|
self.assertEqual(d.copy(), {1:1, 2:2, 3:3})
|
|
|
|
self.assertEqual({}.copy(), {})
|
|
|
|
self.assertRaises(TypeError, d.copy, None)
|
|
|
|
|
|
|
|
def test_get(self):
|
|
|
|
d = {}
|
|
|
|
self.assert_(d.get('c') is None)
|
|
|
|
self.assertEqual(d.get('c', 3), 3)
|
|
|
|
d = {'a' : 1, 'b' : 2}
|
|
|
|
self.assert_(d.get('c') is None)
|
|
|
|
self.assertEqual(d.get('c', 3), 3)
|
|
|
|
self.assertEqual(d.get('a'), 1)
|
|
|
|
self.assertEqual(d.get('a', 3), 1)
|
|
|
|
self.assertRaises(TypeError, d.get)
|
|
|
|
self.assertRaises(TypeError, d.get, None, None, None)
|
|
|
|
|
|
|
|
def test_setdefault(self):
|
|
|
|
# dict.setdefault()
|
|
|
|
d = {}
|
|
|
|
self.assert_(d.setdefault('key0') is None)
|
|
|
|
d.setdefault('key0', [])
|
|
|
|
self.assert_(d.setdefault('key0') is None)
|
|
|
|
d.setdefault('key', []).append(3)
|
|
|
|
self.assertEqual(d['key'][0], 3)
|
|
|
|
d.setdefault('key', []).append(4)
|
|
|
|
self.assertEqual(len(d['key']), 2)
|
|
|
|
self.assertRaises(TypeError, d.setdefault)
|
|
|
|
|
|
|
|
class Exc(Exception): pass
|
|
|
|
|
|
|
|
class BadHash(object):
|
|
|
|
fail = False
|
|
|
|
def __hash__(self):
|
|
|
|
if self.fail:
|
|
|
|
raise Exc()
|
|
|
|
else:
|
|
|
|
return 42
|
|
|
|
|
|
|
|
x = BadHash()
|
|
|
|
d[x] = 42
|
|
|
|
x.fail = True
|
|
|
|
self.assertRaises(Exc, d.setdefault, x, [])
|
|
|
|
|
|
|
|
def test_popitem(self):
|
|
|
|
# dict.popitem()
|
|
|
|
for copymode in -1, +1:
|
|
|
|
# -1: b has same structure as a
|
|
|
|
# +1: b is a.copy()
|
|
|
|
for log2size in range(12):
|
|
|
|
size = 2**log2size
|
|
|
|
a = {}
|
|
|
|
b = {}
|
|
|
|
for i in range(size):
|
|
|
|
a[repr(i)] = i
|
|
|
|
if copymode < 0:
|
|
|
|
b[repr(i)] = i
|
|
|
|
if copymode > 0:
|
|
|
|
b = a.copy()
|
|
|
|
for i in range(size):
|
|
|
|
ka, va = ta = a.popitem()
|
|
|
|
self.assertEqual(va, int(ka))
|
|
|
|
kb, vb = tb = b.popitem()
|
|
|
|
self.assertEqual(vb, int(kb))
|
|
|
|
self.assert_(not(copymode < 0 and ta != tb))
|
|
|
|
self.assert_(not a)
|
|
|
|
self.assert_(not b)
|
|
|
|
|
|
|
|
d = {}
|
|
|
|
self.assertRaises(KeyError, d.popitem)
|
|
|
|
|
|
|
|
def test_pop(self):
|
|
|
|
# Tests for pop with specified key
|
|
|
|
d = {}
|
|
|
|
k, v = 'abc', 'def'
|
|
|
|
d[k] = v
|
|
|
|
self.assertRaises(KeyError, d.pop, 'ghi')
|
|
|
|
|
|
|
|
self.assertEqual(d.pop(k), v)
|
|
|
|
self.assertEqual(len(d), 0)
|
|
|
|
|
|
|
|
self.assertRaises(KeyError, d.pop, k)
|
|
|
|
|
|
|
|
# verify longs/ints get same value when key > 32 bits (for 64-bit archs)
|
|
|
|
# see SF bug #689659
|
|
|
|
x = 4503599627370496L
|
|
|
|
y = 4503599627370496
|
|
|
|
h = {x: 'anything', y: 'something else'}
|
|
|
|
self.assertEqual(h[x], h[y])
|
|
|
|
|
|
|
|
self.assertEqual(d.pop(k, v), v)
|
|
|
|
d[k] = v
|
|
|
|
self.assertEqual(d.pop(k, 1), v)
|
|
|
|
|
|
|
|
self.assertRaises(TypeError, d.pop)
|
|
|
|
|
|
|
|
class Exc(Exception): pass
|
|
|
|
|
|
|
|
class BadHash(object):
|
|
|
|
fail = False
|
|
|
|
def __hash__(self):
|
|
|
|
if self.fail:
|
|
|
|
raise Exc()
|
|
|
|
else:
|
|
|
|
return 42
|
|
|
|
|
|
|
|
x = BadHash()
|
|
|
|
d[x] = 42
|
|
|
|
x.fail = True
|
|
|
|
self.assertRaises(Exc, d.pop, x)
|
|
|
|
|
|
|
|
def test_mutatingiteration(self):
|
|
|
|
d = {}
|
|
|
|
d[1] = 1
|
|
|
|
try:
|
|
|
|
for i in d:
|
|
|
|
d[i+1] = 1
|
|
|
|
except RuntimeError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.fail("changing dict size during iteration doesn't raise Error")
|
|
|
|
|
|
|
|
def test_repr(self):
|
|
|
|
d = {}
|
|
|
|
self.assertEqual(repr(d), '{}')
|
|
|
|
d[1] = 2
|
|
|
|
self.assertEqual(repr(d), '{1: 2}')
|
|
|
|
d = {}
|
|
|
|
d[1] = d
|
|
|
|
self.assertEqual(repr(d), '{1: {...}}')
|
|
|
|
|
|
|
|
class Exc(Exception): pass
|
|
|
|
|
|
|
|
class BadRepr(object):
|
|
|
|
def __repr__(self):
|
|
|
|
raise Exc()
|
|
|
|
|
|
|
|
d = {1: BadRepr()}
|
|
|
|
self.assertRaises(Exc, repr, d)
|
|
|
|
|
|
|
|
def test_le(self):
|
|
|
|
self.assert_(not ({} < {}))
|
|
|
|
self.assert_(not ({1: 2} < {1L: 2L}))
|
|
|
|
|
|
|
|
class Exc(Exception): pass
|
|
|
|
|
|
|
|
class BadCmp(object):
|
|
|
|
def __eq__(self, other):
|
|
|
|
raise Exc()
|
2007-11-21 20:55:51 -04:00
|
|
|
def __hash__(self):
|
|
|
|
return 42
|
2004-09-30 10:46:00 -03:00
|
|
|
|
|
|
|
d1 = {BadCmp(): 1}
|
|
|
|
d2 = {1: 1}
|
|
|
|
try:
|
|
|
|
d1 < d2
|
|
|
|
except Exc:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.fail("< didn't raise Exc")
|
|
|
|
|
2006-02-25 18:38:04 -04:00
|
|
|
def test_missing(self):
|
|
|
|
# Make sure dict doesn't have a __missing__ method
|
|
|
|
self.assertEqual(hasattr(dict, "__missing__"), False)
|
|
|
|
self.assertEqual(hasattr({}, "__missing__"), False)
|
|
|
|
# Test several cases:
|
|
|
|
# (D) subclass defines __missing__ method returning a value
|
|
|
|
# (E) subclass defines __missing__ method raising RuntimeError
|
|
|
|
# (F) subclass sets __missing__ instance variable (no effect)
|
|
|
|
# (G) subclass doesn't define __missing__ at a all
|
|
|
|
class D(dict):
|
|
|
|
def __missing__(self, key):
|
|
|
|
return 42
|
|
|
|
d = D({1: 2, 3: 4})
|
|
|
|
self.assertEqual(d[1], 2)
|
|
|
|
self.assertEqual(d[3], 4)
|
|
|
|
self.assert_(2 not in d)
|
|
|
|
self.assert_(2 not in d.keys())
|
|
|
|
self.assertEqual(d[2], 42)
|
|
|
|
class E(dict):
|
|
|
|
def __missing__(self, key):
|
|
|
|
raise RuntimeError(key)
|
|
|
|
e = E()
|
|
|
|
try:
|
|
|
|
e[42]
|
|
|
|
except RuntimeError, err:
|
|
|
|
self.assertEqual(err.args, (42,))
|
|
|
|
else:
|
2007-03-04 13:18:54 -04:00
|
|
|
self.fail("e[42] didn't raise RuntimeError")
|
2006-02-25 18:38:04 -04:00
|
|
|
class F(dict):
|
|
|
|
def __init__(self):
|
|
|
|
# An instance variable __missing__ should have no effect
|
|
|
|
self.__missing__ = lambda key: None
|
|
|
|
f = F()
|
|
|
|
try:
|
|
|
|
f[42]
|
|
|
|
except KeyError, err:
|
|
|
|
self.assertEqual(err.args, (42,))
|
|
|
|
else:
|
2007-03-04 13:18:54 -04:00
|
|
|
self.fail("f[42] didn't raise KeyError")
|
2006-02-25 18:38:04 -04:00
|
|
|
class G(dict):
|
|
|
|
pass
|
|
|
|
g = G()
|
|
|
|
try:
|
|
|
|
g[42]
|
|
|
|
except KeyError, err:
|
|
|
|
self.assertEqual(err.args, (42,))
|
|
|
|
else:
|
2007-03-04 13:18:54 -04:00
|
|
|
self.fail("g[42] didn't raise KeyError")
|
2006-02-25 18:38:04 -04:00
|
|
|
|
2006-10-29 14:31:42 -04:00
|
|
|
def test_tuple_keyerror(self):
|
|
|
|
# SF #1576657
|
|
|
|
d = {}
|
|
|
|
try:
|
|
|
|
d[(1,)]
|
|
|
|
except KeyError, e:
|
|
|
|
self.assertEqual(e.args, ((1,),))
|
|
|
|
else:
|
|
|
|
self.fail("missing KeyError")
|
2007-03-12 15:07:52 -03:00
|
|
|
|
2007-03-12 12:57:19 -03:00
|
|
|
def test_bad_key(self):
|
|
|
|
# Dictionary lookups should fail if __cmp__() raises an exception.
|
|
|
|
class CustomException(Exception):
|
|
|
|
pass
|
2007-03-12 15:07:52 -03:00
|
|
|
|
2007-03-12 12:57:19 -03:00
|
|
|
class BadDictKey:
|
|
|
|
def __hash__(self):
|
|
|
|
return hash(self.__class__)
|
|
|
|
|
|
|
|
def __cmp__(self, other):
|
|
|
|
if isinstance(other, self.__class__):
|
|
|
|
raise CustomException
|
|
|
|
return other
|
2007-03-12 15:07:52 -03:00
|
|
|
|
2007-03-12 12:57:19 -03:00
|
|
|
d = {}
|
|
|
|
x1 = BadDictKey()
|
|
|
|
x2 = BadDictKey()
|
|
|
|
d[x1] = 1
|
|
|
|
for stmt in ['d[x2] = 2',
|
|
|
|
'z = d[x2]',
|
|
|
|
'x2 in d',
|
|
|
|
'd.has_key(x2)',
|
|
|
|
'd.get(x2)',
|
|
|
|
'd.setdefault(x2, 42)',
|
|
|
|
'd.pop(x2)',
|
|
|
|
'd.update({x2: 2})']:
|
|
|
|
try:
|
|
|
|
exec stmt in locals()
|
|
|
|
except CustomException:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.fail("Statement didn't raise exception")
|
|
|
|
|
|
|
|
def test_resize1(self):
|
|
|
|
# Dict resizing bug, found by Jack Jansen in 2.2 CVS development.
|
|
|
|
# This version got an assert failure in debug build, infinite loop in
|
|
|
|
# release build. Unfortunately, provoking this kind of stuff requires
|
|
|
|
# a mix of inserts and deletes hitting exactly the right hash codes in
|
|
|
|
# exactly the right order, and I can't think of a randomized approach
|
|
|
|
# that would be *likely* to hit a failing case in reasonable time.
|
2007-03-12 15:07:52 -03:00
|
|
|
|
2007-03-12 12:57:19 -03:00
|
|
|
d = {}
|
|
|
|
for i in range(5):
|
|
|
|
d[i] = i
|
|
|
|
for i in range(5):
|
|
|
|
del d[i]
|
|
|
|
for i in range(5, 9): # i==8 was the problem
|
|
|
|
d[i] = i
|
|
|
|
|
|
|
|
def test_resize2(self):
|
|
|
|
# Another dict resizing bug (SF bug #1456209).
|
|
|
|
# This caused Segmentation faults or Illegal instructions.
|
2007-03-12 15:07:52 -03:00
|
|
|
|
2007-03-12 12:57:19 -03:00
|
|
|
class X(object):
|
|
|
|
def __hash__(self):
|
|
|
|
return 5
|
|
|
|
def __eq__(self, other):
|
|
|
|
if resizing:
|
|
|
|
d.clear()
|
|
|
|
return False
|
|
|
|
d = {}
|
|
|
|
resizing = False
|
|
|
|
d[X()] = 1
|
|
|
|
d[X()] = 2
|
|
|
|
d[X()] = 3
|
|
|
|
d[X()] = 4
|
|
|
|
d[X()] = 5
|
|
|
|
# now trigger a resize
|
|
|
|
resizing = True
|
|
|
|
d[9] = 6
|
2006-10-29 14:31:42 -04:00
|
|
|
|
2008-08-11 06:07:59 -03:00
|
|
|
def test_empty_presized_dict_in_freelist(self):
|
|
|
|
# Bug #3537: if an empty but presized dict with a size larger
|
|
|
|
# than 7 was in the freelist, it triggered an assertion failure
|
|
|
|
try:
|
|
|
|
d = {'a': 1/0, 'b': None, 'c': None, 'd': None, 'e': None,
|
|
|
|
'f': None, 'g': None, 'h': None}
|
|
|
|
except ZeroDivisionError:
|
|
|
|
pass
|
|
|
|
d = {}
|
|
|
|
|
Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67952 | georg.brandl | 2008-12-27 18:42:40 +0100 (Sat, 27 Dec 2008) | 2 lines
#4752: actually use custom handler in example.
........
r67953 | georg.brandl | 2008-12-27 19:20:04 +0100 (Sat, 27 Dec 2008) | 3 lines
Patch #4739 by David Laban: add symbols to pydoc help topics,
so that ``help('@')`` works as expected.
........
r67955 | georg.brandl | 2008-12-27 19:27:53 +0100 (Sat, 27 Dec 2008) | 3 lines
Follow-up to r67746 in order to restore backwards-compatibility for
those who (monkey-)patch TextWrapper.wordsep_re with a custom RE.
........
r67957 | georg.brandl | 2008-12-27 19:49:19 +0100 (Sat, 27 Dec 2008) | 2 lines
#4754: improve winsound documentation.
........
r67958 | georg.brandl | 2008-12-27 20:02:59 +0100 (Sat, 27 Dec 2008) | 2 lines
#4682: 'b' is actually unsigned char.
........
r67960 | georg.brandl | 2008-12-27 20:04:44 +0100 (Sat, 27 Dec 2008) | 2 lines
#4695: fix backslashery.
........
r67961 | georg.brandl | 2008-12-27 20:06:04 +0100 (Sat, 27 Dec 2008) | 2 lines
Use :samp: role.
........
r67963 | georg.brandl | 2008-12-27 20:11:15 +0100 (Sat, 27 Dec 2008) | 2 lines
#4671: document that pydoc imports modules.
........
r67965 | antoine.pitrou | 2008-12-27 21:34:52 +0100 (Sat, 27 Dec 2008) | 3 lines
Issue #4677: add two list comprehension tests to pybench.
........
r67967 | benjamin.peterson | 2008-12-27 23:18:58 +0100 (Sat, 27 Dec 2008) | 1 line
fix markup
........
r67970 | alexandre.vassalotti | 2008-12-28 02:52:58 +0100 (Sun, 28 Dec 2008) | 2 lines
Fix name mangling of PyUnicode_ClearFreeList.
........
r67971 | alexandre.vassalotti | 2008-12-28 03:10:35 +0100 (Sun, 28 Dec 2008) | 2 lines
Sort UCS-2/UCS-4 name mangling list.
........
r67973 | alexandre.vassalotti | 2008-12-28 03:58:22 +0100 (Sun, 28 Dec 2008) | 2 lines
Document Py_VaBuildValue.
........
r67982 | benjamin.peterson | 2008-12-28 16:37:31 +0100 (Sun, 28 Dec 2008) | 1 line
fix WORD_BIGEDIAN declaration in Universal builds; fixes #4060 and #4728
........
r67988 | ronald.oussoren | 2008-12-28 20:40:56 +0100 (Sun, 28 Dec 2008) | 1 line
Issue4064: architecture string for universal builds on OSX
........
r67990 | ronald.oussoren | 2008-12-28 20:50:40 +0100 (Sun, 28 Dec 2008) | 3 lines
Update the fix for issue4064 to deal correctly with all three variants of
universal builds that are presented by the configure script.
........
r67995 | benjamin.peterson | 2008-12-28 22:16:07 +0100 (Sun, 28 Dec 2008) | 1 line
#4763 PyErr_ExceptionMatches won't blow up with NULL arguments
........
r68014 | benjamin.peterson | 2008-12-29 18:47:42 +0100 (Mon, 29 Dec 2008) | 1 line
#4764 set IOError.filename when trying to open a directory on POSIX platforms
........
r68016 | benjamin.peterson | 2008-12-29 18:56:58 +0100 (Mon, 29 Dec 2008) | 1 line
#4764 in io.open, set IOError.filename when trying to open a directory on POSIX platforms
........
r68030 | benjamin.peterson | 2008-12-29 22:38:14 +0100 (Mon, 29 Dec 2008) | 1 line
fix French
........
r68057 | vinay.sajip | 2008-12-30 08:01:25 +0100 (Tue, 30 Dec 2008) | 1 line
Minor documentation change relating to NullHandler.
........
r68061 | georg.brandl | 2008-12-30 11:15:49 +0100 (Tue, 30 Dec 2008) | 2 lines
#4778: attributes can't be called.
........
r68112 | benjamin.peterson | 2009-01-01 00:48:39 +0100 (Thu, 01 Jan 2009) | 1 line
#4795 inspect.isgeneratorfunction() should return False instead of None
........
r68115 | benjamin.peterson | 2009-01-01 05:04:41 +0100 (Thu, 01 Jan 2009) | 1 line
simplfy code
........
r68116 | georg.brandl | 2009-01-01 12:46:51 +0100 (Thu, 01 Jan 2009) | 2 lines
#4100: note that element children are not necessarily present on "start" events.
........
r68117 | georg.brandl | 2009-01-01 12:53:55 +0100 (Thu, 01 Jan 2009) | 2 lines
#4156: make clear that "protocol" is to be replaced with the protocol name.
........
r68118 | georg.brandl | 2009-01-01 13:00:19 +0100 (Thu, 01 Jan 2009) | 2 lines
#4185: clarify escape behavior of replacement strings.
........
r68120 | georg.brandl | 2009-01-01 13:15:31 +0100 (Thu, 01 Jan 2009) | 4 lines
#4228: Pack negative values the same way as 2.4
in struct's L format.
........
r68121 | georg.brandl | 2009-01-01 13:43:33 +0100 (Thu, 01 Jan 2009) | 2 lines
Point to types module in new module deprecation notice.
........
r68123 | georg.brandl | 2009-01-01 13:52:29 +0100 (Thu, 01 Jan 2009) | 2 lines
#4784: ... on three counts ...
........
r68124 | georg.brandl | 2009-01-01 13:53:19 +0100 (Thu, 01 Jan 2009) | 2 lines
#4782: Fix markup error that hid load() and loads().
........
r68125 | georg.brandl | 2009-01-01 14:02:09 +0100 (Thu, 01 Jan 2009) | 2 lines
#4776: add data_files and package_dir arguments.
........
r68126 | georg.brandl | 2009-01-01 14:05:13 +0100 (Thu, 01 Jan 2009) | 2 lines
Handlers are in the `logging.handlers` module.
........
r68127 | georg.brandl | 2009-01-01 14:14:49 +0100 (Thu, 01 Jan 2009) | 2 lines
#4767: Use correct submodules for all MIME classes.
........
r68128 | antoine.pitrou | 2009-01-01 15:11:22 +0100 (Thu, 01 Jan 2009) | 3 lines
Issue #3680: Reference cycles created through a dict, set or deque iterator did not get collected.
........
2009-01-01 11:46:10 -04:00
|
|
|
def test_container_iterator(self):
|
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r68133 | antoine.pitrou | 2009-01-01 16:38:03 +0100 (Thu, 01 Jan 2009) | 1 line
fill in actual issue number in tests
........
r68134 | hirokazu.yamamoto | 2009-01-01 16:45:39 +0100 (Thu, 01 Jan 2009) | 2 lines
Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open
file with `str' filename on Windows.
........
r68141 | benjamin.peterson | 2009-01-01 17:43:12 +0100 (Thu, 01 Jan 2009) | 1 line
fix highlighting
........
r68142 | benjamin.peterson | 2009-01-01 18:29:49 +0100 (Thu, 01 Jan 2009) | 2 lines
welcome to 2009, Python!
........
r68145 | amaury.forgeotdarc | 2009-01-02 01:03:54 +0100 (Fri, 02 Jan 2009) | 5 lines
#4801 _collections module fails to build on cygwin.
_PyObject_GC_TRACK is the macro version of PyObject_GC_Track,
and according to documentation it should not be used for extension modules.
........
r68146 | ronald.oussoren | 2009-01-02 11:44:46 +0100 (Fri, 02 Jan 2009) | 2 lines
Fix for issue4472: "configure --enable-shared doesn't work on OSX"
........
r68148 | ronald.oussoren | 2009-01-02 11:48:31 +0100 (Fri, 02 Jan 2009) | 2 lines
Forgot to add a NEWS item in my previous checkin
........
r68149 | ronald.oussoren | 2009-01-02 11:50:48 +0100 (Fri, 02 Jan 2009) | 2 lines
Fix for issue4780
........
r68159 | ronald.oussoren | 2009-01-02 15:48:17 +0100 (Fri, 02 Jan 2009) | 2 lines
Fix for issue 1627952
........
r68160 | ronald.oussoren | 2009-01-02 15:52:09 +0100 (Fri, 02 Jan 2009) | 2 lines
Fix for issue r1737832
........
r68161 | ronald.oussoren | 2009-01-02 16:00:05 +0100 (Fri, 02 Jan 2009) | 3 lines
Fix for issue 1149804
........
r68162 | ronald.oussoren | 2009-01-02 16:06:00 +0100 (Fri, 02 Jan 2009) | 3 lines
Fix for issue 4472 is incompatible with Cygwin, this patch
should fix that.
........
r68166 | benjamin.peterson | 2009-01-02 19:26:23 +0100 (Fri, 02 Jan 2009) | 1 line
document PyMemberDef
........
r68171 | georg.brandl | 2009-01-02 21:25:14 +0100 (Fri, 02 Jan 2009) | 3 lines
#4811: fix markup glitches (mostly remains of the conversion),
found by Gabriel Genellina.
........
r68172 | martin.v.loewis | 2009-01-02 21:32:55 +0100 (Fri, 02 Jan 2009) | 2 lines
Issue #4075: Use OutputDebugStringW in Py_FatalError.
........
r68173 | martin.v.loewis | 2009-01-02 21:40:14 +0100 (Fri, 02 Jan 2009) | 2 lines
Issue #4051: Prevent conflict of UNICODE macros in cPickle.
........
r68174 | benjamin.peterson | 2009-01-02 21:47:27 +0100 (Fri, 02 Jan 2009) | 1 line
fix compilation on non-Windows platforms
........
r68179 | raymond.hettinger | 2009-01-02 22:26:45 +0100 (Fri, 02 Jan 2009) | 1 line
Issue #4615. Document how to use itertools for de-duping.
........
r68195 | georg.brandl | 2009-01-03 14:45:15 +0100 (Sat, 03 Jan 2009) | 2 lines
Remove useless string literal.
........
r68196 | georg.brandl | 2009-01-03 15:29:53 +0100 (Sat, 03 Jan 2009) | 2 lines
Fix indentation.
........
r68210 | georg.brandl | 2009-01-03 20:10:12 +0100 (Sat, 03 Jan 2009) | 2 lines
Set eol-style correctly for mp_distributing.py.
........
r68214 | georg.brandl | 2009-01-03 20:44:48 +0100 (Sat, 03 Jan 2009) | 2 lines
Make indentation consistent.
........
r68215 | georg.brandl | 2009-01-03 21:15:14 +0100 (Sat, 03 Jan 2009) | 2 lines
Fix role name.
........
r68217 | georg.brandl | 2009-01-03 21:30:15 +0100 (Sat, 03 Jan 2009) | 2 lines
Add rstlint, a little tool to find subtle markup problems and inconsistencies in the Doc sources.
........
r68218 | georg.brandl | 2009-01-03 21:38:59 +0100 (Sat, 03 Jan 2009) | 2 lines
Recognize usage of the default role.
........
r68219 | georg.brandl | 2009-01-03 21:47:01 +0100 (Sat, 03 Jan 2009) | 2 lines
Fix uses of the default role.
........
r68220 | georg.brandl | 2009-01-03 21:55:06 +0100 (Sat, 03 Jan 2009) | 2 lines
Remove trailing whitespace.
........
r68221 | georg.brandl | 2009-01-03 22:04:55 +0100 (Sat, 03 Jan 2009) | 2 lines
Remove tabs from the documentation.
........
r68222 | georg.brandl | 2009-01-03 22:11:58 +0100 (Sat, 03 Jan 2009) | 2 lines
Disable the line length checker by default.
........
2009-01-03 17:55:17 -04:00
|
|
|
# Bug #3680: tp_traverse was not implemented for dictiter objects
|
Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67952 | georg.brandl | 2008-12-27 18:42:40 +0100 (Sat, 27 Dec 2008) | 2 lines
#4752: actually use custom handler in example.
........
r67953 | georg.brandl | 2008-12-27 19:20:04 +0100 (Sat, 27 Dec 2008) | 3 lines
Patch #4739 by David Laban: add symbols to pydoc help topics,
so that ``help('@')`` works as expected.
........
r67955 | georg.brandl | 2008-12-27 19:27:53 +0100 (Sat, 27 Dec 2008) | 3 lines
Follow-up to r67746 in order to restore backwards-compatibility for
those who (monkey-)patch TextWrapper.wordsep_re with a custom RE.
........
r67957 | georg.brandl | 2008-12-27 19:49:19 +0100 (Sat, 27 Dec 2008) | 2 lines
#4754: improve winsound documentation.
........
r67958 | georg.brandl | 2008-12-27 20:02:59 +0100 (Sat, 27 Dec 2008) | 2 lines
#4682: 'b' is actually unsigned char.
........
r67960 | georg.brandl | 2008-12-27 20:04:44 +0100 (Sat, 27 Dec 2008) | 2 lines
#4695: fix backslashery.
........
r67961 | georg.brandl | 2008-12-27 20:06:04 +0100 (Sat, 27 Dec 2008) | 2 lines
Use :samp: role.
........
r67963 | georg.brandl | 2008-12-27 20:11:15 +0100 (Sat, 27 Dec 2008) | 2 lines
#4671: document that pydoc imports modules.
........
r67965 | antoine.pitrou | 2008-12-27 21:34:52 +0100 (Sat, 27 Dec 2008) | 3 lines
Issue #4677: add two list comprehension tests to pybench.
........
r67967 | benjamin.peterson | 2008-12-27 23:18:58 +0100 (Sat, 27 Dec 2008) | 1 line
fix markup
........
r67970 | alexandre.vassalotti | 2008-12-28 02:52:58 +0100 (Sun, 28 Dec 2008) | 2 lines
Fix name mangling of PyUnicode_ClearFreeList.
........
r67971 | alexandre.vassalotti | 2008-12-28 03:10:35 +0100 (Sun, 28 Dec 2008) | 2 lines
Sort UCS-2/UCS-4 name mangling list.
........
r67973 | alexandre.vassalotti | 2008-12-28 03:58:22 +0100 (Sun, 28 Dec 2008) | 2 lines
Document Py_VaBuildValue.
........
r67982 | benjamin.peterson | 2008-12-28 16:37:31 +0100 (Sun, 28 Dec 2008) | 1 line
fix WORD_BIGEDIAN declaration in Universal builds; fixes #4060 and #4728
........
r67988 | ronald.oussoren | 2008-12-28 20:40:56 +0100 (Sun, 28 Dec 2008) | 1 line
Issue4064: architecture string for universal builds on OSX
........
r67990 | ronald.oussoren | 2008-12-28 20:50:40 +0100 (Sun, 28 Dec 2008) | 3 lines
Update the fix for issue4064 to deal correctly with all three variants of
universal builds that are presented by the configure script.
........
r67995 | benjamin.peterson | 2008-12-28 22:16:07 +0100 (Sun, 28 Dec 2008) | 1 line
#4763 PyErr_ExceptionMatches won't blow up with NULL arguments
........
r68014 | benjamin.peterson | 2008-12-29 18:47:42 +0100 (Mon, 29 Dec 2008) | 1 line
#4764 set IOError.filename when trying to open a directory on POSIX platforms
........
r68016 | benjamin.peterson | 2008-12-29 18:56:58 +0100 (Mon, 29 Dec 2008) | 1 line
#4764 in io.open, set IOError.filename when trying to open a directory on POSIX platforms
........
r68030 | benjamin.peterson | 2008-12-29 22:38:14 +0100 (Mon, 29 Dec 2008) | 1 line
fix French
........
r68057 | vinay.sajip | 2008-12-30 08:01:25 +0100 (Tue, 30 Dec 2008) | 1 line
Minor documentation change relating to NullHandler.
........
r68061 | georg.brandl | 2008-12-30 11:15:49 +0100 (Tue, 30 Dec 2008) | 2 lines
#4778: attributes can't be called.
........
r68112 | benjamin.peterson | 2009-01-01 00:48:39 +0100 (Thu, 01 Jan 2009) | 1 line
#4795 inspect.isgeneratorfunction() should return False instead of None
........
r68115 | benjamin.peterson | 2009-01-01 05:04:41 +0100 (Thu, 01 Jan 2009) | 1 line
simplfy code
........
r68116 | georg.brandl | 2009-01-01 12:46:51 +0100 (Thu, 01 Jan 2009) | 2 lines
#4100: note that element children are not necessarily present on "start" events.
........
r68117 | georg.brandl | 2009-01-01 12:53:55 +0100 (Thu, 01 Jan 2009) | 2 lines
#4156: make clear that "protocol" is to be replaced with the protocol name.
........
r68118 | georg.brandl | 2009-01-01 13:00:19 +0100 (Thu, 01 Jan 2009) | 2 lines
#4185: clarify escape behavior of replacement strings.
........
r68120 | georg.brandl | 2009-01-01 13:15:31 +0100 (Thu, 01 Jan 2009) | 4 lines
#4228: Pack negative values the same way as 2.4
in struct's L format.
........
r68121 | georg.brandl | 2009-01-01 13:43:33 +0100 (Thu, 01 Jan 2009) | 2 lines
Point to types module in new module deprecation notice.
........
r68123 | georg.brandl | 2009-01-01 13:52:29 +0100 (Thu, 01 Jan 2009) | 2 lines
#4784: ... on three counts ...
........
r68124 | georg.brandl | 2009-01-01 13:53:19 +0100 (Thu, 01 Jan 2009) | 2 lines
#4782: Fix markup error that hid load() and loads().
........
r68125 | georg.brandl | 2009-01-01 14:02:09 +0100 (Thu, 01 Jan 2009) | 2 lines
#4776: add data_files and package_dir arguments.
........
r68126 | georg.brandl | 2009-01-01 14:05:13 +0100 (Thu, 01 Jan 2009) | 2 lines
Handlers are in the `logging.handlers` module.
........
r68127 | georg.brandl | 2009-01-01 14:14:49 +0100 (Thu, 01 Jan 2009) | 2 lines
#4767: Use correct submodules for all MIME classes.
........
r68128 | antoine.pitrou | 2009-01-01 15:11:22 +0100 (Thu, 01 Jan 2009) | 3 lines
Issue #3680: Reference cycles created through a dict, set or deque iterator did not get collected.
........
2009-01-01 11:46:10 -04:00
|
|
|
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")
|
2008-08-11 06:07:59 -03:00
|
|
|
|
2006-02-25 18:38:04 -04:00
|
|
|
|
2006-04-03 01:45:34 -03:00
|
|
|
from test import mapping_tests
|
2004-09-30 12:07:29 -03:00
|
|
|
|
|
|
|
class GeneralMappingTests(mapping_tests.BasicTestMappingProtocol):
|
|
|
|
type2test = dict
|
|
|
|
|
|
|
|
class Dict(dict):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class SubclassMappingTests(mapping_tests.BasicTestMappingProtocol):
|
|
|
|
type2test = Dict
|
|
|
|
|
2004-09-30 10:46:00 -03:00
|
|
|
def test_main():
|
|
|
|
test_support.run_unittest(
|
|
|
|
DictTest,
|
2004-09-30 12:07:29 -03:00
|
|
|
GeneralMappingTests,
|
|
|
|
SubclassMappingTests,
|
2004-09-30 10:46:00 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
test_main()
|