Commit 8cc603ce authored by Taddeus Kroes's avatar Taddeus Kroes

Prettified division by zero exception.

parent 0e7541cf
...@@ -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:
......
...@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment