[Python-checkins] bpo-2661: Make mapping tests better usable for custom mapping classes. (GH-11157)
Miss Islington (bot)
webhook-mailer at python.org
Thu Jun 6 06:13:14 EDT 2019
https://github.com/python/cpython/commit/6af230359e57122708247dac970e05e05529cde6
commit: 6af230359e57122708247dac970e05e05529cde6
branch: master
author: Walter Dörwald <walter at livinglogic.de>
committer: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
date: 2019-06-06T03:13:08-07:00
summary:
bpo-2661: Make mapping tests better usable for custom mapping classes. (GH-11157)
In test_fromkeys() the derived test class now supports all arguments in its
constructor so that the class to be tested can use its own constructor in its
fromkeys() implementation.
In test_mutatingiteration() the test fails as soon as iterating over a
dictionary with one entry and adding new entries in the loop iterates more
than once (to avoid endless loops in faulty implementations).
https://bugs.python.org/issue2661
files:
M Lib/test/mapping_tests.py
diff --git a/Lib/test/mapping_tests.py b/Lib/test/mapping_tests.py
index 53f29f605386..613206a0855a 100644
--- a/Lib/test/mapping_tests.py
+++ b/Lib/test/mapping_tests.py
@@ -448,7 +448,7 @@ def __new__(cls):
class Exc(Exception): pass
class baddict1(self.type2test):
- def __init__(self):
+ def __init__(self, *args, **kwargs):
raise Exc()
self.assertRaises(Exc, baddict1.fromkeys, [1])
@@ -595,12 +595,14 @@ def test_mutatingiteration(self):
d = self._empty_mapping()
d[1] = 1
try:
+ count = 0
for i in d:
d[i+1] = 1
+ if count >= 1:
+ self.fail("changing dict size during iteration doesn't raise Error")
+ count += 1
except RuntimeError:
pass
- else:
- self.fail("changing dict size during iteration doesn't raise Error")
def test_repr(self):
d = self._empty_mapping()
More information about the Python-checkins
mailing list