8000 Test the `popitem` method of `MutableMapping`s too (#378) · zarr-developers/zarr-python@585f0f5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 585f0f5

Browse files
authored
Test the popitem method of MutableMappings too (#378)
Adds a test for the `popitem` method of `MutableMapping`'s as well. Typically this is not used, but it does get used in the default `clear` method. Given this method doesn't guarantee an order, use a store with a single-key value pair to simplify the test logic. Also test the case of an empty store to make sure it errors out properly. Override the `popitem` method appropriate for stores that do not handle removal properly.
1 parent d7ad9fb commit 585f0f5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

zarr/tests/test_storage.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ def test_pop(self):
9393
with pytest.raises(KeyError):
9494
store.pop('xxx')
9595

96+
def test_popitem(self):
97+
store = self.create_store()
98+
store['foo'] = b'bar'
99+
k, v = store.popitem()
100+
assert k == 'foo'
101+
assert v == b'bar'
102+
assert len(store) == 0
103+
with pytest.raises(KeyError):
104+
store.popitem()
105+
96106
def test_writeable_values(self):
97107
store = self.create_store()
98108

@@ -762,6 +772,13 @@ def test_pop(self):
762772
with pytest.raises(NotImplementedError):
763773
store.pop('foo')
764774

775+
def test_popitem(self):
776+
# override because not implemented
777+
store = self.create_store()
778+
store['foo'] = b'bar'
779+
with pytest.raises(NotImplementedError):
780+
store.popitem()
781+
765782

766783
class TestDBMStore(StoreTests, unittest.TestCase):
767784

0 commit comments

Comments
 (0)
0