Skip to content

Commit 4c14740

Browse files
authored
Merge pull request #3868 from asottile/bytes_py26_plus
Use `bytes` directly instead of `binary_type`
2 parents f2e35c8 + 99e31f6 commit 4c14740

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

src/_pytest/assertion/rewrite.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,11 @@ def _saferepr(obj):
402402
JSON reprs.
403403
404404
"""
405-
repr = py.io.saferepr(obj)
406-
if isinstance(repr, six.text_type):
407-
t = six.text_type
405+
r = py.io.saferepr(obj)
406+
if isinstance(r, six.text_type):
407+
return r.replace(u"\n", u"\\n")
408408
else:
409-
t = six.binary_type
410-
return repr.replace(t("\n"), t("\\n"))
409+
return r.replace(b"\n", b"\\n")
411410

412411

413412
from _pytest.assertion.util import format_explanation as _format_explanation # noqa
@@ -446,10 +445,9 @@ def _should_repr_global_name(obj):
446445
def _format_boolop(explanations, is_or):
447446
explanation = "(" + (is_or and " or " or " and ").join(explanations) + ")"
448447
if isinstance(explanation, six.text_type):
449-
t = six.text_type
448+
return explanation.replace(u"%", u"%%")
450449
else:
451-
t = six.binary_type
452-
return explanation.replace(t("%"), t("%%"))
450+
return explanation.replace(b"%", b"%%")
453451

454452

455453
def _call_reprcompare(ops, results, expls, each_obj):

src/_pytest/assertion/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ def escape_for_readable_diff(binary_text):
187187
r = r.replace(r"\r", "\r")
188188
return r
189189

190-
if isinstance(left, six.binary_type):
190+
if isinstance(left, bytes):
191191
left = escape_for_readable_diff(left)
192-
if isinstance(right, six.binary_type):
192+
if isinstance(right, bytes):
193193
right = escape_for_readable_diff(right)
194194
if not verbose:
195195
i = 0 # just in case left or right has zero length

testing/test_capture.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import py
1313
import pytest
1414
import contextlib
15-
from six import binary_type, text_type
15+
from six import text_type
1616
from _pytest import capture
1717
from _pytest.capture import CaptureManager
1818
from _pytest.main import EXIT_NOTESTSCOLLECTED
@@ -24,12 +24,12 @@
2424
def tobytes(obj):
2525
if isinstance(obj, text_type):
2626
obj = obj.encode("UTF-8")
27-
assert isinstance(obj, binary_type)
27+
assert isinstance(obj, bytes)
2828
return obj
2929

3030

3131
def totext(obj):
32-
if isinstance(obj, binary_type):
32+
if isinstance(obj, bytes):
3333
obj = text_type(obj, "UTF-8")
3434
assert isinstance(obj, text_type)
3535
return obj

0 commit comments

Comments
 (0)