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 -*-
#------------------------------------------------------------------------------
# Copyright (c) 2013-2025, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
from ast import literal_eval
from textwrap import dedent
from utils import compile_source
def test_unicode_literal():
source = dedent("""\
from enaml.widgets.api import Window
enamldef MyWindow(Window): win:
attr test = u'I do unicode characters: αΨγ 😀⏰🏔 𠁒𠁝𠁖'
""")
myWindow = compile_source(source, 'MyWindow')()
unicode_literal = u'I do unicode characters: αΨγ 😀⏰🏔 𠁒𠁝𠁖'
assert unicode_literal == myWindow.test
def test_unicode_escape_literal():
source = dedent("""\
from enaml.widgets.api import Window
enamldef MyWindow(Window): win:
attr test = u'I do unicode characters: \\U00020052'
""")
myWindow = compile_source(source, 'MyWindow')()
unicode_escape_literal = u'I do unicode characters: \U00020052'
assert unicode_escape_literal == myWindow.test
def test_raw_unicode_literal():
source = dedent("""\
from enaml.widgets.api import Window
enamldef MyWindow(Window): win:
attr test = r'I do unicode characters: \\U00020052'
""")
myWindow = compile_source(source, 'MyWindow')()
raw_unicode_literal = r'I do unicode characters: \U00020052'
assert raw_unicode_literal == myWindow.test
def test_bytes_literal():
source = dedent("""\
from enaml.widgets.api import Window
enamldef MyWindow(Window): win:
attr test = b'I also do bytes with\\nescapes: \\785 and \\x12'
""")
myWindow = compile_source(source, 'MyWindow')()
bytes_literal = b'I also do bytes with\nescapes: \785 and \x12'
assert bytes_literal == myWindow.test
def test_raw_bytes_literal1():
source = dedent("""\
from enaml.widgets.api import Window
enamldef MyWindow(Window): win:
attr test = br'I do bytes with\\nescapes'
""")
myWindow = compile_source(source, 'MyWindow')()
raw_bytes_literal = br'I do bytes with\nescapes'
assert raw_bytes_literal == myWindow.test
def test_raw_bytes_literal2():
source = dedent("""\
from enaml.widgets.api import Window
enamldef MyWindow(Window): win:
attr test = rb'I do bytes with\\nescapes'
""")
myWindow = compile_source(source, 'MyWindow')()
raw_bytes_literal = literal_eval(r"rb'I do bytes with\nescapes'")
assert raw_bytes_literal == myWindow.test
def test_unicode_identifier():
source = dedent("""\
from enaml.widgets.api import Window
enamldef MyWindow(Window): win:
attr 𠁒 = 'test'
# Check we do not mistake this for an invalid identifier
attr a = 1.e6
""")
myWindow = compile_source(source, 'MyWindow')()
assert getattr(myWindow, """𠁒""") == "test"
if __name__ == '__main__':
test_unicode_literal()
test_unicode_escape_literal()
test_raw_unicode_literal()
test_bytes_literal()
test_raw_bytes_literal1()
test_raw_bytes_literal2()
test_unicode_identifier()
|