-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtest_translate.py
More file actions
100 lines (82 loc) · 2.92 KB
/
test_translate.py
File metadata and controls
100 lines (82 loc) · 2.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""Test the translate path feature."""
from migrate import PathTranslation, build_translation_library, translate_path
EXAMPLE_FILENAME = "Meet the Press (1947)/Season 2020/S2020E01 - January 5, 2020 [SDTV x264 AAC].mp4"
def test_build_library() -> None:
assert build_translation_library(
[
"/media|/mnt/media",
]
) == [
PathTranslation("/media", "/mnt/media"),
]
def test_translate_path_empty() -> None:
"""Test translate_path with an empty translation set."""
assert translate_path("foo", []) == "foo"
def test_translate_path_simple() -> None:
"""Test translate_path with a simple single translation."""
assert (
translate_path(
f"/media/television/{EXAMPLE_FILENAME}",
[
PathTranslation("/media", "/mnt/media"),
],
)
== f"/mnt/media/television/{EXAMPLE_FILENAME}"
)
def test_translate_path_one_of_many() -> None:
"""Test translate_path uses the first matching translation."""
assert (
translate_path(
f"/media/television/{EXAMPLE_FILENAME}",
[
PathTranslation("/media", "/mnt/media"),
PathTranslation("/television", "/mnt/media/television"),
],
)
== f"/mnt/media/television/{EXAMPLE_FILENAME}"
)
def test_translate_path_multiple() -> None:
"""Test translate_path applying chained translations across multiple calls."""
assert (
translate_path(
f"/media/television/{EXAMPLE_FILENAME}",
[
PathTranslation("/media", "/mnt/media"),
PathTranslation("/mnt/media/television", "/tv"),
],
)
== f"/tv/{EXAMPLE_FILENAME}"
)
def test_translate_path_windows_to_linux_normalizes_separators() -> None:
"""Windows-style Plex path should translate to Linux-style and normalize slashes."""
plex_path = rf"D:\Media\television\{EXAMPLE_FILENAME}"
assert (
translate_path(
plex_path,
[
PathTranslation(r"D:\Media", "/mnt/media"),
],
)
== f"/mnt/media/television/{EXAMPLE_FILENAME}"
)
def test_translate_path_linux_to_windows_normalizes_separators() -> None:
"""Linux-style path should translate to Windows-style and normalize slashes."""
linux_path = f"/mnt/media/television/{EXAMPLE_FILENAME}"
assert (
translate_path(
linux_path,
[
PathTranslation("/mnt/media", r"D:\Media"),
],
)
== rf"D:\Media\television\{EXAMPLE_FILENAME}"
)
def test_translate_path_build_library_windows_mapping() -> None:
"""Ensure build_translation_library handles Windows src/dst with the '|' delimiter."""
assert build_translation_library(
[
r"D:\Media|/mnt/media",
]
) == [
PathTranslation(r"D:\Media", "/mnt/media"),
]