Skip to content

Commit

Permalink
Improve ensure_memoryview NumPy testing
Browse files Browse the repository at this point in the history
Try using `ensure_memoryview` with a variety of different NumPy
`ndarray` types to improve test coverage.
  • Loading branch information
jakirkham committed May 13, 2022
1 parent 5be1c69 commit 0a6efb6
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions distributed/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,22 @@ def test_ensure_memoryview(data):
assert not result.readonly


def test_ensure_memoryview_ndarray():
@pytest.mark.parametrize(
"fmt, nitems, shape, strides",
[
("l", 12, (12,), (8,)),
("l", 12, (3, 4), (32, 8)),
("l", 12, (4, 3), (8, 32)),
("l", 12, (3, 2), (32, 16)),
("l", 12, (2, 3), (16, 32)),
],
)
def test_ensure_memoryview_ndarray(fmt, nitems, shape, strides):
np = pytest.importorskip("numpy")
result = ensure_memoryview(np.arange(12).reshape(3, 4)[:, ::2].T)
data = np.ndarray(
shape, dtype=fmt, buffer=np.arange(nitems, dtype=fmt), strides=strides
)
result = ensure_memoryview(data)
assert isinstance(result, memoryview)
assert result.ndim == 1
assert result.format == "B"
Expand Down

0 comments on commit 0a6efb6

Please sign in to comment.