Skip to content

Commit 7f8bfc7

Browse files
committed
Move first-party hypothesis test to its own file
1 parent e1d2dc9 commit 7f8bfc7

File tree

3 files changed

+42
-40
lines changed

3 files changed

+42
-40
lines changed

torch_np/tests/__init__.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

torch_np/tests/test_ndarray_methods.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@
44

55
# import numpy as np
66
import torch
7-
from hypothesis import given
8-
from hypothesis import strategies as st
97
from pytest import raises as assert_raises
108

119
import torch_np as np
1210
from torch_np._ndarray import ndarray
1311
from torch_np.testing import assert_equal
1412

15-
from . import xps
16-
1713

1814
class TestIndexing:
1915
def test_indexing_simple(self):
@@ -30,30 +26,6 @@ def test_setitem(self):
3026
assert_equal(a, [[8, 2, 3], [4, 5, 6]])
3127

3228

33-
def integer_array_indices(shape, result_shape) -> st.SearchStrategy[tuple]:
34-
# See hypothesis.extra.numpy.integer_array_indices()
35-
# n.b. result_shape only accepts a shape, as opposed to only accepting a strategy
36-
def array_for(index_shape, size):
37-
return xps.arrays(
38-
dtype=xps.integer_dtypes(),
39-
shape=index_shape,
40-
elements=st.integers(-size, size - 1),
41-
)
42-
43-
return st.tuples(*(array_for(result_shape, size) for size in shape))
44-
45-
46-
@given(
47-
x=xps.arrays(dtype=xps.integer_dtypes(), shape=xps.array_shapes()),
48-
data=st.data(),
49-
)
50-
def test_integer_indexing(x, data):
51-
result_shape = data.draw(xps.array_shapes(), label="result_shape")
52-
idx = data.draw(integer_array_indices(x.shape, result_shape), label="idx")
53-
result = x[idx]
54-
assert result.shape == result_shape
55-
56-
5729
class TestReshape:
5830
def test_reshape_function(self):
5931
arr = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]

torch_np/tests/test_stuff.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import warnings
2+
3+
import pytest
4+
5+
pytest.importorskip("hypothesis")
6+
7+
from hypothesis import given
8+
from hypothesis import strategies as st
9+
from hypothesis.errors import HypothesisWarning
10+
from hypothesis.extra.array_api import make_strategies_namespace
11+
12+
import torch_np
13+
14+
__all__ = ["xps"]
15+
16+
with warnings.catch_warnings():
17+
warnings.filterwarnings("ignore", category=HypothesisWarning)
18+
xps = make_strategies_namespace(torch_np, api_version="2021.12")
19+
20+
21+
def integer_array_indices(shape, result_shape) -> st.SearchStrategy[tuple]:
22+
# See hypothesis.extra.numpy.integer_array_indices()
23+
# n.b. result_shape only accepts a shape, as opposed to only accepting a strategy
24+
def array_for(index_shape, size):
25+
return xps.arrays(
26+
dtype=xps.integer_dtypes(),
27+
shape=index_shape,
28+
elements=st.integers(-size, size - 1),
29+
)
30+
31+
return st.tuples(*(array_for(result_shape, size) for size in shape))
32+
33+
34+
@given(
35+
x=xps.arrays(dtype=xps.integer_dtypes(), shape=xps.array_shapes()),
36+
data=st.data(),
37+
)
38+
def test_integer_indexing(x, data):
39+
result_shape = data.draw(xps.array_shapes(), label="result_shape")
40+
idx = data.draw(integer_array_indices(x.shape, result_shape), label="idx")
41+
result = x[idx]
42+
assert result.shape == result_shape

0 commit comments

Comments
 (0)