| 1 |
import opencc |
| 2 |
|
| 3 |
|
| 4 |
def _check(actual, expected): |
| 5 |
if actual != expected: |
| 6 |
raise AssertionError('expected {!r}, got {!r}'.format(expected, actual)) |
| 7 |
|
| 8 |
|
| 9 |
def main(): |
| 10 |
print('opencc module:', opencc.__file__) |
| 11 |
print('opencc version:', opencc.__version__) |
| 12 |
assert opencc.__version__, '__version__ must be non-empty' |
| 13 |
|
| 14 |
|
| 15 |
for config in ('s2t', 's2tw', 's2twp', 's2hk', 's2hkp', 't2s', 't2tw', 't2hk'): |
| 16 |
config_file = config + '.json' |
| 17 |
assert ( |
| 18 |
config in opencc.CONFIGS or config_file in opencc.CONFIGS |
| 19 |
), '{} or {} not in opencc.CONFIGS'.format(config, config_file) |
| 20 |
|
| 21 |
al |
| 22 |
_check(opencc.OpenCC('s2t').convert('汉字'), '漢字') |
| 23 |
|
| 24 |
t) |
| 25 |
_check(opencc.OpenCC('s2twp').convert('打印机和鼠标'), '印表機和滑鼠') |
| 26 |
|
| 27 |
ng |
| 28 |
_check(opencc.OpenCC('s2hk').convert('鼠标'), '鼠標') |
| 29 |
|
| 30 |
ed |
| 31 |
_check(opencc.OpenCC('t2s').convert('開放中文轉換'), '开放中文转换') |
| 32 |
|
| 33 |
t) |
| 34 |
_check(opencc.OpenCC('tw2s').convert('台灣'), '台湾') |
| 35 |
|
| 36 |
p) |
| 37 |
_check(opencc.OpenCC('tw2sp').convert('滑鼠'), '鼠标') |
| 38 |
|
| 39 |
|
| 40 |
_check(opencc.OpenCC('s2t').convert('汉字'), '漢字') |
| 41 |
|
| 42 |
print('All checks passed.') |
| 43 |
|
| 44 |
|
| 45 |
if __name__ == '__main__': |
| 46 |
main() |