Skip to content

Mapping tests cannot be passed by user implementations #46913

Closed

Description

@danderson
mannequin
BPO 2661
Nosy @doerwalter, @rhettinger, @merwok, @serhiy-storchaka, @miss-islington
PRs
  • bpo-2661: Make mapping tests better usable for custom mapping classes. #11157
  • Files
  • mapping-tests.diff
  • 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 = <Date 2019-06-06.10:14:31.458>
    created_at = <Date 2008-04-19.22:09:32.677>
    labels = ['tests', 'type-bug', 'library', '3.9']
    title = 'Mapping tests cannot be passed by user implementations'
    updated_at = <Date 2019-06-06.10:14:31.083>
    user = 'https://bugs.python.org/danderson'

    bugs.python.org fields:

    activity = <Date 2019-06-06.10:14:31.083>
    actor = 'cheryl.sabella'
    assignee = 'doerwalter'
    closed = True
    closed_date = <Date 2019-06-06.10:14:31.458>
    closer = 'cheryl.sabella'
    components = ['Library (Lib)', 'Tests']
    creation = <Date 2008-04-19.22:09:32.677>
    creator = 'danderson'
    dependencies = []
    files = ['35800']
    hgrepos = []
    issue_num = 2661
    keywords = ['patch']
    message_count = 10.0
    messages = ['65639', '87739', '87762', '153835', '153843', '221825', '221832', '331686', '331812', '344797']
    nosy_count = 6.0
    nosy_names = ['doerwalter', 'rhettinger', 'danderson', 'eric.araujo', 'serhiy.storchaka', 'miss-islington']
    pr_nums = ['11157']
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue2661'
    versions = ['Python 3.9']

    Activity

    1. danderson commented on Apr 19, 2008

      dandersonmannequin
      MannequinAuthor

      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.

    2. added
      stdlib
      type-bug
      on Apr 19, 2008
    3. added
      tests
      on May 12, 2009
    4. rhettinger commented on May 14, 2009

      @rhettinger
      Contributor

      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.

    5. doerwalter commented on May 14, 2009

      @doerwalter
      Contributor

      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?

    6. merwok commented on Feb 21, 2012

      @merwok
      Member

      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.

    7. merwok commented on Feb 21, 2012

      @merwok
      Member

      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.

    8. BreamoreBoy commented on Jun 29, 2014

      BreamoreBoymannequin
      Mannequin

      @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?

    9. doerwalter commented on Jun 29, 2014

      @doerwalter
      Contributor

      Here is a patch that implements suggestion 2 and 3.

    10. serhiy-storchaka commented on Dec 12, 2018

      @serhiy-storchaka
      Member

      Walter, do you mind to create a PR?

    11. doerwalter commented on Dec 14, 2018

      @doerwalter
      Contributor

      OK, I've created the pull request (11157).

    12. miss-islington commented on Jun 6, 2019

      @miss-islington
      Contributor

      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

    13. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.9 (EOL)stdlibteststype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions