-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
bpo-46301: cover uncomparable values in Enum._convert_
#30472
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4440,6 +4440,15 @@ def test__all__(self): | |
CONVERT_STRING_TEST_NAME_E = 5 | ||
CONVERT_STRING_TEST_NAME_F = 5 | ||
|
||
# We also need values that cannot be compared: | ||
UNCOMPARABLE_A = 5 | ||
UNCOMPARABLE_C = (9, 1) # naming order is broken on purpose | ||
UNCOMPARABLE_B = 'value' | ||
|
||
COMPLEX_C = 1j | ||
COMPLEX_A = 2j | ||
COMPLEX_B = 3j | ||
|
||
class TestIntEnumConvert(unittest.TestCase): | ||
def setUp(self): | ||
# Reset the module-level test variables to their original integer | ||
|
@@ -4477,6 +4486,32 @@ def test_convert(self): | |
and name not in dir(IntEnum)], | ||
[], msg='Names other than CONVERT_TEST_* found.') | ||
|
||
def test_convert_uncomparable(self): | ||
uncomp = enum.Enum._convert_( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moreover, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change the |
||
'Uncomparable', | ||
MODULE, | ||
filter=lambda x: x.startswith('UNCOMPARABLE_'), | ||
) | ||
|
||
# Should be ordered by `name` only: | ||
self.assertEqual( | ||
list(uncomp), | ||
[uncomp.UNCOMPARABLE_A, uncomp.UNCOMPARABLE_B, uncomp.UNCOMPARABLE_C], | ||
) | ||
|
||
def test_convert_complex(self): | ||
uncomp = enum.Enum._convert_( | ||
'Uncomparable', | ||
MODULE, | ||
filter=lambda x: x.startswith('COMPLEX_'), | ||
) | ||
|
||
# Should be ordered by `name` only: | ||
self.assertEqual( | ||
list(uncomp), | ||
[uncomp.COMPLEX_A, uncomp.COMPLEX_B, uncomp.COMPLEX_C], | ||
) | ||
|
||
@unittest.skipUnless(python_version == (3, 8), | ||
'_convert was deprecated in 3.8') | ||
def test_convert_warn(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All we need for this test is for
UNCOMPARABLE_*
to be different types of values:UNCOMPABLE_A
= 5UNCOMPABLE_C
= (9, 4)UNCOMPABLE_B
= 'hello'