forked from lra/mackup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_tests.py
215 lines (149 loc) · 6.88 KB
/
config_tests.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import unittest
import os.path
from mackup.constants import (
ENGINE_DROPBOX,
ENGINE_GDRIVE,
ENGINE_ICLOUD,
ENGINE_FS,
)
from mackup.config import Config, ConfigError
class TestConfig(unittest.TestCase):
def setUp(self):
realpath = os.path.dirname(os.path.realpath(__file__))
os.environ["HOME"] = os.path.join(realpath, "fixtures")
def test_config_no_config(self):
cfg = Config()
# Should should do the same as the default, empty configuration
assert isinstance(cfg.engine, str)
assert cfg.engine == ENGINE_DROPBOX
assert isinstance(cfg.path, str)
print(cfg.path)
assert cfg.path == "/home/some_user/Dropbox"
assert isinstance(cfg.directory, str)
assert cfg.directory == "Mackup"
assert isinstance(cfg.fullpath, str)
assert cfg.fullpath == "/home/some_user/Dropbox/Mackup"
assert cfg.apps_to_ignore == set()
assert cfg.apps_to_sync == set()
def test_config_empty(self):
cfg = Config("mackup-empty.cfg")
assert isinstance(cfg.engine, str)
assert cfg.engine == ENGINE_DROPBOX
assert isinstance(cfg.path, str)
assert cfg.path == "/home/some_user/Dropbox"
assert isinstance(cfg.directory, str)
assert cfg.directory == "Mackup"
assert isinstance(cfg.fullpath, str)
assert cfg.fullpath == "/home/some_user/Dropbox/Mackup"
assert cfg.apps_to_ignore == set()
assert cfg.apps_to_sync == set()
def test_config_engine_dropbox(self):
cfg = Config("mackup-engine-dropbox.cfg")
assert isinstance(cfg.engine, str)
assert cfg.engine == ENGINE_DROPBOX
assert isinstance(cfg.path, str)
assert cfg.path == "/home/some_user/Dropbox"
assert isinstance(cfg.directory, str)
assert cfg.directory == "some_weirld_name"
assert isinstance(cfg.fullpath, str)
assert cfg.fullpath == "/home/some_user/Dropbox/some_weirld_name"
assert cfg.apps_to_ignore == set()
assert cfg.apps_to_sync == set()
def test_config_engine_filesystem_absolute(self):
cfg = Config("mackup-engine-file_system-absolute.cfg")
assert isinstance(cfg.engine, str)
assert cfg.engine == ENGINE_FS
assert isinstance(cfg.path, str)
assert cfg.path == "/some/absolute/folder"
assert isinstance(cfg.directory, str)
assert cfg.directory == "custom_folder"
assert isinstance(cfg.fullpath, str)
assert cfg.fullpath == "/some/absolute/folder/custom_folder"
assert cfg.apps_to_ignore == set(["subversion", "sequel-pro"])
assert cfg.apps_to_sync == set()
def test_config_engine_filesystem(self):
cfg = Config("mackup-engine-file_system.cfg")
assert isinstance(cfg.engine, str)
assert cfg.engine == ENGINE_FS
assert isinstance(cfg.path, str)
assert cfg.path.endswith(
os.path.join(os.environ["HOME"], "some/relative/folder")
)
assert isinstance(cfg.directory, str)
assert cfg.directory == "Mackup"
assert isinstance(cfg.fullpath, str)
assert cfg.fullpath == os.path.join(
os.environ["HOME"], "some/relative/folder", "Mackup"
)
assert cfg.apps_to_ignore == set()
assert cfg.apps_to_sync == set(["sabnzbd", "sublime-text-3", "x11"])
def test_config_engine_google_drive(self):
cfg = Config("mackup-engine-google_drive.cfg")
assert isinstance(cfg.engine, str)
assert cfg.engine == ENGINE_GDRIVE
assert isinstance(cfg.path, str)
assert cfg.path == "/Users/whatever/Google Drive"
assert isinstance(cfg.directory, str)
assert cfg.directory == "Mackup"
assert isinstance(cfg.fullpath, str)
assert cfg.fullpath.endswith("/Google Drive/Mackup")
assert cfg.apps_to_ignore == set(["subversion", "sequel-pro", "sabnzbd"])
assert cfg.apps_to_sync == set(["sublime-text-3", "x11", "sabnzbd"])
def test_config_engine_icloud(self):
cfg = Config("mackup-engine-icloud.cfg")
assert isinstance(cfg.engine, str)
assert cfg.engine == ENGINE_ICLOUD
assert isinstance(cfg.path, str)
assert cfg.path == os.path.expanduser(
"~/Library/Mobile Documents/com~apple~CloudDocs/"
)
assert isinstance(cfg.directory, str)
assert cfg.directory == "Mackup"
assert isinstance(cfg.fullpath, str)
assert cfg.fullpath.endswith("/com~apple~CloudDocs/Mackup")
assert cfg.apps_to_ignore == set(["subversion", "sequel-pro", "sabnzbd"])
assert cfg.apps_to_sync == set(["sublime-text-3", "x11", "sabnzbd"])
def test_config_engine_filesystem_no_path(self):
with self.assertRaises(ConfigError):
Config("mackup-engine-file_system-no_path.cfg")
def test_config_engine_unknown(self):
with self.assertRaises(ConfigError):
Config("mackup-engine-unknown.cfg")
def test_config_apps_to_ignore(self):
cfg = Config("mackup-apps_to_ignore.cfg")
assert isinstance(cfg.engine, str)
assert cfg.engine == ENGINE_DROPBOX
assert isinstance(cfg.path, str)
assert cfg.path == "/home/some_user/Dropbox"
assert isinstance(cfg.directory, str)
assert cfg.directory == "Mackup"
assert isinstance(cfg.fullpath, str)
assert cfg.fullpath == "/home/some_user/Dropbox/Mackup"
assert cfg.apps_to_ignore == set(["subversion", "sequel-pro", "sabnzbd"])
assert cfg.apps_to_sync == set()
def test_config_apps_to_sync(self):
cfg = Config("mackup-apps_to_sync.cfg")
assert isinstance(cfg.engine, str)
assert cfg.engine == ENGINE_DROPBOX
assert isinstance(cfg.path, str)
assert cfg.path == "/home/some_user/Dropbox"
assert isinstance(cfg.directory, str)
assert cfg.directory == "Mackup"
assert isinstance(cfg.fullpath, str)
assert cfg.fullpath == "/home/some_user/Dropbox/Mackup"
assert cfg.apps_to_ignore == set()
assert cfg.apps_to_sync == set(["sabnzbd", "sublime-text-3", "x11"])
def test_config_apps_to_ignore_and_sync(self):
cfg = Config("mackup-apps_to_ignore_and_sync.cfg")
assert isinstance(cfg.engine, str)
assert cfg.engine == ENGINE_DROPBOX
assert isinstance(cfg.path, str)
assert cfg.path == "/home/some_user/Dropbox"
assert isinstance(cfg.directory, str)
assert cfg.directory == "Mackup"
assert isinstance(cfg.fullpath, str)
assert cfg.fullpath == "/home/some_user/Dropbox/Mackup"
assert cfg.apps_to_ignore == set(["subversion", "sequel-pro", "sabnzbd"])
assert cfg.apps_to_sync == set(["sabnzbd", "sublime-text-3", "x11", "vim"])
def test_config_old_config(self):
self.assertRaises(SystemExit, Config, "mackup-old-config.cfg")