File: test_louis.py

package info (click to toggle)
liblouis 3.36.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 86,248 kB
  • sloc: ansic: 37,162; makefile: 1,298; python: 772; lisp: 390; sh: 339; perl: 221; cpp: 21
file content (191 lines) | stat: -rw-r--r-- 5,849 bytes parent folder | download | duplicates (2)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import unittest

import louis


class TestUnicodeComposed(unittest.TestCase):
    @unittest.expectedFailure
    def test_1(self):
        self.assertEqual(
            louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "😂"),
            '"<face with tears of joy">',
        )

    def test_2(self):
        self.assertEqual(
            louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "a 😂"),
            'a "<face with tears of joy">',
        )

    def test_3(self):
        self.assertEqual(
            louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "😂 b"),
            '"<face with tears of joy"> b',
        )

    def test_4(self):
        self.assertEqual(
            louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "a 😂 b"),
            'a "<face with tears of joy"> b',
        )

    def test_8(self):
        self.assertEqual(
            louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "before 😂"),
            'before "<face with tears of joy">',
        )

    def test_9(self):
        self.assertEqual(
            louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "😂 after"),
            '"<face with tears of joy"> after',
        )

    def test_10(self):
        self.assertEqual(
            louis.translateString(
                ["en-ueb-g1.ctb", "tests/test.cti"], "before 😂 after"
            ),
            'before "<face with tears of joy"> after',
        )

    @unittest.expectedFailure
    def test_11(self):
        self.assertEqual(
            louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "🤣"),
            '"<rolling on the floor laughing">',
        )

    def test_12(self):
        self.assertEqual(
            louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "a 🤣"),
            'a "<rolling on the floor laughing">',
        )

    def test_13(self):
        self.assertEqual(
            louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "🤣 b"),
            '"<rolling on the floor laughing"> b',
        )

    def test_14(self):
        self.assertEqual(
            louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "a 🤣 b"),
            'a "<rolling on the floor laughing"> b',
        )


class TestUnicodeDecomposed(unittest.TestCase):
    @unittest.expectedFailure
    def test_1(self):
        self.assertEqual(
            louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "\ud83d\ude02"),
            '"<face with tears of joy">',
        )

    def test_2(self):
        self.assertEqual(
            louis.translateString(
                ["en-ueb-g1.ctb", "tests/test.cti"], "a \ud83d\ude02"
            ),
            'a "<face with tears of joy">',
        )

    def test_3(self):
        self.assertEqual(
            louis.translateString(
                ["en-ueb-g1.ctb", "tests/test.cti"], "\ud83d\ude02 b"
            ),
            '"<face with tears of joy"> b',
        )

    def test_4(self):
        self.assertEqual(
            louis.translateString(
                ["en-ueb-g1.ctb", "tests/test.cti"], "a \ud83d\ude02 b"
            ),
            'a "<face with tears of joy"> b',
        )

    def test_8(self):
        self.assertEqual(
            louis.translateString(
                ["en-ueb-g1.ctb", "tests/test.cti"], "before \ud83d\ude02"
            ),
            'before "<face with tears of joy">',
        )

    def test_9(self):
        self.assertEqual(
            louis.translateString(
                ["en-ueb-g1.ctb", "tests/test.cti"], "\ud83d\ude02 after"
            ),
            '"<face with tears of joy"> after',
        )

    def test_10(self):
        self.assertEqual(
            louis.translateString(
                ["en-ueb-g1.ctb", "tests/test.cti"], "before \ud83d\ude02 after"
            ),
            'before "<face with tears of joy"> after',
        )

    @unittest.expectedFailure
    def test_11(self):
        self.assertEqual(
            louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "\ud83e\udd23"),
            '"<rolling on the floor laughing">',
        )

    def test_12(self):
        self.assertEqual(
            louis.translateString(
                ["en-ueb-g1.ctb", "tests/test.cti"], "a \ud83e\udd23"
            ),
            'a "<rolling on the floor laughing">',
        )

    def test_13(self):
        self.assertEqual(
            louis.translateString(
                ["en-ueb-g1.ctb", "tests/test.cti"], "\ud83e\udd23 b"
            ),
            '"<rolling on the floor laughing"> b',
        )

    def test_14(self):
        self.assertEqual(
            louis.translateString(
                ["en-ueb-g1.ctb", "tests/test.cti"], "a \ud83e\udd23 b"
            ),
            'a "<rolling on the floor laughing"> b',
        )


class TestEndianness(unittest.TestCase):
    def test_1(self):
        self.assertEqual(
            louis.translate(
                ["unicode.dis", "en-chardefs.cti"], "abcdefghijklmnopqrstuvwxyz"
            )[0],
            "⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵",
        )

    def test_2(self):
        # invert encoding
        _encoding = louis.conversionEncoding
        _endianness = "le" if louis._endianness == "be" else "be"
        louis.conversionEncoding = "utf_%d_%s" % (louis.wideCharBytes * 8, _endianness)
        with self.assertRaises(UnicodeDecodeError):
            self.assertEqual(
                louis.translate(
                    ["unicode.dis", "en-chardefs.cti"], "abcdefghijklmnopqrstuvwxyz"
                )[0],
                "⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵",
            )
        louis.conversionEncoding = _encoding


if __name__ == "__main__":
    unittest.main()