-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
bpo-46301: remove refleak from Enum tests
#30510
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 1 commit
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 |
|---|---|---|
|
|
@@ -4449,6 +4449,12 @@ def test__all__(self): | |
| COMPLEX_A = 2j | ||
| COMPLEX_B = 3j | ||
|
|
||
| class _ModuleWrapper: | ||
| """We use this class as a namespace for swapping modules.""" | ||
|
|
||
| def __init__(self, module): | ||
| self.__dict__.update(module.__dict__) | ||
|
|
||
| class TestIntEnumConvert(unittest.TestCase): | ||
| def setUp(self): | ||
| # Reset the module-level test variables to their original integer | ||
|
|
@@ -4487,11 +4493,17 @@ def test_convert(self): | |
| [], msg='Names other than CONVERT_TEST_* found.') | ||
|
|
||
| def test_convert_uncomparable(self): | ||
| uncomp = enum.Enum._convert_( | ||
| 'Uncomparable', | ||
| MODULE, | ||
| filter=lambda x: x.startswith('UNCOMPARABLE_'), | ||
| ) | ||
| # We swap a module to some other object with `__dict__` | ||
| # because otherwise refleak is created. | ||
| # `_convert_` uses a module side effect that does this. See 30472 | ||
| with support.swap_item( | ||
| sys.modules, MODULE, _ModuleWrapper(sys.modules[MODULE]), | ||
| ): | ||
|
||
| uncomp = enum.Enum._convert_( | ||
| 'Uncomparable', | ||
| MODULE, | ||
| filter=lambda x: x.startswith('UNCOMPARABLE_'), | ||
| ) | ||
|
|
||
| # Should be ordered by `name` only: | ||
| self.assertEqual( | ||
|
|
@@ -4500,11 +4512,14 @@ def test_convert_uncomparable(self): | |
| ) | ||
|
|
||
| def test_convert_complex(self): | ||
| uncomp = enum.Enum._convert_( | ||
| 'Uncomparable', | ||
| MODULE, | ||
| filter=lambda x: x.startswith('COMPLEX_'), | ||
| ) | ||
| with support.swap_item( | ||
| sys.modules, MODULE, _ModuleWrapper(sys.modules[MODULE]), | ||
| ): | ||
| uncomp = enum.Enum._convert_( | ||
| 'Uncomparable', | ||
| MODULE, | ||
| filter=lambda x: x.startswith('COMPLEX_'), | ||
| ) | ||
|
|
||
| # Should be ordered by `name` only: | ||
| self.assertEqual( | ||
|
|
||
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.
I like this. Please switch over the other
_convert_tests to use it, which will allow the removal of thesetUp()methods in those tests.