MCPcopy
hub / github.com/mitmproxy/mitmproxy / test_bytes_to_escaped_str

Function test_bytes_to_escaped_str

test/mitmproxy/utils/test_strutils.py:44–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42
43
44def test_bytes_to_escaped_str():
45 assert strutils.bytes_to_escaped_str(b"foo") == "foo"
46 assert strutils.bytes_to_escaped_str(b"\b") == r"\x08"
47 assert strutils.bytes_to_escaped_str(rb"&!?=\)") == r"&!?=\\)"
48 assert strutils.bytes_to_escaped_str(b"\xc3\xbc") == r"\xc3\xbc"
49 assert strutils.bytes_to_escaped_str(b"'") == r"'"
50 assert strutils.bytes_to_escaped_str(b'"') == r'"'
51
52 assert strutils.bytes_to_escaped_str(b"'", escape_single_quotes=True) == r"\'"
53 assert strutils.bytes_to_escaped_str(b'"', escape_single_quotes=True) == r'"'
54
55 assert strutils.bytes_to_escaped_str(b"\r\n\t") == "\\r\\n\\t"
56 assert strutils.bytes_to_escaped_str(b"\r\n\t", True) == "\r\n\t"
57
58 assert strutils.bytes_to_escaped_str(b"\n", False) == r"\n"
59 assert strutils.bytes_to_escaped_str(b"\n", True) == "\n"
60 assert strutils.bytes_to_escaped_str(b"\\n", True) == "\\ \\ n".replace(" ", "")
61 assert strutils.bytes_to_escaped_str(b"\\\n", True) == "\\ \\ \n".replace(" ", "")
62 assert strutils.bytes_to_escaped_str(b"\\\\n", True) == "\\ \\ \\ \\ n".replace(
63 " ", ""
64 )
65
66 with pytest.raises(ValueError):
67 strutils.bytes_to_escaped_str("such unicode")
68
69
70def test_escaped_str_to_bytes():

Callers

nothing calls this directly

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…