Ticket #18175: sorted_dict_copy_2.diff

File sorted_dict_copy_2.diff, 1.2 KB (added by linovia, 13 years ago)

Test & patch with a comment

  • django/utils/datastructures.py

     
    128128        return self.__class__([(key, copy.deepcopy(value, memo))
    129129                               for key, value in self.iteritems()])
    130130
     131    def __copy__(self):
     132        # We need this to make sure copy.copy doesn't alter this instance
     133        return self.copy()
     134
    131135    def __setitem__(self, key, value):
    132136        if key not in self:
    133137            self.keyOrder.append(key)
  • tests/regressiontests/utils/datastructures.py

     
    111111            {7: 'seven', 1: 'one', 9: 'nine'}
    112112        )
    113113
     114    def test_copy(self):
     115        d = SortedDict(((1, "one"), (0, "zero"), (2, "two")))
     116        copy.copy(d)
     117        self.assertEqual(
     118            d.keys(),
     119            [1, 0, 2]
     120        )
     121
    114122    def test_clear(self):
    115123        self.d1.clear()
    116124        self.assertEqual(self.d1, {})
Back to Top