testcase_manager.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:budou 作者: google 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号