Skip to content

Commit f111fd2

Browse files
csabellarhettinger
authored andcommitted
bpo-30308: Code coverage for argument in random.shuffle (#1504)
* bpo-30308: Code coverage for argument in random.shuffle * bpo-30308: Code coverage for argument in random.shuffle * bpo-30308: Code coverage for argument in random.shuffle
1 parent 991adca commit f111fd2

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Lib/test/test_random.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from test import support
1010
from fractions import Fraction
1111

12+
1213
class TestBasicOps:
1314
# Superclass with tests common to all generators.
1415
# Subclasses must arrange for self.gen to retrieve the Random instance
@@ -50,7 +51,7 @@ def __hash__(self):
5051
@unittest.mock.patch('random._urandom') # os.urandom
5152
def test_seed_when_randomness_source_not_found(self, urandom_mock):
5253
# Random.seed() uses time.time() when an operating system specific
53-
# randomness source is not found. To test this on machines were it
54+
# randomness source is not found. To test this on machines where it
5455
# exists, run the above test, test_seedargs(), again after mocking
5556
# os.urandom() so that it raises the exception expected when the
5657
# randomness source is not available.
@@ -88,6 +89,15 @@ def test_shuffle(self):
8889
self.assertTrue(lst != shuffled_lst)
8990
shuffle(lst)
9091
self.assertTrue(lst != shuffled_lst)
92+
self.assertRaises(TypeError, shuffle, (1, 2, 3))
93+
94+
def test_shuffle_random_argument(self):
95+
# Test random argument to shuffle.
96+
shuffle = self.gen.shuffle
97+
mock_random = unittest.mock.Mock(return_value=0.5)
98+
seq = bytearray(b'abcdefghijk')
99+
shuffle(seq, mock_random)
100+
mock_random.assert_called_with()
91101

92102
def test_choice(self):
93103
choice = self.gen.choice

0 commit comments

Comments
 (0)