Skip to content

Commit f0385f8

Browse files
committed
Support git apply -p1 by default
See #4116.
1 parent 08378fa commit f0385f8

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

hypothesis-python/RELEASE.rst

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RELEASE_TYPE: patch
2+
3+
This patch tweaks the paths in ``@example(...)`` patches, so that
4+
both ``git apply`` and ``patch`` will work by default.

hypothesis-python/src/hypothesis/extra/_patching.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ def make_patch(triples, *, msg="Hypothesis: add explicit examples", when=None):
205205
ud = difflib.unified_diff(
206206
source_before.splitlines(keepends=True),
207207
source_after.splitlines(keepends=True),
208-
fromfile=str(fname),
209-
tofile=str(fname),
208+
fromfile=f"./{fname}", # git strips the first part of the path by default
209+
tofile=f"./{fname}",
210210
)
211211
diffs.append("".join(ud))
212212
return "".join(diffs)

hypothesis-python/tests/patching/test_patching.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ def test_adds_simple_patch(tst, example, expected):
7474

7575

7676
SIMPLE_PATCH_BODY = f'''\
77-
--- {WHERE}
78-
+++ {WHERE}
77+
--- ./{WHERE}
78+
+++ ./{WHERE}
7979
@@ -18,6 +18,7 @@
8080
8181
@@ -86,8 +86,8 @@ def fn(x):
8686
8787
'''
8888
CASES_PATCH_BODY = f'''\
89-
--- {WHERE}
90-
+++ {WHERE}
89+
--- ./{WHERE}
90+
+++ ./{WHERE}
9191
@@ -25,6 +25,9 @@
9292
class Cases:
9393
@example(n=0, label="whatever")
@@ -98,8 +98,8 @@ def mth(self, n, label):
9898
9999
'''
100100
TOPLEVEL_PATCH_BODY = f'''\
101-
--- {WHERE_TOP}
102-
+++ {WHERE_TOP}
101+
--- ./{WHERE_TOP}
102+
+++ ./{WHERE_TOP}
103103
@@ -19,5 +19,6 @@
104104
105105
@@ -109,8 +109,8 @@ def fn_top(x):
109109
"""A trivial test function."""
110110
'''
111111
COVERING_PATCH_BODY = f'''\
112-
--- {WHERE}
113-
+++ {WHERE}
112+
--- ./{WHERE}
113+
+++ ./{WHERE}
114114
@@ -31,7 +31,7 @@
115115
116116
@given(st.integers())

0 commit comments

Comments
 (0)