forked from mozillazg/python-pinyin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_core_cls.py
58 lines (36 loc) · 1.46 KB
/
test_core_cls.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
55
56
57
58
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from pypinyin.constants import Style
from pypinyin.core import (
Pinyin, to_fixed, handle_nopinyin, single_pinyin, phrase_pinyin)
def test_use_pre_seg_to_skip_seg():
class A(Pinyin):
def pre_seg(self, hans, **kwargs):
return ['a', 'b', 'c']
mypinyin = A()
assert Pinyin().pinyin('测试') == [['cè'], ['shì']]
assert mypinyin.pinyin('测试') == [['a'], ['b'], ['c']]
def test_use_post_seg_to_change_seg_result():
class A(Pinyin):
def post_seg(self, hans, seg_data, **kwargs):
return ['a', 'b', 'c']
mypinyin = A()
assert Pinyin().pinyin('测试') == [['cè'], ['shì']]
assert mypinyin.pinyin('测试') == [['a'], ['b'], ['c']]
def test_use_seg_function_change_seg_func():
def seg(han):
return ['a', 'b', 'c']
class A(Pinyin):
def get_seg(self):
return seg
mypinyin = A()
assert Pinyin().pinyin('测试') == [['cè'], ['shì']]
assert mypinyin.pinyin('测试') == [['a'], ['b'], ['c']]
def test_to_fixed_for_compatibly():
assert to_fixed('cè', Style.INITIALS) == 'c'
def test_handle_nopinyin_for_compatibly():
assert handle_nopinyin('test') == [['test']]
def test_single_pinyin_for_compatibly():
assert single_pinyin('测', Style.TONE, False) == [['cè']]
def test_phrase_pinyin_for_compatibly():
assert phrase_pinyin('测试', Style.TONE, False) == [['cè'], ['shì']]