Commit 121f7ab4 authored by Stefan Behnel's avatar Stefan Behnel

Extend test to assure that normal conversion to C integers does not allow...

Extend test to assure that normal conversion to C integers does not allow strings, but only (optimised) casting does.
parent 3078d82e
...@@ -10,6 +10,9 @@ def double_to_short_int(double x): ...@@ -10,6 +10,9 @@ def double_to_short_int(double x):
4 4
>>> double_to_short_int(4) >>> double_to_short_int(4)
4 4
>>> double_to_short_int('4') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
""" """
cdef short r = int(x) cdef short r = int(x)
return r return r
...@@ -22,6 +25,9 @@ def double_to_pyssizet_int(double x): ...@@ -22,6 +25,9 @@ def double_to_pyssizet_int(double x):
4 4
>>> double_to_pyssizet_int(4) >>> double_to_pyssizet_int(4)
4 4
>>> double_to_pyssizet_int('4') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
""" """
cdef Py_ssize_t r = int(x) cdef Py_ssize_t r = int(x)
return r return r
...@@ -34,6 +40,9 @@ def int_to_pyssizet_int(int x): ...@@ -34,6 +40,9 @@ def int_to_pyssizet_int(int x):
4 4
>>> int_to_pyssizet_int(4) >>> int_to_pyssizet_int(4)
4 4
>>> int_to_pyssizet_int('4') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
""" """
cdef Py_ssize_t r = int(x) cdef Py_ssize_t r = int(x)
return r return r
...@@ -56,6 +65,9 @@ def int_to_short_int(int x): ...@@ -56,6 +65,9 @@ def int_to_short_int(int x):
""" """
>>> int_to_short_int(4) >>> int_to_short_int(4)
4 4
>>> int_to_short_int('4') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...integer...
""" """
cdef short r = int(x) cdef short r = int(x)
return r return r
...@@ -66,6 +78,9 @@ def short_to_float_float(short x): ...@@ -66,6 +78,9 @@ def short_to_float_float(short x):
""" """
>>> short_to_float_float(4) >>> short_to_float_float(4)
4.0 4.0
>>> short_to_float_float('4') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...integer...
""" """
cdef float r = float(x) cdef float r = float(x)
return r return r
...@@ -76,6 +91,9 @@ def short_to_double_float(short x): ...@@ -76,6 +91,9 @@ def short_to_double_float(short x):
""" """
>>> short_to_double_float(4) >>> short_to_double_float(4)
4.0 4.0
>>> short_to_double_float('4') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...integer...
""" """
cdef double r = float(x) cdef double r = float(x)
return r return r
...@@ -86,6 +104,9 @@ def short_to_double_int(short x): ...@@ -86,6 +104,9 @@ def short_to_double_int(short x):
""" """
>>> short_to_double_int(4) >>> short_to_double_int(4)
4.0 4.0
>>> short_to_double_int('4') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...integer...
""" """
cdef double r = int(x) cdef double r = int(x)
return r return r
...@@ -97,6 +118,9 @@ def float_to_float_float(float x): ...@@ -97,6 +118,9 @@ def float_to_float_float(float x):
True True
>>> float_to_float_float(4) >>> float_to_float_float(4)
4.0 4.0
>>> float_to_float_float('4') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
""" """
cdef float r = float(x) cdef float r = float(x)
return r return r
...@@ -109,6 +133,9 @@ def double_to_double_float(double x): ...@@ -109,6 +133,9 @@ def double_to_double_float(double x):
True True
>>> double_to_double_float(4) >>> double_to_double_float(4)
4.0 4.0
>>> double_to_double_float('4') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
""" """
cdef double r = float(x) cdef double r = float(x)
return r return r
...@@ -123,6 +150,9 @@ def double_to_py_int(double x): ...@@ -123,6 +150,9 @@ def double_to_py_int(double x):
4 4
>>> double_to_py_int(4) >>> double_to_py_int(4)
4 4
>>> double_to_py_int('4') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
""" """
return int(x) return int(x)
...@@ -134,6 +164,9 @@ def double_to_double_int(double x): ...@@ -134,6 +164,9 @@ def double_to_double_int(double x):
4.0 4.0
>>> double_to_double_int(4) >>> double_to_double_int(4)
4.0 4.0
>>> double_to_double_int('4') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
""" """
cdef double r = int(x) cdef double r = int(x)
return r return r
...@@ -150,6 +183,9 @@ def float_to_float_int(float x): ...@@ -150,6 +183,9 @@ def float_to_float_int(float x):
4.0 4.0
>>> float_to_float_int(4) >>> float_to_float_int(4)
4.0 4.0
>>> float_to_float_int('4') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
""" """
cdef float r = int(x) cdef float r = int(x)
return r return r
...@@ -166,6 +202,9 @@ def float_to_double_int(float x): ...@@ -166,6 +202,9 @@ def float_to_double_int(float x):
4.0 4.0
>>> float_to_double_int(4) >>> float_to_double_int(4)
4.0 4.0
>>> float_to_double_int('4') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
""" """
cdef double r = int(x) cdef double r = int(x)
return r return r
...@@ -182,6 +221,9 @@ def double_to_float_int(double x): ...@@ -182,6 +221,9 @@ def double_to_float_int(double x):
4.0 4.0
>>> double_to_float_int(4) >>> double_to_float_int(4)
4.0 4.0
>>> double_to_float_int('4') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
""" """
cdef float r = int(x) cdef float r = int(x)
return r return r
......
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