Beef-up tests for dict literals

This commit is contained in:
Raymond Hettinger 2007-12-19 00:21:06 +00:00
parent 85dfcf3530
commit 3b63556d4a
1 changed files with 10 additions and 1 deletions

View File

@ -1,7 +1,7 @@
import unittest import unittest
from test import test_support from test import test_support
import sys, UserDict, cStringIO import sys, UserDict, cStringIO, random, string
class DictTest(unittest.TestCase): class DictTest(unittest.TestCase):
@ -10,6 +10,15 @@ class DictTest(unittest.TestCase):
self.assertEqual(dict(), {}) self.assertEqual(dict(), {})
self.assert_(dict() is not {}) self.assert_(dict() is not {})
def test_literal_constructor(self):
# check literal constructor for different sized dicts (to exercise the BUILD_MAP oparg
items = []
for n in range(400):
dictliteral = '{' + ', '.join('%r: %d' % item for item in items) + '}'
self.assertEqual(eval(dictliteral), dict(items))
items.append((''.join([random.choice(string.letters) for j in range(8)]), n))
random.shuffle(items)
def test_bool(self): def test_bool(self):
self.assert_(not {}) self.assert_(not {})
self.assert_({1: 2}) self.assert_({1: 2})