fixing potential doctest failures due to dict key ordering

This commit is contained in:
Mahmoud Hashemi 2015-04-09 21:33:49 -07:00
parent 807b45e609
commit 0ba5e29f6a
2 changed files with 8 additions and 5 deletions

View File

@ -73,7 +73,8 @@ class LRU(dict):
>>> cap_cache = LRU(max_size=2)
>>> cap_cache['a'], cap_cache['b'] = 'A', 'B'
>>> dict(cap_cache)
>>> from pprint import pprint as pp
>>> pp(dict(cap_cache))
{'a': 'A', 'b': 'B'}
>>> [cap_cache['b'] for i in range(3)][0]
'B'
@ -255,7 +256,8 @@ class LRI(dict):
>>> cap_cache = LRI(max_size=2)
>>> cap_cache['a'], cap_cache['b'] = 'A', 'B'
>>> cap_cache
>>> from pprint import pprint as pp
>>> pp(cap_cache)
{'a': 'A', 'b': 'B'}
>>> [cap_cache['b'] for i in range(3)][0]
'B'

View File

@ -101,16 +101,17 @@ class OrderedMultiDict(dict):
Note that calling :func:`dict` on an OMD results in a dict of keys
to *lists* of values:
>>> from pprint import pprint as pp # ensuring proper key ordering
>>> omd = OrderedMultiDict([('a', 1), ('b', 2), ('a', 3)])
>>> dict(omd)
>>> pp(dict(omd))
{'a': [1, 3], 'b': [2]}
Note that modifying those lists will modify the OMD. If you want a
safe-to-modify or flat dictionary, use :meth:`OrderedMultiDict.todict()`.
>>> omd.todict()
>>> pp(omd.todict())
{'a': 3, 'b': 2}
>>> omd.todict(multi=True)
>>> pp(omd.todict(multi=True))
{'a': [1, 3], 'b': [2]}
With ``multi=False``, items appear with the keys in to original