diff options
author | Mario Šaško <mariosasko777@gmail.com> | 2024-10-22 20:42:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-22 20:42:22 (GMT) |
commit | 34653bba644aa5481613f398153757d7357e39ea (patch) | |
tree | 837d85c45083e45145b2fc885a954856f7e8bda5 /Lib/test | |
parent | aaed91cabcedc16c089c4b1c9abb1114659a83d3 (diff) | |
download | cpython-34653bba644aa5481613f398153757d7357e39ea.zip cpython-34653bba644aa5481613f398153757d7357e39ea.tar.gz cpython-34653bba644aa5481613f398153757d7357e39ea.tar.bz2 |
gh-125259: Fix error notes removal in enum initialization (GH-125647)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_enum.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 7184769..b9e13fb 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -1888,6 +1888,25 @@ class TestSpecial(unittest.TestCase): class Wrong(Enum, str): NotHere = 'error before this point' + def test_raise_custom_error_on_creation(self): + class InvalidRgbColorError(ValueError): + def __init__(self, r, g, b): + self.r = r + self.g = g + self.b = b + super().__init__(f'({r}, {g}, {b}) is not a valid RGB color') + + with self.assertRaises(InvalidRgbColorError): + class RgbColor(Enum): + RED = (255, 0, 0) + GREEN = (0, 255, 0) + BLUE = (0, 0, 255) + INVALID = (256, 0, 0) + + def __init__(self, r, g, b): + if not all(0 <= val <= 255 for val in (r, g, b)): + raise InvalidRgbColorError(r, g, b) + def test_intenum_transitivity(self): class number(IntEnum): one = 1 |