Skip to content

Commit

Permalink
Remedy test and PEP8 warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdscxsj committed Oct 24, 2017
1 parent 4f60d39 commit 9cc8541
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
25 changes: 16 additions & 9 deletions pypinyin/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
)
from pypinyin.compat import PY2

_formal_styles = ['NORMAL', 'TONE', 'TONE2', 'TONE3', 'INITIALS', 'FIRST_LETTER',
'FINALS', 'FINALS_TONE', 'FINALS_TONE2', 'FINALS_TONE3',
_formal_styles = ['NORMAL', 'TONE', 'TONE2', 'TONE3',
'INITIALS', 'FIRST_LETTER', 'FINALS',
'FINALS_TONE', 'FINALS_TONE2', 'FINALS_TONE3',
'BOPOMOFO', 'BOPOMOFO_FIRST', 'CYRILLIC', 'CYRILLIC_FIRST']
_layman_styles = ['zhao', 'zh4ao', 'zha4o', 'zhao4', 'zh', 'z', 'ao', 'ào', 'a4o', 'ao4']
_option_styles = _layman_styles + _formal_styles[len(_layman_styles) - len(_formal_styles):]
_layman_styles = ['zhao', 'zh4ao', 'zha4o', 'zhao4', 'zh', 'z',
'ao', 'ào', 'a4o', 'ao4']
_option_styles = _layman_styles + \
_formal_styles[len(_layman_styles) - len(_formal_styles):]
_default_style = _layman_styles[1]


Expand All @@ -32,16 +35,20 @@ def get_parser():
parser.add_argument('-V', '--version', action='version',
version='{0} {1}'.format(__title__, __version__))
# 要执行的函数名称
parser.add_argument('-f', '--func', help='function name (default: "pinyin")',
parser.add_argument('-f', '--func',
help='function name (default: "pinyin")',
choices=['pinyin', 'slug'],
default='pinyin')
# 拼音风格
parser.add_argument('-s', '--style', help='pinyin style (default: "%s")' % _default_style,
parser.add_argument('-s', '--style',
help='pinyin style (default: "%s")' % _default_style,
choices=_option_styles, default=_default_style)
parser.add_argument('-p', '--separator', help='slug separator (default: "-")',
parser.add_argument('-p', '--separator',
help='slug separator (default: "-")',
default='-')
parser.add_argument('-e', '--errors', help=('how to handle none-pinyin string '
'(default: "default")'),
parser.add_argument('-e', '--errors',
help=('how to handle none-pinyin string'
' (default: "default")'),
choices=['default', 'ignore', 'replace'],
default='default')
# 输出多音字
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def test_default():
options = get_parser().parse_args(['你好'])
assert options.func == 'pinyin'
assert options.style == 'TONE'
assert options.style == 'zh4ao'
assert options.separator == '-'
assert not options.heteronym
assert options.hans == '你好'
Expand All @@ -18,12 +18,12 @@ def test_default():

def test_custom():
options = get_parser().parse_args(['--func', 'slug',
'--style', 'NORMAL',
'--style', 'zhao',
'--separator', ' ',
'--errors', 'ignore',
'--heteronym', '你好啊'])
assert options.func == 'slug'
assert options.style == 'NORMAL'
assert options.style == 'zhao'
assert options.separator == ' '
assert options.errors == 'ignore'
assert options.heteronym
Expand Down

0 comments on commit 9cc8541

Please sign in to comment.