forked from streamlink/streamlink
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli_utils_path.py
More file actions
55 lines (38 loc) · 1.92 KB
/
Copy pathtest_cli_utils_path.py
File metadata and controls
55 lines (38 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pytest
from streamlink_cli.utils.path import replace_chars
from tests import posix_only, windows_only
@pytest.mark.parametrize("char", [i for i in range(32)])
def test_replace_chars_unprintable(char: int):
assert replace_chars(f"foo{chr(char)}{chr(char)}bar") == "foo_bar", "Replaces unprintable characters"
@posix_only
@pytest.mark.parametrize("char", "/".split())
def test_replace_chars_posix(char: str):
assert replace_chars(f"foo{char}{char}bar") == "foo_bar", "Replaces multiple unsupported characters in a row"
@windows_only
@pytest.mark.parametrize("char", "\x7f\"*/:<>?\\|".split())
def test_replace_chars_windows(char: str):
assert replace_chars(f"foo{char}{char}bar") == "foo_bar", "Replaces multiple unsupported characters in a row"
@posix_only
def test_replace_chars_posix_all():
assert replace_chars("".join(chr(i) for i in range(32)) + "/") == "_"
@windows_only
def test_replace_chars_windows_all():
assert replace_chars("".join(chr(i) for i in range(32)) + "\x7f\"*/:<>?\\|") == "_"
@posix_only
def test_replace_chars_posix_override():
all_chars = "".join(chr(i) for i in range(32)) + "\x7f\"*:/<>?\\|"
assert replace_chars(all_chars) == "_\x7f\"*:_<>?\\|"
assert replace_chars(all_chars, "posix") == "_\x7f\"*:_<>?\\|"
assert replace_chars(all_chars, "unix") == "_\x7f\"*:_<>?\\|"
assert replace_chars(all_chars, "windows") == "_"
assert replace_chars(all_chars, "win32") == "_"
@windows_only
def test_replace_chars_windows_override():
all_chars = "".join(chr(i) for i in range(32)) + "\x7f\"*:/<>?\\|"
assert replace_chars(all_chars) == "_"
assert replace_chars(all_chars, "posix") == "_\x7f\"*:_<>?\\|"
assert replace_chars(all_chars, "unix") == "_\x7f\"*:_<>?\\|"
assert replace_chars(all_chars, "windows") == "_"
assert replace_chars(all_chars, "win32") == "_"
def test_replace_chars_replacement():
assert replace_chars("\x00", None, "+") == "+"