The items() and iteritems() methods did not contain correct values after
a call to `pop(i)`.
Fixes https://github.com/mitsuhiko/babel/issues/196
return self._keys[:]
def pop(self, key, default=missing):
- if default is missing:
- return dict.pop(self, key)
- elif key not in self:
- return default
- self._keys.remove(key)
- return dict.pop(self, key, default)
+ try:
+ value = dict.pop(self, key)
+ self._keys.remove(key)
+ return value
+ except KeyError as e:
+ if default == missing:
+ raise e
+ else:
+ return default
def popitem(self, key):
self._keys.remove(key)
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://babel.edgewall.org/log/.
-import doctest
-import unittest
from babel import util
assert not util.pathmatch('**.py', 'templates/index.html')
assert util.pathmatch('**/templates/*.html', 'templates/index.html')
assert not util.pathmatch('**/templates/*.html', 'templates/foo/bar.html')
+
+def test_odict_pop():
+ odict = util.odict()
+ odict[0] = 1
+ value = odict.pop(0)
+ assert 1 == value
+ assert [] == list(odict.items())
+ assert odict.pop(2, None) is None
+ try:
+ odict.pop(2)
+ assert False
+ except KeyError:
+ assert True