Commit 272efcf6 authored by Stefan Behnel's avatar Stefan Behnel

Fix exception messages for float division by zero, as well as their tests...

Fix exception messages for float division by zero, as well as their tests (which were wrong in Py2.6).
parent c292d6cb
...@@ -1086,7 +1086,7 @@ c_op = { ...@@ -1086,7 +1086,7 @@ c_op = {
{{if order == 'CObj' and c_op in '%/'}} {{if order == 'CObj' and c_op in '%/'}}
#define {{zerodiv_check('operand')}} if (unlikely(zerodivision_check && ((operand) == 0))) { \ #define {{zerodiv_check('operand')}} if (unlikely(zerodivision_check && ((operand) == 0))) { \
PyErr_SetString(PyExc_ZeroDivisionError, "integer division{{if op == 'Remainder'}} or modulo{{endif}} by zero"); \ PyErr_SetString(PyExc_ZeroDivisionError, "float division{{if op == 'Remainder'}} or modulo{{endif}} by zero"); \
return NULL; \ return NULL; \
} }
{{endif}} {{endif}}
......
...@@ -30,31 +30,31 @@ def div_by_0(x): ...@@ -30,31 +30,31 @@ def div_by_0(x):
""" """
>>> div_by_0(0) # doctest: +ELLIPSIS >>> div_by_0(0) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
>>> div_by_0(0.0) # doctest: +ELLIPSIS >>> div_by_0(0.0) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
>>> div_by_0(1) # doctest: +ELLIPSIS >>> div_by_0(1) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
>>> div_by_0(1.0) # doctest: +ELLIPSIS >>> div_by_0(1.0) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
>>> float('inf') / 0.0 # doctest: +ELLIPSIS >>> float('inf') / 0.0 # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
>>> div_by_0(float('inf')) # doctest: +ELLIPSIS >>> div_by_0(float('inf')) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
>>> div_by_0(float('-inf')) # doctest: +ELLIPSIS >>> div_by_0(float('-inf')) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
>>> float('nan') / 0.0 # doctest: +ELLIPSIS >>> float('nan') / 0.0 # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
>>> div_by_0(float('nan')) # doctest: +ELLIPSIS >>> div_by_0(float('nan')) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
""" """
return x / 0.0 return x / 0.0
...@@ -77,10 +77,10 @@ def div_1_by(x): ...@@ -77,10 +77,10 @@ def div_1_by(x):
nan nan
>>> div_1_by(0) # doctest: +ELLIPSIS >>> div_1_by(0) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
>>> div_1_by(0.0) # doctest: +ELLIPSIS >>> div_1_by(0.0) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
""" """
return 1.0 / x return 1.0 / x
...@@ -157,10 +157,10 @@ def div_neg_2_by(x): ...@@ -157,10 +157,10 @@ def div_neg_2_by(x):
nan nan
>>> div_neg_2_by(0) # doctest: +ELLIPSIS >>> div_neg_2_by(0) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
>>> div_neg_2_by(0.0) # doctest: +ELLIPSIS >>> div_neg_2_by(0.0) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
""" """
return (-2.0) / x return (-2.0) / x
...@@ -195,10 +195,10 @@ def div_nan_by(x): ...@@ -195,10 +195,10 @@ def div_nan_by(x):
nan nan
>>> div_nan_by(0) # doctest: +ELLIPSIS >>> div_nan_by(0) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
>>> div_nan_by(0.0) # doctest: +ELLIPSIS >>> div_nan_by(0.0) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
""" """
return float("nan") / x return float("nan") / x
...@@ -235,13 +235,13 @@ def div_inf_by(x): ...@@ -235,13 +235,13 @@ def div_inf_by(x):
nan nan
>>> float("inf") / 0.0 # doctest: +ELLIPSIS >>> float("inf") / 0.0 # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
>>> div_inf_by(0) # doctest: +ELLIPSIS >>> div_inf_by(0) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
>>> div_inf_by(0.0) # doctest: +ELLIPSIS >>> div_inf_by(0.0) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
""" """
return float("inf") / x return float("inf") / x
...@@ -258,12 +258,12 @@ def div_neg_inf_by(x): ...@@ -258,12 +258,12 @@ def div_neg_inf_by(x):
inf inf
>>> float("-inf") / 0.0 # doctest: +ELLIPSIS >>> float("-inf") / 0.0 # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
>>> div_neg_inf_by(0) # doctest: +ELLIPSIS >>> div_neg_inf_by(0) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
>>> div_neg_inf_by(0.0) # doctest: +ELLIPSIS >>> div_neg_inf_by(0.0) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division by zero ZeroDivisionError: float division...
""" """
return float("-inf") / x return float("-inf") / x
...@@ -9,7 +9,7 @@ def modobj(obj2, obj3): ...@@ -9,7 +9,7 @@ def modobj(obj2, obj3):
'5' '5'
>>> modobj(1, 0) # doctest: +ELLIPSIS >>> modobj(1, 0) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division...by zero ZeroDivisionError: integer division...
""" """
obj1 = obj2 % obj3 obj1 = obj2 % obj3
return obj1 return obj1
...@@ -19,7 +19,7 @@ def mod_10_obj(int2): ...@@ -19,7 +19,7 @@ def mod_10_obj(int2):
""" """
>>> mod_10_obj(0) # doctest: +ELLIPSIS >>> mod_10_obj(0) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ZeroDivisionError: ...division...by zero ZeroDivisionError: integer division...
>>> mod_10_obj(3) >>> mod_10_obj(3)
1 1
""" """
......
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