summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-01-13 18:21:34 (GMT)
committerGitHub <noreply@github.com>2024-01-13 18:21:34 (GMT)
commite08179216bb0481d7a58800bc8bac63cc97952a8 (patch)
treea536d6fe42085a31ad170cc1ce4a6dbd4f87a686 /Lib/test
parent94b1d1fa38ada8cf7d196184a04a195c152eed75 (diff)
downloadcpython-e08179216bb0481d7a58800bc8bac63cc97952a8.zip
cpython-e08179216bb0481d7a58800bc8bac63cc97952a8.tar.gz
cpython-e08179216bb0481d7a58800bc8bac63cc97952a8.tar.bz2
[3.12] gh-114014: Update `fractions.Fraction()`'s rational parsing regex (GH-114015) (#114023)
Fix a bug in the regex used for parsing a string input to the `fractions.Fraction` constructor. That bug led to an inconsistent exception message being given for some inputs. --------- (cherry picked from commit dd56b5748317c3d504d6a9660d9207620c547f5c) Co-authored-by: Crowthebird <78076854+thatbirdguythatuknownot@users.noreply.github.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Mark Dickinson <dickinsm@gmail.com> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_fractions.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_fractions.py b/Lib/test/test_fractions.py
index 4f4ea7c..1e97d5c 100644
--- a/Lib/test/test_fractions.py
+++ b/Lib/test/test_fractions.py
@@ -261,6 +261,30 @@ class FractionTest(unittest.TestCase):
self.assertRaisesMessage(
ValueError, "Invalid literal for Fraction: '1.1e+1__1'",
F, "1.1e+1__1")
+ self.assertRaisesMessage(
+ ValueError, "Invalid literal for Fraction: '123.dd'",
+ F, "123.dd")
+ self.assertRaisesMessage(
+ ValueError, "Invalid literal for Fraction: '123.5_dd'",
+ F, "123.5_dd")
+ self.assertRaisesMessage(
+ ValueError, "Invalid literal for Fraction: 'dd.5'",
+ F, "dd.5")
+ self.assertRaisesMessage(
+ ValueError, "Invalid literal for Fraction: '7_dd'",
+ F, "7_dd")
+ self.assertRaisesMessage(
+ ValueError, "Invalid literal for Fraction: '1/dd'",
+ F, "1/dd")
+ self.assertRaisesMessage(
+ ValueError, "Invalid literal for Fraction: '1/123_dd'",
+ F, "1/123_dd")
+ self.assertRaisesMessage(
+ ValueError, "Invalid literal for Fraction: '789edd'",
+ F, "789edd")
+ self.assertRaisesMessage(
+ ValueError, "Invalid literal for Fraction: '789e2_dd'",
+ F, "789e2_dd")
# Test catastrophic backtracking.
val = "9"*50 + "_"
self.assertRaisesMessage(