Skip to content

Utils

Utils

zarr.testing.utils

T module-attribute

T = TypeVar('T')

__all__ module-attribute

__all__ = ['assert_bytes_equal']

gpu_mark module-attribute

gpu_mark = gpu

skip_if_no_gpu module-attribute

skip_if_no_gpu = skipif(
    not has_cupy(),
    reason="CuPy not installed or no GPU available",
)

assert_bytes_equal

assert_bytes_equal(
    b1: Buffer | BytesLike | None,
    b2: Buffer | BytesLike | None,
) -> None

Help function to assert if two bytes-like or Buffers are equal

Warnings

Always copies data, only use for testing and debugging

Source code in zarr/testing/utils.py
def assert_bytes_equal(b1: Buffer | BytesLike | None, b2: Buffer | BytesLike | None) -> None:
    """Help function to assert if two bytes-like or Buffers are equal

    Warnings
    --------
    Always copies data, only use for testing and debugging
    """
    if isinstance(b1, Buffer):
        b1 = b1.to_bytes()
    if isinstance(b2, Buffer):
        b2 = b2.to_bytes()
    assert b1 == b2

gpu_test

gpu_test(func: T) -> T
Source code in zarr/testing/utils.py
def gpu_test(func: T) -> T:
    return cast(T, gpu_mark(skip_if_no_gpu(func)))

has_cupy

has_cupy() -> bool
Source code in zarr/testing/utils.py
def has_cupy() -> bool:
    try:
        import cupy

        return cast("bool", cupy.cuda.runtime.getDeviceCount() > 0)
    except ImportError:
        return False
    except cupy.cuda.runtime.CUDARuntimeError:
        return False