summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_random.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-04-05 16:02:12 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2018-04-05 16:02:12 (GMT)
commitbaf304e82e1b54dbeee6b78ddf168e33ed8d557a (patch)
tree502f940b1263b11be58f59249c7f6d3ac1b7072e /Lib/test/test_random.py
parent83f564fd242c1af9dbe6d4273ad50586489000e3 (diff)
downloadcpython-baf304e82e1b54dbeee6b78ddf168e33ed8d557a.zip
cpython-baf304e82e1b54dbeee6b78ddf168e33ed8d557a.tar.gz
cpython-baf304e82e1b54dbeee6b78ddf168e33ed8d557a.tar.bz2
bpo-33203: Ensure random.choice always raises IndexError on empty sequence (GH-6338) (GH-6387)
(cherry picked from commit 091e95e9004b794280ab35becec2c3e30dd5e96e) Co-authored-by: Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
Diffstat (limited to 'Lib/test/test_random.py')
-rw-r--r--Lib/test/test_random.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
index 468c4a4..eee245d 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -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: