Skip to content

bpo-30308: Code coverage for argument in random.shuffle #1504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Lib/test/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from test import support
from fractions import Fraction


class TestBasicOps:
# Superclass with tests common to all generators.
# Subclasses must arrange for self.gen to retrieve the Random instance
Expand Down Expand Up @@ -50,7 +51,7 @@ def __hash__(self):
@unittest.mock.patch('random._urandom') # os.urandom
def test_seed_when_randomness_source_not_found(self, urandom_mock):
# Random.seed() uses time.time() when an operating system specific
# randomness source is not found. To test this on machines were it
# randomness source is not found. To test this on machines where it
# exists, run the above test, test_seedargs(), again after mocking
# os.urandom() so that it raises the exception expected when the
# randomness source is not available.
Expand Down Expand Up @@ -88,6 +89,15 @@ def test_shuffle(self):
self.assertTrue(lst != shuffled_lst)
shuffle(lst)
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')
shuffle(seq, mock_random)
mock_random.assert_called_with()

def test_choice(self):
choice = self.gen.choice
Expand Down