-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_filenames.py
187 lines (176 loc) · 10.8 KB
/
test_filenames.py
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
from typing import Dict
from unittest import TestCase
from pyicloud_ipd.asset_version import AssetVersion
from pyicloud_ipd.utils import disambiguate_filenames
from pyicloud_ipd.version_size import AssetVersionSize, LivePhotoVersionSize, VersionSize
class PathsTestCase(TestCase):
def test_disambiguate_filenames_all_diff(self) -> None:
"""want all and they are all different (probably unreal case)"""
_setup: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ORIGINAL: AssetVersion("IMG_1.DNG", 1, "http", "jpeg"),
AssetVersionSize.ALTERNATIVE: AssetVersion("IMG_1.HEIC", 1, "http", "jpeg"),
AssetVersionSize.ADJUSTED: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.MEDIUM: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.THUMB: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
LivePhotoVersionSize.ORIGINAL: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.MEDIUM: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.THUMB: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
}
_expect: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ORIGINAL: AssetVersion("IMG_1.DNG", 1, "http", "jpeg"),
AssetVersionSize.ALTERNATIVE: AssetVersion("IMG_1.HEIC", 1, "http", "jpeg"),
AssetVersionSize.ADJUSTED: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
}
_result = disambiguate_filenames(
_setup,
[AssetVersionSize.ORIGINAL, AssetVersionSize.ALTERNATIVE, AssetVersionSize.ADJUSTED],
)
self.assertDictEqual(_result, _expect)
def test_disambiguate_filenames_keep_orgraw_alt_adj(self) -> None:
"""keep originals as raw, keep alt as well, but edit alt; edits are the same file type - alternative will be renamed"""
_setup: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ORIGINAL: AssetVersion("IMG_1.DNG", 1, "http", "jpeg"),
AssetVersionSize.ALTERNATIVE: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.ADJUSTED: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.MEDIUM: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.THUMB: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
LivePhotoVersionSize.ORIGINAL: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.MEDIUM: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.THUMB: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
}
_expect: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ORIGINAL: AssetVersion("IMG_1.DNG", 1, "http", "jpeg"),
AssetVersionSize.ALTERNATIVE: AssetVersion("IMG_1-alternative.JPG", 1, "http", "jpeg"),
AssetVersionSize.ADJUSTED: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
}
_result = disambiguate_filenames(
_setup,
[AssetVersionSize.ORIGINAL, AssetVersionSize.ALTERNATIVE, AssetVersionSize.ADJUSTED],
)
self.assertDictEqual(_result, _expect)
def test_disambiguate_filenames_keep_latest(self) -> None:
"""want to keep just latest"""
_setup: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ORIGINAL: AssetVersion("IMG_1.HEIC", 1, "http", "jpeg"),
AssetVersionSize.ADJUSTED: AssetVersion("IMG_1.HEIC", 1, "http", "jpeg"),
AssetVersionSize.MEDIUM: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.THUMB: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
LivePhotoVersionSize.ORIGINAL: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.MEDIUM: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.THUMB: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
}
_expect: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ADJUSTED: AssetVersion("IMG_1.HEIC", 1, "http", "jpeg"),
}
_result = disambiguate_filenames(_setup, [AssetVersionSize.ADJUSTED])
self.assertDictEqual(_result, _expect)
def test_disambiguate_filenames_keep_org_adj_diff(self) -> None:
"""keep as is"""
_setup: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ORIGINAL: AssetVersion("IMG_1.HEIC", 1, "http", "jpeg"),
AssetVersionSize.ADJUSTED: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.MEDIUM: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.THUMB: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
LivePhotoVersionSize.ORIGINAL: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.MEDIUM: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.THUMB: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
}
_expect: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ORIGINAL: AssetVersion("IMG_1.HEIC", 1, "http", "jpeg"),
AssetVersionSize.ADJUSTED: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
}
_result = disambiguate_filenames(
_setup, [AssetVersionSize.ORIGINAL, AssetVersionSize.ADJUSTED]
)
self.assertDictEqual(_result, _expect)
def test_disambiguate_filenames_keep_org_alt_diff(self) -> None:
"""keep then as is"""
_setup: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ORIGINAL: AssetVersion("IMG_1.DNG", 1, "http", "jpeg"),
AssetVersionSize.ALTERNATIVE: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.MEDIUM: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.THUMB: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
LivePhotoVersionSize.ORIGINAL: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.MEDIUM: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.THUMB: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
}
_expect: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ORIGINAL: AssetVersion("IMG_1.DNG", 1, "http", "jpeg"),
AssetVersionSize.ALTERNATIVE: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
}
_result = disambiguate_filenames(
_setup, [AssetVersionSize.ORIGINAL, AssetVersionSize.ALTERNATIVE]
)
self.assertDictEqual(_result, _expect)
def test_disambiguate_filenames_keep_all_when_org_adj_same(self) -> None:
"""tweak adj"""
_setup: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ORIGINAL: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.ALTERNATIVE: AssetVersion("IMG_1.CR2", 1, "http", "jpeg"),
AssetVersionSize.ADJUSTED: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.MEDIUM: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.THUMB: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
LivePhotoVersionSize.ORIGINAL: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.MEDIUM: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.THUMB: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
}
_expect: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ORIGINAL: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.ALTERNATIVE: AssetVersion("IMG_1.CR2", 1, "http", "jpeg"),
AssetVersionSize.ADJUSTED: AssetVersion("IMG_1-adjusted.JPG", 1, "http", "jpeg"),
}
_result = disambiguate_filenames(
_setup,
[AssetVersionSize.ORIGINAL, AssetVersionSize.ADJUSTED, AssetVersionSize.ALTERNATIVE],
)
self.assertDictEqual(_result, _expect)
def test_disambiguate_filenames_keep_org_alt_missing(self) -> None:
"""keep alt when it is missing"""
_setup: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ORIGINAL: AssetVersion("IMG_1.HEIC", 1, "http", "jpeg"),
AssetVersionSize.ADJUSTED: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.MEDIUM: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.THUMB: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
LivePhotoVersionSize.ORIGINAL: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.MEDIUM: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.THUMB: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
}
_expect: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ORIGINAL: AssetVersion("IMG_1.HEIC", 1, "http", "jpeg"),
}
_result = disambiguate_filenames(
_setup, [AssetVersionSize.ORIGINAL, AssetVersionSize.ALTERNATIVE]
)
self.assertDictEqual(_result, _expect)
def test_disambiguate_filenames_keep_alt_missing(self) -> None:
"""keep alt when it is missing"""
_setup: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ORIGINAL: AssetVersion("IMG_1.HEIC", 1, "http", "jpeg"),
AssetVersionSize.MEDIUM: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.THUMB: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
LivePhotoVersionSize.ORIGINAL: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.MEDIUM: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.THUMB: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
}
_expect: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ALTERNATIVE: AssetVersion("IMG_1.HEIC", 1, "http", "jpeg"),
}
_result = disambiguate_filenames(_setup, [AssetVersionSize.ALTERNATIVE])
self.assertDictEqual(_result, _expect)
def test_disambiguate_filenames_keep_adj_alt_missing(self) -> None:
"""keep alt when it is missing"""
_setup: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ORIGINAL: AssetVersion("IMG_1.HEIC", 1, "http", "jpeg"),
AssetVersionSize.MEDIUM: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
AssetVersionSize.THUMB: AssetVersion("IMG_1.JPG", 1, "http", "jpeg"),
LivePhotoVersionSize.ORIGINAL: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.MEDIUM: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
LivePhotoVersionSize.THUMB: AssetVersion("IMG_1.MOV", 1, "http", "jpeg"),
}
_expect: Dict[VersionSize, AssetVersion] = {
AssetVersionSize.ADJUSTED: AssetVersion("IMG_1.HEIC", 1, "http", "jpeg"),
}
_result = disambiguate_filenames(
_setup, [AssetVersionSize.ADJUSTED, AssetVersionSize.ALTERNATIVE]
)
self.assertDictEqual(_result, _expect)