summaryrefslogtreecommitdiff
path: root/tests/testutils/patch.py
blob: df287f374539661c1f1d821eb2830d67d4059efa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import subprocess


def apply(file, patch):
    try:
        subprocess.check_output(['patch', file, patch])
    except subprocess.CalledProcessError as e:
        message = "Patch failed with exit code {}\n Output:\n {}".format(
            e.returncode, e.output)
        print(message)
        raise


def remove(file, patch):
    try:
        subprocess.check_output(['patch', '--reverse', file, patch])
    except subprocess.CalledProcessError as e:
        message = "patch --reverse failed with exit code {}\n Output:\n {}".format(
            e.returncode, e.output)
        print(message)
        raise