import opencc
def _check(actual, expected):
if actual != expected:
raise AssertionError('expected {!r}, got {!r}'.format(expected, actual))
def main():
print('opencc module:', opencc.__file__)
print('opencc version:', opencc.__version__)
assert opencc.__version__, '__version__ must be non-empty'
for config in ('s2t', 's2tw', 's2twp', 's2hk', 's2hkp', 't2s', 't2tw', 't2hk'):
config_file = config + '.json'
assert (
config in opencc.CONFIGS or config_file in opencc.CONFIGS
), '{} or {} not in opencc.CONFIGS'.format(config, config_file)
_check(opencc.OpenCC('s2t').convert('汉字'), '漢字')
_check(opencc.OpenCC('s2twp').convert('打印机和鼠标'), '印表機和滑鼠')
_check(opencc.OpenCC('s2hk').convert('鼠标'), '鼠標')
_check(opencc.OpenCC('t2s').convert('開放中文轉換'), '开放中文转换')
_check(opencc.OpenCC('tw2s').convert('台灣'), '台湾')
_check(opencc.OpenCC('tw2sp').convert('滑鼠'), '鼠标')
_check(opencc.OpenCC('s2t').convert('汉字'), '漢字')
print('All checks passed.')
if __name__ == '__main__':
main()