You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PaddleSpeech/third_party/python-pinyin/tests/test_core_cls.py

55 lines
1.5 KiB

from pypinyin.constants import Style
from pypinyin.core import (Pinyin, _default_convert)
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('测试') == [[''], ['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('测试') == [[''], ['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('测试') == [[''], ['shì']]
assert mypinyin.pinyin('测试') == [['a'], ['b'], ['c']]
def test_to_fixed_for_compatibly():
assert _default_convert.convert_style('', '', style=Style.INITIALS, strict=True, default='') == 'c'
def test_handle_nopinyin_for_compatibly():
assert _default_convert.handle_nopinyin('test') == [['test']]
def test_single_pinyin_for_compatibly():
assert _default_convert.single_pinyin('', Style.TONE, False) == [['']]
def test_phrase_pinyin_for_compatibly():
assert _default_convert.phrase_pinyin('测试', Style.TONE, False) == [[''], ['shì']]