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

Method test_1_field_compare

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

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 12

subTestMethod · 0.95
assertEqualMethod · 0.95
assertNotEqualMethod · 0.95
assertRaisesRegexMethod · 0.95
assertLessMethod · 0.95
assertLessEqualMethod · 0.95
assertGreaterMethod · 0.95
assertGreaterEqualMethod · 0.95
enumerateFunction · 0.85
fnFunction · 0.85
CClass · 0.70
clsClass · 0.50

Tested by

no test coverage detected