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))
评论列表
文章目录