bpo-40465: Remove random module features deprecated in 3.9 (GH-25874)

This commit is contained in:
Raymond Hettinger 2021-05-04 01:55:40 -07:00 committed by GitHub
parent 87109f4d85
commit 70a071d9e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 64 deletions

View file

@ -48,12 +48,11 @@ class TestBasicOps:
self.gen.seed(arg)
for arg in [1+2j, tuple('abc'), MySeed()]:
with self.assertWarns(DeprecationWarning):
with self.assertRaises(TypeError):
self.gen.seed(arg)
for arg in [list(range(3)), dict(one=1)]:
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, self.gen.seed, arg)
self.assertRaises(TypeError, self.gen.seed, arg)
self.assertRaises(TypeError, self.gen.seed, 1, 2, 3, 4)
self.assertRaises(TypeError, type(self.gen), [])
@ -105,15 +104,6 @@ class TestBasicOps:
self.assertTrue(lst != shuffled_lst)
self.assertRaises(TypeError, shuffle, (1, 2, 3))
def test_shuffle_random_argument(self):
# Test random argument to shuffle.
shuffle = self.gen.shuffle
mock_random = unittest.mock.Mock(return_value=0.5)
seq = bytearray(b'abcdefghijk')
with self.assertWarns(DeprecationWarning):
shuffle(seq, mock_random)
mock_random.assert_called_with()
def test_choice(self):
choice = self.gen.choice
with self.assertRaises(IndexError):
@ -164,7 +154,7 @@ class TestBasicOps:
self.assertRaises(TypeError, self.gen.sample, dict.fromkeys('abcdef'), 2)
def test_sample_on_sets(self):
with self.assertWarns(DeprecationWarning):
with self.assertRaises(TypeError):
population = {10, 20, 30, 40, 50, 60, 70}
self.gen.sample(population, k=5)