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

Preserve values #56

Merged
merged 17 commits into from
Apr 9, 2024
Merged

Preserve values #56

merged 17 commits into from
Apr 9, 2024

Conversation

15r10nk
Copy link
Owner

@15r10nk 15r10nk commented Mar 9, 2024

Fix incorrect values and preserve correct values in the same structure.

This will allow to combine inline-snapshot with libraries like dirty-equals.

Features:

  • compares lists, dicts and tuples recursively
  • changes only the code which has a different value (with fix)
  • updates only the parts which have a different representation (with update)
  • lists and tuples are aligned (like in a source diff) and the algorithm tries to maximizes the number of matching values.

@15r10nk
Copy link
Owner Author

15r10nk commented Mar 22, 2024

hi @alexmojaki,

This is the upcoming feature which supports the combination of dirty-equals with inline-snapshots. You could help me with testing this branch for your use cases.

@alexmojaki
Copy link

Thanks. I just tried it and found a problem: the order of dict items is not preserved. The code gets updated to reflect the order of the actual value, whereas I'd prefer it used the order in the existing snapshot code where possible, at least for fix (as opposed to update).

@15r10nk
Copy link
Owner Author

15r10nk commented Mar 25, 2024

the order in the following example is preserved:

from inline_snapshot import snapshot


def test_function():
    assert {2: 3, 1: 5} == snapshot({1: 5, 2: 6})

pytest --inline-snapshot=fix

from inline_snapshot import snapshot


def test_function():
    assert {2: 3, 1: 5} == snapshot({1: 5, 2: 3})

I think I implemented the behavior which you described. Changing the order with update is currently not implemented.

Can you give me an example where inline-snapshot does not what you want it to do?

@alexmojaki
Copy link

OK, I think the problem is just that I should have uninstalled inline-snapshot before running pip install git+https://github.com/15r10nk/inline-snapshot.git@preserve-values .

@15r10nk
Copy link
Owner Author

15r10nk commented Mar 27, 2024

hi @alexmojaki,

I'm pretty much done with the implementation (documentation still missing). I changed almost the complete implementation and you could do me a favor if you could use the last version of this branch to test it.

@15r10nk 15r10nk force-pushed the preserve-values branch 3 times, most recently from e285058 to e6d041a Compare April 3, 2024 20:34
Copy link

@alexmojaki alexmojaki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been using this branch without problems, including in snapshots that contain non-dirty-equals variable expressions. I'm very excited for this to be released and to tell my coworkers about it!

docs/eq_snapshot.md Show resolved Hide resolved
docs/eq_snapshot.md Show resolved Hide resolved
docs/eq_snapshot.md Show resolved Hide resolved
@15r10nk 15r10nk merged commit 9419055 into main Apr 9, 2024
26 checks passed
@15r10nk 15r10nk deleted the preserve-values branch April 9, 2024 10:01
@15r10nk
Copy link
Owner Author

15r10nk commented Apr 9, 2024

@alexmojaki, 0.8.0 has been released. Thank you very much for your feedback. I will clarify the different flags soon when I revise some parts of the documentation.

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

Successfully merging this pull request may close these issues.

2 participants