Commit daf549e4 authored by Chris Lamb's avatar Chris Lamb 👀
Browse files

Split out a custom call to assert_diff for a .startswith equivalent.

parent 74a59a8f
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ import sys

from diffoscope.comparators.python import PycFile

from ..utils.data import assert_diff, load_fixture
from ..utils.data import assert_diff_startswith, load_fixture


pyc1 = load_fixture("test1.pyc-renamed")
@@ -47,8 +47,7 @@ def differences(pyc1, pyc2):


def test_diff(differences):
    assert_diff(
    assert_diff_startswith(
        differences[0],
        "pyc_expected_diff",
        lambda haystack, needle: haystack.startswith(needle),
    )
+8 −2
Original line number Diff line number Diff line
@@ -56,12 +56,18 @@ def get_data(filename):
        return f.read()


def assert_diff(difference, filename, cmp=lambda x, y: x == y):
def assert_diff(difference, filename):
    # Assign seen and expected values to local variables to improve contextual
    # information in failed tests.
    seen = difference.unified_diff
    expected = get_data(filename)
    assert cmp(seen, expected)
    assert seen == expected


def assert_diff_startswith(difference, filename):
    haystack = difference.unified_diff
    needle = get_data(filename)
    assert needle.startswith(haystack)


# https://code.activestate.com/recipes/576620-changedirectory-context-manager/#c3