basetest.py 文件源码

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

项目:protoc-gen-lua-bin 作者: u0u0 项目源码 文件源码
def _Diff(lhs, rhs):
  """Given two pathnames, compare two files.  Raise if they differ."""
  # Some people rely on being able to specify TEST_DIFF in the environment to
  # have tests use their own diff wrapper for use when updating golden data.
  external_diff = os.environ.get('TEST_DIFF')
  if external_diff:
    return _DiffViaExternalProgram(lhs, rhs, external_diff)
  try:
    with open(lhs, 'r') as lhs_f:
      with open(rhs, 'r') as rhs_f:
        diff_text = ''.join(
            difflib.unified_diff(lhs_f.readlines(), rhs_f.readlines()))
    if not diff_text:
      return True
    raise OutputDifferedError('\nComparing %s and %s\nTest output differed '
                              'from golden file:\n%s' % (lhs, rhs, diff_text))
  except EnvironmentError as error:
    # Unable to read the files.
    raise DiffFailureError('\nComparing %s and %s\nFailure diffing test output '
                           'with golden file: %s\n' % (lhs, rhs, error))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号