2007-02-28 08:35:50 +08:00
|
|
|
"""
|
|
|
|
# Tests for stuff in django.utils.datastructures.
|
|
|
|
|
|
|
|
>>> from django.utils.datastructures import *
|
|
|
|
|
|
|
|
### MergeDict #################################################################
|
|
|
|
|
|
|
|
>>> d1 = {'chris':'cool','camri':'cute','cotton':'adorable','tulip':'snuggable', 'twoofme':'firstone'}
|
|
|
|
>>> d2 = {'chris2':'cool2','camri2':'cute2','cotton2':'adorable2','tulip2':'snuggable2'}
|
|
|
|
>>> d3 = {'chris3':'cool3','camri3':'cute3','cotton3':'adorable3','tulip3':'snuggable3'}
|
|
|
|
>>> d4 = {'twoofme':'secondone'}
|
|
|
|
>>> md = MergeDict( d1,d2,d3 )
|
|
|
|
>>> md['chris']
|
|
|
|
'cool'
|
|
|
|
>>> md['camri']
|
|
|
|
'cute'
|
|
|
|
>>> md['twoofme']
|
|
|
|
'firstone'
|
|
|
|
>>> md2 = md.copy()
|
|
|
|
>>> md2['chris']
|
|
|
|
'cool'
|
|
|
|
|
|
|
|
### MultiValueDict ##########################################################
|
|
|
|
|
|
|
|
>>> d = MultiValueDict({'name': ['Adrian', 'Simon'], 'position': ['Developer']})
|
|
|
|
>>> d['name']
|
|
|
|
'Simon'
|
|
|
|
>>> d.getlist('name')
|
|
|
|
['Adrian', 'Simon']
|
|
|
|
>>> d.get('lastname', 'nonexistent')
|
|
|
|
'nonexistent'
|
|
|
|
>>> d.setlist('lastname', ['Holovaty', 'Willison'])
|
|
|
|
|
2007-03-08 17:28:45 +08:00
|
|
|
### SortedDict #################################################################
|
|
|
|
|
|
|
|
>>> d = SortedDict()
|
|
|
|
>>> d['one'] = 'one'
|
|
|
|
>>> d['two'] = 'two'
|
|
|
|
>>> d['three'] = 'three'
|
|
|
|
>>> d['one']
|
|
|
|
'one'
|
|
|
|
>>> d['two']
|
|
|
|
'two'
|
|
|
|
>>> d['three']
|
|
|
|
'three'
|
|
|
|
>>> d.keys()
|
|
|
|
['one', 'two', 'three']
|
|
|
|
>>> d.values()
|
|
|
|
['one', 'two', 'three']
|
|
|
|
>>> d['one'] = 'not one'
|
|
|
|
>>> d['one']
|
|
|
|
'not one'
|
2007-03-09 13:34:42 +08:00
|
|
|
>>> d.keys() == d.copy().keys()
|
|
|
|
True
|
2007-04-25 15:30:54 +08:00
|
|
|
>>> print repr(d)
|
|
|
|
{'one': 'not one', 'two': 'two', 'three': 'three'}
|
2007-03-08 17:28:45 +08:00
|
|
|
|
|
|
|
### DotExpandedDict ############################################################
|
|
|
|
|
|
|
|
>>> d = DotExpandedDict({'person.1.firstname': ['Simon'], 'person.1.lastname': ['Willison'], 'person.2.firstname': ['Adrian'], 'person.2.lastname': ['Holovaty']})
|
|
|
|
>>> d['person']['1']['lastname']
|
|
|
|
['Willison']
|
|
|
|
>>> d['person']['2']['lastname']
|
|
|
|
['Holovaty']
|
|
|
|
>>> d['person']['2']['firstname']
|
|
|
|
['Adrian']
|
2007-08-12 20:02:08 +08:00
|
|
|
|
|
|
|
### FileDict ################################################################
|
|
|
|
|
|
|
|
>>> d = FileDict({'content': 'once upon a time...'})
|
|
|
|
>>> repr(d)
|
|
|
|
"{'content': '<omitted>'}"
|
|
|
|
>>> d = FileDict({'other-key': 'once upon a time...'})
|
|
|
|
>>> repr(d)
|
|
|
|
"{'other-key': 'once upon a time...'}"
|
2007-03-08 17:28:45 +08:00
|
|
|
"""
|