Skip to content

Commit 9ec5dc3

Browse files
committed
Add tests for ordering with dataclass fields, including compare=False
1 parent 2443aa9 commit 9ec5dc3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Lib/test/test_dataclasses/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,16 @@ class C:
406406
self.assertGreaterEqual(C(1), C(0))
407407
self.assertGreaterEqual(C(1), C(1))
408408

409+
@dataclass(order=True)
410+
class C2:
411+
x: int
412+
y: int = field(compare=False)
413+
414+
self.assertLess(C2(0, 10), C2(1, -5))
415+
self.assertLessEqual(C2(1, 10), C2(1, -5))
416+
self.assertGreater(C2(2, -1), C2(1, 999))
417+
self.assertGreaterEqual(C2(1, 10), C2(1, -5))
418+
409419
def test_simple_compare(self):
410420
# Ensure that order=False is the default.
411421
@dataclass

0 commit comments

Comments
 (0)