summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_random.py
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2022-05-12 04:54:51 (GMT)
committerGitHub <noreply@github.com>2022-05-12 04:54:51 (GMT)
commit68fec31364e96d122aae0571c14683b4ddb0ebd0 (patch)
treee7dc4bbfb5dc85b0a08c2c6c8cd9143d70e0fb3f /Lib/test/test_random.py
parentf67d71b431af064409c1f41f6d73becee01882ae (diff)
downloadcpython-68fec31364e96d122aae0571c14683b4ddb0ebd0.zip
cpython-68fec31364e96d122aae0571c14683b4ddb0ebd0.tar.gz
cpython-68fec31364e96d122aae0571c14683b4ddb0ebd0.tar.bz2
gh-86388 Remove deprecated behaviors in randrange() (#92677)
Diffstat (limited to 'Lib/test/test_random.py')
-rw-r--r--Lib/test/test_random.py80
1 files changed, 37 insertions, 43 deletions
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
index 32e7868..fcf17a9 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -485,50 +485,44 @@ class SystemRandom_TestBasicOps(TestBasicOps, unittest.TestCase):
self.assertEqual(rint, 0)
def test_randrange_errors(self):
- raises = partial(self.assertRaises, ValueError, self.gen.randrange)
+ raises_value_error = partial(self.assertRaises, ValueError, self.gen.randrange)
+ raises_type_error = partial(self.assertRaises, TypeError, self.gen.randrange)
+
# Empty range
- raises(3, 3)
- raises(-721)
- raises(0, 100, -12)
- # Non-integer start/stop
- self.assertWarns(DeprecationWarning, raises, 3.14159)
- self.assertWarns(DeprecationWarning, self.gen.randrange, 3.0)
- self.assertWarns(DeprecationWarning, self.gen.randrange, Fraction(3, 1))
- self.assertWarns(DeprecationWarning, raises, '3')
- self.assertWarns(DeprecationWarning, raises, 0, 2.71828)
- self.assertWarns(DeprecationWarning, self.gen.randrange, 0, 2.0)
- self.assertWarns(DeprecationWarning, self.gen.randrange, 0, Fraction(2, 1))
- self.assertWarns(DeprecationWarning, raises, 0, '2')
- # Zero and non-integer step
- raises(0, 42, 0)
- self.assertWarns(DeprecationWarning, raises, 0, 42, 0.0)
- self.assertWarns(DeprecationWarning, raises, 0, 0, 0.0)
- self.assertWarns(DeprecationWarning, raises, 0, 42, 3.14159)
- self.assertWarns(DeprecationWarning, self.gen.randrange, 0, 42, 3.0)
- self.assertWarns(DeprecationWarning, self.gen.randrange, 0, 42, Fraction(3, 1))
- self.assertWarns(DeprecationWarning, raises, 0, 42, '3')
- self.assertWarns(DeprecationWarning, self.gen.randrange, 0, 42, 1.0)
- self.assertWarns(DeprecationWarning, raises, 0, 0, 1.0)
-
- 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)
+ raises_value_error(3, 3)
+ raises_value_error(-721)
+ raises_value_error(0, 100, -12)
+
+ # Zero step
+ raises_value_error(0, 42, 0)
+ raises_type_error(0, 42, 0.0)
+ raises_type_error(0, 0, 0.0)
+
+ # Non-integer stop
+ raises_type_error(3.14159)
+ raises_type_error(3.0)
+ raises_type_error(Fraction(3, 1))
+ raises_type_error('3')
+ raises_type_error(0, 2.71827)
+ 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, 3.14159)
+ raises_type_error(0, 42, 3.0)
+ raises_type_error(0, 42, Fraction(3, 1))
+ raises_type_error(0, 42, '3')
+ raises_type_error(0, 42, 1.0)
+ raises_type_error(0, 0, 1.0)
def test_randrange_step(self):
# bpo-42772: When stop is None, the step argument was being ignored.