forked from pytest-dev/pytest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make dataclasses/attrs comparison recursive, fixes pytest-dev#4675
- Loading branch information
1 parent
3de85a9
commit e2e7f15
Showing
4 changed files
with
142 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Make dataclasses/attrs comparison recursive. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
testing/example_scripts/dataclasses/test_compare_recursive_dataclasses.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from dataclasses import dataclass | ||
from dataclasses import field | ||
|
||
|
||
@dataclass | ||
class SimpleDataObject: | ||
field_a: int = field() | ||
field_b: int = field() | ||
|
||
|
||
@dataclass | ||
class ComplexDataObject2: | ||
field_a: SimpleDataObject = field() | ||
field_b: SimpleDataObject = field() | ||
|
||
|
||
@dataclass | ||
class ComplexDataObject: | ||
field_a: SimpleDataObject = field() | ||
field_b: ComplexDataObject2 = field() | ||
|
||
|
||
def test_recursive_dataclasses(): | ||
|
||
left = ComplexDataObject( | ||
SimpleDataObject(1, "b"), | ||
ComplexDataObject2(SimpleDataObject(1, "b"), SimpleDataObject(2, "c"),), | ||
) | ||
right = ComplexDataObject( | ||
SimpleDataObject(1, "b"), | ||
ComplexDataObject2(SimpleDataObject(1, "b"), SimpleDataObject(3, "c"),), | ||
) | ||
|
||
assert left == right |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters