def test_get(self): self.assertEqual(pinyin.get('你好'), 'nihao') self.assertEqual(pinyin.get(u('你好')), 'nihao') self.assertEqual(pinyin.get('你好吗?'), 'nihaoma?') self.assertEqual(pinyin.get('你好吗?'), u('nihaoma?')) self.assertEqual(pinyin.get('你好'), 'nihao') self.assertEqual(pinyin.get('叶'), 'ye')
def test_get(self): self.assertEqual(pinyin.get('你好'), pinyin.get('你好', format="diacritical")) self.assertEqual(pinyin.get(u('你好'), format="strip"), u('nihao')) self.assertEqual(pinyin.get(u('你好'), format="numerical"), u('ni3hao3')) self.assertEqual(pinyin.get(u('你好'), format="diacritical"), u('nǐhǎo')) self.assertEqual(pinyin.get('你好吗?'), u('nǐhǎoma?')) self.assertEqual(pinyin.get('你好吗?'), u('nǐhǎoma?')) self.assertEqual(pinyin.get('你好'), u('nǐhǎo')) self.assertEqual(pinyin.get('叶'), u('yè'))
def pinyin(): parser = argparse.ArgumentParser() parser.add_argument("chars", help="Input chinese words") args = parser.parse_args() if not args.chars: parser.print_help() return print(get(u(args.chars)))
def test_correct_diacritical(self): self.assertEqual(pinyin.get("操"), u("cāo")) self.assertEqual(pinyin.get("小"), u("xiǎo")) self.assertEqual(pinyin.get("绝"), u("jué")) self.assertEqual(pinyin.get("被"), u("bèi")) self.assertEqual(pinyin.get("略"), u("lvè"))
def test_mixed_chinese_english_input(self): self.assertEqual(pinyin.get('hi你好'), u('hinǐhǎo'))
def test_get_initial(self): self.assertEqual(pinyin.get_initial('你好'), u('n h')) self.assertEqual(pinyin.get_initial('你好吗?'), u('n h m ?')) self.assertEqual(pinyin.get_initial('你好吗?'), u('n h m ?')) self.assertEqual(pinyin.get_initial('你好'), 'n h')
def test_get_initial_with_delimiter(self): self.assertEqual(pinyin.get_initial('你好', "-"), u('n-h')) self.assertEqual(pinyin.get_initial('你好吗?', "-"), u('n-h-m-?')) self.assertEqual(pinyin.get_initial('你好吗?', "-"), u('n-h-m-?'))
def test_get_with_delimiter(self): self.assertEqual(pinyin.get('你好', " "), u('nǐ hǎo')) self.assertEqual(pinyin.get('你好吗?', " "), u('nǐ hǎo ma ?')) self.assertEqual(pinyin.get('你好吗?', " "), u('nǐ hǎo ma ?'))
def test_correct_diacritical(self): self.assertEqual(pinyin.get("操"), u("cāo")) self.assertEqual(pinyin.get("小"), u("xiǎo")) self.assertEqual(pinyin.get("绝"), u("jué")) self.assertEqual(pinyin.get("被"), u("bèi"))