summaryrefslogtreecommitdiff
path: root/tests/testutils/patch.py
blob: 6dec68ca9c9d4e26a7c481a87e62a4bbfa830897 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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