def test(self): sorted_dict = SortedDict((x, x.upper()) for x in LOWER) copy = sorted_dict.copy() self.assertIsInstance(copy, SortedDict) self.assertIs(False, sorted_dict is copy) self.assertEqual(dict(sorted_dict), dict(copy)) self.assertEqual(sorted_dict.keys(), copy.keys())
def test(self): sorted_dict = SortedDict((x, x.upper()) for x in LOWER) keys = sorted_dict.sorted_keys self.assertEqual(keys, list(LOWER)) self.assertTrue(dict(sorted_dict)) sorted_dict.clear() self.assertIs(sorted_dict.sorted_keys, keys) self.assertEqual(keys, []) self.assertFalse(dict(sorted_dict))
def test(self): sorted_dict = SortedDict((x, x.upper()) for x in 'abc') self.assertRaises(TypeError, sorted_dict.pop) self.assertRaises(TypeError, sorted_dict.pop, None, None, None) a = sorted_dict.pop('a') self.assertEqual(a, 'A') self.assertEqual(dict(sorted_dict), {'b': 'B', 'c': 'C'}) self.assertEqual(sorted_dict.keys(), ['b', 'c']) self.assertRaises(KeyError, sorted_dict.pop, 'a') obj = object() self.assertIs(sorted_dict.pop('a', obj), obj) self.assertEqual(sorted_dict.pop('b', obj), 'B')
def test(self): sd = SortedDict() sd['1'] = 1 sd['2'] = 2 sd['10'] = 10 self.assertEqual(sd.keys(), ['1', '10', '2'])
def test(self): sorted_dict = SortedDict((x, x.upper()) for x in LOWER) self.assertEqual(sorted_dict.values(), list(UPPER))
def test(self): sorted_dict = SortedDict((x, x.upper()) for x in LOWER) self.assertEqual(sorted_dict.keys(), sorted_dict.sorted_keys)
def test(self): sorted_dict = SortedDict((x, x.upper()) for x in LOWER) self.assertEqual(sorted_dict.items(), zip(LOWER, UPPER))
def test(self): sorted_dict = SortedDict((x, x.upper()) for x in LOWER) self.assertIs(True, sorted_dict.has_key('a')) self.assertIs(False, sorted_dict.has_key(0))
def test(self): sorted_dict = SortedDict((x, x.upper()) for x in LOWER) self.assertIs(None, sorted_dict.get(0)) self.assertEqual('0', sorted_dict.get(0, '0')) self.assertEqual('A', sorted_dict.get('a'))
def test(self): sorted_dict = SortedDict.fromkeys('ba', 'A') self.assertIsInstance(sorted_dict, SortedDict) self.assertEqual(sorted_dict.items(), [('a', 'A'), ('b', 'A')])
def test(self): sd = SortedDict({'2': 2, '10': 10}) self.assertEqual(sd.__repr__(), """SortedDict({'10': 10, '2': 2})""")