Skip to content

Commit

Permalink
Support git apply -p1 by default
Browse files Browse the repository at this point in the history
See #4116.
  • Loading branch information
Zac-HD committed Oct 5, 2024
1 parent a85e329 commit fa60b2a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 4 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RELEASE_TYPE: patch

This patch tweaks the paths in ``@example(...)`` patches, so that
both ``git apply`` and ``patch`` will work by default.
4 changes: 2 additions & 2 deletions hypothesis-python/src/hypothesis/extra/_patching.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ def make_patch(triples, *, msg="Hypothesis: add explicit examples", when=None):
ud = difflib.unified_diff(
source_before.splitlines(keepends=True),
source_after.splitlines(keepends=True),
fromfile=str(fname),
tofile=str(fname),
fromfile=f"./{fname}", # git strips the first part of the path by default
tofile=f"./{fname}",
)
diffs.append("".join(ud))
return "".join(diffs)
Expand Down
16 changes: 8 additions & 8 deletions hypothesis-python/tests/patching/test_patching.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def test_adds_simple_patch(tst, example, expected):


SIMPLE_PATCH_BODY = f'''\
--- {WHERE}
+++ {WHERE}
--- ./{WHERE}
+++ ./{WHERE}
@@ -18,6 +18,7 @@
Expand All @@ -86,8 +86,8 @@ def fn(x):
'''
CASES_PATCH_BODY = f'''\
--- {WHERE}
+++ {WHERE}
--- ./{WHERE}
+++ ./{WHERE}
@@ -25,6 +25,9 @@
class Cases:
@example(n=0, label="whatever")
Expand All @@ -98,8 +98,8 @@ def mth(self, n, label):
'''
TOPLEVEL_PATCH_BODY = f'''\
--- {WHERE_TOP}
+++ {WHERE_TOP}
--- ./{WHERE_TOP}
+++ ./{WHERE_TOP}
@@ -19,5 +19,6 @@
Expand All @@ -109,8 +109,8 @@ def fn_top(x):
"""A trivial test function."""
'''
COVERING_PATCH_BODY = f'''\
--- {WHERE}
+++ {WHERE}
--- ./{WHERE}
+++ ./{WHERE}
@@ -31,7 +31,7 @@
@given(st.integers())
Expand Down

0 comments on commit fa60b2a

Please sign in to comment.