summaryrefslogtreecommitdiff
path: root/Lib/test/test_dictcomps.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_dictcomps.py')
-rw-r--r--Lib/test/test_dictcomps.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_dictcomps.py b/Lib/test/test_dictcomps.py
index afe68a8de7..927e3103e6 100644
--- a/Lib/test/test_dictcomps.py
+++ b/Lib/test/test_dictcomps.py
@@ -81,6 +81,35 @@ class DictComprehensionTest(unittest.TestCase):
compile("{x: y for y, x in ((1, 2), (3, 4))} += 5", "<test>",
"exec")
+ def test_evaluation_order(self):
+ expected = {
+ 'H': 'W',
+ 'e': 'o',
+ 'l': 'l',
+ 'o': 'd',
+ }
+
+ expected_calls = [
+ ('key', 'H'), ('value', 'W'),
+ ('key', 'e'), ('value', 'o'),
+ ('key', 'l'), ('value', 'r'),
+ ('key', 'l'), ('value', 'l'),
+ ('key', 'o'), ('value', 'd'),
+ ]
+
+ actual_calls = []
+
+ def add_call(pos, value):
+ actual_calls.append((pos, value))
+ return value
+
+ actual = {
+ add_call('key', k): add_call('value', v)
+ for k, v in zip('Hello', 'World')
+ }
+
+ self.assertEqual(actual, expected)
+ self.assertEqual(actual_calls, expected_calls)
if __name__ == "__main__":
unittest.main()