(self)
| 461 | self.assertTrue(fn(C(1, 1), C(1, 0))) |
| 462 | |
| 463 | def test_compare_subclasses(self): |
| 464 | # Comparisons fail for subclasses, even if no fields |
| 465 | # are added. |
| 466 | @dataclass |
| 467 | class B: |
| 468 | i: int |
| 469 | |
| 470 | @dataclass |
| 471 | class C(B): |
| 472 | pass |
| 473 | |
| 474 | for idx, (fn, expected) in enumerate([(lambda a, b: a == b, False), |
| 475 | (lambda a, b: a != b, True)]): |
| 476 | with self.subTest(idx=idx): |
| 477 | self.assertEqual(fn(B(0), C(0)), expected) |
| 478 | |
| 479 | for idx, fn in enumerate([lambda a, b: a < b, |
| 480 | lambda a, b: a <= b, |
| 481 | lambda a, b: a > b, |
| 482 | lambda a, b: a >= b]): |
| 483 | with self.subTest(idx=idx): |
| 484 | with self.assertRaisesRegex(TypeError, |
| 485 | "not supported between instances of 'B' and 'C'"): |
| 486 | fn(B(0), C(0)) |
| 487 | |
| 488 | def test_eq_order(self): |
| 489 | # Test combining eq and order. |
nothing calls this directly
no test coverage detected