'Test num dict access and modification'

def test_dict_access_and_mod(self):

    dict_0 = {}
    dict_1 = {1: u'Elephant'}
    dict_2 = {1: u'Elephant', 2: u'Mouse'}
    num_dict_0 = NumDict()
    num_dict_1 = NumDict(dict_1)
    num_dict_2 = NumDict(dict_2)
    self.assertEqual(num_dict_2[1], u'Elephant')
    with self.assertRaises(KeyError):
        _ = num_dict_1[u'Mouse']
    with self.assertRaises(KeyError):
        _ = num_dict_1.__getitem__(u'Mouse')
    with self.assertRaises(KeyError):
        _ = num_dict_1[None]
    with self.assertRaises(KeyError):
        _ = num_dict_1.__getitem__(None)
    num_dict_3 = NumDict(num_dict_2)
    self.assertEqual(num_dict_2, num_dict_3)
    num_dict_3[2] = u'Frog'
    self.assertNotEqual(num_dict_2, num_dict_3)
    num_dict_3[u'3'] = u'Armadillo'
    num_dict_3[None] = u'Cockroach'
    num_dict_3[12390809518259081208909880312L] = u'Squid'
    num_dict_3[u'12390809518259081208909880312'] = u'Octopus'
    self.assertEqual(num_dict_3[12390809518259081208909880312L], u'Octopus')
    with self.assertRaises(TypeError):
        num_dict_3.__setitem__(u'Gorilla', 1)
    with self.assertRaises(TypeError):
        num_dict_3[u'Chimpanzee'] = 1
    with self.assertRaises(TypeError):
        num_dict_3[(4, 1)] = 1
    with self.assertRaises(TypeError):
        num_dict_3[[1, 3, 4]] = 1
    del num_dict_3[3]
    del num_dict_3[None]
    with self.assertRaises(KeyError):
        del num_dict_3[3]
    with self.assertRaises(KeyError):
        num_dict_3.__delitem__(3)
    with self.assertRaises(KeyError):
        del num_dict_3[u'Mouse']
    num_dict_3.clear()
    self.assertEqual(num_dict_3, {})
    num_dict_2a = dict_2.copy()
    self.assertEqual(num_dict_2, num_dict_2a)
    num_dict_2b = num_dict_2.copy()
    self.assertEqual(num_dict_2b, num_dict_2)
    num_dict_2c = UserDict({1: u'Elephant', 2: u'Mouse'})
    num_dict_2d = num_dict_2c.copy()
    self.assertEqual(num_dict_2c, num_dict_2d)
    class MyNumDict(NumDict, ):
        u'\n                                                subclass    Numdict    for    testing\n                                                '
        def display(self):
            u'\n                                                                add    a    method    to    subclass    to    differentiate    from    superclass\n                                                                '
            print(u'MyNumDict:', self)
    my_num_dict = MyNumDict(num_dict_2)
    my_num_dict_a = my_num_dict.copy()
    self.assertEqual(my_num_dict_a, my_num_dict)
    my_num_dict[1] = u'Frog'
    self.assertNotEqual(my_num_dict_a, my_num_dict)
    self.assertEqual(sorted(six.iterkeys(num_dict_2)), sorted(six.iterkeys(dict_2)))
    self.assertEqual(sorted(six.iteritems(num_dict_2)), sorted(six.iteritems(dict_2)))
    self.assertEqual(sorted(six.itervalues(num_dict_2)), sorted(six.itervalues(dict_2)))
    for i in num_dict_2:
        self.assertIn(i, num_dict_2)
        self.assertEqual((i in num_dict_1), (i in dict_1))
        self.assertEqual((i in num_dict_0), (i in dict_0))
    self.assertFalse((None in num_dict_2))
    self.assertEqual((None in num_dict_2), (None in dict_2))
    dict_2[None] = u'Cow'
    num_dict_2[None] = dict_2[None]
    self.assertTrue((None in num_dict_2))
    self.assertEqual((None in num_dict_2), (None in dict_2))
    self.assertFalse((u'Penguin' in num_dict_2))
    test = NumDict()
    test.update(dict_2)
    self.assertEqual(test, num_dict_2)
    for i in num_dict_2:
        self.assertEqual(num_dict_2.get(i), num_dict_2[i])
        self.assertEqual(num_dict_1.get(i), dict_1.get(i))
        self.assertEqual(num_dict_0.get(i), dict_0.get(i))
    for i in [u'purple', None, 12312301924091284, 23]:
        self.assertEqual(num_dict_2.get(i), dict_2.get(i), i)
    with self.assertRaises(AssertionError):
        i = u'1'
        self.assertEqual(num_dict_2.get(i), dict_2.get(i), i)
    num_dict_2b = num_dict_2
    for i in range(20):
        num_dict_2[i] = six.text_type(i)
        num_dict_2b[six.text_type(i)] = six.text_type(i)
    self.assertEqual(num_dict_2, num_dict_2b)
    ikeys = []
    for k in num_dict_2:
        ikeys.append(k)
    self.assertEqual(set(ikeys), set(num_dict_2.keys()))
    val = 1
    test = NumDict()
    self.assertEqual(test.setdefault(val, 42), 42)
    self.assertEqual(test.setdefault(val, u'42'), 42)
    self.assertNotEqual(test.setdefault(val, 42), u'42')
    self.assertNotEqual(test.setdefault(val, u'42'), u'42')
    self.assertIn(val, test)
    self.assertEqual(test.setdefault(val, 23), 42)
    self.assertEqual(test.setdefault(val, u'23'), 42)
    self.assertNotEqual(test.setdefault(val, 23), u'42')
    self.assertNotEqual(test.setdefault(val, u'23'), u'42')
    self.assertIn(val, test)
    val = 1
    test = NumDict({val: 42})
    self.assertEqual(test.pop(val), 42)
    self.assertRaises(KeyError, test.pop, val)
    self.assertEqual(test.pop(val, 1), 1)
    test[val] = 42
    self.assertEqual(test.pop(val, 1), 42)
    val = 1
    test = NumDict({val: 42})
    self.assertEqual(test.popitem(), (val, 42))
    self.assertRaises(KeyError, test.popitem)
