diff options
Diffstat (limited to 'numpy/random/tests')
-rw-r--r-- | numpy/random/tests/test_random.py | 22 | ||||
-rw-r--r-- | numpy/random/tests/test_regression.py | 29 |
2 files changed, 42 insertions, 9 deletions
diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py index 08039cbbe..a06de58e3 100644 --- a/numpy/random/tests/test_random.py +++ b/numpy/random/tests/test_random.py @@ -260,11 +260,13 @@ class TestRandomDist(TestCase): def test_random_integers(self): np.random.seed(self.seed) - actual = np.random.random_integers(-99, 99, size=(3, 2)) - desired = np.array([[31, 3], - [-52, 41], - [-48, -66]]) - assert_array_equal(actual, desired) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + actual = np.random.random_integers(-99, 99, size=(3, 2)) + desired = np.array([[31, 3], + [-52, 41], + [-48, -66]]) + assert_array_equal(actual, desired) def test_random_integers_max_int(self): # Tests whether random_integers can generate the @@ -272,10 +274,12 @@ class TestRandomDist(TestCase): # into a C long. Previous implementations of this # method have thrown an OverflowError when attempting # to generate this integer. - actual = np.random.random_integers(np.iinfo('l').max, - np.iinfo('l').max) - desired = np.iinfo('l').max - assert_equal(actual, desired) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + actual = np.random.random_integers(np.iinfo('l').max, + np.iinfo('l').max) + desired = np.iinfo('l').max + assert_equal(actual, desired) def test_random_integers_deprecated(self): with warnings.catch_warnings(): diff --git a/numpy/random/tests/test_regression.py b/numpy/random/tests/test_regression.py index 133a1aa5a..b50b6b260 100644 --- a/numpy/random/tests/test_regression.py +++ b/numpy/random/tests/test_regression.py @@ -113,5 +113,34 @@ class TestRegression(TestCase): assert_(c in a) assert_raises(ValueError, np.random.choice, a, p=probs*0.9) + def test_shuffle_of_array_of_different_length_strings(self): + # Test that permuting an array of different length strings + # will not cause a segfault on garbage collection + # Tests gh-7710 + np.random.seed(1234) + + a = np.array(['a', 'a' * 1000]) + + for _ in range(100): + np.random.shuffle(a) + + # Force Garbage Collection - should not segfault. + import gc + gc.collect() + + def test_shuffle_of_array_of_objects(self): + # Test that permuting an array of objects will not cause + # a segfault on garbage collection. + # See gh-7719 + np.random.seed(1234) + a = np.array([np.arange(1), np.arange(4)]) + + for _ in range(1000): + np.random.shuffle(a) + + # Force Garbage Collection - should not segfault. + import gc + gc.collect() + if __name__ == "__main__": run_module_suite() |