mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-34610: Fixed iterator of multiprocessing.managers.DictProxy. (GH-9113)
This commit is contained in:
parent
ddd1949fea
commit
e0e5065dae
3 changed files with 28 additions and 1 deletions
|
|
@ -2080,6 +2080,16 @@ class _TestContainers(BaseTestCase):
|
|||
a.append('hello')
|
||||
self.assertEqual(f[0][:], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'hello'])
|
||||
|
||||
def test_list_iter(self):
|
||||
a = self.list(list(range(10)))
|
||||
it = iter(a)
|
||||
self.assertEqual(list(it), list(range(10)))
|
||||
self.assertEqual(list(it), []) # exhausted
|
||||
# list modified during iteration
|
||||
it = iter(a)
|
||||
a[0] = 100
|
||||
self.assertEqual(next(it), 100)
|
||||
|
||||
def test_list_proxy_in_list(self):
|
||||
a = self.list([self.list(range(3)) for _i in range(3)])
|
||||
self.assertEqual([inner[:] for inner in a], [[0, 1, 2]] * 3)
|
||||
|
|
@ -2110,6 +2120,19 @@ class _TestContainers(BaseTestCase):
|
|||
self.assertEqual(sorted(d.values()), [chr(i) for i in indices])
|
||||
self.assertEqual(sorted(d.items()), [(i, chr(i)) for i in indices])
|
||||
|
||||
def test_dict_iter(self):
|
||||
d = self.dict()
|
||||
indices = list(range(65, 70))
|
||||
for i in indices:
|
||||
d[i] = chr(i)
|
||||
it = iter(d)
|
||||
self.assertEqual(list(it), indices)
|
||||
self.assertEqual(list(it), []) # exhausted
|
||||
# dictionary changed size during iteration
|
||||
it = iter(d)
|
||||
d.clear()
|
||||
self.assertRaises(RuntimeError, next, it)
|
||||
|
||||
def test_dict_proxy_nested(self):
|
||||
pets = self.dict(ferrets=2, hamsters=4)
|
||||
supplies = self.dict(water=10, feed=3)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue