Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/syrupy/extensions/amber/serializer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import collections
import inspect
import textwrap
from collections import OrderedDict
from collections.abc import Callable, Generator, Iterable
from types import (
Expand Down Expand Up @@ -184,6 +185,9 @@ def __read_file_with_markers(
snapshot_data = ""
elif test_name is not None and line.startswith(cls._indent):
snapshot_data += line[indent_len:]
elif test_name is not None and line.strip() == "":
# Remove trailing whitespace (but not newline character) from empty line.
snapshot_data += textwrap.dedent(line)
except FileNotFoundError:
pass
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
Line2

Line3

# ---
# name: test_multiline_repr_with_no_indentation
Line1
Line2

Line3

# ---
# name: test_trailing_2_newlines_in_repr
ReprWithNewline
Expand Down
7 changes: 7 additions & 0 deletions tests/syrupy/extensions/amber/test_amber_newlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ def __repr__(self) -> str:
"Line1",
"Line2\n", # extra newline
"Line3 ", # with an extra space
"", # newline at end
]
)


def test_multiline_repr(snapshot):
assert MultilineRepr() == snapshot


def test_multiline_repr_with_no_indentation(snapshot):
# snapshot file has been manually edited
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Syrupy amber snapshots are an exact representation of the data being snapshotted. We can't ignore trailing newlines, see the comments I left in the linked issue.

# remove newlines from this test if you update the snapshot
assert MultilineRepr() == snapshot
Loading