(self)
| 374 | self.assertGreaterEqual(C(), C()) |
| 375 | |
| 376 | def test_1_field_compare(self): |
| 377 | # Ensure that order=False is the default. |
| 378 | @dataclass |
| 379 | class C0: |
| 380 | x: int |
| 381 | |
| 382 | @dataclass(order=False) |
| 383 | class C1: |
| 384 | x: int |
| 385 | |
| 386 | for cls in [C0, C1]: |
| 387 | with self.subTest(cls=cls): |
| 388 | self.assertEqual(cls(1), cls(1)) |
| 389 | self.assertNotEqual(cls(0), cls(1)) |
| 390 | for idx, fn in enumerate([lambda a, b: a < b, |
| 391 | lambda a, b: a <= b, |
| 392 | lambda a, b: a > b, |
| 393 | lambda a, b: a >= b]): |
| 394 | with self.subTest(idx=idx): |
| 395 | with self.assertRaisesRegex(TypeError, |
| 396 | f"not supported between instances of '{cls.__name__}' and '{cls.__name__}'"): |
| 397 | fn(cls(0), cls(0)) |
| 398 | |
| 399 | @dataclass(order=True) |
| 400 | class C: |
| 401 | x: int |
| 402 | self.assertLess(C(0), C(1)) |
| 403 | self.assertLessEqual(C(0), C(1)) |
| 404 | self.assertLessEqual(C(1), C(1)) |
| 405 | self.assertGreater(C(1), C(0)) |
| 406 | self.assertGreaterEqual(C(1), C(0)) |
| 407 | self.assertGreaterEqual(C(1), C(1)) |
| 408 | |
| 409 | def test_simple_compare(self): |
| 410 | # Ensure that order=False is the default. |
nothing calls this directly
no test coverage detected