Skip to content

Suppress warning about duplicate write to zip #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion zarr/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import zipfile
import shutil
import atexit
import warnings


import numpy as np
Expand Down Expand Up @@ -830,7 +831,9 @@ def __setitem__(self, key, value):
if self.mode == 'r':
err_read_only()
value = ensure_bytes(value)
self.zf.writestr(key, value)
with warnings.catch_warnings():
warnings.simplefilter("ignore", UserWarning)
self.zf.writestr(key, value)

def __delitem__(self, key):
raise NotImplementedError
Expand Down
16 changes: 16 additions & 0 deletions zarr/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import array
import shutil
import os
import warnings


import numpy as np
Expand Down Expand Up @@ -645,6 +646,21 @@ def test_mode(self):
with assert_raises(PermissionError):
store['foo'] = b'bar'

def test_duplicate(self):
caught = False
with warnings.catch_warnings():
warnings.simplefilter("error", UserWarning)
try:
with ZipStore('example.zip', mode='w') as store:
store['foo'] = b'bar'
store['foo'] = b'baz'
except UserWarning:
caught = False
else:
caught = True

self.assertTrue(caught, "Failed to catch UserWarning.")


def test_getsize():
store = dict()
Expand Down