Skip to content

Commit

Permalink
0d arrays as elements test
Browse files Browse the repository at this point in the history
  • Loading branch information
honno committed Sep 29, 2021
1 parent 6bec46a commit 150efd1
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions hypothesis-python/tests/array_api/test_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ def test_generate_arrays_from_unsigned_ints(x):
assert_array_namespace(x)


@given(
xps.arrays(
dtype=xp.uint8,
shape=(5, 5),
elements=xps.from_dtype(xp.uint8).map(lambda e: xp.asarray(e, dtype=xp.uint8)),
)
)
def test_generate_arrays_from_0d_arrays(x):
"""Generate arrays from 0d array elements."""
assert x.shape == (5, 5)
assert_array_namespace(x)


def test_minimize_arrays_with_default_dtype_shape_strategies():
"""Strategy with default scalar_dtypes and array_shapes strategies minimize
to a boolean 1-dimensional array of size 1."""
Expand Down Expand Up @@ -229,19 +242,17 @@ def test_generate_unique_arrays(x):
assert count_unique(x) == x.size


def test_cannot_draw_unique_arrays_with_too_small_elements():
@fails_with(InvalidArgument)
@given(xps.arrays(xp.int8, 10, elements=st.integers(0, 5), unique=True))
def test_cannot_draw_unique_arrays_with_too_small_elements(_):
"""Unique strategy with elements strategy range smaller than its size raises
helpful error."""
strat = xps.arrays(xp.int8, 10, elements=st.integers(0, 5), unique=True)
with pytest.raises(InvalidArgument):
strat.example()


@fails_with(InvalidArgument)
@given(xps.arrays(xp.int8, 10, fill=st.just("not a castable value")))
def test_cannot_fill_arrays_with_non_castable_value():
"""Strategy with fill not castable to dtype raises helpful error."""
strat = xps.arrays(xp.int8, 10, fill=st.just("not a castable value"))
with pytest.raises(InvalidArgument):
strat.example()


@given(
Expand Down

0 comments on commit 150efd1

Please sign in to comment.