You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mapping tests cannot be passed by user implementations #46913
3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/doerwalter'closed_at=<Date2019-06-06.10:14:31.458>created_at=<Date2008-04-19.22:09:32.677>labels= ['tests', 'type-bug', 'library', '3.9']
title='Mapping tests cannot be passed by user implementations'updated_at=<Date2019-06-06.10:14:31.083>user='https://bugs.python.org/danderson'
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.
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.
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.
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.
BreamoreBoy commented on Jun 29, 2014
BreamoreBoymannequin
Mannequin
More actions
@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?
New changeset 6af2303 by Miss Islington (bot) (Walter Dörwald) in branch 'master': bpo-2661: Make mapping tests better usable for custom mapping classes. (GH-11157) 6af2303
3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error
Activity
danderson commentedon Apr 19, 2008
Some test cases in Lib/test/mapping_tests.py are problematic for users
wishing to test their own implementations of the mapping protocol:
to look like a dict when repr() is applied. It is unclear why this is
required of conforming mapping protocol implementations.
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.
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.
rhettinger commentedon May 14, 2009
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.
doerwalter commentedon May 14, 2009
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?
merwok commentedon Feb 21, 2012
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.
merwok commentedon Feb 21, 2012
BreamoreBoy commentedon Jun 29, 2014
@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?
doerwalter commentedon Jun 29, 2014
Here is a patch that implements suggestion 2 and 3.
serhiy-storchaka commentedon Dec 12, 2018
Walter, do you mind to create a PR?
doerwalter commentedon Dec 14, 2018
OK, I've created the pull request (11157).
miss-islington commentedon Jun 6, 2019
New changeset 6af2303 by Miss Islington (bot) (Walter Dörwald) in branch 'master':
bpo-2661: Make mapping tests better usable for custom mapping classes. (GH-11157)
6af2303