Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
trs
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
trs
Commits
8cc603ce
Commit
8cc603ce
authored
Jan 14, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prettified division by zero exception.
parent
0e7541cf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
3 deletions
+4
-3
src/rules/fractions.py
src/rules/fractions.py
+1
-2
tests/test_rules_fractions.py
tests/test_rules_fractions.py
+3
-1
No files found.
src/rules/fractions.py
View file @
8cc603ce
...
@@ -19,9 +19,8 @@ def match_constant_division(node):
...
@@ -19,9 +19,8 @@ def match_constant_division(node):
nominator
,
denominator
=
node
nominator
,
denominator
=
node
# a / 0
# a / 0
# TODO: move to parser
if
denominator
==
0
:
if
denominator
==
0
:
raise
ZeroDivisionError
()
raise
ZeroDivisionError
(
'Division by zero: %s.'
%
node
)
# a / 1
# a / 1
if
denominator
==
1
:
if
denominator
==
1
:
...
...
tests/test_rules_fractions.py
View file @
8cc603ce
...
@@ -12,7 +12,9 @@ class TestRulesFractions(RulesTestCase):
...
@@ -12,7 +12,9 @@ class TestRulesFractions(RulesTestCase):
a
,
zero
=
tree
(
'a,0'
)
a
,
zero
=
tree
(
'a,0'
)
root
=
a
/
zero
root
=
a
/
zero
self
.
assertRaises
(
ZeroDivisionError
,
match_constant_division
,
root
)
with
self
.
assertRaises
(
ZeroDivisionError
)
as
cm
:
match_constant_division
(
root
)
self
.
assertEqual
(
cm
.
exception
.
message
,
'Division by zero: a / 0.'
)
root
=
a
/
1
root
=
a
/
1
possibilities
=
match_constant_division
(
root
)
possibilities
=
match_constant_division
(
root
)
...
...
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