Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add assertions to implement the intent in ''.format_map test #57659

Closed
4kir4 mannequin opened this issue Nov 22, 2011 · 5 comments
Closed

add assertions to implement the intent in ''.format_map test #57659

4kir4 mannequin opened this issue Nov 22, 2011 · 5 comments
Assignees
Labels
tests Tests in the Lib/test dir

Comments

@4kir4
Copy link
Mannequin

4kir4 mannequin commented Nov 22, 2011

BPO 13450
Nosy @rhettinger, @ericvsmith, @merwok, @4kir4
Files
  • correct-assertions-in-test_format_map.patch: additional assertions with ValueError
  • 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/ericvsmith'
    closed_at = <Date 2012-03-12.22:29:19.635>
    created_at = <Date 2011-11-22.00:42:35.933>
    labels = ['tests']
    title = "add assertions to implement the intent in ''.format_map test"
    updated_at = <Date 2012-03-12.22:29:19.633>
    user = 'https://github.com/4kir4'

    bugs.python.org fields:

    activity = <Date 2012-03-12.22:29:19.633>
    actor = 'python-dev'
    assignee = 'eric.smith'
    closed = True
    closed_date = <Date 2012-03-12.22:29:19.635>
    closer = 'python-dev'
    components = ['Tests']
    creation = <Date 2011-11-22.00:42:35.933>
    creator = 'akira'
    dependencies = []
    files = ['23748']
    hgrepos = []
    issue_num = 13450
    keywords = ['patch']
    message_count = 5.0
    messages = ['148096', '148113', '148130', '148395', '155500']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'eric.smith', 'eric.araujo', 'akira', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue13450'
    versions = ['Python 3.2', 'Python 3.3']

    @4kir4
    Copy link
    Mannequin Author

    4kir4 mannequin commented Nov 22, 2011

    It seems that some assertions in Lib/test/test_unicode.py:UnicodeTest.test_format_map do not implement their intent e.g.,

            self.assertRaises(TypeError, '{'.format_map)
            self.assertRaises(TypeError, '}'.format_map)
            self.assertRaises(TypeError, 'a{'.format_map)
            self.assertRaises(TypeError, 'a}'.format_map)
            self.assertRaises(TypeError, '{a'.format_map)
            self.assertRaises(TypeError, '}a'.format_map)

    The intent might be to test:

      >>> '{'.format_map({})
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      ValueError: Single '{' encountered in format string

    But it actually tests:

      >>> '{'.format_map()
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: format_map() takes exactly one argument (0 given)

    Provided correct-assertions-in-test_format_map.patch contains additional assertions e.g.,

          self.assertRaises(ValueError, '{'.format_map, {})

    Old assertions might be useful so they're left untouched.

    @4kir4 4kir4 mannequin added the tests Tests in the Lib/test dir label Nov 22, 2011
    @4kir4 4kir4 mannequin changed the title fix ''.format_map test add assertions to implement the intent in ''.format_map test Nov 22, 2011
    @ericvsmith ericvsmith self-assigned this Nov 22, 2011
    @ericvsmith
    Copy link
    Member

    I don't think the existing tests have any value. I might leave one of them, but I think I'll just use your new tests instead.

    akira: I'd like to add your name to the Misc/ACKS file, if it's not already there. What's your full name?

    Thanks for the bug report and patch.

    @4kir4
    Copy link
    Mannequin Author

    4kir4 mannequin commented Nov 22, 2011

    TypeError tests can check that an implementation raises a correct exception type i.e., it doesn't raise ValueError prematurely on invalid format_string without checking that there is mapping argument.

    METH_O does it for CPython. I'm not sure how other implementations might behave.

    eric: I'd read http://docs.python.org/devguide/patch.html#preparation but I thought 4 lines are not worth it to change Misc/ACKS. Full pseudonym: Akira Li

    @merwok
    Copy link
    Member

    merwok commented Nov 26, 2011

    When someone puts thought into a report or patch, they deserve to be in Misc/ACKS. Just noticing one typo doesn’t qualify, but pretty much anything above does. :)

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 12, 2012

    New changeset 995cddd15313 by Eric V. Smith in branch '3.2':
    str.format_map tests don't do what they say: fix to actually implement the intent of the test. Closes bpo-13450.
    http://hg.python.org/cpython/rev/995cddd15313

    New changeset 0df295d590a8 by Eric V. Smith in branch 'default':
    str.format_map tests don't do what they say: fix to actually implement the intent of the test. Closes bpo-13450. Patch by Akira Li.
    http://hg.python.org/cpython/rev/0df295d590a8

    @python-dev python-dev mannequin closed this as completed Mar 12, 2012
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    tests Tests in the Lib/test dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants