Debian Codegraph @

python/tests/pypi_smoke.py

raw symbols SCIP
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 # Verify that key built-in configs are present in the installed package
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 # Simplified → Traditional
22 _check(opencc.OpenCC('s2t').convert('汉字'), '漢字')
23
24 # Simplified → Taiwan (with phrase replacement)
25 _check(opencc.OpenCC('s2twp').convert('打印机和鼠标'), '印表機和滑鼠')
26
27 # Simplified → Hong Kong
28 _check(opencc.OpenCC('s2hk').convert('鼠标'), '鼠標')
29
30 # Traditional → Simplified
31 _check(opencc.OpenCC('t2s').convert('開放中文轉換'), '开放中文转换')
32
33 # Taiwan → Simplified: character-variant conversion only (no vocabulary replacement)
34 _check(opencc.OpenCC('tw2s').convert('台灣'), '台湾')
35
36 # Taiwan → Simplified: with Mainland vocabulary replacement (tw2sp)
37 _check(opencc.OpenCC('tw2sp').convert('滑鼠'), '鼠标')
38
39 # Config stem without .json suffix resolves correctly
40 _check(opencc.OpenCC('s2t').convert('汉字'), '漢字')
41
42 print('All checks passed.')
43
44
45 if __name__ == '__main__':
46 main()