summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorSebastian Berg <sebastianb@nvidia.com>2022-10-05 22:00:04 +0200
committerSebastian Berg <sebastianb@nvidia.com>2022-10-05 22:33:33 +0200
commit7a951f9d114a574ecfbe049dfb7f58a91884eba8 (patch)
tree3900e3e751bf80bf5c79601beea1dc3760c401cf /numpy
parenteec99b48df9ce782090157b657bf14f3b79c4981 (diff)
downloadnumpy-7a951f9d114a574ecfbe049dfb7f58a91884eba8.tar.gz
TST: Add deprecation tests for out-of-bound pyint conversion deprecation
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/tests/test_deprecations.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py
index 5c13fcd4f..164e504bf 100644
--- a/numpy/core/tests/test_deprecations.py
+++ b/numpy/core/tests/test_deprecations.py
@@ -1196,3 +1196,37 @@ class TestLoadtxtParseIntsViaFloat(_DeprecationTestCase):
np.loadtxt(["10.5"], dtype=dtype)
except ValueError as e:
assert isinstance(e.__cause__, DeprecationWarning)
+
+
+class TestPyIntConversion(_DeprecationTestCase):
+ message = r".*stop allowing conversion of out-of-bound.*"
+
+ @pytest.mark.parametrize("dtype", np.typecodes["AllInteger"])
+ def test_deprecated_scalar(self, dtype):
+ dtype = np.dtype(dtype)
+ info = np.iinfo(dtype)
+
+ # Cover the most common creation paths (all end up in the
+ # same place):
+ def scalar(value, dtype):
+ dtype.type(value)
+
+ def assign(value, dtype):
+ arr = np.array([0, 0, 0], dtype=dtype)
+ arr[2] = value
+
+ def create(value, dtype):
+ np.array([value], dtype=dtype)
+
+ for creation_func in [scalar, assign, create]:
+ try:
+ self.assert_deprecated(
+ lambda: creation_func(info.min - 1, dtype))
+ except OverflowError:
+ pass # OverflowErrors always happened also before and are OK.
+
+ try:
+ self.assert_deprecated(
+ lambda: creation_func(info.max + 1, dtype))
+ except OverflowError:
+ pass # OverflowErrors always happened also before and are OK.