diff options
Diffstat (limited to 'tests/run/special_methods_T561.pyx')
-rw-r--r-- | tests/run/special_methods_T561.pyx | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/run/special_methods_T561.pyx b/tests/run/special_methods_T561.pyx index 5eb9dddfc..bd68291e7 100644 --- a/tests/run/special_methods_T561.pyx +++ b/tests/run/special_methods_T561.pyx @@ -956,3 +956,44 @@ cdef class ReverseMethodsExist: return "radd" def __rsub__(self, other): return "rsub" + + +cdef class ArgumentTypeConversions: + """ + The user can set the signature of special method arguments so that + it doesn't match the C signature. This just tests that a few + variations work + + >>> obj = ArgumentTypeConversions() + >>> obj[1] + 1 + >>> obj["not a number!"] + Traceback (most recent call last): + ... + TypeError: an integer is required + >>> obj < obj + In comparison 0 + True + >>> obj == obj + In comparison 2 + False + + Here I'm not sure how reproducible the flags are between Python versions. + Therefore I'm just checking that they end with ".0" + >>> memoryview(obj) # doctest:+ELLIPSIS + Traceback (most recent call last): + ... + RuntimeError: From __getbuffer__ with flags ....0 + """ + # force conversion of object to int + def __getitem__(self, int x): + return x + + # force conversion of comparison (int) to object + def __richcmp__(self, other, object comparison): + print "In comparison", comparison + return not bool(comparison) + + # force conversion of flags (int) to double + def __getbuffer__(self, Py_buffer *buffer, double flags): + raise RuntimeError("From __getbuffer__ with flags {}".format(flags)) |