hickle
hickle copied to clipboard
Failing test with Python 3.11: AttributeError: property 'dtype' of 'Dataset' object has no setter
$ python3.11 -mpytest --no-cov
============================= test session starts ==============================
platform linux -- Python 3.11.0+, pytest-7.1.2, pluggy-1.0.0+repack
benchmark: 3.2.2 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /home/edward/src/2022/vendor/hickle-5.0.2, configfile: tox.ini
plugins: benchmark-3.2.2, astropy-header-0.2.2, forked-1.4.0, flaky-3.7.0, anyio-3.6.2, sugar-0.9.6, openfiles-0.5.0, hypothesis-6.36.0, arraydiff-0.5.0, doctestplus-0.12.1, kgb-7.1.1, repeat-0.9.1, django-4.5.2, timeout-2.1.0, astropy-0.10.0, pylama-7.4.3, cov-4.0.0, tornasync-0.6.0.post2, remotedata-0.3.3, filter-subpackage-0.1.1, mock-3.8.2, requests-mock-1.9.3, xdist-2.5.0, asyncio-0.19.0
asyncio: mode=Mode.STRICT
collected 102 items
hickle/tests/test_01_hickle_helpers.py ..F... [ 5%]
hickle/tests/test_02_hickle_lookup.py ....................... [ 28%]
hickle/tests/test_03_load_builtins.py ...... [ 34%]
hickle/tests/test_04_load_numpy.py .... [ 38%]
hickle/tests/test_05_load_scipy.py .. [ 40%]
hickle/tests/test_06_load_astropy.py ......... [ 49%]
hickle/tests/test_07_load_pandas.py . [ 50%]
hickle/tests/test_99_hickle_core.py .......... [ 59%]
hickle/tests/test_hickle.py ....................................... [ 98%]
hickle/tests/test_legacy_load.py .. [100%]
=================================== FAILURES ===================================
____________________________ test_H5NodeFilterProxy ____________________________
h5_data = <HDF5 file "hickle_helpers_test_H5NodeFilterProxy.hdf5" (mode r)>
def test_H5NodeFilterProxy(h5_data):
"""
tests H5NodeFilterProxy class. This class allows to temporarily rewrite
attributes of h5py.Group and h5py.Dataset nodes before being loaded by
hickle._load method.
"""
# load data and try to directly modify 'type' and 'base_type' Attributes
# which will fail cause hdf5 file is opened for read only
h5_node = h5_data['somedata']
with pytest.raises(OSError):
try:
h5_node.attrs['type'] = pickle.dumps(list)
except RuntimeError as re:
raise OSError(re).with_traceback(re.__traceback__)
with pytest.raises(OSError):
try:
h5_node.attrs['base_type'] = b'list'
except RuntimeError as re:
raise OSError(re).with_traceback(re.__traceback__)
# verify that 'type' expands to tuple before running
# the remaining tests
object_type = pickle.loads(h5_node.attrs['type'])
assert object_type is tuple
assert object_type(h5_node[()].tolist()) == dummy_data
# Wrap node by H5NodeFilterProxy and rerun the above tests
# again. This time modifying Attributes shall be possible.
h5_node = H5NodeFilterProxy(h5_node)
h5_node.attrs['type'] = pickle.dumps(list)
h5_node.attrs['base_type'] = b'list'
object_type = pickle.loads(h5_node.attrs['type'])
assert object_type is list
# test proper pass through of item and attribute access
# to wrapped h5py.Group or h5py.Dataset object respective
assert object_type(h5_node[()].tolist()) == list(dummy_data)
assert h5_node.shape == np.array(dummy_data).shape
with pytest.raises(AttributeError,match = r"can't\s+set\s+attribute"):
> h5_node.dtype = np.float32
/home/edward/src/2022/vendor/hickle-5.0.2/hickle/tests/test_01_hickle_helpers.py:154:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <hickle.helpers.H5NodeFilterProxy object at 0x7f4c808b2090>
name = 'dtype', value = <class 'numpy.float32'>
def __setattr__(self, name, value):
# if wrapped _h5_node and attrs shall be set store value on local attributes
# otherwise pass on to wrapped _h5_node
if name in {'_h5_node'}:
super().__setattr__(name, value)
return
if name in {'attrs'}: # pragma: no cover
raise AttributeError('attribute is read-only')
_h5_node = super().__getattribute__('_h5_node')
> setattr(_h5_node, name, value)
E AttributeError: property 'dtype' of 'Dataset' object has no setter
/home/edward/src/2022/vendor/hickle-5.0.2/hickle/helpers.py:180: AttributeError
During handling of the above exception, another exception occurred:
h5_data = <HDF5 file "hickle_helpers_test_H5NodeFilterProxy.hdf5" (mode r)>
def test_H5NodeFilterProxy(h5_data):
"""
tests H5NodeFilterProxy class. This class allows to temporarily rewrite
attributes of h5py.Group and h5py.Dataset nodes before being loaded by
hickle._load method.
"""
# load data and try to directly modify 'type' and 'base_type' Attributes
# which will fail cause hdf5 file is opened for read only
h5_node = h5_data['somedata']
with pytest.raises(OSError):
try:
h5_node.attrs['type'] = pickle.dumps(list)
except RuntimeError as re:
raise OSError(re).with_traceback(re.__traceback__)
with pytest.raises(OSError):
try:
h5_node.attrs['base_type'] = b'list'
except RuntimeError as re:
raise OSError(re).with_traceback(re.__traceback__)
# verify that 'type' expands to tuple before running
# the remaining tests
object_type = pickle.loads(h5_node.attrs['type'])
assert object_type is tuple
assert object_type(h5_node[()].tolist()) == dummy_data
# Wrap node by H5NodeFilterProxy and rerun the above tests
# again. This time modifying Attributes shall be possible.
h5_node = H5NodeFilterProxy(h5_node)
h5_node.attrs['type'] = pickle.dumps(list)
h5_node.attrs['base_type'] = b'list'
object_type = pickle.loads(h5_node.attrs['type'])
assert object_type is list
# test proper pass through of item and attribute access
# to wrapped h5py.Group or h5py.Dataset object respective
assert object_type(h5_node[()].tolist()) == list(dummy_data)
assert h5_node.shape == np.array(dummy_data).shape
> with pytest.raises(AttributeError,match = r"can't\s+set\s+attribute"):
E AssertionError: Regex pattern "can't\\s+set\\s+attribute" does not match "property 'dtype' of 'Dataset' object has no setter".
/home/edward/src/2022/vendor/hickle-5.0.2/hickle/tests/test_01_hickle_helpers.py:153: AssertionError
=============================== warnings summary ===============================
hickle/tests/test_06_load_astropy.py::test_create_astropy_constant
/usr/lib/python3/dist-packages/astropy/constants/constant.py:99: AstropyUserWarning: Constant 'Gravitational constant' already has a definition in the None system from 'CODATA 2018' reference
warnings.warn('Constant {!r} already has a definition in the '
hickle/tests/test_06_load_astropy.py::test_create_astropy_constant
/usr/lib/python3/dist-packages/astropy/constants/constant.py:99: AstropyUserWarning: Constant 'Electron charge' already has a definition in the 'emu' system from 'CODATA 2018' reference
warnings.warn('Constant {!r} already has a definition in the '
hickle/tests/test_06_load_astropy.py::test_astropy_time_array
hickle/tests/test_06_load_astropy.py::test_astropy_time_array
hickle/tests/test_06_load_astropy.py::test_astropy_time_array
hickle/tests/test_06_load_astropy.py::test_astropy_time_array
hickle/tests/test_06_load_astropy.py::test_astropy_time_array
hickle/tests/test_06_load_astropy.py::test_astropy_time_array
hickle/tests/test_06_load_astropy.py::test_astropy_time_array
hickle/tests/test_06_load_astropy.py::test_astropy_time_array
/home/edward/src/2022/vendor/hickle-5.0.2/hickle/tests/test_06_load_astropy.py:169: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
assert reloaded.value[index].tostring() == t1.value[index].tostring()
hickle/tests/test_06_load_astropy.py::test_astropy_time_array
hickle/tests/test_06_load_astropy.py::test_astropy_time_array
hickle/tests/test_06_load_astropy.py::test_astropy_time_array
hickle/tests/test_06_load_astropy.py::test_astropy_time_array
hickle/tests/test_06_load_astropy.py::test_astropy_time_array
hickle/tests/test_06_load_astropy.py::test_astropy_time_array
hickle/tests/test_06_load_astropy.py::test_astropy_time_array
hickle/tests/test_06_load_astropy.py::test_astropy_time_array
/home/edward/src/2022/vendor/hickle-5.0.2/hickle/tests/test_06_load_astropy.py:177: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
assert reloaded.value[index].tostring() == t1.value[index].tostring()
hickle/tests/test_hickle.py::test_scalar_compression
/home/edward/src/2022/vendor/hickle-5.0.2/hickle/tests/test_hickle.py:745: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
data = {'a': 0, 'b': np.float(2), 'c': True}
hickle/tests/test_hickle.py::test_slash_dict_keys
/usr/lib/python3/dist-packages/pytest_tornasync/plugin.py:45: PytestRemovedIn8Warning: Passing None has been deprecated.
See https://docs.pytest.org/en/latest/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests for alternatives in common use cases.
pyfuncitem.obj(**testargs)
hickle/tests/test_legacy_load.py::test_4_0_0_load
/home/edward/src/2022/vendor/hickle-5.0.2/hickle/loaders/load_scipy.py:91: DeprecationWarning: Please use `csr_matrix` from the `scipy.sparse` namespace, the `scipy.sparse.csr` namespace is deprecated.
self.object_type = pickle.loads(item.attrs['type'])
hickle/tests/test_legacy_load.py::test_4_0_0_load
/home/edward/src/2022/vendor/hickle-5.0.2/hickle/loaders/load_scipy.py:91: DeprecationWarning: Please use `csc_matrix` from the `scipy.sparse` namespace, the `scipy.sparse.csc` namespace is deprecated.
self.object_type = pickle.loads(item.attrs['type'])
hickle/tests/test_legacy_load.py::test_4_0_0_load
/home/edward/src/2022/vendor/hickle-5.0.2/hickle/loaders/load_scipy.py:91: DeprecationWarning: Please use `bsr_matrix` from the `scipy.sparse` namespace, the `scipy.sparse.bsr` namespace is deprecated.
self.object_type = pickle.loads(item.attrs['type'])
hickle/tests/test_legacy_load.py::test_4_0_0_load
/home/edward/src/2022/vendor/hickle-5.0.2/hickle/lookup.py:1611: MockedLambdaWarning: presenting '<function _moc_numpy_array_object_lambda at 0x7f4c796220c0>' instead of stored lambda 'type'
warnings.warn(
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED hickle/tests/test_01_hickle_helpers.py::test_H5NodeFilterProxy - Asser...
================== 1 failed, 101 passed, 24 warnings in 3.88s ==================
Looks like a regex update is needed for this line:
> with pytest.raises(AttributeError,match = r"can't\s+set\s+attribute"):
E AssertionError: Regex pattern "can't\\s+set\\s+attribute" does not match "property 'dtype' of 'Dataset' object has no setter".
Not sure if this is h5py or Py 3.11