Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-42222: Improve tests for invalid argument types in randrange() #29021

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions Lib/test/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,10 @@ def test_randrange_errors(self):

# 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))
Expand All @@ -501,34 +503,23 @@ def test_randrange_errors(self):
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))
raises_type_error(0, 42, '3')
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
Expand Down