def test_apply_patch_for_files_inplace(f, mtime, data_path, media_path): file_input = os.path.join(data_path, 'old', f) file_expected = os.path.join(data_path, 'new', f) file_output = os.path.join(media_path, os.path.split(f)[-1]) file_patch = os.path.join(data_path, 'patch_full', f + '.abindiff') if f == 'created_file.txt': with open(file_output, 'wb'): pass # touch else: shutil.copy(file_input, file_output) patch.apply_patch_for_files(file_output, file_output, file_patch, allow_empty=f == 'created_file.txt') with open(file_output, 'rb') as fp: data_actual = fp.read() with open(file_expected, 'rb') as fp: data_expected = fp.read() assert data_expected == data_actual assert abs(os.stat(file_output).st_mtime - mtime) < 0.002
def test_apply_patch_for_files_complex_gzip_auto(f, mtime, data_path, media_path): file_input = os.path.join(data_path, 'old', f) file_expected = os.path.join(data_path, 'new', f) file_output = os.path.join(media_path, os.path.split(f)[-1]) file_patch = os.path.join(data_path, 'patch_gzip', f + '.abindiff.gz') patch.apply_patch_for_files(file_input, file_output, file_patch, allow_empty=f == 'created_file.txt') with open(file_output, 'rb') as fp: data_actual = fp.read() with open(file_expected, 'rb') as fp: data_expected = fp.read() assert data_expected == data_actual assert abs(os.stat(file_output).st_mtime - mtime) < 0.002