summaryrefslogtreecommitdiff
path: root/numpy/random
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2021-02-19 11:10:48 -0600
committerSebastian Berg <sebastian@sipsolutions.net>2021-02-19 11:10:48 -0600
commitdfdff63cd6c53f1fd1d1c4a9754332887b746e7e (patch)
tree78b0df6b5ba0967d60079dd6bccc317bc15f966c /numpy/random
parent60e82e19df952ec13272afe6bf345ac21442ce8e (diff)
downloadnumpy-dfdff63cd6c53f1fd1d1c4a9754332887b746e7e.tar.gz
TST: Add test for shuffle warning and assert stacklevel
The test checks that the warning originates in the correct file (test_random.py). I am not quite sure how safe the test is, though. Unfortunately, there is no "obvious" way to test stacklevels.
Diffstat (limited to 'numpy/random')
-rw-r--r--numpy/random/tests/test_random.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py
index 5f8b39ef9..a0c72b419 100644
--- a/numpy/random/tests/test_random.py
+++ b/numpy/random/tests/test_random.py
@@ -1,5 +1,7 @@
import warnings
+import pytest
+
import numpy as np
from numpy.testing import (
assert_, assert_raises, assert_equal, assert_warns,
@@ -510,6 +512,16 @@ class TestRandomDist:
assert_equal(
sorted(b.data[~b.mask]), sorted(b_orig.data[~b_orig.mask]))
+ @pytest.mark.parametrize("random",
+ [np.random, np.random.RandomState(), np.random.default_rng()])
+ def test_shuffle_untyped_warning(self, random):
+ # Create a dict works like a sequence but isn't one
+ values = {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6}
+ with pytest.warns(UserWarning,
+ match="you are shuffling a 'dict' object") as rec:
+ random.shuffle(values)
+ assert "test_random" in rec[0].filename
+
def test_shuffle_memoryview(self):
# gh-18273
# allow graceful handling of memoryviews