Skip to content

Commit

Permalink
diff.py(diff): make number of context lines configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
glacambre committed Dec 18, 2023
1 parent abf72fb commit e580ba5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/e3/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def diff(
item1name: str = "expected",
item2name: str = "output",
ignore_white_chars: bool = True,
context: int = 1,
) -> str:
"""Compute diff between two files or list of strings.
Expand All @@ -48,6 +49,7 @@ def diff(
:param item2name: name to display for b in the diff
:param ignore_white_chars: if True (default) then empty lines,
trailing and leading white chars on each line are ignored
:param context: number of context lines to add to the diff
:return: A diff string. If the string is equal to '' it means that there
is no difference
Expand Down Expand Up @@ -92,7 +94,9 @@ def diff(
line for line in contents[k] if re.search(ignore, line) is None
]

return "".join(unified_diff(contents[0], contents[1], item1name, item2name, n=1))
return "".join(
unified_diff(contents[0], contents[1], item1name, item2name, n=context)
)


def patch(
Expand Down

0 comments on commit e580ba5

Please sign in to comment.