summaryrefslogtreecommitdiff
path: root/Lib/test/test_compiler.py
diff options
context:
space:
mode:
authorAlexandre Vassalotti <alexandre@peadrop.com>2010-01-11 22:36:12 +0000
committerAlexandre Vassalotti <alexandre@peadrop.com>2010-01-11 22:36:12 +0000
commitb646547bb45fe1df6abefd94f892c633798d91d2 (patch)
treeef1add045741d309129266726f5ba45562184091 /Lib/test/test_compiler.py
parent0ca7452794bef03b66f56cc996a73cac066d0ec1 (diff)
downloadcpython-git-b646547bb45fe1df6abefd94f892c633798d91d2.tar.gz
Issue #2333: Backport set and dict comprehensions syntax.
Diffstat (limited to 'Lib/test/test_compiler.py')
-rw-r--r--Lib/test/test_compiler.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_compiler.py b/Lib/test/test_compiler.py
index 8d4a3a995e..b54894da70 100644
--- a/Lib/test/test_compiler.py
+++ b/Lib/test/test_compiler.py
@@ -140,6 +140,36 @@ class CompilerTest(unittest.TestCase):
'eval')
self.assertEquals(eval(c), [(0, 3), (1, 3), (2, 3)])
+ def testSetLiteral(self):
+ c = compiler.compile('{1, 2, 3}', '<string>', 'eval')
+ self.assertEquals(eval(c), {1,2,3})
+ c = compiler.compile('{1, 2, 3,}', '<string>', 'eval')
+ self.assertEquals(eval(c), {1,2,3})
+
+ def testDictLiteral(self):
+ c = compiler.compile('{1:2, 2:3, 3:4}', '<string>', 'eval')
+ self.assertEquals(eval(c), {1:2, 2:3, 3:4})
+ c = compiler.compile('{1:2, 2:3, 3:4,}', '<string>', 'eval')
+ self.assertEquals(eval(c), {1:2, 2:3, 3:4})
+
+ def testSetComp(self):
+ c = compiler.compile('{x for x in range(1, 4)}', '<string>', 'eval')
+ self.assertEquals(eval(c), {1, 2, 3})
+ c = compiler.compile('{x * y for x in range(3) if x != 0'
+ ' for y in range(4) if y != 0}',
+ '<string>',
+ 'eval')
+ self.assertEquals(eval(c), {1, 2, 3, 4, 6})
+
+ def testDictComp(self):
+ c = compiler.compile('{x:x+1 for x in range(1, 4)}', '<string>', 'eval')
+ self.assertEquals(eval(c), {1:2, 2:3, 3:4})
+ c = compiler.compile('{(x, y) : y for x in range(2) if x != 0'
+ ' for y in range(3) if y != 0}',
+ '<string>',
+ 'eval')
+ self.assertEquals(eval(c), {(1, 2): 2, (1, 1): 1})
+
def testWith(self):
# SF bug 1638243
c = compiler.compile('from __future__ import with_statement\n'
@@ -248,6 +278,8 @@ l[0]
l[3:4]
d = {'a': 2}
d = {}
+d = {x: y for x, y in zip(range(5), range(5,10))}
+s = {x for x in range(10)}
s = {1}
t = ()
t = (1, 2)