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(amber): indent multiline strings, close #193 #194

Merged
merged 2 commits into from
Apr 17, 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
5 changes: 4 additions & 1 deletion src/syrupy/extensions/amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ def serialize_string(
if "\n" in data:
return (
cls.with_indent("'\n", depth)
+ str(data)
+ "".join(
cls.with_indent(line, depth + 1 if depth else depth)
for line in str(data).splitlines(keepends=True)
)
+ "\n"
+ cls.with_indent("'", depth)
)
Expand Down
17 changes: 14 additions & 3 deletions tests/__snapshots__/test_extension_amber.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,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 @@ -139,11 +150,11 @@
},
]
---
# name: test_list_in_dict
# name: test_multiline_string_in_dict
<class 'dict'> {
'value': '
line 1
line 2
line 1
line 2
',
}
---
Expand Down
8 changes: 7 additions & 1 deletion tests/test_extension_amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ def test_newline_control_characters(snapshot):
assert snapshot == "line 1\r\nline 2\r\n"


def test_list_in_dict(snapshot):
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