-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix: assertrepr_compare respects dict insertion order #14050
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Assertion comparison output now preserves dictionary insertion order instead of sorting keys. | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -192,3 +192,31 @@ def __repr__(self): | |||||||||||||||||
| assert saferepr_unlimited(A()).startswith( | ||||||||||||||||||
| "<[ValueError(42) raised in repr()] A object at 0x" | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def test_saferepr_dict_preserves_insertion_order(): | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add type annotations to the tests ( |
||||||||||||||||||
| d = {"b": 1, "a": 2} | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we have more keys here just for safety?
Suggested change
|
||||||||||||||||||
| assert saferepr(d, maxsize=None) == "{'b': 1, 'a': 2}" | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def test_saferepr_dict_truncation_preserves_insertion_order(): | ||||||||||||||||||
| from _pytest._io.saferepr import SafeRepr | ||||||||||||||||||
|
|
||||||||||||||||||
| d = {"b": 1, "a": 2} | ||||||||||||||||||
| s = SafeRepr(maxsize=None) | ||||||||||||||||||
| s.maxdict = 1 | ||||||||||||||||||
| assert s.repr(d) == "{'b': 1, ...}" | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def test_saferepr_dict_fillvalue_when_level_is_zero(): | ||||||||||||||||||
| from _pytest._io.saferepr import SafeRepr | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move these imports from local to global. |
||||||||||||||||||
|
|
||||||||||||||||||
| s = SafeRepr(maxsize=None) | ||||||||||||||||||
| assert s.repr_dict({"a": 1}, level=0) == "{...}" | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def test_saferepr_dict_empty(): | ||||||||||||||||||
| from _pytest._io.saferepr import SafeRepr | ||||||||||||||||||
|
|
||||||||||||||||||
| s = SafeRepr(maxsize=None) | ||||||||||||||||||
| assert s.repr_dict({}, level=1) == "{}" | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please also add an integration test like the one suggested in #14066 (comment)? Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.