|
1
|
|
|
"""This module is for testing installing skins via given folders.""" |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
import os.path |
|
5
|
|
|
import shutil |
|
6
|
|
|
import sys |
|
7
|
|
|
import tempfile |
|
8
|
|
|
|
|
9
|
|
|
from unittest import TestCase |
|
10
|
|
|
|
|
11
|
|
|
FOLDER_INSTALLER = sys.modules["Rainmeter.install.from_folder"] |
|
12
|
|
|
SKIN_PATH_PROVIDER = sys.modules["Rainmeter.path.skin_path_provider"] |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
class TestFolderInstaller(TestCase): |
|
16
|
|
|
""" |
|
17
|
|
|
Test for the levenshtein module using unittest. |
|
18
|
|
|
""" |
|
19
|
|
|
|
|
20
|
|
|
def test_find_inis_correct_count(self): |
|
21
|
|
|
"""Find 8 ini files in skin_folder.""" |
|
22
|
|
|
tests_folder = os.path.dirname(os.path.abspath(__file__)) |
|
23
|
|
|
folder_path = os.path.join(tests_folder, "skin_folder") |
|
24
|
|
|
|
|
25
|
|
|
inis = FOLDER_INSTALLER.find_inis_in_folder(folder_path) |
|
26
|
|
|
|
|
27
|
|
|
self.assertEqual(len(inis), 8) |
|
28
|
|
|
|
|
29
|
|
|
def test_find_inis_exists(self): |
|
30
|
|
|
"""All found ini files exist.""" |
|
31
|
|
|
tests_folder = os.path.dirname(os.path.abspath(__file__)) |
|
32
|
|
|
folder_path = os.path.join(tests_folder, "skin_folder") |
|
33
|
|
|
|
|
34
|
|
|
inis = FOLDER_INSTALLER.find_inis_in_folder(folder_path) |
|
35
|
|
|
|
|
36
|
|
|
for ini in inis: |
|
37
|
|
|
self.assertTrue(os.path.exists(ini)) |
|
38
|
|
|
|
|
39
|
|
|
def test_find_skin_name_in_inis(self): |
|
40
|
|
|
"""Skin name BeatTime found via ini files.""" |
|
41
|
|
|
tests_folder = os.path.dirname(os.path.abspath(__file__)) |
|
42
|
|
|
folder_path = os.path.join(tests_folder, "skin_folder") |
|
43
|
|
|
|
|
44
|
|
|
inis = FOLDER_INSTALLER.find_inis_in_folder(folder_path) |
|
45
|
|
|
skin_name = FOLDER_INSTALLER.find_skin_name_in_inis(inis) |
|
46
|
|
|
|
|
47
|
|
|
self.assertEqual(skin_name, "BeatTime") |
|
48
|
|
|
|
|
49
|
|
|
def test_find_resources_folder(self): |
|
50
|
|
|
"""Should find a resources folder.""" |
|
51
|
|
|
tests_folder = os.path.dirname(os.path.abspath(__file__)) |
|
52
|
|
|
folder_path = os.path.join(tests_folder, "skin_folder") |
|
53
|
|
|
|
|
54
|
|
|
maybe_resources_folder = FOLDER_INSTALLER.find_resources_folder_in_folder(folder_path) |
|
55
|
|
|
|
|
56
|
|
|
self.assertNotEqual(maybe_resources_folder, None) |
|
57
|
|
|
|
|
58
|
|
|
def test_existence_resource_folder(self): |
|
59
|
|
|
"""Found folder should exist.""" |
|
60
|
|
|
tests_folder = os.path.dirname(os.path.abspath(__file__)) |
|
61
|
|
|
folder_path = os.path.join(tests_folder, "skin_folder") |
|
62
|
|
|
|
|
63
|
|
|
maybe_resources_folder = FOLDER_INSTALLER.find_resources_folder_in_folder(folder_path) |
|
64
|
|
|
|
|
65
|
|
|
self.assertTrue(os.path.exists(maybe_resources_folder)) |
|
66
|
|
|
|
|
67
|
|
|
def test_common_path_exists(self): |
|
68
|
|
|
"""Common path between inis exists.""" |
|
69
|
|
|
tests_folder = os.path.dirname(os.path.abspath(__file__)) |
|
70
|
|
|
folder_path = os.path.join(tests_folder, "skin_folder") |
|
71
|
|
|
|
|
72
|
|
|
inis = FOLDER_INSTALLER.find_inis_in_folder(folder_path) |
|
73
|
|
|
common_path = FOLDER_INSTALLER.common_path(inis) |
|
74
|
|
|
|
|
75
|
|
|
self.assertTrue(os.path.exists(common_path)) |
|
76
|
|
|
|
|
77
|
|
|
def test_common_path_of_skin_exists(self): |
|
78
|
|
|
"""Common path testing with ini and @Resources folder mixed.""" |
|
79
|
|
|
tests_folder = os.path.dirname(os.path.abspath(__file__)) |
|
80
|
|
|
folder_path = os.path.join(tests_folder, "skin_folder") |
|
81
|
|
|
|
|
82
|
|
|
inis = FOLDER_INSTALLER.find_inis_in_folder(folder_path) |
|
83
|
|
|
resources = FOLDER_INSTALLER.find_resources_folders(folder_path) |
|
84
|
|
|
|
|
85
|
|
|
paths = list(inis) |
|
86
|
|
|
paths.extend(resources) |
|
87
|
|
|
|
|
88
|
|
|
common_path = FOLDER_INSTALLER.common_path(paths) |
|
89
|
|
|
|
|
90
|
|
|
self.assertTrue(os.path.exists(common_path)) |
|
91
|
|
|
|
|
92
|
|
|
def test_install_into_skins_folder(self): |
|
93
|
|
|
"""Install simple skin into Rainmeter skins folder.""" |
|
94
|
|
|
tests_folder = os.path.dirname(os.path.abspath(__file__)) |
|
95
|
|
|
folder_path = os.path.join(tests_folder, "skin_folder") |
|
96
|
|
|
|
|
97
|
|
|
# we need to make a temp copy first since we do not want to delete our original test data |
|
98
|
|
|
with tempfile.TemporaryDirectory() as temp_path: |
|
99
|
|
|
dst_path = os.path.join(temp_path, "skin_folder") |
|
100
|
|
|
shutil.copytree(folder_path, dst_path) |
|
101
|
|
|
|
|
102
|
|
|
actual_skin_path = FOLDER_INSTALLER.install_into_skins_folder(dst_path) |
|
103
|
|
|
self.assertTrue(os.path.isdir(actual_skin_path)) |
|
104
|
|
|
|
|
105
|
|
|
skins_path = SKIN_PATH_PROVIDER.get_cached_skin_path() |
|
106
|
|
|
skin_path = os.path.join(skins_path, "BeatTime") |
|
107
|
|
|
skin_path_exists = os.path.exists(skin_path) |
|
108
|
|
|
|
|
109
|
|
|
self.assertEquals(actual_skin_path, skin_path) |
|
110
|
|
|
|
|
111
|
|
|
resources_path = os.path.join(skin_path, "@Resources") |
|
112
|
|
|
resources_path_exists = os.path.exists(resources_path) |
|
113
|
|
|
|
|
114
|
|
|
# cleanup |
|
115
|
|
|
shutil.rmtree(skin_path) |
|
116
|
|
|
|
|
117
|
|
|
self.assertTrue(skin_path_exists) |
|
118
|
|
|
self.assertTrue(resources_path_exists) |
|
119
|
|
|
|
|
120
|
|
View Code Duplication |
def test_install_multi_skin(self): |
|
|
|
|
|
|
121
|
|
|
"""Install multi skin configuration into Rainmeter skins folder.""" |
|
122
|
|
|
tests_folder = os.path.dirname(os.path.abspath(__file__)) |
|
123
|
|
|
folder_path = os.path.join(tests_folder, "multi_skin_folder") |
|
124
|
|
|
|
|
125
|
|
|
# we need to make a temp copy first since we do not want to delete our original test data |
|
126
|
|
|
with tempfile.TemporaryDirectory() as temp_path: |
|
127
|
|
|
dst_path = os.path.join(temp_path, "multi_skin_folder") |
|
128
|
|
|
shutil.copytree(folder_path, dst_path) |
|
129
|
|
|
|
|
130
|
|
|
actual_skin_path = FOLDER_INSTALLER.install_into_skins_folder(dst_path) |
|
131
|
|
|
self.assertTrue(os.path.isdir(actual_skin_path)) |
|
132
|
|
|
|
|
133
|
|
|
skins_path = SKIN_PATH_PROVIDER.get_cached_skin_path() |
|
134
|
|
|
skin_path = os.path.join(skins_path, "Miniml") |
|
135
|
|
|
skin_path_exists = os.path.exists(skin_path) |
|
136
|
|
|
|
|
137
|
|
|
self.assertEquals(actual_skin_path, skin_path) |
|
138
|
|
|
|
|
139
|
|
|
# cleanup |
|
140
|
|
|
shutil.rmtree(skin_path) |
|
141
|
|
|
|
|
142
|
|
|
self.assertTrue(skin_path_exists) |
|
143
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
class TestFolderInstallerFolderAlreadyExists(TestCase): |
|
146
|
|
|
"""Standalone class for method testing folder_already_exists.""" |
|
147
|
|
|
|
|
148
|
|
View Code Duplication |
def test_existing(self): |
|
|
|
|
|
|
149
|
|
|
""" |
|
150
|
|
|
Given |
|
151
|
|
|
installing a skin with name BeatTime from a folder |
|
152
|
|
|
|
|
153
|
|
|
Then |
|
154
|
|
|
checking after the installation if that skin already exists |
|
155
|
|
|
|
|
156
|
|
|
Should |
|
157
|
|
|
detect an already existing skin |
|
158
|
|
|
""" |
|
159
|
|
|
tests_folder = os.path.dirname(os.path.abspath(__file__)) |
|
160
|
|
|
folder_path = os.path.join(tests_folder, "skin_folder") |
|
161
|
|
|
|
|
162
|
|
|
# we need to make a temp copy first since we do not want to delete our original test data |
|
163
|
|
|
with tempfile.TemporaryDirectory() as temp_path: |
|
164
|
|
|
dst_path = os.path.join(temp_path, "skin_folder") |
|
165
|
|
|
shutil.copytree(folder_path, dst_path) |
|
166
|
|
|
|
|
167
|
|
|
actual_skin_path = FOLDER_INSTALLER.install_into_skins_folder(dst_path) |
|
168
|
|
|
self.assertTrue(len(actual_skin_path) > 0) |
|
169
|
|
|
self.assertTrue(os.path.isdir(actual_skin_path)) |
|
170
|
|
|
|
|
171
|
|
|
skins_path = SKIN_PATH_PROVIDER.get_cached_skin_path() |
|
172
|
|
|
skin_path = os.path.join(skins_path, "BeatTime") |
|
173
|
|
|
skin_path_exists = FOLDER_INSTALLER.folder_already_exists(dst_path) |
|
174
|
|
|
self.assertEquals(actual_skin_path, skin_path) |
|
175
|
|
|
|
|
176
|
|
|
# cleanup the installed skin to make it reproduceable |
|
177
|
|
|
shutil.rmtree(skin_path) |
|
178
|
|
|
|
|
179
|
|
|
self.assertTrue(skin_path_exists) |
|
180
|
|
|
|
|
181
|
|
|
def test_not_existing(self): |
|
182
|
|
|
"""A skin skin_folder should not be already installed at destination.""" |
|
183
|
|
|
tests_folder = os.path.dirname(os.path.abspath(__file__)) |
|
184
|
|
|
folder_path = os.path.join(tests_folder, "skin_folder") |
|
185
|
|
|
|
|
186
|
|
|
# we need to make a temp copy first since we do not want to delete our original test data |
|
187
|
|
|
with tempfile.TemporaryDirectory() as temp_path: |
|
188
|
|
|
dst_path = os.path.join(temp_path, "skin_folder") |
|
189
|
|
|
shutil.copytree(folder_path, dst_path) |
|
190
|
|
|
|
|
191
|
|
|
self.assertFalse(FOLDER_INSTALLER.folder_already_exists(dst_path)) |
|
192
|
|
|
|