def test_escape_reversibility_escapes_leading_periods():
    for i in range(20):
        s = make_str_for_esc(include_escapes=chars_to_escape,
                             include_leading_periods=True)
        s_e = escape_path(s)
        s_e_u = unescape_path(s_e)
        assert_equal(s, s_e_u)
def test_escape_reversibility_escapes_bytes():
    for i in range(20):
        s = make_str_for_esc(include_escapes=chars_to_escape)
        s = s.encode('utf-8')
        s_e = escape_path(s)
        s_e_u = unescape_path(s_e)
        assert_equal(s, s_e_u.encode('utf-8'))
def test_escape_reversibility_leading_periods_bytes():
    for i in range(20):
        s = make_str_for_esc(include_leading_periods=True)
        s = s.encode('utf-8')
        s_e = escape_path(s)
        s_e_u = unescape_path(s_e)
        assert_equal(s, s_e_u.encode('utf-8'))
def test_escape_reversibility_no_escapes():
    for i in range(20):
        s = make_str_for_esc()
        s_e = escape_path(s)
        s_e_u = unescape_path(s_e)
        assert_equal(s, s_e)
        assert_equal(s, s_e_u)
def test_unescaping_u():
    fmts = [b'{0:04x}'.decode('ascii'), b'{0:04X}'.decode('ascii')]
    prefix = b'\\u'.decode('ascii')
    for i in range(20):
        s = make_str_for_esc(pack_digits=True)
        index = random.randrange(1, len(s) - 1)
        c = s[index]
        n = ord(c)
        c_e = prefix + random.choice(fmts).format(n)
        s_e = s[:index] + c_e + s[(index + 1):]
        assert_equal(s, unescape_path(s_e))