Skip to content

Consider formatting multiline strings differently #164

@RazerM

Description

@RazerM

Here's an example of how the snapshot is currently formatted:

snapshots['test_foo 1'] = '''ID                                   Name         Description
------------------------------------ ------------ -------------------------------
32fd8c27-9110-463f-89c0-eb676814923a Item 1       An item with a long description
32fd8c27-9110-463f-89c0-eb676814923a Item 2
32fd8c27-9110-463f-89c0-eb676814923a Another item
'''

I think the following is better for reviewing the snapshots, and is the exact same string:

snapshots['test_foo 1'] = '''\
ID                                   Name         Description
------------------------------------ ------------ -------------------------------
32fd8c27-9110-463f-89c0-eb676814923a Item 1       An item with a long description
32fd8c27-9110-463f-89c0-eb676814923a Item 2
32fd8c27-9110-463f-89c0-eb676814923a Another item
'''

I can provide a PR if this would be accepted

In the meantime, I'm using

from snapshottest.formatter import Formatter
from snapshottest.formatters import TypeFormatter, format_str


def format_str_custom(value, indent, formatter):
    formatted = format_str(value, indent, formatter)
    return re.sub(r"^(['\"]{3})(.*)", r"\1\\\n\2", formatted)


Formatter.register_formatter(TypeFormatter((str,), format_str_custom))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions