Skip to content

Commit

Permalink
wip: python difflib
Browse files Browse the repository at this point in the history
  • Loading branch information
iamogbz committed Jan 2, 2020
1 parent 6035f26 commit b02db82
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions src/syrupy/serializers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
ABC,
abstractmethod,
)
from itertools import zip_longest
from difflib import ndiff
from typing import (
TYPE_CHECKING,
List,
Expand All @@ -20,12 +20,6 @@
SnapshotFile,
)
from syrupy.exceptions import SnapshotDoesNotExist
from syrupy.terminal import (
error_style,
green,
red,
success_style,
)


if TYPE_CHECKING:
Expand Down Expand Up @@ -194,17 +188,6 @@ def _write_snapshot_to_file(self, snapshot_file: "SnapshotFile") -> None:
def diff_lines(
self, serialized_data: "SerializedData", snapshot_data: "SerializedData"
) -> List[str]:
received = serialized_data.splitlines()
stored = snapshot_data.splitlines()
marker_received = error_style("+")
marker_stored = success_style("-")
diff = []
for received_line, stored_line in zip_longest(received, stored):
if received_line is None:
diff.append(f"{marker_stored} {green(stored_line)}")
elif stored_line is None:
diff.append(f"{marker_received} {red(received_line)}")
elif received_line != stored_line:
diff.append(f"{marker_stored} {green(stored_line)}")
diff.append(f"{marker_received} {red(received_line)}")
return diff
received = str(serialized_data).splitlines()
stored = str(snapshot_data).splitlines()
return list(ndiff(stored, received))

0 comments on commit b02db82

Please sign in to comment.