Properly escape \r \n \t bytes

This commit is contained in:
Anthony Sottile 2018-11-18 15:12:43 -08:00
parent 9a1e518cc3
commit 95c6d591f7
2 changed files with 6 additions and 1 deletions

View File

@ -185,6 +185,9 @@ def get_default_arg_names(function):
_non_printable_ascii_translate_table = {
i: u"\\x{:02x}".format(i) for i in range(128) if i not in range(32, 127)
}
_non_printable_ascii_translate_table.update(
{ord("\t"): u"\\t", ord("\r"): u"\\r", ord("\n"): u"\\n"}
)
def _translate_non_printable(s):

View File

@ -390,9 +390,11 @@ class TestMetafunc(object):
pytest.param("\x05", 2),
pytest.param(b"\x00", 3),
pytest.param(b"\x05", 4),
pytest.param("\t", 5),
pytest.param(b"\t", 6),
],
)
assert result == ["\\x00-1", "\\x05-2", "\\x00-3", "\\x05-4"]
assert result == ["\\x00-1", "\\x05-2", "\\x00-3", "\\x05-4", "\\t-5", "\\t-6"]
def test_idmaker_manual_ids_must_be_printable(self):
from _pytest.python import idmaker