-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathpath_to_string_test.py
More file actions
53 lines (37 loc) · 2.09 KB
/
path_to_string_test.py
File metadata and controls
53 lines (37 loc) · 2.09 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
from pathlib import Path, PurePath
import pytest
from .path_to_string import path_to_string
def test_path_to_string_with_string():
assert path_to_string("test.txt") == "test.txt"
assert path_to_string("/home/user/file.txt") == "/home/user/file.txt"
def test_path_to_string_with_valid_url():
assert path_to_string("file:///path/to/resource") == "/path/to/resource"
assert path_to_string("file:///another/path") == "/another/path"
def test_path_to_string_with_bytes():
assert path_to_string(b"test.txt") == "test.txt"
assert path_to_string(b"/home/user/file.txt") == "/home/user/file.txt"
# Invalid bytes are replaced with � so traversal components are preserved.
assert path_to_string(b"\xff") == "�"
assert path_to_string(b"\xff/../../../etc/passwd") == "�/../../../etc/passwd"
# Surrogate bytes (AIKIDO-B3YABOSP pattern) also survive as replacement chars.
assert path_to_string(b"\xed\xa0\x80/../etc/passwd") == "���/../etc/passwd"
def test_path_to_string_with_empty_string():
assert path_to_string("") == ""
def test_path_to_string_with_none():
assert path_to_string(None) is None
def test_path_to_string_with_other_types():
assert path_to_string(123) is None # Integer input
assert path_to_string([]) is None # List input
assert path_to_string({}) is None # Dictionary input
def test_path_to_string_with_pure_path():
assert path_to_string(PurePath("./", "/folder", "/test.py")) == "/test.py"
assert path_to_string(PurePath("./", "/folder", "test2.py")) == "/folder/test2.py"
assert path_to_string(PurePath(".", ".", ".")) == "."
assert path_to_string(PurePath()) == "."
assert path_to_string(PurePath("test1", "test2", "test3")) == "test1/test2/test3"
def test_path_to_string_with_path():
assert path_to_string(Path("./", "/folder", "/test.py")) == "/test.py"
assert path_to_string(Path("./", "/folder", "test2.py")) == "/folder/test2.py"
assert path_to_string(Path(".", ".", ".")) == "."
assert path_to_string(Path()) == "."
assert path_to_string(Path("test1", "test2", "test3")) == "test1/test2/test3"