diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2020-12-28 19:10:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-28 19:10:34 (GMT) |
commit | a9621bb301dba44494e81edc00e3a3b62c96af26 (patch) | |
tree | b5b79c36977d682803b3b7fcbc35b156f18d4809 /Lib/test/test_random.py | |
parent | 1031f23fc3aed6760785bf0f8290bd2b2cce41c2 (diff) | |
download | cpython-a9621bb301dba44494e81edc00e3a3b62c96af26.zip cpython-a9621bb301dba44494e81edc00e3a3b62c96af26.tar.gz cpython-a9621bb301dba44494e81edc00e3a3b62c96af26.tar.bz2 |
bpo-42222: Modernize integer test/conversion in randrange() (#23064)
Diffstat (limited to 'Lib/test/test_random.py')
-rw-r--r-- | Lib/test/test_random.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index e7f911d..436f3c9 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -542,6 +542,26 @@ class SystemRandom_TestBasicOps(TestBasicOps, unittest.TestCase): raises(0, 42, 0) raises(0, 42, 3.14159) + def test_randrange_argument_handling(self): + randrange = self.gen.randrange + with self.assertWarns(DeprecationWarning): + randrange(10.0, 20, 2) + with self.assertWarns(DeprecationWarning): + randrange(10, 20.0, 2) + with self.assertWarns(DeprecationWarning): + randrange(10, 20, 1.0) + with self.assertWarns(DeprecationWarning): + randrange(10, 20, 2.0) + with self.assertWarns(DeprecationWarning): + with self.assertRaises(ValueError): + randrange(10.5) + with self.assertWarns(DeprecationWarning): + with self.assertRaises(ValueError): + randrange(10, 20.5) + with self.assertWarns(DeprecationWarning): + with self.assertRaises(ValueError): + randrange(10, 20, 1.5) + def test_randbelow_logic(self, _log=log, int=int): # check bitcount transition points: 2**i and 2**(i+1)-1 # show that: k = int(1.001 + _log(n, 2)) |