Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improve the test to check close to the limit.
  • Loading branch information
gpshead committed Sep 4, 2022
commit 87bd23d3df3aca81b88a5f245e70fded7055ab92
20 changes: 12 additions & 8 deletions Lib/test/test_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,13 @@ def test_denial_of_service_prevented_int_to_str(self):
self.assertGreater(seconds_to_convert, 0.02,
msg="'We're gonna need a bigger boat (int).'")

with self.assertRaises(ValueError) as err:
start = process_time()
str(huge_int)
seconds_to_fail_huge = process_time() - start
# We test with the limit almost at the size needed to check performance.
# The performant limit check is slightly fuzzy, give it a some room.
with support.adjust_int_max_str_digits(int(.995 * 120_412)):
with self.assertRaises(ValueError) as err:
start = process_time()
str(huge_int)
seconds_to_fail_huge = process_time() - start
self.assertIn('conversion', str(err.exception))
self.assertLess(seconds_to_fail_huge, seconds_to_convert/8)

Expand Down Expand Up @@ -686,10 +689,11 @@ def test_denial_of_service_prevented_str_to_int(self):
self.assertGreater(seconds_to_convert, 0.02,
msg="'We're gonna need a bigger boat (str).'")

with self.assertRaises(ValueError) as err:
start = process_time()
int(huge)
seconds_to_fail_huge = process_time() - start
with support.adjust_int_max_str_digits(200_000 - 1):
with self.assertRaises(ValueError) as err:
start = process_time()
int(huge)
seconds_to_fail_huge = process_time() - start
self.assertIn('conversion', str(err.exception))
self.assertLess(seconds_to_fail_huge, seconds_to_convert/8)

Expand Down