Skip to content

Commit 2bf2cdc

Browse files
committed
use pytest to test warnings
1 parent 78014cb commit 2bf2cdc

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
asciitree
22
nose
3+
pytest
34
numpy
45
fasteners
56
numcodecs

zarr/tests/test_creation.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
import numpy as np
1010
from nose.tools import eq_ as eq, assert_is_none, assert_is_instance, assert_raises
1111
from numpy.testing import assert_array_equal
12+
import pytest
1213

1314

14-
from zarr.creation import (array, empty, zeros, ones, full, open_array, empty_like, zeros_like,
15-
ones_like, full_like, open_like, create)
15+
from zarr.creation import (array, empty, zeros, ones, full, open_array, empty_like,
16+
zeros_like, ones_like, full_like, open_like, create)
1617
from zarr.sync import ThreadSynchronizer
1718
from zarr.core import Array
1819
from zarr.storage import DirectoryStore
@@ -23,8 +24,9 @@
2324

2425

2526
# needed for PY2/PY3 consistent behaviour
26-
warnings.resetwarnings()
27-
warnings.simplefilter('always')
27+
if PY2: # pragma: py3 no cover
28+
warnings.resetwarnings()
29+
warnings.simplefilter('always')
2830

2931

3032
# something bcolz-like
@@ -438,8 +440,6 @@ def test_create():
438440

439441

440442
def test_compression_args():
441-
warnings.resetwarnings()
442-
warnings.simplefilter('always')
443443

444444
z = create(100, compression='zlib', compression_opts=9)
445445
assert_is_instance(z, Array)
@@ -458,16 +458,12 @@ def test_compression_args():
458458
eq('zlib', z.compressor.codec_id)
459459
eq(9, z.compressor.level)
460460

461-
warnings.resetwarnings()
462-
warnings.simplefilter('error')
463-
with assert_raises(UserWarning):
461+
with pytest.warns(UserWarning):
464462
# 'compressor' overrides 'compression'
465463
create(100, compressor=Zlib(9), compression='bz2', compression_opts=1)
466-
with assert_raises(UserWarning):
464+
with pytest.warns(UserWarning):
467465
# 'compressor' ignores 'compression_opts'
468466
create(100, compressor=Zlib(9), compression_opts=1)
469-
warnings.resetwarnings()
470-
warnings.simplefilter('always')
471467

472468

473469
def test_create_read_only():
@@ -485,8 +481,8 @@ def test_create_read_only():
485481
with assert_raises(PermissionError):
486482
z[:] = 0
487483

488-
# this is subtly different, but here we want to create an array with data, and then have it
489-
# be read-only
484+
# this is subtly different, but here we want to create an array with data, and then
485+
# have it be read-only
490486
a = np.arange(100)
491487
z = array(a, read_only=True)
492488
assert_array_equal(a, z[...])

zarr/tests/test_hierarchy.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from nose.tools import (assert_raises, eq_ as eq, assert_is, assert_true,
1616
assert_is_instance, assert_false, assert_is_none)
1717
from nose import SkipTest
18+
import pytest
1819

1920

2021
from zarr.storage import (DictStore, DirectoryStore, ZipStore, init_group, init_array,
@@ -31,8 +32,9 @@
3132

3233

3334
# needed for PY2/PY3 consistent behaviour
34-
warnings.resetwarnings()
35-
warnings.simplefilter('always')
35+
if PY2: # pragma: py3 no cover
36+
warnings.resetwarnings()
37+
warnings.simplefilter('always')
3638

3739

3840
# noinspection PyStatementEffect
@@ -363,16 +365,8 @@ def test_create_errors(self):
363365
eq(42, d.fill_value)
364366

365367
# h5py compatibility, ignore 'shuffle'
366-
warnings.resetwarnings()
367-
warnings.simplefilter('always')
368-
d = g.create_dataset('y1', shape=100, chunks=10, shuffle=True)
369-
assert not hasattr(d, 'shuffle')
370-
warnings.resetwarnings()
371-
warnings.simplefilter('error')
372-
with assert_raises(UserWarning):
373-
g.create_dataset('y2', shape=100, chunks=10, shuffle=True)
374-
warnings.resetwarnings()
375-
warnings.simplefilter('always')
368+
with pytest.warns(UserWarning, match="ignoring keyword argument 'shuffle'"):
369+
g.create_dataset('y', shape=100, chunks=10, shuffle=True)
376370

377371
# read-only
378372
g = self.create_group(read_only=True)
@@ -406,6 +400,7 @@ def test_create_overwrite(self):
406400
# overwrite array with group
407401
d = getattr(g, method_name)('foo/bar', shape=400, chunks=40,
408402
overwrite=True)
403+
eq((400,), d.shape)
409404
assert_is_instance(g['foo'], Group)
410405
except NotImplementedError:
411406
pass
@@ -1069,6 +1064,7 @@ def test_group_completions():
10691064
def test_group_key_completions():
10701065
g = group()
10711066
d = dir(g)
1067+
# noinspection PyProtectedMember
10721068
k = g._ipython_key_completions_()
10731069

10741070
# none of these names should be an attribute
@@ -1103,6 +1099,7 @@ def test_group_key_completions():
11031099
g.zeros('asdf;', shape=100)
11041100

11051101
d = dir(g)
1102+
# noinspection PyProtectedMember
11061103
k = g._ipython_key_completions_()
11071104

11081105
assert 'foo' in d

0 commit comments

Comments
 (0)