Revert patches in reverse order

Change-Id: I8f3431691d93043fb49570f68417cf3011b5d806
This commit is contained in:
Sergey Abramov 2016-06-30 11:05:09 +03:00
parent fdafa2666d
commit 60386fe00c
6 changed files with 20 additions and 15 deletions

View File

@ -168,7 +168,7 @@ def test_applied_patches(mocker, container, prefix, patches, error):
pass
assert [
mock.call(container, prefix, *patches),
mock.call(container, prefix, *patches, revert=True)
mock.call(container, prefix, *patches[::-1], revert=True)
] == apply_patches.call_args_list

View File

@ -36,7 +36,7 @@ def test_applied_context_manager(mocker, patches, cwd, is_exception):
pass
assert [
mock.call(cwd, patches),
mock.call(cwd, patches, revert=True)
mock.call(cwd, patches[::-1], revert=True)
] == patch_mock.call_args_list

View File

@ -42,7 +42,11 @@ def test_applied_patches(mocker, node, mock_open,
error_idx = error_idx or len(patches) + 1
mock_shutil_side_effect = []
revert_patches = []
for idx, path in enumerate(patches):
if idx < error_idx:
revert_patches.append(path)
if idx <= error_idx:
mock_open_calls.append(mock.call(path, "rb"))
mock_patch_calls.append(mock.call(
@ -57,17 +61,17 @@ def test_applied_patches(mocker, node, mock_open,
else:
mock_shutil_side_effect.append(None)
for idx, path in enumerate(patches):
if idx < error_idx:
mock_shutil_side_effect.append(None)
mock_patch_calls.append(mock.call(
["patch", "-R", "-p1", "-d", cwd], node=node, stdin=ssh.PIPE
))
mock_open_calls.append(mock.call(path, "rb"))
mock_shutil_calls.append(mock.call(
mock_open.return_value,
mock_popen.return_value.__enter__.return_value.stdin
))
revert_patches.reverse()
for path in revert_patches:
mock_shutil_side_effect.append(None)
mock_patch_calls.append(mock.call(
["patch", "-R", "-p1", "-d", cwd], node=node, stdin=ssh.PIPE
))
mock_open_calls.append(mock.call(path, "rb"))
mock_shutil_calls.append(mock.call(
mock_open.return_value,
mock_popen.return_value.__enter__.return_value.stdin
))
mock_shutil = mocker.patch(
"shutil.copyfileobj", side_effect=mock_shutil_side_effect)

View File

@ -239,7 +239,7 @@ def applied_patches(container, prefix, *patches):
try:
yield
finally:
apply_patches(container, prefix, *patches, revert=True)
apply_patches(container, prefix, *patches[::-1], revert=True)
@contextlib.contextmanager

View File

@ -36,7 +36,7 @@ def applied_patch(cwd, *patches):
try:
yield
finally:
patch_apply(cwd, patches, revert=True)
patch_apply(cwd, patches[::-1], revert=True)
def get_filenames_from_single_patch(patch):

View File

@ -245,6 +245,7 @@ def applied_patches(cwd, node, *patches):
patched_files.append(path)
yield
finally:
patched_files.reverse()
for path in patched_files:
with open(path, "rb") as patch:
with popen(