File: test_itb_util.py

package info (click to toggle)
ibus-typing-booster 2.10.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 87,788 kB
  • sloc: xml: 799,041; python: 22,939; sh: 3,519; makefile: 342
file content (103 lines) | stat: -rwxr-xr-x 3,776 bytes parent folder | download
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
#!/usr/bin/python3

# ibus-typing-booster - A completion input method for IBus
#
# Copyright (c) 2019 Mike FABIAN <mfabian@redhat.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>

'''
This file implements test cases for miscellaneous stuff in itb_util.py.
'''

import sys
import locale
import unittest
import unicodedata

from gi import require_version
require_version('IBus', '1.0')
from gi.repository import IBus

sys.path.insert(0, "../engine")
import itb_util
sys.path.pop(0)

class ItbUtilTestCase(unittest.TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        locale.resetlocale()

    def test_dummy(self):
        self.assertEqual(True, True)

    def test_is_right_to_left_messages(self):
        locale.setlocale(locale.LC_MESSAGES, 'de_DE.UTF-8')
        self.assertEqual(itb_util.is_right_to_left_messages(), False)
        locale.setlocale(locale.LC_MESSAGES, 'ar_EG.UTF-8')
        self.assertEqual(itb_util.is_right_to_left_messages(), True)
        locale.setlocale(locale.LC_MESSAGES, 'C')
        self.assertEqual(itb_util.is_right_to_left_messages(), False)
        # Result should be False for an invalid locale:
        try:
            locale.setlocale(locale.LC_MESSAGES, 'nonsense')
        except locale.Error:
            pass
        self.assertEqual(itb_util.is_right_to_left_messages(), False)
        # LC_ALL should have higher priority than LC_MESSAGES:
        locale.setlocale(locale.LC_MESSAGES, 'de_DE.UTF-8')
        locale.setlocale(locale.LC_ALL, 'ar_EG.UTF-8')
        self.assertEqual(itb_util.is_right_to_left_messages(), True)
        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
        self.assertEqual(itb_util.is_right_to_left_messages(), False)
        locale.setlocale(locale.LC_ALL, 'C')
        self.assertEqual(itb_util.is_right_to_left_messages(), False)

    def test_remove_accents(self):
        self.assertEqual(
            itb_util.remove_accents('abcÅøßẞüxyz'),
            'abcAossSSuxyz')
        self.assertEqual(
            itb_util.remove_accents(
                unicodedata.normalize('NFD', 'abcÅøßẞüxyz')),
            'abcAossSSuxyz')
        self.assertEqual(
            unicodedata.normalize(
                'NFC',
                itb_util.remove_accents('abcÅøßẞüxyz', keep='åÅØø')),
            'abcÅøssSSuxyz')
        self.assertEqual(
            unicodedata.normalize(
                'NFC',
                itb_util.remove_accents(
                    unicodedata.normalize('NFD', 'abcÅøßẞüxyz'),
                    keep=unicodedata.normalize('NFD', 'åÅØø'))),
            'abcÅøssSSuxyz')
        self.assertEqual(
            unicodedata.normalize(
                'NFC',
                itb_util.remove_accents('alkoholförgiftning', keep='åÅÖö')),
            'alkoholförgiftning')
        self.assertEqual(
            unicodedata.normalize(
                'NFC',
                itb_util.remove_accents(
                    unicodedata.normalize('NFD', 'alkoholförgiftning'),
                    keep=unicodedata.normalize('NFD', 'åÅÖö'))),
            'alkoholförgiftning')

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