Skip to content

Commit

Permalink
Bump pytest from 7.4.4 to 8.0.2 (#51)
Browse files Browse the repository at this point in the history
* Bump pytest from 7.4.4 to 8.0.2

Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.4.4 to 8.0.2.
- [Release notes](https://github.com/pytest-dev/pytest/releases)
- [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst)
- [Commits](pytest-dev/pytest@7.4.4...8.0.2)

---
updated-dependencies:
- dependency-name: pytest
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* Fix failing tests.

* Include non-numpy support.

* Warn with Zarr backend.

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Bradley Dice <[email protected]>
  • Loading branch information
dependabot[bot] and bdice authored Mar 26, 2024
1 parent 2f47519 commit 9df749c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
2 changes: 1 addition & 1 deletion requirements/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
coverage==7.4.3
pytest==7.4.4
pytest==8.0.2
pytest-cov==4.1.0
pytest-xdist==3.5.0
4 changes: 2 additions & 2 deletions synced_collections/numpy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ def _is_numpy_scalar(data):
def _is_complex(data):
"""Check if an object is complex.
This function works for both numpy raw Python data types.
This function works for numpy arrays, scalars, and raw Python data types.
Returns
-------
bool
Whether or not the input is a complex number.
"""
return (NUMPY and numpy.iscomplex(data).any()) or (isinstance(data, complex))
return (NUMPY and numpy.iscomplexobj(data)) or isinstance(data, complex)
56 changes: 33 additions & 23 deletions tests/synced_collection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
# This software is licensed under the BSD 3-Clause License.
import platform
from collections.abc import MutableMapping, MutableSequence
from contextlib import nullcontext
from copy import deepcopy
from typing import Any, Tuple, Type

import pytest

from synced_collections import SyncedCollection
from synced_collections.backends.collection_zarr import ZarrCollection
from synced_collections.errors import KeyTypeError
from synced_collections.numpy_utils import NumpyConversionWarning

Expand Down Expand Up @@ -526,15 +528,16 @@ def test_set_get_numpy_float_data(self, synced_collection, dtype, shape):
# should fail to set correctly.
raw_value = value.item() if shape is None else value.tolist()
test_value = value.item(0) if isinstance(raw_value, list) else raw_value
has_corresponding_python_type = isinstance(
test_value, (numpy.number, numpy.bool_)
)
should_fail = isinstance(test_value, (numpy.number, numpy.bool_))

if has_corresponding_python_type:
with pytest.raises((ValueError, TypeError)), pytest.warns(
NumpyConversionWarning
):
synced_collection["numpy_dtype_val"] = value
maybe_warn = nullcontext()
if isinstance(synced_collection, ZarrCollection):
maybe_warn = pytest.warns(NumpyConversionWarning)

if should_fail:
with pytest.raises((ValueError, TypeError)):
with maybe_warn:
synced_collection["numpy_dtype_val"] = value
else:
with pytest.warns(NumpyConversionWarning):
synced_collection["numpy_dtype_val"] = value
Expand All @@ -553,10 +556,13 @@ def test_set_get_numpy_complex_data(self, synced_collection, dtype, shape):
# not a priority to test here).
value = dtype(random_sample(shape))

with pytest.raises((ValueError, TypeError)), pytest.warns(
NumpyConversionWarning
):
synced_collection["numpy_dtype_val"] = value
maybe_warn = nullcontext()
if isinstance(synced_collection, ZarrCollection):
maybe_warn = pytest.warns(NumpyConversionWarning)

with pytest.raises((ValueError, TypeError)):
with maybe_warn:
synced_collection["numpy_dtype_val"] = value


class SyncedListTest(SyncedCollectionTest):
Expand Down Expand Up @@ -813,11 +819,14 @@ def test_set_get_numpy_float_data(self, synced_collection, dtype, shape):
test_value = value.item(0) if isinstance(raw_value, list) else raw_value
should_fail = isinstance(test_value, (numpy.number, numpy.bool_))

maybe_warn = nullcontext()
if isinstance(synced_collection, ZarrCollection):
maybe_warn = pytest.warns(NumpyConversionWarning)

if should_fail:
with pytest.raises((ValueError, TypeError)), pytest.warns(
NumpyConversionWarning
):
synced_collection.append(value)
with pytest.raises((ValueError, TypeError)):
with maybe_warn:
synced_collection.append(value)
else:
with pytest.warns(NumpyConversionWarning):
synced_collection.append(value)
Expand All @@ -840,14 +849,15 @@ def test_set_get_numpy_complex_data(self, synced_collection, dtype, shape):
# not a priority to test here).
value = dtype(random_sample(shape))

with pytest.raises((ValueError, TypeError)), pytest.warns(
NumpyConversionWarning
):
synced_collection.append(value)
maybe_warn = nullcontext()
if isinstance(synced_collection, ZarrCollection):
maybe_warn = pytest.warns(NumpyConversionWarning)

with pytest.raises((ValueError, TypeError)):
with maybe_warn:
synced_collection.append(value)

with pytest.raises((ValueError, TypeError)), pytest.warns(
NumpyConversionWarning
):
with pytest.raises((ValueError, TypeError)):
synced_collection[-1] = value

@pytest.mark.parametrize("dtype", NUMPY_INT_TYPES)
Expand Down

0 comments on commit 9df749c

Please sign in to comment.