py.builtins._totext -> string literals or six.text_type

This commit is contained in:
Anthony Sottile 2018-08-22 19:21:00 -07:00
parent 17eec5b97e
commit 0fc4a806e5
9 changed files with 23 additions and 29 deletions

View File

@ -3,7 +3,6 @@ exception classes and constants handling test outcomes
as well as functions creating them
"""
from __future__ import absolute_import, division, print_function
import py
import sys
@ -21,7 +20,7 @@ class OutcomeException(BaseException):
if self.msg:
val = self.msg
if isinstance(val, bytes):
val = py._builtin._totext(val, errors="replace")
val = val.decode("UTF-8", errors="replace")
return val
return "<%s instance>" % (self.__class__.__name__,)

View File

@ -741,7 +741,7 @@ class FunctionMixin(PyobjMixin):
def _repr_failure_py(self, excinfo, style="long"):
if excinfo.errisinstance(fail.Exception):
if not excinfo.value.pytrace:
return py._builtin._totext(excinfo.value)
return six.text_type(excinfo.value)
return super(FunctionMixin, self)._repr_failure_py(excinfo, style=style)
def repr_failure(self, excinfo, outerr=None):

View File

@ -3,7 +3,6 @@ from __future__ import absolute_import, division, print_function
import sys
import _pytest._code
import py
import pytest
from test_excinfo import TWMock
from six import text_type
@ -83,7 +82,7 @@ def test_code_from_func():
def test_unicode_handling():
value = py.builtin._totext("\xc4\x85\xc4\x87\n", "utf-8").encode("utf8")
value = u"ąć".encode("UTF-8")
def f():
raise Exception(value)
@ -96,7 +95,7 @@ def test_unicode_handling():
@pytest.mark.skipif(sys.version_info[0] >= 3, reason="python 2 only issue")
def test_unicode_handling_syntax_error():
value = py.builtin._totext("\xc4\x85\xc4\x87\n", "utf-8").encode("utf8")
value = u"ąć".encode("UTF-8")
def f():
raise SyntaxError("invalid syntax", (None, 1, 3, value))

View File

@ -8,6 +8,7 @@ import textwrap
import _pytest
import py
import pytest
import six
from _pytest._code.code import (
ExceptionInfo,
FormattedExcinfo,
@ -884,10 +885,10 @@ raise ValueError()
class MyRepr(TerminalRepr):
def toterminal(self, tw):
tw.line(py.builtin._totext("я", "utf-8"))
tw.line(u"я")
x = py.builtin._totext(MyRepr())
assert x == py.builtin._totext("я", "utf-8")
x = six.text_type(MyRepr())
assert x == u"я"
def test_toterminal_long(self, importasmod):
mod = importasmod(

View File

@ -3,7 +3,6 @@ import re
import sys
import attr
import _pytest._code
import py
import pytest
from _pytest import python, fixtures
@ -295,9 +294,7 @@ class TestMetafunc(object):
)
assert result == ["a0-1.0", "a1-b1"]
# unicode mixing, issue250
result = idmaker(
(py.builtin._totext("a"), "b"), [pytest.param({}, b"\xc3\xb4")]
)
result = idmaker((u"a", "b"), [pytest.param({}, b"\xc3\xb4")])
assert result == ["a0-\\xc3\\xb4"]
def test_idmaker_with_bytes_regex(self):
@ -309,7 +306,6 @@ class TestMetafunc(object):
def test_idmaker_native_strings(self):
from _pytest.python import idmaker
totext = py.builtin._totext
result = idmaker(
("a", "b"),
[
@ -324,7 +320,7 @@ class TestMetafunc(object):
pytest.param({7}, set("seven")),
pytest.param(tuple("eight"), (8, -8, 8)),
pytest.param(b"\xc3\xb4", b"name"),
pytest.param(b"\xc3\xb4", totext("other")),
pytest.param(b"\xc3\xb4", u"other"),
],
)
assert result == [

View File

@ -509,12 +509,12 @@ class TestAssert_reprcompare(object):
assert "raised in repr()" not in expl
def test_unicode(self):
left = py.builtin._totext("£€", "utf-8")
right = py.builtin._totext("£", "utf-8")
left = u"£€"
right = u"£"
expl = callequal(left, right)
assert expl[0] == py.builtin._totext("'£€' == '£'", "utf-8")
assert expl[1] == py.builtin._totext("- £€", "utf-8")
assert expl[2] == py.builtin._totext("+ £", "utf-8")
assert expl[0] == u"'£€' == '£'"
assert expl[1] == u"- £€"
assert expl[2] == u"+ £"
def test_nonascii_text(self):
"""
@ -542,7 +542,7 @@ class TestAssert_reprcompare(object):
expl = callequal(left, right)
for line in expl:
assert isinstance(line, py.builtin.text)
msg = py.builtin._totext("\n").join(expl)
msg = u"\n".join(expl)
assert msg

View File

@ -654,12 +654,10 @@ class TestRewriteOnImport(object):
def test_readonly(self, testdir):
sub = testdir.mkdir("testing")
sub.join("test_readonly.py").write(
py.builtin._totext(
"""
b"""
def test_rewritten():
assert "@py_builtins" in globals()
"""
).encode("utf-8"),
""",
"wb",
)
old_mode = sub.stat().mode

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function
# note: py.io capture tests where copied from
@ -1083,9 +1084,9 @@ class TestStdCapture(object):
def test_capturing_readouterr_unicode(self):
with self.getcapture() as cap:
print("hx\xc4\x85\xc4\x87")
print("hxąć")
out, err = cap.readouterr()
assert out == py.builtin._totext("hx\xc4\x85\xc4\x87\n", "utf8")
assert out == u"hxąć\n"
@pytest.mark.skipif(
"sys.version_info >= (3,)", reason="text output different for bytes on python3"
@ -1095,7 +1096,7 @@ class TestStdCapture(object):
# triggered an internal error in pytest
print("\xa6")
out, err = cap.readouterr()
assert out == py.builtin._totext("\ufffd\n", "unicode-escape")
assert out == u"\ufffd\n"
def test_reset_twice_error(self):
with self.getcapture() as cap:

View File

@ -941,7 +941,7 @@ def test_double_colon_split_method_issue469(testdir):
def test_unicode_issue368(testdir):
path = testdir.tmpdir.join("test.xml")
log = LogXML(str(path), None)
ustr = py.builtin._totext("ВНИ!", "utf-8")
ustr = u"ВНИ!"
class Report(BaseReport):
longrepr = ustr