mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Fixes issue #6766: Updated multiprocessing Proxy Objects to support nesting
This commit is contained in:
parent
1aa642f6bd
commit
86a7668426
3 changed files with 192 additions and 56 deletions
|
@ -1628,13 +1628,33 @@ class _TestContainers(BaseTestCase):
|
|||
d = [a, b]
|
||||
e = self.list(d)
|
||||
self.assertEqual(
|
||||
e[:],
|
||||
[element[:] for element in e],
|
||||
[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 0, 1, 2, 3, 4]]
|
||||
)
|
||||
|
||||
f = self.list([a])
|
||||
a.append('hello')
|
||||
self.assertEqual(f[:], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'hello']])
|
||||
self.assertEqual(f[0][:], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'hello'])
|
||||
|
||||
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)
|
||||
|
||||
a[0][-1] = 55
|
||||
self.assertEqual(a[0][:], [0, 1, 55])
|
||||
for i in range(1, 3):
|
||||
self.assertEqual(a[i][:], [0, 1, 2])
|
||||
|
||||
self.assertEqual(a[1].pop(), 2)
|
||||
self.assertEqual(len(a[1]), 2)
|
||||
for i in range(0, 3, 2):
|
||||
self.assertEqual(len(a[i]), 3)
|
||||
|
||||
del a
|
||||
|
||||
b = self.list()
|
||||
b.append(b)
|
||||
del b
|
||||
|
||||
def test_dict(self):
|
||||
d = self.dict()
|
||||
|
@ -1646,6 +1666,52 @@ 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_proxy_nested(self):
|
||||
pets = self.dict(ferrets=2, hamsters=4)
|
||||
supplies = self.dict(water=10, feed=3)
|
||||
d = self.dict(pets=pets, supplies=supplies)
|
||||
|
||||
self.assertEqual(supplies['water'], 10)
|
||||
self.assertEqual(d['supplies']['water'], 10)
|
||||
|
||||
d['supplies']['blankets'] = 5
|
||||
self.assertEqual(supplies['blankets'], 5)
|
||||
self.assertEqual(d['supplies']['blankets'], 5)
|
||||
|
||||
d['supplies']['water'] = 7
|
||||
self.assertEqual(supplies['water'], 7)
|
||||
self.assertEqual(d['supplies']['water'], 7)
|
||||
|
||||
del pets
|
||||
del supplies
|
||||
self.assertEqual(d['pets']['ferrets'], 2)
|
||||
d['supplies']['blankets'] = 11
|
||||
self.assertEqual(d['supplies']['blankets'], 11)
|
||||
|
||||
pets = d['pets']
|
||||
supplies = d['supplies']
|
||||
supplies['water'] = 7
|
||||
self.assertEqual(supplies['water'], 7)
|
||||
self.assertEqual(d['supplies']['water'], 7)
|
||||
|
||||
d.clear()
|
||||
self.assertEqual(len(d), 0)
|
||||
self.assertEqual(supplies['water'], 7)
|
||||
self.assertEqual(pets['hamsters'], 4)
|
||||
|
||||
l = self.list([pets, supplies])
|
||||
l[0]['marmots'] = 1
|
||||
self.assertEqual(pets['marmots'], 1)
|
||||
self.assertEqual(l[0]['marmots'], 1)
|
||||
|
||||
del pets
|
||||
del supplies
|
||||
self.assertEqual(l[0]['marmots'], 1)
|
||||
|
||||
outer = self.list([[88, 99], l])
|
||||
self.assertIsInstance(outer[0], list) # Not a ListProxy
|
||||
self.assertEqual(outer[-1][-1]['feed'], 3)
|
||||
|
||||
def test_namespace(self):
|
||||
n = self.Namespace()
|
||||
n.name = 'Bob'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue