-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathtest_pathutils.py
More file actions
51 lines (43 loc) · 1.41 KB
/
test_pathutils.py
File metadata and controls
51 lines (43 loc) · 1.41 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
import pytest
from manage.pathutils import Path, PurePath, relative_to
def test_path_match():
p = Path("python3.12.exe")
assert p.match("*.exe")
assert p.match("python*")
assert p.match("python*.exe")
assert p.match("python3.12*.exe")
assert p.match("*hon3.*")
assert p.match("p*3.*.exe")
assert not p.match("*.com")
assert not p.match("example*")
assert not p.match("example*.com")
assert not p.match("*ple*")
def test_path_stem():
p = Path("python3.12.exe")
assert p.stem == "python3.12"
assert p.suffix == ".exe"
p = Path("python3.12")
assert p.stem == "python3"
assert p.suffix == ".12"
p = Path("python3")
assert p.stem == "python3"
assert p.suffix == ""
p = Path(".exe")
assert p.stem == ""
assert p.suffix == ".exe"
def test_path_relative_to():
p = Path(r"C:\A\B\C\python.exe")
actual = relative_to(p, r"C:\A\B\C")
assert isinstance(actual, Path)
assert str(actual) == "python.exe"
actual = relative_to(p, "C:\\")
assert isinstance(actual, Path)
assert str(actual) == r"A\B\C\python.exe"
actual = relative_to(str(p), r"C:\A\B")
assert isinstance(actual, str)
assert actual == r"C\python.exe"
actual = relative_to(bytes(p), r"C:\A\B")
assert isinstance(actual, bytes)
assert actual == rb"C\python.exe"
assert relative_to(p, r"C:\A\B\C\D") is p
assert relative_to(p, None) is p