|
9 | 9 | from test import support
|
10 | 10 | from fractions import Fraction
|
11 | 11 |
|
| 12 | + |
12 | 13 | class TestBasicOps:
|
13 | 14 | # Superclass with tests common to all generators.
|
14 | 15 | # Subclasses must arrange for self.gen to retrieve the Random instance
|
@@ -50,7 +51,7 @@ def __hash__(self):
|
50 | 51 | @unittest.mock.patch('random._urandom') # os.urandom
|
51 | 52 | def test_seed_when_randomness_source_not_found(self, urandom_mock):
|
52 | 53 | # 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 |
54 | 55 | # exists, run the above test, test_seedargs(), again after mocking
|
55 | 56 | # os.urandom() so that it raises the exception expected when the
|
56 | 57 | # randomness source is not available.
|
@@ -88,6 +89,15 @@ def test_shuffle(self):
|
88 | 89 | self.assertTrue(lst != shuffled_lst)
|
89 | 90 | shuffle(lst)
|
90 | 91 | 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() |
91 | 101 |
|
92 | 102 | def test_choice(self):
|
93 | 103 | choice = self.gen.choice
|
|
0 commit comments