This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Mapping tests cannot be passed by user implementations
Type: behavior Stage: resolved
Components: Library (Lib), Tests Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: doerwalter Nosy List: danderson, doerwalter, eric.araujo, miss-islington, rhettinger, serhiy.storchaka
Priority: low Keywords: patch

Created on 2008-04-19 22:09 by danderson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
mapping-tests.diff doerwalter, 2014-06-29 09:05 review
Pull Requests
URL Status Linked Edit
PR 11157 merged doerwalter, 2018-12-14 12:07
Messages (10)
msg65639 - (view) Author: David Anderson (danderson) Date: 2008-04-19 22:09
Some test cases in Lib/test/mapping_tests.py are problematic for users
wishing to test their own implementations of the mapping protocol: 

 - TestHashMappingProtocol.test_repr() requires the user implementations
to look like a dict when repr() is applied. It is unclear why this is
required of conforming mapping protocol implementations.
 - TestMappingProtocol.test_fromkeys() cannot pass for any
implementation that uses its constructor in fromkeys(), because baddict1
defines a constructor accepting no arguments. It should accept *args,
**kwargs to be sane for user implementations that handle passing data
sources to the constructor.
 - TestHashMappingProtocol.test_mutatingiteration(), for some faulty
implementations, makes the iteration degrade into an infinite loop.
Making the test more strict (eg. keeping an explicit iteration count and
failing if it goes >1) would be more helpful to buggy implementations.

These all seem like trivial issues. If it is agreed that the repr_test
should be removed from the ABC tests, I can provide a patch implementing
these three corrections.
msg87739 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-05-14 16:28
Walter, this is your code.  Care to incorporate any of David's ideas?

David, for my own code, the usual technique for something like
test_repr() is to subclass TestHashMappingProtocol and override the test
method with a customized test_repr() method.
msg87762 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2009-05-14 20:44
Any custom mapping class should have a repr test anyway, so IMHO it
doesn't matter whether the base test has a repr test or not.

The suggested fixes for TestMappingProtocol.test_fromkeys() and
TestHashMappingProtocol.test_mutatingiteration() sound OK however.

David, can you provide a patch?
msg153835 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-02-21 02:39
I think it would be great to test the stdlib’s mapping classes against common tests; there is a patch to add more MutableMapping methods to dbm classes for example, and it was not trivial to get good test coverage.

Not sure about the status of the module though, i.e. if we should officially support people using mapping_tests to check their code; it would be very useful for classes that don’t inherit from an ABC, but the whole test package is not intended for public use.
msg153843 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-02-21 03:26
> I think it would be great to test the stdlib’s mapping classes against common tests
grep told me that most of them already do.  Sorry for the noise, it’s late/soon here.
msg221825 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-29 00:19
@Walter/Raymond as there is still no patch for this issue do you want to leave it open just in case anybody wants to work on it, move it to langushing, close it or what?
msg221832 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2014-06-29 09:05
Here is a patch that implements suggestion 2 and 3.
msg331686 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-12-12 09:41
Walter, do you mind to create a PR?
msg331812 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2018-12-14 12:11
OK, I've created the pull request (11157).
msg344797 - (view) Author: miss-islington (miss-islington) Date: 2019-06-06 10:13
New changeset 6af230359e57122708247dac970e05e05529cde6 by Miss Islington (bot) (Walter Dörwald) in branch 'master':
bpo-2661: Make mapping tests better usable for custom mapping classes. (GH-11157)
https://github.com/python/cpython/commit/6af230359e57122708247dac970e05e05529cde6
History
Date User Action Args
2022-04-11 14:56:33adminsetgithub: 46913
2019-06-06 10:14:31cheryl.sabellasetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.9, - Python 2.7, Python 3.2, Python 3.3
2019-06-06 10:13:13miss-islingtonsetnosy: + miss-islington
messages: + msg344797
2018-12-14 12:11:30doerwaltersetmessages: + msg331812
2018-12-14 12:07:28doerwaltersetstage: needs patch -> patch review
pull_requests: + pull_request10390
2018-12-12 16:09:34BreamoreBoysetnosy: - BreamoreBoy
2018-12-12 09:41:24serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg331686
2014-06-29 09:05:53doerwaltersetfiles: + mapping-tests.diff
keywords: + patch
messages: + msg221832
2014-06-29 00:19:37BreamoreBoysetnosy: + BreamoreBoy
messages: + msg221825
2012-02-21 03:26:04eric.araujosetmessages: + msg153843
2012-02-21 02:39:56eric.araujosetversions: + Python 2.7, Python 3.2, Python 3.3, - Python 3.1
nosy: + eric.araujo

messages: + msg153835

stage: needs patch
2009-05-14 20:44:38doerwaltersetmessages: + msg87762
2009-05-14 16:28:46rhettingersetpriority: normal -> low

nosy: + doerwalter
messages: + msg87739

assignee: doerwalter
2009-05-12 13:22:08pitrousetnosy: + rhettinger
2009-05-12 13:09:10ajaksu2setpriority: normal
components: + Tests
versions: + Python 3.1, - Python 3.0
2008-04-19 22:09:32dandersoncreate