Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: v0.4.0 - Amber serializer changes #192

Merged
merged 2 commits into from
Apr 19, 2020
Merged
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
8 changes: 6 additions & 2 deletions src/syrupy/extensions/amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,12 @@ def serialize_string(
if "\n" in data:
return (
cls.with_indent("'\n", depth)
+ str(data)
+ cls.with_indent("\n'", depth)
+ "".join(
cls.with_indent(line, depth + 1 if depth else depth)
for line in str(data).splitlines(keepends=True)
)
+ "\n"
+ cls.with_indent("'", depth)
)
return cls.with_indent(repr(data), depth)

Expand Down
19 changes: 19 additions & 0 deletions tests/__snapshots__/test_extension_amber.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@
'd': ...,
}
---
# name: test_deeply_nested_multiline_string_in_dict
<class 'dict'> {
'value_a': <class 'dict'> {
'value_b': '
line 1
line 2
line 3
',
},
}
---
# name: test_dict[actual0]
<class 'dict'> {
'a': <class 'dict'> {
Expand Down Expand Up @@ -160,6 +171,14 @@
},
]
---
# name: test_multiline_string_in_dict
<class 'dict'> {
'value': '
line 1
line 2
',
}
---
# name: test_multiple_snapshots
'First.'
---
Expand Down
11 changes: 11 additions & 0 deletions tests/test_extension_amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ def test_newline_control_characters(snapshot):
assert snapshot == "line 1\r\nline 2\r\n"


def test_multiline_string_in_dict(snapshot):
lines = "\n".join(["line 1", "line 2"])
assert {"value": lines} == snapshot


def test_deeply_nested_multiline_string_in_dict(snapshot):
lines = "\n".join(["line 1", "line 2", "line 3"])
d = {"value_a": {"value_b": lines}}
assert d == snapshot


@pytest.mark.parametrize("actual", [False, True])
def test_bool(actual, snapshot):
assert actual == snapshot
Expand Down