Debian Codegraph @

hypothesis-python/tests/numpy/test_sampled_from.py

raw
1 # This file is part of Hypothesis, which may be found at
2 # https://github.com/HypothesisWorks/hypothesis/
3 #
4 # Copyright the Hypothesis Authors.
5 # Individual contributors are listed in AUTHORS.rst and the git log.
6 #
7 # This Source Code Form is subject to the terms of the Mozilla Public License,
8 # v. 2.0. If a copy of the MPL was not distributed with this file, You can
9 # obtain one at https://mozilla.org/MPL/2.0/.
10
11 from hypothesis import given
12 from hypothesis.errors import InvalidArgument
13 from hypothesis.extra import numpy as npst
14 from hypothesis.strategies import data, sampled_from
15
16 from tests.common.utils import fails_with
17
18
19 @given(
20 data(), npst.arrays(dtype=npst.scalar_dtypes(), shape=npst.array_shapes(max_dims=1))
21 )
22 def test_can_sample_1D_numpy_array_without_warning(data, arr):
23 data.draw(sampled_from(arr))
24
25
26 @fails_with(InvalidArgument)
27 @given(
28 data(),
29 npst.arrays(
30 dtype=npst.scalar_dtypes(), shape=npst.array_shapes(min_dims=2, max_dims=5)
31 ),
32 )
33 def test_sampling_multi_dimensional_arrays_is_deprecated(data, arr):
34 data.draw(sampled_from(arr))