Ticket #15812: sorteddict.patch
File sorteddict.patch, 1.5 KB (added by , 14 years ago) |
---|
-
django/utils/datastructures.py
175 175 yield self[key] 176 176 177 177 def update(self, dict_): 178 for k, v in dict_.iteritems(): 178 if getattr(dict_, 'iteritems', None) is not None: 179 dict_ = dict_.iteritems() 180 for k, v in dict_: 181 # This works for tuples, lists, and other iterators too. 179 182 self[k] = v 180 183 181 184 def setdefault(self, key, default): -
tests/regressiontests/utils/datastructures.py
114 114 d = SortedDict(((1, "one"), (0, "zero"), (2, "two"))) 115 115 self.assertEqual(repr(d), "{1: 'one', 0: 'zero', 2: 'two'}") 116 116 117 118 def test_tuple_update(self): 119 d = SortedDict() 120 d.update(((1, "one"), (0, "zero"), (2, "two"))) 121 self.assertEqual(repr(d), "{1: 'one', 0: 'zero', 2: 'two'}") 122 123 def test_generator_update(self): 124 def some_generator(): 125 for i in range(3, 0, -1): 126 yield (i, 'o' * i) 127 d = SortedDict() 128 d.update(some_generator()) 129 self.assertEqual(repr(d), "{3: 'ooo', 2: 'oo', 1: 'o'}") 130 131 117 132 def test_pickle(self): 118 133 self.assertEqual( 119 134 pickle.loads(pickle.dumps(self.d1, 2)),