1""" 2>>> ONE, TEN, HUNDRED 3(1, 10, 100) 4>>> THOUSAND # doctest: +ELLIPSIS 5Traceback (most recent call last): 6NameError: ...name 'THOUSAND' is not defined 7 8>>> TWO == 2 or TWO 9True 10>>> THREE == 3 or THREE 11True 12>>> FIVE == 5 or FIVE 13True 14>>> SEVEN # doctest: +ELLIPSIS 15Traceback (most recent call last): 16NameError: ...name 'SEVEN' is not defined 17 18>>> FOUR == 4 or FOUR 19True 20>>> EIGHT == 8 or EIGHT 21True 22>>> SIXTEEN # doctest: +ELLIPSIS 23Traceback (most recent call last): 24NameError: ...name 'SIXTEEN' is not defined 25 26>>> RANK_0 == 11 or RANK_0 27True 28>>> RANK_1 == 37 or RANK_1 29True 30>>> RANK_2 == 389 or RANK_2 31True 32>>> RANK_3 # doctest: +ELLIPSIS 33Traceback (most recent call last): 34NameError: ...name 'RANK_3' is not defined 35 36>>> set(PyxEnum) == {TWO, THREE, FIVE} 37True 38>>> str(PyxEnum.TWO).split(".")[-1] # Py3.10 changed the output here 39'TWO' 40>>> PyxEnum.TWO + PyxEnum.THREE == PyxEnum.FIVE 41True 42>>> PyxEnum(2) is PyxEnum["TWO"] is PyxEnum.TWO 43True 44 45# not leaking into module namespace 46>>> IntEnum # doctest: +ELLIPSIS 47Traceback (most recent call last): 48NameError: ...name 'IntEnum' is not defined 49""" 50 51 52cdef extern from *: 53 cpdef enum: # ExternPyx 54 ONE "1" 55 TEN "10" 56 HUNDRED "100" 57 58 cdef enum: # ExternSecretPyx 59 THOUSAND "1000" 60 61cpdef enum PyxEnum: 62 TWO = 2 63 THREE = 3 64 FIVE = 5 65 66cdef enum SecretPyxEnum: 67 SEVEN = 7 68 69def test_as_variable_from_cython(): 70 """ 71 >>> test_as_variable_from_cython() 72 """ 73 import sys 74 if sys.version_info >= (2, 7): 75 assert list(PyxEnum) == [TWO, THREE, FIVE], list(PyxEnum) 76 assert list(PxdEnum) == [RANK_0, RANK_1, RANK_2], list(PxdEnum) 77 else: 78 # No OrderedDict. 79 assert set(PyxEnum) == {TWO, THREE, FIVE}, list(PyxEnum) 80 assert set(PxdEnum) == {RANK_0, RANK_1, RANK_2}, list(PxdEnum) 81 82cdef int verify_pure_c() nogil: 83 cdef int x = TWO 84 cdef int y = PyxEnum.THREE 85 cdef int z = SecretPyxEnum.SEVEN 86 return x + y + z 87 88# Use it to suppress warning. 89verify_pure_c() 90 91def verify_resolution_GH1533(): 92 """ 93 >>> verify_resolution_GH1533() 94 3 95 """ 96 THREE = 100 97 return int(PyxEnum.THREE) 98