classification
Title: Mapping tests cannot be passed by user implementations
Type: behavior Stage:
Components: Library (Lib), Tests Versions: Python 3.1
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: doerwalter Nosy List: danderson, doerwalter, rhettinger
Priority: low Keywords:

Created on 2008-04-19 22:09 by danderson, last changed 2009-05-14 20:44 by doerwalter.

Messages (3)
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?
History
Date User Action Args
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