Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f484363b
Commit
f484363b
authored
Jun 21, 2008
by
Andrew M. Kuchling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use repr() for bad input strings; this makes the empty string or binary characters more visible
parent
d8972644
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
10 deletions
+10
-10
Lib/fractions.py
Lib/fractions.py
+1
-1
Lib/test/test_fractions.py
Lib/test/test_fractions.py
+9
-9
No files found.
Lib/fractions.py
View file @
f484363b
...
...
@@ -70,7 +70,7 @@ class Fraction(Rational):
input
=
numerator
m
=
_RATIONAL_FORMAT
.
match
(
input
)
if
m
is
None
:
raise
ValueError
(
'Invalid literal for Fraction:
'
+
input
)
raise
ValueError
(
'Invalid literal for Fraction:
%r'
%
input
)
numerator
=
m
.
group
(
'num'
)
decimal
=
m
.
group
(
'decimal'
)
if
decimal
:
...
...
Lib/test/test_fractions.py
View file @
f484363b
...
...
@@ -86,38 +86,38 @@ class FractionTest(unittest.TestCase):
ZeroDivisionError
,
"Fraction(3, 0)"
,
F
,
"3/0"
)
self
.
assertRaisesMessage
(
ValueError
,
"Invalid literal for Fraction:
3/
"
,
ValueError
,
"Invalid literal for Fraction:
'3/'
"
,
F
,
"3/"
)
self
.
assertRaisesMessage
(
ValueError
,
"Invalid literal for Fraction:
3 /2
"
,
ValueError
,
"Invalid literal for Fraction:
'3 /2'
"
,
F
,
"3 /2"
)
self
.
assertRaisesMessage
(
# Denominators don't need a sign.
ValueError
,
"Invalid literal for Fraction:
3/+2
"
,
ValueError
,
"Invalid literal for Fraction:
'3/+2'
"
,
F
,
"3/+2"
)
self
.
assertRaisesMessage
(
# Imitate float's parsing.
ValueError
,
"Invalid literal for Fraction:
+ 3/2
"
,
ValueError
,
"Invalid literal for Fraction:
'+ 3/2'
"
,
F
,
"+ 3/2"
)
self
.
assertRaisesMessage
(
# Avoid treating '.' as a regex special character.
ValueError
,
"Invalid literal for Fraction:
3a2
"
,
ValueError
,
"Invalid literal for Fraction:
'3a2'
"
,
F
,
"3a2"
)
self
.
assertRaisesMessage
(
# Only parse ordinary decimals, not scientific form.
ValueError
,
"Invalid literal for Fraction:
3.2e4
"
,
ValueError
,
"Invalid literal for Fraction:
'3.2e4'
"
,
F
,
"3.2e4"
)
self
.
assertRaisesMessage
(
# Don't accept combinations of decimals and fractions.
ValueError
,
"Invalid literal for Fraction:
3/7.2
"
,
ValueError
,
"Invalid literal for Fraction:
'3/7.2'
"
,
F
,
"3/7.2"
)
self
.
assertRaisesMessage
(
# Don't accept combinations of decimals and fractions.
ValueError
,
"Invalid literal for Fraction:
3.2/7
"
,
ValueError
,
"Invalid literal for Fraction:
'3.2/7'
"
,
F
,
"3.2/7"
)
self
.
assertRaisesMessage
(
# Allow 3. and .3, but not .
ValueError
,
"Invalid literal for Fraction:
.
"
,
ValueError
,
"Invalid literal for Fraction:
'.'
"
,
F
,
"."
)
def
testImmutable
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment