Пример #1
0
    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())
Пример #2
0
    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))
Пример #3
0
    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')
Пример #4
0
 def test(self):
     sd = SortedDict()
     sd['1'] = 1
     sd['2'] = 2
     sd['10'] = 10
     self.assertEqual(sd.keys(), ['1', '10', '2'])
Пример #5
0
 def test(self):
     sorted_dict = SortedDict((x, x.upper()) for x in LOWER)
     self.assertEqual(sorted_dict.values(), list(UPPER))
Пример #6
0
 def test(self):
     sorted_dict = SortedDict((x, x.upper()) for x in LOWER)
     self.assertEqual(sorted_dict.keys(), sorted_dict.sorted_keys)
Пример #7
0
 def test(self):
     sorted_dict = SortedDict((x, x.upper()) for x in LOWER)
     self.assertEqual(sorted_dict.items(), zip(LOWER, UPPER))
Пример #8
0
 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))
Пример #9
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'))
Пример #10
0
 def test(self):
     sorted_dict = SortedDict.fromkeys('ba', 'A')
     self.assertIsInstance(sorted_dict, SortedDict)
     self.assertEqual(sorted_dict.items(), [('a', 'A'), ('b', 'A')])
Пример #11
0
 def test(self):
     sd = SortedDict({'2': 2, '10': 10})
     self.assertEqual(sd.__repr__(), """SortedDict({'10': 10, '2': 2})""")