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

Method test_0_field_compare

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

Source from the content-addressed store, hash-verified

346 self.assertEqual(getattr(c, name), name)
347
348 def test_0_field_compare(self):
349 # Ensure that order=False is the default.
350 @dataclass
351 class C0:
352 pass
353
354 @dataclass(order=False)
355 class C1:
356 pass
357
358 for cls in [C0, C1]:
359 with self.subTest(cls=cls):
360 self.assertEqual(cls(), cls())
361 for idx, fn in enumerate([lambda a, b: a < b,
362 lambda a, b: a <= b,
363 lambda a, b: a > b,
364 lambda a, b: a >= b]):
365 with self.subTest(idx=idx):
366 with self.assertRaisesRegex(TypeError,
367 f"not supported between instances of '{cls.__name__}' and '{cls.__name__}'"):
368 fn(cls(), cls())
369
370 @dataclass(order=True)
371 class C:
372 pass
373 self.assertLessEqual(C(), C())
374 self.assertGreaterEqual(C(), C())
375
376 def test_1_field_compare(self):
377 # Ensure that order=False is the default.

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected