(self)
| 2737 | raise Exception('Exception not raised.') |
| 2738 | |
| 2739 | def test_missing_override(self): |
| 2740 | class Color(Enum): |
| 2741 | red = 1 |
| 2742 | green = 2 |
| 2743 | blue = 3 |
| 2744 | @classmethod |
| 2745 | def _missing_(cls, item): |
| 2746 | if item == 'three': |
| 2747 | return cls.blue |
| 2748 | elif item == 'bad return': |
| 2749 | # trigger internal error |
| 2750 | return 5 |
| 2751 | elif item == 'error out': |
| 2752 | raise ZeroDivisionError |
| 2753 | else: |
| 2754 | # trigger not found |
| 2755 | return None |
| 2756 | self.assertIs(Color('three'), Color.blue) |
| 2757 | try: |
| 2758 | Color(7) |
| 2759 | except ValueError as exc: |
| 2760 | self.assertTrue(exc.__context__ is None) |
| 2761 | else: |
| 2762 | raise Exception('Exception not raised.') |
| 2763 | try: |
| 2764 | Color('bad return') |
| 2765 | except TypeError as exc: |
| 2766 | self.assertTrue(isinstance(exc.__context__, ValueError)) |
| 2767 | else: |
| 2768 | raise Exception('Exception not raised.') |
| 2769 | try: |
| 2770 | Color('error out') |
| 2771 | except ZeroDivisionError as exc: |
| 2772 | self.assertTrue(isinstance(exc.__context__, ValueError)) |
| 2773 | else: |
| 2774 | raise Exception('Exception not raised.') |
| 2775 | |
| 2776 | def test_missing_exceptions_reset(self): |
| 2777 | import gc |
nothing calls this directly
no test coverage detected