Skip to content

Commit

Permalink
Merge pull request #2735 from fgmacedo/fgm-fix-reprfuncargs-toterminal
Browse files Browse the repository at this point in the history
2731.bug Fix ReprFuncArgs with mixed unicode and utf-8 args.
  • Loading branch information
RonnyPfannschmidt committed Aug 31, 2017
2 parents b770a32 + 59cdef9 commit 5e00549
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion _pytest/_code/code.py
Expand Up @@ -863,7 +863,7 @@ def toterminal(self, tw):
if self.args:
linesofar = ""
for name, value in self.args:
ns = "%s = %s" % (name, value)
ns = "%s = %s" % (safe_str(name), safe_str(value))
if len(ns) + len(linesofar) + 2 > tw.fullwidth:
if linesofar:
tw.line(linesofar)
Expand Down
1 change: 1 addition & 0 deletions changelog/2731.bugfix
@@ -0,0 +1 @@
Fix ``ReprFuncArgs`` with mixed unicode and UTF-8 args.
22 changes: 22 additions & 0 deletions testing/code/test_code.py
@@ -1,9 +1,11 @@
# coding: utf-8
from __future__ import absolute_import, division, print_function
import sys

import _pytest._code
import py
import pytest
from test_excinfo import TWMock


def test_ne():
Expand Down Expand Up @@ -172,3 +174,23 @@ def test_getsource(self):
source = entry.getsource()
assert len(source) == 6
assert 'assert False' in source[5]


class TestReprFuncArgs(object):

def test_not_raise_exception_with_mixed_encoding(self):
from _pytest._code.code import ReprFuncArgs

tw = TWMock()

args = [
('unicode_string', u"São Paulo"),
('utf8_string', 'S\xc3\xa3o Paulo'),
]

r = ReprFuncArgs(args)
r.toterminal(tw)
if sys.version_info[0] >= 3:
assert tw.lines[0] == 'unicode_string = São Paulo, utf8_string = São Paulo'
else:
assert tw.lines[0] == 'unicode_string = São Paulo, utf8_string = São Paulo'

0 comments on commit 5e00549

Please sign in to comment.