Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Sep 5, 2024
1 parent 0ea7eba commit 7f9611b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
rev: v1.11.2
hooks:
- id: mypy
files: src|tests/v3/test_api.py
files: src|tests/v3/test_(api|array|buffer).py
additional_dependencies:
# Package dependencies
- asciitree
Expand Down
26 changes: 16 additions & 10 deletions tests/v3/test_buffer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import types

import numpy as np
import pytest

Expand Down Expand Up @@ -27,14 +29,14 @@
cp = None


def test_nd_array_like(xp):
def test_nd_array_like(xp: types.ModuleType) -> None:
ary = xp.arange(10)
assert isinstance(ary, ArrayLike)
assert isinstance(ary, NDArrayLike)


@pytest.mark.asyncio
async def test_async_array_prototype():
async def test_async_array_prototype() -> None:
"""Test the use of a custom buffer prototype"""

expect = np.zeros((9, 9), dtype="uint16", order="F")
Expand All @@ -55,13 +57,15 @@ async def test_async_array_prototype():
prototype=my_prototype,
)
got = await a.getitem(selection=(slice(0, 9), slice(0, 9)), prototype=my_prototype)
assert isinstance(got, TestNDArrayLike)
assert np.array_equal(expect, got)
# ignoring a mypy error here that TestNDArrayLike doesn't meet the NDArrayLike protocol
# The test passes, so it clearly does.
assert isinstance(got, TestNDArrayLike) # type: ignore[unreachable]
assert np.array_equal(expect, got) # type: ignore[unreachable]


@gpu_test
@pytest.mark.asyncio
async def test_async_array_gpu_prototype():
async def test_async_array_gpu_prototype() -> None:
"""Test the use of the GPU buffer prototype"""

expect = cp.zeros((9, 9), dtype="uint16", order="F")
Expand All @@ -85,7 +89,7 @@ async def test_async_array_gpu_prototype():


@pytest.mark.asyncio
async def test_codecs_use_of_prototype():
async def test_codecs_use_of_prototype() -> None:
expect = np.zeros((10, 10), dtype="uint16", order="F")
a = await AsyncArray.create(
StorePath(StoreExpectingTestBuffer(mode="w")) / "test_codecs_use_of_prototype",
Expand All @@ -112,13 +116,15 @@ async def test_codecs_use_of_prototype():
prototype=my_prototype,
)
got = await a.getitem(selection=(slice(0, 10), slice(0, 10)), prototype=my_prototype)
assert isinstance(got, TestNDArrayLike)
assert np.array_equal(expect, got)
# ignoring a mypy error here that TestNDArrayLike doesn't meet the NDArrayLike protocol
# The test passes, so it clearly does.
assert isinstance(got, TestNDArrayLike) # type: ignore[unreachable]
assert np.array_equal(expect, got) # type: ignore[unreachable]


@gpu_test
@pytest.mark.asyncio
async def test_codecs_use_of_gpu_prototype():
async def test_codecs_use_of_gpu_prototype() -> None:
expect = cp.zeros((10, 10), dtype="uint16", order="F")
a = await AsyncArray.create(
StorePath(MemoryStore(mode="w")) / "test_codecs_use_of_gpu_prototype",
Expand Down Expand Up @@ -147,7 +153,7 @@ async def test_codecs_use_of_gpu_prototype():
assert cp.array_equal(expect, got)


def test_numpy_buffer_prototype():
def test_numpy_buffer_prototype() -> None:
buffer = cpu.buffer_prototype.buffer.create_zero_length()
ndbuffer = cpu.buffer_prototype.nd_buffer.create(shape=(1, 2), dtype=np.dtype("int64"))
assert isinstance(buffer.as_array_like(), np.ndarray)
Expand Down

0 comments on commit 7f9611b

Please sign in to comment.