| 1 |
import unittest |
| 2 |
|
| 3 |
import louis |
| 4 |
|
| 5 |
|
| 6 |
class TestUnicodeComposed(unittest.TestCase): |
| 7 |
@unittest.expectedFailure |
| 8 |
def test_1(self): |
| 9 |
self.assertEqual( |
| 10 |
louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "😂"), |
| 11 |
'"<face with tears of joy">', |
| 12 |
) |
| 13 |
|
| 14 |
def test_2(self): |
| 15 |
self.assertEqual( |
| 16 |
louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "a 😂"), |
| 17 |
'a "<face with tears of joy">', |
| 18 |
) |
| 19 |
|
| 20 |
def test_3(self): |
| 21 |
self.assertEqual( |
| 22 |
louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "😂 b"), |
| 23 |
'"<face with tears of joy"> b', |
| 24 |
) |
| 25 |
|
| 26 |
def test_4(self): |
| 27 |
self.assertEqual( |
| 28 |
louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "a 😂 b"), |
| 29 |
'a "<face with tears of joy"> b', |
| 30 |
) |
| 31 |
|
| 32 |
def test_8(self): |
| 33 |
self.assertEqual( |
| 34 |
louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "before 😂"), |
| 35 |
'before "<face with tears of joy">', |
| 36 |
) |
| 37 |
|
| 38 |
def test_9(self): |
| 39 |
self.assertEqual( |
| 40 |
louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "😂 after"), |
| 41 |
'"<face with tears of joy"> after', |
| 42 |
) |
| 43 |
|
| 44 |
def test_10(self): |
| 45 |
self.assertEqual( |
| 46 |
louis.translateString( |
| 47 |
["en-ueb-g1.ctb", "tests/test.cti"], "before 😂 after" |
| 48 |
), |
| 49 |
'before "<face with tears of joy"> after', |
| 50 |
) |
| 51 |
|
| 52 |
@unittest.expectedFailure |
| 53 |
def test_11(self): |
| 54 |
self.assertEqual( |
| 55 |
louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "🤣"), |
| 56 |
'"<rolling on the floor laughing">', |
| 57 |
) |
| 58 |
|
| 59 |
def test_12(self): |
| 60 |
self.assertEqual( |
| 61 |
louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "a 🤣"), |
| 62 |
'a "<rolling on the floor laughing">', |
| 63 |
) |
| 64 |
|
| 65 |
def test_13(self): |
| 66 |
self.assertEqual( |
| 67 |
louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "🤣 b"), |
| 68 |
'"<rolling on the floor laughing"> b', |
| 69 |
) |
| 70 |
|
| 71 |
def test_14(self): |
| 72 |
self.assertEqual( |
| 73 |
louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "a 🤣 b"), |
| 74 |
'a "<rolling on the floor laughing"> b', |
| 75 |
) |
| 76 |
|
| 77 |
|
| 78 |
class TestUnicodeDecomposed(unittest.TestCase): |
| 79 |
@unittest.expectedFailure |
| 80 |
def test_1(self): |
| 81 |
self.assertEqual( |
| 82 |
louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "\ud83d\ude02"), |
| 83 |
'"<face with tears of joy">', |
| 84 |
) |
| 85 |
|
| 86 |
def test_2(self): |
| 87 |
self.assertEqual( |
| 88 |
louis.translateString( |
| 89 |
["en-ueb-g1.ctb", "tests/test.cti"], "a \ud83d\ude02" |
| 90 |
), |
| 91 |
'a "<face with tears of joy">', |
| 92 |
) |
| 93 |
|
| 94 |
def test_3(self): |
| 95 |
self.assertEqual( |
| 96 |
louis.translateString( |
| 97 |
["en-ueb-g1.ctb", "tests/test.cti"], "\ud83d\ude02 b" |
| 98 |
), |
| 99 |
'"<face with tears of joy"> b', |
| 100 |
) |
| 101 |
|
| 102 |
def test_4(self): |
| 103 |
self.assertEqual( |
| 104 |
louis.translateString( |
| 105 |
["en-ueb-g1.ctb", "tests/test.cti"], "a \ud83d\ude02 b" |
| 106 |
), |
| 107 |
'a "<face with tears of joy"> b', |
| 108 |
) |
| 109 |
|
| 110 |
def test_8(self): |
| 111 |
self.assertEqual( |
| 112 |
louis.translateString( |
| 113 |
["en-ueb-g1.ctb", "tests/test.cti"], "before \ud83d\ude02" |
| 114 |
), |
| 115 |
'before "<face with tears of joy">', |
| 116 |
) |
| 117 |
|
| 118 |
def test_9(self): |
| 119 |
self.assertEqual( |
| 120 |
louis.translateString( |
| 121 |
["en-ueb-g1.ctb", "tests/test.cti"], "\ud83d\ude02 after" |
| 122 |
), |
| 123 |
'"<face with tears of joy"> after', |
| 124 |
) |
| 125 |
|
| 126 |
def test_10(self): |
| 127 |
self.assertEqual( |
| 128 |
louis.translateString( |
| 129 |
["en-ueb-g1.ctb", "tests/test.cti"], "before \ud83d\ude02 after" |
| 130 |
), |
| 131 |
'before "<face with tears of joy"> after', |
| 132 |
) |
| 133 |
|
| 134 |
@unittest.expectedFailure |
| 135 |
def test_11(self): |
| 136 |
self.assertEqual( |
| 137 |
louis.translateString(["en-ueb-g1.ctb", "tests/test.cti"], "\ud83e\udd23"), |
| 138 |
'"<rolling on the floor laughing">', |
| 139 |
) |
| 140 |
|
| 141 |
def test_12(self): |
| 142 |
self.assertEqual( |
| 143 |
louis.translateString( |
| 144 |
["en-ueb-g1.ctb", "tests/test.cti"], "a \ud83e\udd23" |
| 145 |
), |
| 146 |
'a "<rolling on the floor laughing">', |
| 147 |
) |
| 148 |
|
| 149 |
def test_13(self): |
| 150 |
self.assertEqual( |
| 151 |
louis.translateString( |
| 152 |
["en-ueb-g1.ctb", "tests/test.cti"], "\ud83e\udd23 b" |
| 153 |
), |
| 154 |
'"<rolling on the floor laughing"> b', |
| 155 |
) |
| 156 |
|
| 157 |
def test_14(self): |
| 158 |
self.assertEqual( |
| 159 |
louis.translateString( |
| 160 |
["en-ueb-g1.ctb", "tests/test.cti"], "a \ud83e\udd23 b" |
| 161 |
), |
| 162 |
'a "<rolling on the floor laughing"> b', |
| 163 |
) |
| 164 |
|
| 165 |
|
| 166 |
class TestEndianness(unittest.TestCase): |
| 167 |
def test_1(self): |
| 168 |
self.assertEqual( |
| 169 |
louis.translate( |
| 170 |
["unicode.dis", "en-chardefs.cti"], "abcdefghijklmnopqrstuvwxyz" |
| 171 |
)[0], |
| 172 |
"⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵", |
| 173 |
) |
| 174 |
|
| 175 |
def test_2(self): |
| 176 |
|
| 177 |
_encoding = louis.conversionEncoding |
| 178 |
_endianness = "le" if louis._endianness == "be" else "be" |
| 179 |
louis.conversionEncoding = "utf_%d_%s" % (louis.wideCharBytes * 8, _endianness) |
| 180 |
with self.assertRaises(UnicodeDecodeError): |
| 181 |
self.assertEqual( |
| 182 |
louis.translate( |
| 183 |
["unicode.dis", "en-chardefs.cti"], "abcdefghijklmnopqrstuvwxyz" |
| 184 |
)[0], |
| 185 |
"⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵", |
| 186 |
) |
| 187 |
louis.conversionEncoding = _encoding |
| 188 |
|
| 189 |
|
| 190 |
if __name__ == "__main__": |
| 191 |
unittest.main() |