|
1 """ |
|
2 # Tests for stuff in django.utils.datastructures. |
|
3 |
|
4 >>> from django.utils.datastructures import * |
|
5 |
|
6 ### MergeDict ################################################################# |
|
7 |
|
8 >>> d1 = {'chris':'cool','camri':'cute','cotton':'adorable','tulip':'snuggable', 'twoofme':'firstone'} |
|
9 >>> d2 = {'chris2':'cool2','camri2':'cute2','cotton2':'adorable2','tulip2':'snuggable2'} |
|
10 >>> d3 = {'chris3':'cool3','camri3':'cute3','cotton3':'adorable3','tulip3':'snuggable3'} |
|
11 >>> d4 = {'twoofme':'secondone'} |
|
12 >>> md = MergeDict( d1,d2,d3 ) |
|
13 >>> md['chris'] |
|
14 'cool' |
|
15 >>> md['camri'] |
|
16 'cute' |
|
17 >>> md['twoofme'] |
|
18 'firstone' |
|
19 >>> md2 = md.copy() |
|
20 >>> md2['chris'] |
|
21 'cool' |
|
22 |
|
23 ### MultiValueDict ########################################################## |
|
24 |
|
25 >>> d = MultiValueDict({'name': ['Adrian', 'Simon'], 'position': ['Developer']}) |
|
26 >>> d['name'] |
|
27 'Simon' |
|
28 >>> d.getlist('name') |
|
29 ['Adrian', 'Simon'] |
|
30 >>> d.get('lastname', 'nonexistent') |
|
31 'nonexistent' |
|
32 >>> d.setlist('lastname', ['Holovaty', 'Willison']) |
|
33 |
|
34 ### SortedDict ################################################################# |
|
35 |
|
36 >>> d = SortedDict() |
|
37 >>> d['one'] = 'one' |
|
38 >>> d['two'] = 'two' |
|
39 >>> d['three'] = 'three' |
|
40 >>> d['one'] |
|
41 'one' |
|
42 >>> d['two'] |
|
43 'two' |
|
44 >>> d['three'] |
|
45 'three' |
|
46 >>> d.keys() |
|
47 ['one', 'two', 'three'] |
|
48 >>> d.values() |
|
49 ['one', 'two', 'three'] |
|
50 >>> d['one'] = 'not one' |
|
51 >>> d['one'] |
|
52 'not one' |
|
53 >>> d.keys() == d.copy().keys() |
|
54 True |
|
55 |
|
56 ### DotExpandedDict ############################################################ |
|
57 |
|
58 >>> d = DotExpandedDict({'person.1.firstname': ['Simon'], 'person.1.lastname': ['Willison'], 'person.2.firstname': ['Adrian'], 'person.2.lastname': ['Holovaty']}) |
|
59 >>> d['person']['1']['lastname'] |
|
60 ['Willison'] |
|
61 >>> d['person']['2']['lastname'] |
|
62 ['Holovaty'] |
|
63 >>> d['person']['2']['firstname'] |
|
64 ['Adrian'] |
|
65 """ |