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

unittest: use ascii() instead of repr() to display values on error #54370

Closed
vstinner opened this issue Oct 21, 2010 · 3 comments
Closed

unittest: use ascii() instead of repr() to display values on error #54370

vstinner opened this issue Oct 21, 2010 · 3 comments
Labels
stdlib Python modules in the Lib dir topic-unicode

Comments

@vstinner
Copy link
Member

BPO 10161
Nosy @vstinner, @voidspace
Files
  • unittest_ascii.patch
  • 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 = None
    closed_at = <Date 2010-10-24.21:05:33.001>
    created_at = <Date 2010-10-21.00:14:03.526>
    labels = ['library', 'expert-unicode']
    title = 'unittest: use ascii() instead of repr() to display values on error'
    updated_at = <Date 2010-10-25.01:11:34.284>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2010-10-25.01:11:34.284>
    actor = 'michael.foord'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-10-24.21:05:33.001>
    closer = 'vstinner'
    components = ['Library (Lib)', 'Unicode']
    creation = <Date 2010-10-21.00:14:03.526>
    creator = 'vstinner'
    dependencies = []
    files = ['19311']
    hgrepos = []
    issue_num = 10161
    keywords = ['patch']
    message_count = 3.0
    messages = ['119248', '119531', '119532']
    nosy_count = 2.0
    nosy_names = ['vstinner', 'michael.foord']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue10161'
    versions = ['Python 3.2']

    @vstinner
    Copy link
    Member Author

    On a failure, unittest does its best to display values. But sometimes, the output doesn't help me. Example:

    FAIL: test_listdir (test.test_pep277.UnicodeFileTests)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/Users/db3l/buildarea/3.x.bolen-tiger/build/Lib/test/test_pep277.py", line 157, in test_listdir
        self.assertEqual(sf0, sf2)
    AssertionError: Items in the first set but not the second:
    '@test_18608_tmp/ ̈�Υ�Ϋ'
    '@test_18608_tmp/ẛ῁῍᾿�῏῝῾�῟῭'
    Items in the second set but not the first:
    '@test_18608_tmp/ ̈�ΥΥ�̈'
    '@test_18608_tmp/ẛ῁῍᾿�᾿῾῾῾῁̀�͂̀'
    '@test_18608_tmp/¨�ϒϒ�̈'

    This is a test on unicode filenames. I would prefer to see non-ASCII characters as \xHH or \uXXXX than strange characters or boxes.

    Do you think that it is a good idea to replace calls to repr() by ascii() in the unittest library?

    In Python2, repr(unicode) escapes all non-ASCII characters. But in Python3, only control characters and surrogates are escaped. So the output depends on the terminal encoding.

    Write non-ASCII characters in a backtrace may also raise a new error if the terminal is unable to a character. Raise an error while printing an error is just horrible :-)

    --

    Attached patch is a try to replace repr() by ascii() in the unittest module. But I don't know this library, so don't trust the patch :-)

    @vstinner vstinner added stdlib Python modules in the Lib dir topic-unicode labels Oct 21, 2010
    @vstinner
    Copy link
    Member Author

    Closed with r85829: patch test_pep277 instead of unittest.

    @voidspace
    Copy link
    Contributor

    Although this is still a real issue for other users of unittest. If I get time to think about it properly I may reopen.

    @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
    stdlib Python modules in the Lib dir topic-unicode
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants