Skip to content

Commit fefce3b

Browse files
authored
Test pop with default argument (#380)
* Test `pop` with default argument Adds another case to `test_pop` for stores generally, which merely tests if `pop` can handle the default argument correctly when no key can be found. * Test `pop` with the default value of `None` Some implementations of `pop` might carelessly set the `default` to `None` when not passed. However this would make it impossible to distinguish the case where the user passed `None` for the `default` intentionally versus not passing anything for the `default`. The result being both cases would raise a `KeyError`, but the error would be incorrect in the first case. The usual way of solving this is to create some dummy object and make that the `default` when if it is not set. That way one can compare if the dummy object is seen and only raise then. Thus passing `None` for the `default` would not error, but return `None` if the `key` does not exist as expected. This test is added to catch this potential oversight. * Test `pop` with a non-trivial `bytes` object
1 parent 585f0f5 commit fefce3b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

zarr/tests/test_storage.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ def test_pop(self):
9292
assert len(store) == 0
9393
with pytest.raises(KeyError):
9494
store.pop('xxx')
95+
v = store.pop('xxx', b'default')
96+
assert v == b'default'
97+
v = store.pop('xxx', b'')
98+
assert v == b''
99+
v = store.pop('xxx', None)
100+
assert v is None
95101

96102
def test_popitem(self):
97103
store = self.create_store()

0 commit comments

Comments
 (0)