summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dict.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_dict.py')
-rw-r--r--Lib/test/test_dict.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index de483ab..d5a3d9e 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -37,6 +37,38 @@ class DictTest(unittest.TestCase):
dictliteral = '{' + ', '.join(formatted_items) + '}'
self.assertEqual(eval(dictliteral), dict(items))
+ def test_merge_operator(self):
+
+ a = {0: 0, 1: 1, 2: 1}
+ b = {1: 1, 2: 2, 3: 3}
+
+ c = a.copy()
+ c |= b
+
+ self.assertEqual(a | b, {0: 0, 1: 1, 2: 2, 3: 3})
+ self.assertEqual(c, {0: 0, 1: 1, 2: 2, 3: 3})
+
+ c = b.copy()
+ c |= a
+
+ self.assertEqual(b | a, {1: 1, 2: 1, 3: 3, 0: 0})
+ self.assertEqual(c, {1: 1, 2: 1, 3: 3, 0: 0})
+
+ c = a.copy()
+ c |= [(1, 1), (2, 2), (3, 3)]
+
+ self.assertEqual(c, {0: 0, 1: 1, 2: 2, 3: 3})
+
+ self.assertIs(a.__or__(None), NotImplemented)
+ self.assertIs(a.__or__(()), NotImplemented)
+ self.assertIs(a.__or__("BAD"), NotImplemented)
+ self.assertIs(a.__or__(""), NotImplemented)
+
+ self.assertRaises(TypeError, a.__ior__, None)
+ self.assertEqual(a.__ior__(()), {0: 0, 1: 1, 2: 1})
+ self.assertRaises(ValueError, a.__ior__, "BAD")
+ self.assertEqual(a.__ior__(""), {0: 0, 1: 1, 2: 1})
+
def test_bool(self):
self.assertIs(not {}, True)
self.assertTrue({1: 2})