MCPcopy Index your code
hub / github.com/python/cpython / test_compare_subclasses

Method test_compare_subclasses

Lib/test/test_dataclasses/__init__.py:463–486  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 7

subTestMethod · 0.95
assertEqualMethod · 0.95
assertRaisesRegexMethod · 0.95
enumerateFunction · 0.85
fnFunction · 0.85
BClass · 0.70
CClass · 0.70

Tested by

no test coverage detected