| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -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 | ||
| Expand Down Expand Up | @@ -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_( | ||
|
Comment thread
Copy link
Copy Markdown
Member
Author
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityMoreover, _convert_ was not tested on plain Enum
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality_convert_ was not intended to be called on plain Enum -- it's purpose it to convert existing constants in a module to enums, and existing constants will already be str or int (or possibly something else, like complex).
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityChange the UNCOMPARABLE_* values as suggested above, and also add a test using a complex type.
Sorry, something went wrong.
All reactions
|
||
| '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): | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityAll we need for this test is for UNCOMPARABLE_* to be different types of values:
UNCOMPABLE_A = 5
UNCOMPABLE_C = (9, 4)
UNCOMPABLE_B = 'hello'
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.