def testStringKeys(self):
        d = {'a':1, 'b':2, '3':3, 3:4}
        self.assertEqual(d['a'], 1)
        self.assertEqual(d['b'], 2)

        # XXX: the length here is 3 because we have the same keys for "3"
        # and 3

        #self.assertEqual(len(d), 4)
        # XXX: we have to have constant handling in the translator in
        # order to distinguish ints and strings, so the lines below do
        # not work
        #self.assertEqual(d['3'], 3)
        #self.assertEqual(d[3], 4)

        try:
            x = d['notthere']
            self.fail('__getitem__ must raise KeyError')
        except __HOLE__, e:
            self.assertEqual(e.__class__.__name__, 'KeyError')
            self.assertEqual(str(e), "'notthere'")

        d = {}
        self.assertEqual(1, d.setdefault('foo', 1))
        self.assertEqual(1, d.setdefault('foo', 2))
        self.assertEqual(1, d.get('foo', 2))
        self.assertEqual(2, d.get('bar', 2))
        self.assertEqual(3, d.setdefault('bar', 3))

        d = {}
        d.update({1:1})
        d.update({2:2}, a='a')
        self.assertEqual(d, {1:1, 2:2, 'a':'a'})
        self.assertRaises(TypeError, getattr(d, 'update'), {}, {})
dataset/ETHPy150Open anandology/pyjamas/examples/libtest/DictTest.py/DictTest.testStringKeys