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

Consider formatting multiline strings differently #164

Open
RazerM opened this issue Sep 28, 2022 · 0 comments
Open

Consider formatting multiline strings differently #164

RazerM opened this issue Sep 28, 2022 · 0 comments

Comments

@RazerM
Copy link

RazerM commented Sep 28, 2022

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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant