summaryrefslogtreecommitdiff
path: root/tests/run/unicode_imports.srctree
blob: 262f4949aac3b54193a93130946abc83d04d4247 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# -*- coding: utf-8 -*-
# tag: py3, pep489

PYTHON setup.py build_ext --inplace
PYTHON -m mydoctest

########### mydoctest.py #######

import sys
if sys.version_info < (3, 5):
    # The module is only Cythonized and not build for these versions
    # so don't run the tests
    exit()
    
import doctest
import from_py
val = doctest.testmod(from_py)[0]
import from_cy
val += doctest.testmod(from_cy)[0]

exit(val)

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

# -*- coding: utf-8 -*-

from __future__ import unicode_literals

import sys
from Cython.Build import cythonize

files = ["mymoð.pyx", "from_cy.pyx"]


# For Python 2 and Python <= 3.4 just run pyx->c; 
# don't compile the C file
modules = cythonize(files)

if sys.version_info >= (3, 5):
    from distutils.core import setup

    setup(
        ext_modules = modules
    )

############ mymoð.pyx #########

def f():
    return True

cdef public api void cdef_func():
    pass

############ pxd_moð.pxd ##########

cdef struct S:
    int x
    
cdef public api void cdef_func() # just to test generation of headers
    
############ from_py.py #########

# -*- coding: utf-8 -*-

import mymoð
from mymoð import f

__doc__ = """
>>> mymoð.f()
True
>>> f()
True
"""

######### from_cy.pyx ##########

# -*- coding: utf-8 -*-

import mymoð

from mymoð import f

cimport pxd_moð
from pxd_moð cimport S


def test_imported():
    """
    >>> test_imported()
    True
    """
    return mymoð.f() and f() # True and True


def test_cimported():
    """
    >>> test_cimported()
    3
    """
    cdef pxd_moð.S v1
    v1.x = 1
    cdef S v2
    v2.x = 2
    return v1.x + v2.x