diff options
author | Stephen Morton <git@tungol.org> | 2024-11-11 07:08:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-11 07:08:58 (GMT) |
commit | 6ee542d491589b470ec7cdd353463ff9ff52d098 (patch) | |
tree | c000c0a3583a0d0a683ee8598c51e5c3f744b9ab /Lib/test/_test_multiprocessing.py | |
parent | 82269c7d580e1aad71ff11fe891cf7f97eb45703 (diff) | |
download | cpython-6ee542d491589b470ec7cdd353463ff9ff52d098.zip cpython-6ee542d491589b470ec7cdd353463ff9ff52d098.tar.gz cpython-6ee542d491589b470ec7cdd353463ff9ff52d098.tar.bz2 |
gh-126417: validate ABC methods on multiprocessing proxy types (#126454)
Checks that appropriate dunder __ methods exist on the dict and list proxy types.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Lib/test/_test_multiprocessing.py')
-rw-r--r-- | Lib/test/_test_multiprocessing.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index bcb024d..8329a84 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -2464,6 +2464,19 @@ class _TestContainers(BaseTestCase): a = self.list() self.assertIsInstance(a, collections.abc.MutableSequence) + # MutableSequence also has __iter__, but we can iterate over + # ListProxy using __getitem__ instead. Adding __iter__ to ListProxy + # would change the behavior of a list modified during iteration. + mutable_sequence_methods = ( + '__contains__', '__delitem__', '__getitem__', '__iadd__', + '__len__', '__reversed__', '__setitem__', 'append', + 'clear', 'count', 'extend', 'index', 'insert', 'pop', 'remove', + 'reverse', + ) + for name in mutable_sequence_methods: + with self.subTest(name=name): + self.assertTrue(callable(getattr(a, name))) + def test_list_iter(self): a = self.list(list(range(10))) it = iter(a) @@ -2508,6 +2521,15 @@ class _TestContainers(BaseTestCase): a = self.dict() self.assertIsInstance(a, collections.abc.MutableMapping) + mutable_mapping_methods = ( + '__contains__', '__delitem__', '__eq__', '__getitem__', '__iter__', + '__len__', '__ne__', '__setitem__', 'clear', 'get', 'items', + 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values', + ) + for name in mutable_mapping_methods: + with self.subTest(name=name): + self.assertTrue(callable(getattr(a, name))) + def test_dict_iter(self): d = self.dict() indices = list(range(65, 70)) |