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

Add deep unordered for nested data structures #17

Merged
merged 2 commits into from
Sep 18, 2024

Conversation

arminfriedl
Copy link

Automatically applies unordered to nested elements in complicated data structures.

Automatically applies `unordered` to nested elements in complicated
data structures.
Copy link

codecov bot commented Sep 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (9efae14) to head (46c7512).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #17   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           93        99    +6     
  Branches        21        25    +4     
=========================================
+ Hits            93        99    +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

tests/test_unordered.py Outdated Show resolved Hide resolved
@Mogost Mogost requested review from utapyngo and removed request for Mogost September 18, 2024 10:07
@utapyngo
Copy link
Owner

@arminfriedl, what will you use this for? Can you give a concrete example?

@arminfriedl
Copy link
Author

Yes sure - we compare serialized database states (query results) with expected database states (query results). They sometimes contain nested dicts-with-lists-of-dicts-... (you get the idea). There are many of these were there is no "order by" in the query hence order is not really part of the assertion. And the order also does happen to change. We could apply current unordered manually to the expected data, but it is quite cumbersome to do it fine grained in deeply nested structures.

Another case are integration tests for REST responses where we have similar issues. Even though the JSON data contains lists-of-dicts-of-dicts-of-lists-... (again you get the idea), the order of the elements is sometimes irrelevant and an implementation detail which may (and does) change.

Right now we have this helper function to apply unordered recursively in our own code. I do think however the better place for this is upstream. At the end one can choose to use the fine-grained regular unordered or the coarse-grained, recursive unordered_deep, depending on the test case and the data structure.

@utapyngo utapyngo merged commit 886cb62 into utapyngo:master Sep 18, 2024
29 checks passed
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.

3 participants