Skip to content

Commit

Permalink
feat: bugfix, pass indent to multiline open tag, close #332 (#334)
Browse files Browse the repository at this point in the history
Using "feat" to force minor bump for serializer changes.
  • Loading branch information
Noah authored Aug 24, 2020
1 parent 791c704 commit 3b06a98
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/syrupy/extensions/amber/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ def __serialize_lines(
) -> str:
lines = ends.join(lines)
lines_end = "\n" if lines else ""
formatted_open_tag = (
open_tag if include_type else cls.with_indent(open_tag, depth)
)
formatted_close_tag = cls.with_indent(close_tag, depth)
return (
f"{cls.with_indent(cls.object_type(data), depth)} " if include_type else ""
) + f"{open_tag}\n{lines}{lines_end}{cls.with_indent(close_tag, depth)}"
) + f"{formatted_open_tag}\n{lines}{lines_end}{formatted_close_tag}"
40 changes: 40 additions & 0 deletions tests/__snapshots__/test_extension_amber.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,46 @@
<class 'dict'> {
}
---
# name: test_dict[actual4]
<class 'dict'> {
'key': <class 'list'> [
'
line1
line2
',
],
}
---
# name: test_dict[actual5]
<class 'dict'> {
'key': <class 'list'> [
1,
'
line1
line2
',
2,
'
line3
line4
',
],
}
---
# name: test_dict[actual6]
<class 'dict'> {
'key': <class 'list'> [
1,
<class 'list'> [
'
line1
line2
',
],
2,
],
}
---
# name: test_doubly_parametrized[bar-foo]
'foo'
---
Expand Down
3 changes: 3 additions & 0 deletions tests/test_extension_amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def test_set(snapshot, actual):
ExampleTuple(a=1, b=2, c=3, d=4): {"e": False},
},
{},
{"key": ["line1\nline2"]},
{"key": [1, "line1\nline2", 2, "line3\nline4"]},
{"key": [1, ["line1\nline2"], 2]},
],
)
def test_dict(snapshot, actual):
Expand Down

0 comments on commit 3b06a98

Please sign in to comment.