mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
bpo-33203: Ensure random.choice always raises IndexError on empty sequence (GH-6338)
This commit is contained in:
parent
74940913d2
commit
091e95e900
3 changed files with 9 additions and 1 deletions
|
@ -651,7 +651,10 @@ class MersenneTwister_TestBasicOps(TestBasicOps, unittest.TestCase):
|
|||
# Population range too large (n >= maxsize)
|
||||
self.gen._randbelow(maxsize+1, maxsize = maxsize)
|
||||
self.gen._randbelow(5640, maxsize = maxsize)
|
||||
|
||||
# issue 33203: test that _randbelow raises ValueError on
|
||||
# n == 0 also in its getrandbits-independent branch.
|
||||
with self.assertRaises(ValueError):
|
||||
self.gen._randbelow(0, maxsize=maxsize)
|
||||
# This might be going too far to test a single line, but because of our
|
||||
# noble aim of achieving 100% test coverage we need to write a case in
|
||||
# which the following line in Random._randbelow() gets executed:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue