cython

Форк
0
/
unicode_identifiers_normalization.srctree 
80 строк · 2.1 Кб
1
# -*- coding: utf-8 -*-
2
# mode: run
3
# tag: pure3.0, pep3131
4

5
PYTHON build_tests.py
6
# show behaviour in Python mode
7
PYTHON -m doctest test0.py
8
PYTHON -m doctest test1.py
9
PYTHON -m doctest test2.py
10

11
PYTHON setup.py build_ext --inplace
12
# test in Cython mode
13
PYTHON -c "import doctest; import test0 as m; exit(doctest.testmod(m)[0])"
14
PYTHON -c "import doctest; import test1 as m; exit(doctest.testmod(m)[0])"
15
PYTHON -c "import doctest; import test2 as m; exit(doctest.testmod(m)[0])"
16

17
########## setup.py #########
18

19
from Cython.Build.Dependencies import cythonize
20
from distutils.core import setup
21

22
setup(
23
  ext_modules = cythonize("test*.py"),
24
)
25

26
######### build_tests.py ########
27
# -*- coding: utf-8 -*-
28
from __future__ import unicode_literals
29
import unicodedata
30

31
# a few pairs of unicode strings that should be equivalent after normalization
32
string_pairs = [("fi", "fi"), # ligature and two letters
33
                ("a\u0301", '\u00e1'), # a with acute accent with combining character or as 1 character
34
                ("α\u0334\u0362", "α\u0362\u0334") # alpha with a pair of combining characters
35
                    # in a different order. No single character to normalize to
36
                ]
37

38
# Show that the pairs genuinely aren't equal before normalization
39
for sp in string_pairs:
40
    assert sp[0] != sp[1]
41
    assert unicodedata.normalize('NFKC', sp[0]) == unicodedata.normalize('NFKC', sp[1])
42
    
43
# some code that accesses the identifiers through the two different names
44
#  contains doctests
45
example_code = [
46
"""
47
class C:
48
    '''
49
    >>> C().get()
50
    True
51
    '''
52
    def __init__(self):
53
        self.{0} = True
54
    def get(self):
55
        return self.{1}
56
""", """
57
def pass_through({0}):
58
    '''
59
    >>> pass_through(True)
60
    True
61
    '''
62
    return {1}
63
""", """
64
import cython
65
{0} = True
66
def test():
67
    '''
68
    >>> test()
69
    True
70
    '''
71
    return {1}
72
"""]
73

74
from io import open
75

76
for idx, (code, strings) in enumerate(zip(example_code, string_pairs)):
77
    with open("test{0}.py".format(idx), "w", encoding="utf8") as f:
78
        code = code.format(*strings)
79
        f.write("# -*- coding: utf-8 -*-\n")
80
        f.write(code)
81

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.