Skip to content

Commit d0c6d40

Browse files
committed
Update test_collections.py to include test_issue584().
Added testing for | and |= operators for ChainMap objects.
1 parent 906eff0 commit d0c6d40

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Lib/test/test_collections.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,30 @@ def __contains__(self, key):
232232
for k, v in dict(a=1, B=20, C=30, z=100).items(): # check get
233233
self.assertEqual(d.get(k, 100), v)
234234

235+
def test_issue584(self):
236+
'Tests for changes in issue584 dealing with | and |= operators'
237+
a = ChainMap(dict(a=1, b=2), dict(c=3, d=4))
238+
b = ChainMap(dict(a=10, e=5), dict(b=20, d=4))
239+
c = dict(a = 10, c = 30)
240+
241+
## Testing | operator between chainmaps
242+
d = a | b
243+
self.assertEqual(d, ChainMap(a.maps[0] | dict(b), *a.maps[1:]))
244+
245+
## Testing |= operator between chainmaps
246+
a |= b
247+
self.assertEqual(d, a)
248+
249+
## Testing | operator between chainmap and mapping, and vice versa
250+
e = b | c
251+
self.assertEqual(e, ChainMap(e.maps[0] | c, *b.maps[1:]))
252+
253+
f = c | b
254+
self.assertEqual(f, ChainMap(c | dict(b)))
255+
256+
## Testing |= operator between chainmap and mapping
257+
b |= c
258+
self.assertEqual(e,b)
235259

236260
################################################################################
237261
### Named Tuples

0 commit comments

Comments
 (0)