Commit 85bdf910 authored by Robert Bradshaw's avatar Robert Bradshaw

Tests for #258.

parent 80135d83
cdef extern from *:
ctypedef class __builtin__.list [object PyListObject]:
pass
cdef list foo = []
# This is too invasive for Python 0.11.x, re-enable in 0.12
NEW_ERRORS = u"""
:2:4: list already a builtin Cython type
"""
_ERRORS = u"""
5:16: Cannot coerce list to type 'list'
"""
cdef extern from "Python.h":
ctypedef class __builtin__.str [object PyStringObject]:
cdef long ob_shash
ctypedef class __builtin__.list [object PyListObject]:
cdef Py_ssize_t ob_size
cdef Py_ssize_t allocated
ctypedef class __builtin__.dict [object PyDictObject]:
pass
cdef str s = "abc"
cdef list L = [1,2,4]
cdef dict d = {'A': 'a'}
def test_list(list L):
"""
>>> test_list(range(10))
True
>>> class list_subclass(list): pass
>>> test_list(list_subclass([1,2,3]))
True
"""
return L.ob_size <= L.allocated
def test_str(str s):
"""
>>> test_str("abc")
True
>>> class str_subclass(str): pass
>>> test_str(str_subclass("xyz"))
True
"""
cdef char* ss = s
return hash(s) == s.ob_shash
def test_tuple(tuple t):
"""
Actual builtin types are restrictive wrt subclassing so optimizations can be safely performed.
>>> test_tuple((1,2))
2
>>> class tuple_subclass(tuple): pass
>>> test_tuple(tuple_subclass((1,2)))
Traceback (most recent call last):
...
TypeError: Argument 't' has incorrect type (expected tuple, got tuple_subclass)
"""
return len(t)
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