Skip to content

gh-105522: Correctly handle possible exceptions in Enum creation in test_enum #105523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 16, 2023

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Jun 8, 2023

@sobolevn sobolevn changed the title gh-105522: Simplify test_enum by removing extra exception handling gh-105522: Correctly handle possible exceptions in Enum creation in test_enum Jun 12, 2023
@sobolevn
Copy link
Member Author

Here's how a potential exception looks like:

======================================================================
ERROR: test_pickle_enum (test.test_enum.TestSpecial.test_pickle_enum)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython/Lib/test/test_enum.py", line 1458, in test_pickle_enum
    raise Stooges
  File "/Users/sobolev/Desktop/cpython/Lib/test/test_enum.py", line 65, in <module>
    class Stooges(Enum):
  File "/Users/sobolev/Desktop/cpython/Lib/enum.py", line 494, in __prepare__
    raise RuntimeError('Exc', cls)
RuntimeError: ('Exc', 'Stooges')

And here's how it looks if there are multiple exceptions:

======================================================================
ERROR: test_floatenum_fromhex (test.test_enum.TestSpecial.test_floatenum_fromhex)
----------------------------------------------------------------------
  + Exception Group Traceback (most recent call last):
  |   File "/Users/sobolev/Desktop/cpython/Lib/test/test_enum.py", line 55, in inner
  |     raise ExceptionGroup('Enum Exceptions', excs)
  | ExceptionGroup: Enum Exceptions (2 sub-exceptions)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/Users/sobolev/Desktop/cpython/Lib/test/test_enum.py", line 81, in <module>
    |     class FloatStooges(float, Enum):
    |   File "/Users/sobolev/Desktop/cpython/Lib/enum.py", line 494, in __prepare__
    |     raise RuntimeError('Exc', cls)
    | RuntimeError: ('Exc', 'FloatStooges')
    +---------------- 2 ----------------
    | Traceback (most recent call last):
    |   File "/Users/sobolev/Desktop/cpython/Lib/test/test_enum.py", line 108, in <module>
    |     class IntFlagStooges(IntFlag):
    |   File "/Users/sobolev/Desktop/cpython/Lib/enum.py", line 494, in __prepare__
    |     raise RuntimeError('Exc', cls)
    | RuntimeError: ('Exc', 'IntFlagStooges')
    +------------------------------------

@sobolevn
Copy link
Member Author

@ethanfurman friendly ping :)

@sobolevn
Copy link
Member Author

@ethanfurman friendly ping (x2) 😄

Copy link
Member

@ethanfurman ethanfurman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor change and it looks good!

@@ -38,6 +38,25 @@ def load_tests(loader, tests, ignore):
))
return tests

def reraise_enum_exceptions(*enum_types_or_exceptions):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def reraise_enum_exceptions(*enum_types_or_exceptions):
def reraise_if_not_enum(*enum_types_or_exceptions):

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! 👍

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@sobolevn
Copy link
Member Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@ethanfurman: please review the changes made to this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants