Skip to content

Commit

Permalink
Add missing test for popitem() and fix bug in the C impl.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Apr 8, 2021
1 parent 0062ca9 commit fc07461
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/BTrees/BTreeTemplate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,7 @@ BTree_popitem(BTree* self, PyObject* args)
}

Py_DECREF(key);
return result_val;
return result;
}


Expand Down
2 changes: 1 addition & 1 deletion src/BTrees/BucketTemplate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ bucket_popitem(Bucket* self, PyObject* args)
}

Py_DECREF(key);
return result_val;
return result;
}


Expand Down
17 changes: 17 additions & 0 deletions src/BTrees/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,23 @@ def _getCollectionsABC(self):
from BTrees._compat import collections_abc
return collections_abc.MutableMapping

def test_popitem(self):
t = self._makeOne()
# Empty
with self.assertRaises(KeyError):
t.popitem()

self._populate(t, 2000)
self.assertEqual(len(t), 2000)
for i in range(2000):
self.assertEqual(t.popitem(), (i, i))
self.assertEqual(len(t), 2000 - i - 1)

# Back to empty
self.assertEqual(len(t), 0)
with self.assertRaises(KeyError):
t.popitem()

def testShortRepr(self):
# test the repr because buckets have a complex repr implementation
# internally the cutoff from a stack allocated buffer to a heap
Expand Down

0 comments on commit fc07461

Please sign in to comment.