-
Notifications
You must be signed in to change notification settings - Fork 47
/
test_pinyin.py
54 lines (40 loc) · 2.14 KB
/
test_pinyin.py
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
# -*- coding: utf-8 -*-
import unittest
import pinyin
from pinyin._compat import u
class BasicTestSuite(unittest.TestCase):
"""Basic test cases."""
def test_get(self):
self.assertEqual(pinyin.get('你好'),
pinyin.get('你好', format="diacritical"))
self.assertEqual(pinyin.get(u('你好'), format="strip"), u('nihao'))
self.assertEqual(pinyin.get(u('你好'), format="numerical"), u('ni3hao3'))
self.assertEqual(pinyin.get(u('你好'), format="diacritical"), u('nǐhǎo'))
self.assertEqual(pinyin.get('你好吗?'), u('nǐhǎoma?'))
self.assertEqual(pinyin.get('你好吗?'), u('nǐhǎoma?'))
self.assertEqual(pinyin.get('你好'), u('nǐhǎo'))
self.assertEqual(pinyin.get('叶'), u('yè'))
self.assertEqual(pinyin.get('少女'), u('shǎonv̌'))
def test_get_with_delimiter(self):
self.assertEqual(pinyin.get('你好', " "), u('nǐ hǎo'))
self.assertEqual(pinyin.get('你好吗?', " "), u('nǐ hǎo ma ?'))
self.assertEqual(pinyin.get('你好吗?', " "), u('nǐ hǎo ma ?'))
def test_get_initial_with_delimiter(self):
self.assertEqual(pinyin.get_initial('你好', "-"), u('n-h'))
self.assertEqual(pinyin.get_initial('你好吗?', "-"), u('n-h-m-?'))
self.assertEqual(pinyin.get_initial('你好吗?', "-"), u('n-h-m-?'))
def test_get_initial(self):
self.assertEqual(pinyin.get_initial('你好'), u('n h'))
self.assertEqual(pinyin.get_initial('你好吗?'), u('n h m ?'))
self.assertEqual(pinyin.get_initial('你好吗?'), u('n h m ?'))
self.assertEqual(pinyin.get_initial('你好'), 'n h')
def test_mixed_chinese_english_input(self):
self.assertEqual(pinyin.get('hi你好'), u('hinǐhǎo'))
def test_correct_diacritical(self):
self.assertEqual(pinyin.get("操"), u("cāo"))
self.assertEqual(pinyin.get("小"), u("xiǎo"))
self.assertEqual(pinyin.get("绝"), u("jué"))
self.assertEqual(pinyin.get("被"), u("bèi"))
self.assertEqual(pinyin.get("略"), u("lvè"))
if __name__ == '__main__':
unittest.main()