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

Method test_eq_order

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

Source from the content-addressed store, hash-verified

486 fn(B(0), C(0))
487
488 def test_eq_order(self):
489 # Test combining eq and order.
490 for (eq, order, result ) in [
491 (False, False, 'neither'),
492 (False, True, 'exception'),
493 (True, False, 'eq_only'),
494 (True, True, 'both'),
495 ]:
496 with self.subTest(eq=eq, order=order):
497 if result == 'exception':
498 with self.assertRaisesRegex(ValueError, 'eq must be true if order is true'):
499 @dataclass(eq=eq, order=order)
500 class C:
501 pass
502 else:
503 @dataclass(eq=eq, order=order)
504 class C:
505 pass
506
507 if result == 'neither':
508 self.assertNotIn('__eq__', C.__dict__)
509 self.assertNotIn('__lt__', C.__dict__)
510 self.assertNotIn('__le__', C.__dict__)
511 self.assertNotIn('__gt__', C.__dict__)
512 self.assertNotIn('__ge__', C.__dict__)
513 elif result == 'both':
514 self.assertIn('__eq__', C.__dict__)
515 self.assertIn('__lt__', C.__dict__)
516 self.assertIn('__le__', C.__dict__)
517 self.assertIn('__gt__', C.__dict__)
518 self.assertIn('__ge__', C.__dict__)
519 elif result == 'eq_only':
520 self.assertIn('__eq__', C.__dict__)
521 self.assertNotIn('__lt__', C.__dict__)
522 self.assertNotIn('__le__', C.__dict__)
523 self.assertNotIn('__gt__', C.__dict__)
524 self.assertNotIn('__ge__', C.__dict__)
525 else:
526 assert False, f'unknown result {result!r}'
527
528 def test_field_no_default(self):
529 @dataclass

Callers

nothing calls this directly

Calls 4

subTestMethod · 0.95
assertRaisesRegexMethod · 0.95
assertNotInMethod · 0.95
assertInMethod · 0.95

Tested by

no test coverage detected