mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
bpo-40465: Remove random module features deprecated in 3.9 (GH-25874)
This commit is contained in:
parent
87109f4d85
commit
70a071d9e1
4 changed files with 25 additions and 64 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue