summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2021-10-19 18:40:30 (GMT)
committerGitHub <noreply@github.com>2021-10-19 18:40:30 (GMT)
commit574241632bd19e56ed488ee4d8999aefc6a8d7cd (patch)
treefbb2f7bf3e455b72406950ab0231ea6853bed111
parentfdbdf3f7359832820a11ece4c4b01581004d6fe7 (diff)
downloadcpython-574241632bd19e56ed488ee4d8999aefc6a8d7cd.zip
cpython-574241632bd19e56ed488ee4d8999aefc6a8d7cd.tar.gz
cpython-574241632bd19e56ed488ee4d8999aefc6a8d7cd.tar.bz2
bpo-42222: Improve tests for invalid argument types in randrange() (GH-29021)
-rw-r--r--Lib/test/test_random.py31
1 files changed, 11 insertions, 20 deletions
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
index 3c5511d..cdae889 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -491,8 +491,10 @@ class SystemRandom_TestBasicOps(TestBasicOps, unittest.TestCase):
# Zero step
raises_value_error(0, 42, 0)
+ raises_type_error(0, 42, 0.0)
+ raises_type_error(0, 0, 0.0)
- # Non-integer start/stop/step
+ # Non-integer stop
raises_type_error(3.14159)
raises_type_error(3.0)
raises_type_error(Fraction(3, 1))
@@ -501,10 +503,16 @@ class SystemRandom_TestBasicOps(TestBasicOps, unittest.TestCase):
raises_type_error(0, 2.0)
raises_type_error(0, Fraction(2, 1))
raises_type_error(0, '2')
+ raises_type_error(0, 2.71827, 2)
+
+ # Non-integer start
+ raises_type_error(2.71827, 5)
+ raises_type_error(2.0, 5)
+ raises_type_error(Fraction(2, 1), 5)
+ raises_type_error('2', 5)
+ raises_type_error(2.71827, 5, 2)
# Non-integer step
- raises_type_error(0, 42, 1.0)
- raises_type_error(0, 0, 1.0)
raises_type_error(0, 42, 3.14159)
raises_type_error(0, 42, 3.0)
raises_type_error(0, 42, Fraction(3, 1))
@@ -512,23 +520,6 @@ class SystemRandom_TestBasicOps(TestBasicOps, unittest.TestCase):
raises_type_error(0, 42, 1.0)
raises_type_error(0, 0, 1.0)
- def test_randrange_argument_handling(self):
- randrange = self.gen.randrange
- with self.assertRaises(TypeError):
- randrange(10.0, 20, 2)
- with self.assertRaises(TypeError):
- randrange(10, 20.0, 2)
- with self.assertRaises(TypeError):
- randrange(10, 20, 1.0)
- with self.assertRaises(TypeError):
- randrange(10, 20, 2.0)
- with self.assertRaises(TypeError):
- randrange(10.5)
- with self.assertRaises(TypeError):
- randrange(10, 20.5)
- with self.assertRaises(TypeError):
- randrange(10, 20, 1.5)
-
def test_randrange_step(self):
# bpo-42772: When stop is None, the step argument was being ignored.
randrange = self.gen.randrange