summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2006-08-28 15:27:34 (GMT)
committerGuido van Rossum <guido@python.org>2006-08-28 15:27:34 (GMT)
commit86e58e239e39845e706c4afa392423f0fedcdf39 (patch)
tree1d0f4d942e644ee5c903636d87176b98a7203371 /Lib/test
parentecfd0b2f3bfd622c3ba148e53d3feebb8c1ae721 (diff)
downloadcpython-86e58e239e39845e706c4afa392423f0fedcdf39.zip
cpython-86e58e239e39845e706c4afa392423f0fedcdf39.tar.gz
cpython-86e58e239e39845e706c4afa392423f0fedcdf39.tar.bz2
SF patch 1547796 by Georg Brandl -- set literals.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_grammar.py9
-rw-r--r--Lib/test/test_set.py11
2 files changed, 15 insertions, 5 deletions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index 331d527..93dc9ec 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -685,8 +685,8 @@ print L
print 'atoms'
-### atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' [dictmaker] '}' | NAME | NUMBER | STRING
-### dictmaker: test ':' test (',' test ':' test)* [',']
+### atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' [dictsetmaker] '}' | NAME | NUMBER | STRING
+### dictsetmaker: (test ':' test (',' test ':' test)* [',']) | (test (',' test)* [','])
x = (1)
x = (1 or 2 or 3)
@@ -706,6 +706,11 @@ x = {'one': 1, 'two': 2}
x = {'one': 1, 'two': 2,}
x = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6}
+x = {'one'}
+x = {'one', 1,}
+x = {'one', 'two', 'three'}
+x = {2, 3, 4,}
+
x = x
x = 'x'
x = 123
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index 23926be..556e390 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -261,6 +261,11 @@ class TestSet(TestJointOps):
t = self.thetype(s)
self.assertNotEqual(id(s), id(t))
+ def test_set_literal(self):
+ s = set([1,2,3])
+ t = {1,2,3}
+ self.assertEqual(s, t)
+
def test_hash(self):
self.assertRaises(TypeError, hash, self.s)
@@ -626,7 +631,7 @@ class TestBasicOpsEmpty(TestBasicOps):
self.set = set(self.values)
self.dup = set(self.values)
self.length = 0
- self.repr = "set([])"
+ self.repr = "{}"
#------------------------------------------------------------------------------
@@ -637,7 +642,7 @@ class TestBasicOpsSingleton(TestBasicOps):
self.set = set(self.values)
self.dup = set(self.values)
self.length = 1
- self.repr = "set([3])"
+ self.repr = "{3}"
def test_in(self):
self.failUnless(3 in self.set)
@@ -654,7 +659,7 @@ class TestBasicOpsTuple(TestBasicOps):
self.set = set(self.values)
self.dup = set(self.values)
self.length = 1
- self.repr = "set([(0, 'zero')])"
+ self.repr = "{(0, 'zero')}"
def test_in(self):
self.failUnless((0, "zero") in self.set)