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

Unicode returns in doctest can make subsequent tests fail #52717

Closed
regebro mannequin opened this issue Apr 20, 2010 · 2 comments
Closed

Unicode returns in doctest can make subsequent tests fail #52717

regebro mannequin opened this issue Apr 20, 2010 · 2 comments
Labels
extension-modules C modules in the Modules dir tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@regebro
Copy link
Mannequin

regebro mannequin commented Apr 20, 2010

BPO 8471
Nosy @birkenfeld, @regebro
Files
  • doctest_unicode.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-08-01.08:22:32.184>
    created_at = <Date 2010-04-20.15:41:12.123>
    labels = ['extension-modules', 'type-bug', 'tests']
    title = 'Unicode returns in doctest can make subsequent tests fail'
    updated_at = <Date 2010-08-01.08:22:32.182>
    user = 'https://github.com/regebro'

    bugs.python.org fields:

    activity = <Date 2010-08-01.08:22:32.182>
    actor = 'georg.brandl'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-08-01.08:22:32.184>
    closer = 'georg.brandl'
    components = ['Extension Modules', 'Tests']
    creation = <Date 2010-04-20.15:41:12.123>
    creator = 'lregebro'
    dependencies = []
    files = ['17007']
    hgrepos = []
    issue_num = 8471
    keywords = ['patch']
    message_count = 2.0
    messages = ['103728', '112288']
    nosy_count = 2.0
    nosy_names = ['georg.brandl', 'lregebro']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue8471'
    versions = ['Python 2.6', 'Python 2.5', 'Python 2.7']

    @regebro
    Copy link
    Mannequin Author

    regebro mannequin commented Apr 20, 2010

    If we return unicode, SpoofOut's buf variable becomes automagically converted to unicode. This means all subsequent output becomes converted to unicode, and if the output contains non-ascii characters that fails.

    That means that

        >>> print u'\xe9'.encode('utf-8')
        é

    Will work just fine, but

        >>> print u'abc'
        abc
    
        >>> print u'\xe9'.encode('utf-8')
        é

    Will fail.

    The reason for this is that when "resetting" the doctest output only a truncate(0) is done, so the buf variable will continue to be unicode. I include tests + a patch that will set self.buf to '' if empty when trunkated. Other options are also possible, like changing the .truncate(0) to a .buf = '' but that's ugly, or adding a reset() method on SpoofOUt.

    @regebro regebro mannequin added extension-modules C modules in the Modules dir tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error labels Apr 20, 2010
    @birkenfeld
    Copy link
    Member

    Thanks, applied in r83392.

    @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
    extension-modules C modules in the Modules dir tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant