def add_test_case(source, words, tokens, language):
with open(TESTCASES_PATH) as f:
cases = [json.loads(row) for row in f.readlines() if row.strip()]
for case in cases:
if case['sentence'] == source:
print('The test case "%s" is already included.' % (source))
print('Do you want to update the test case with the new configuration? '
'Enter `yes` to update or `no` to cencel. (y/n)')
while True:
response = input(colorize('Update?: '))
if response in {'y', 'yes'}:
break
elif response in {'n', 'no'}:
return False
else:
print('Please enter `yes` or `no`.')
with open(TESTCASES_PATH, 'a') as f:
f.write(json.dumps({
'sentence': source,
'language': language,
'tokens': tokens,
'expected': words,
}, ensure_ascii=False, sort_keys=True).encode('utf-8') + '\n')
print('Thank you for submission. Your test case "%s" is added.\n\n' % (
source))
评论列表
文章目录