summaryrefslogtreecommitdiffstats
path: root/tests/unit/test-010-transliterate.py
blob: 87e4b84dfda3171ec3b297161042103521bee0d0 (plain)
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
# -*- coding: utf-8 -*-

import unittest


class TestTransliteration(unittest.TestCase):
    def test_001_raw_fr_FR(self):
        """
            The special thing about this case is that the givenname starts with
            a special character.
        """
        from pykolab import utils
        givenname = r'Étienne-Nicolas'
        surname = r'Méhul'

        preferredlanguage = 'fr_FR'

        self.assertEqual('Etienne-Nicolas', utils.translate(givenname, preferredlanguage))
        self.assertEqual('Mehul', utils.translate(surname, preferredlanguage))

    def test_002_unicode_fr_FR(self):
        """
            The special thing about this case is that the givenname starts with
            a special character.
        """
        from pykolab import utils
        givenname = 'Étienne-Nicolas'
        surname = 'Méhul'

        preferredlanguage = 'fr_FR'

        self.assertEqual('Etienne-Nicolas', utils.translate(givenname, preferredlanguage))
        self.assertEqual('Mehul', utils.translate(surname, preferredlanguage))

    def test_003_raw_es_ES(self):
        """
            The special thing about this case is that the givenname starts with
            a special character.
        """
        from pykolab import utils
        givenname = r'Álvaro'
        surname = r'Fuentes'

        preferredlanguage = 'es_ES'

        self.assertEqual('Alvaro', utils.translate(givenname, preferredlanguage))
        self.assertEqual('Fuentes', utils.translate(surname, preferredlanguage))

    def test_004_unicode_es_ES(self):
        """
            The special thing about this case is that the givenname starts with
            a special character.
        """
        from pykolab import utils
        givenname = 'Álvaro'
        surname = 'Fuentes'

        preferredlanguage = 'es_ES'

        self.assertEqual('Alvaro', utils.translate(givenname, preferredlanguage))
        self.assertEqual('Fuentes', utils.translate(surname, preferredlanguage))

    def test_005_raw_ru_RU(self):
        from pykolab import utils
        givenname = r'Николай'
        surname = r'Римский-Корсаков'

        preferredlanguage = 'ru_RU'

        self.assertEqual('Nikolaj', utils.translate(givenname, preferredlanguage))
        self.assertEqual('Rimskij-Korsakov', utils.translate(surname, preferredlanguage))

    def test_006_unicode_ru_RU(self):
        from pykolab import utils
        givenname = u'Николай'
        surname = u'Римский-Корсаков'

        preferredlanguage = 'ru_RU'

        self.assertEqual('Nikolaj', utils.translate(givenname, preferredlanguage))
        self.assertEqual('Rimskij-Korsakov', utils.translate(surname, preferredlanguage))

    def test_007_raw_ru_RU(self):
        from pykolab import utils
        givenname = r'Юлия'
        surname = r'Ёлкина'

        preferredlanguage = 'ru_RU'

        self.assertEqual('Yuliya', utils.translate(givenname, preferredlanguage))
        self.assertEqual('Yolkina', utils.translate(surname, preferredlanguage))

    def test_008_unicode_ru_RU(self):
        from pykolab import utils
        givenname = u'Юлия'
        surname = u'Ёлкина'

        preferredlanguage = 'ru_RU'

        self.assertEqual('Yuliya', utils.translate(givenname, preferredlanguage))
        self.assertEqual('Yolkina', utils.translate(surname, preferredlanguage))

    def test_009_raw_decode(self):
        raw_str = r"Николай"
        self.assertEqual('Николай', raw_str.decode("string_escape"))

        raw_str = r"raw"
        self.assertEqual('raw', raw_str.decode("string_escape"))

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