PYTHON setup.py build_ext --inplace
PYTHON -c "import a; a.test(a)"

######## setup.py ########

from Cython.Build.Dependencies import cythonize

from distutils.core import setup

setup(
    ext_modules=cythonize("a.py"),
)


######## a.py ########

class ExtTypePass(object):
    pass


class ExtTypePxdDocstring(object):
    pass


class ExtTypeDocstring(object):
    """huhu!"""  # this should override the .pxd docstring


class ExtTypeAttributes(object):
    """
    >>> x = ExtTypeAttributes()
    >>> x.b
    [1, 2, 3]
    """
    def __init__(self):
        self.a = 123
        self.b = [1, 2, 3]


class TypedMethod():
    """
    >>> t = TypedMethod()
    >>> t.meth()
    97
    """
    def meth(self):
        x = bytearray(b'abcdefg')
        return x[0]


def func(a, b, c):
    """
    >>> func(1, 2, 3)
    6
    """
    return a + b + c


def test(module):
    import os.path
    assert not os.path.basename(__file__).endswith('.py'), __file__
    assert not os.path.basename(__file__).endswith('.pyc'), __file__
    assert not os.path.basename(__file__).endswith('.pyo'), __file__

    assert not ExtTypePass().__doc__, ExtTypePass().__doc__
    assert ExtTypeDocstring().__doc__ == "huhu!", ExtTypeDocstring().__doc__
    assert ExtTypePxdDocstring().__doc__ == "ho, ho, ho!", ExtTypePxdDocstring().__doc__
    assert '>>> ' in func.__doc__

    import doctest
    result = doctest.testmod(module, verbose=True)
    assert not result.failed, result.failed


######## a.pxd ########

cimport cython

cdef class ExtTypePass:
    pass


cdef class ExtTypePxdDocstring:
    """ho, ho, ho!"""


cdef class ExtTypeAttributes:
    cdef int a
    cdef readonly list b


cdef class TypedMethod:
    @cython.locals(x='char[:]')
    cpdef meth(self)


cpdef int func(x, int y, z) except? -1  # argument names should not matter, types should
