Skip to content
Snippets Groups Projects
Commit daf549e4 authored by Chris Lamb's avatar Chris Lamb :eyes:
Browse files

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

parent 74a59a8f
No related branches found
No related tags found
No related merge requests found
......@@ -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),
)
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment