Ticket #6050: 6050.diff
File 6050.diff, 3.2 KB (added by , 17 years ago) |
---|
-
django/utils/datastructures.py
60 60 if isinstance(data, dict): 61 61 self.keyOrder = data.keys() 62 62 else: 63 self.keyOrder = [key for key, value in data] 63 self.keyOrder = [] 64 for key, value in data: 65 if key not in self.keyOrder: 66 self.keyOrder.append(key) 64 67 65 68 def __deepcopy__(self, memo): 66 69 from copy import deepcopy -
tests/regressiontests/utils/datastructures.py
1 """ 2 >>> from django.utils.datastructures import SortedDict 3 4 >>> d = SortedDict() 5 >>> d[7] = 'seven' 6 >>> d[1] = 'one' 7 >>> d[9] = 'nine' 8 >>> d.keys() 9 [7, 1, 9] 10 >>> d.values() 11 ['seven', 'one', 'nine'] 12 >>> d.items() 13 [(7, 'seven'), (1, 'one'), (9, 'nine')] 14 15 # Overwriting an item keeps it's place. 16 >>> d[1] = 'ONE' 17 >>> d.values() 18 ['seven', 'ONE', 'nine'] 19 20 # New items go to the end. 21 >>> d[0] = 'nil' 22 >>> d.keys() 23 [7, 1, 9, 0] 24 25 # Deleting an item, then inserting the same key again will place it at the end. 26 >>> del d[7] 27 >>> d.keys() 28 [1, 9, 0] 29 >>> d[7] = 'lucky number 7' 30 >>> d.keys() 31 [1, 9, 0, 7] 32 33 # Changing the keys won't do anything, it's only a copy of the keys dict. 34 >>> k = d.keys() 35 >>> k.remove(9) 36 >>> d.keys() 37 [1, 9, 0, 7] 38 39 # Initialising a SortedDict with two keys will just take the first one. A real 40 # dict will actually take the second value so we will too, but we'll keep the 41 # ordering from the first key found. 42 >>> tuples = ((2, 'two'), (1, 'one'), (2, 'second-two')) 43 >>> d = SortedDict(tuples) 44 >>> d.keys() 45 [2, 1] 46 >>> real_dict = dict(tuples) 47 >>> real_dict.values() 48 ['one', 'second-two'] 49 >>> d.values() 50 ['second-two', 'one'] 51 """ 52 No newline at end of file -
tests/regressiontests/utils/timesince.py
1 timesince_tests ="""1 """ 2 2 >>> from datetime import datetime, timedelta 3 3 >>> from django.utils.timesince import timesince 4 4 -
tests/regressiontests/utils/tests.py
6 6 7 7 from django.utils import html, checksums 8 8 9 from timesince import timesince_tests 9 import timesince 10 import datastructures 10 11 12 # Extra tests 13 __test__ = { 14 'timesince': timesince, 15 'datastructures': datastructures, 16 } 17 11 18 class TestUtilsHtml(TestCase): 12 19 13 20 def check_output(self, function, value, output=None): … … 142 149 for value, output in items: 143 150 self.check_output(f, value, output) 144 151 145 __test__ = {146 'timesince_tests': timesince_tests,147 }148 149 152 if __name__ == "__main__": 150 153 import doctest 151 154 doctest.testmod()