How to use the patchy.unpatch function in patchy

To help you get started, we’ve selected a few patchy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adamchainz / patchy / tests / test_patch_then_unpatch.py View on Github external
"""

    patchy.patch(sample, patch_text)
    assert sample() == 9001

    # Check that we use the cache
    orig_mkdtemp = patchy.api.mkdtemp

    def mkdtemp(*args, **kwargs):
        raise AssertionError(
            "mkdtemp should not be called, the unpatch should be cached."
        )

    try:
        patchy.api.mkdtemp = mkdtemp
        patchy.unpatch(sample, patch_text)
    finally:
        patchy.api.mkdtemp = orig_mkdtemp
    assert sample() == 1

    # Check that we use the cache going forwards again
    try:
        patchy.api.mkdtemp = mkdtemp
        patchy.patch(sample, patch_text)
    finally:
        patchy.api.mkdtemp = orig_mkdtemp
    assert sample() == 9001
github adamchainz / patchy / tests / test_unpatch.py View on Github external
def test_unpatch_invalid_unreversed():
    """
    We need to balk on patches that fail on application
    """

    def sample():
        return 1

    # This patch would make sense forwards but doesn't backwards
    bad_patch = """\
        @@ -1,2 +1,2 @@
         def sample():
        -    return 1
        +    return 2"""
    with pytest.raises(ValueError) as excinfo:
        patchy.unpatch(sample, bad_patch)

    assert "Unreversed patch detected!" in str(excinfo.value)
    assert sample() == 1
github adamchainz / patchy / tests / test_unpatch.py View on Github external
def test_unpatch_invalid_hunk():
    """
    We need to balk on patches that fail on application
    """

    def sample():
        return 1

    # This patch would make sense forwards but doesn't backwards
    bad_patch = """\
        @@ -1,2 +1,2 @@
         def sample():
        -    return 3
        +    return 2"""
    with pytest.raises(ValueError) as excinfo:
        patchy.unpatch(sample, bad_patch)

    assert "Hunk #1 FAILED" in str(excinfo.value)
    assert sample() == 1
github adamchainz / patchy / tests / test_unpatch.py View on Github external
def test_unpatch():
    def sample():
        return 9001

    patchy.unpatch(
        sample,
        """\
        @@ -1,2 +1,2 @@
         def sample():
        -    return 1
        +    return 9001
        """,
    )
    assert sample() == 1