-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_wallpaperfm.py
executable file
·180 lines (140 loc) · 4.43 KB
/
test_wallpaperfm.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
#!/usr/bin/env python
"""
Integration tests for wallpaperfm.py
"""
import os
import unittest
import imp
try:
imp.find_module("coverage")
COVERAGE_CMD = "coverage run --append --source wallpaperfm.py "
except ImportError:
COVERAGE_CMD = ""
if os.name == "nt":
OS_CMD = ""
else:
OS_CMD = " ./"
class TestSequenceFunctions(unittest.TestCase):
def remove_file(self, file):
if os.path.isfile(file):
os.remove(file)
def mkdir(self, dir):
if not os.path.exists(dir):
os.mkdir(dir)
def setUp(self):
self.username = "RJ"
self.mkdir("my_cache")
self.cmd = (
COVERAGE_CMD + OS_CMD +
"wallpaperfm.py --Cache my_cache "
"--Local -u " + self.username + " ")
def helper_run(self, args):
# Arrange
cmd = COVERAGE_CMD + OS_CMD + "wallpaperfm.py " + args
# Act
print(cmd)
os.system(cmd)
# Assert
# Should run with no exceptions
# (Could run with subprocess.Popen() and check output)
def test_help(self):
""" Test usage with help option """
# Arrange
args = " --help"
# Act/Assert
self.helper_run(args)
def test_no_options(self):
""" Test usage with no options """
# Arrange
args = ""
# Act/Assert
self.helper_run(args)
def test_unknown_option(self):
""" Test usage with unknown options """
# Arrange
args = " --someunknownoption"
# Act/Assert
self.helper_run(args)
def test_unknown_mode(self):
""" Test usage with unknown mode """
# Arrange
args = " --Mode superduperanimated"
# Act/Assert
self.helper_run(args)
def helper_run_and_assert_file(self, args, outfile, ext=".png"):
# Arrange
cmd = self.cmd + " " + args + " -f " + outfile
self.remove_file(outfile + ext)
self.assertFalse(os.path.isfile(outfile + ext))
# Act
print(cmd)
os.system(cmd)
# Assert
self.assertTrue(os.path.isfile(outfile + ext))
def test_tiled_albums(self):
""" Test tiled albums """
# Arrange
outfile = "out_tiled"
args = " -m tile --AlbumSize 120 --Interspace 4 --FinalOpacity 40"
# Act/Assert
self.helper_run_and_assert_file(args, outfile)
def test_default_username(self):
""" Test tiled albums """
# Arrange
cmd = self.cmd + " -m tile" # no outfile given
outfile = "RJ.png"
self.remove_file(outfile)
self.assertFalse(os.path.isfile(outfile))
# Act
print(cmd)
os.system(cmd)
# Assert
self.assertTrue(os.path.isfile(outfile))
def test_tiled_albums_jpg(self):
""" Test tiled albums """
# Arrange
outfile = "out_tiled_jpg"
args = " -m tile --ImageType jpg --BackgroundColor red --Radius 25"
# Act/Assert
self.helper_run_and_assert_file(args, outfile, ext=".jpg")
def test_glass_albums(self):
""" Test glassy albums """
# Arrange
outfile = "out_glass"
args = (
" -m glass --AlbumNumber 8 --EndPoint 80 --Offset 30 "
" --ImageSize 1920x1080 --CanvasSize 1900x1900 --Past 12month "
" -x http://images.amazon.com/images/P/B00001ZTYQ.01._SCMZZZZZ "
)
# Act/Assert
self.helper_run_and_assert_file(args, outfile)
def test_collage_albums(self):
""" Test collage albums """
# Arrange
outfile = "out_collage"
args = (
" -m collage --AlbumSize 200 --AlbumOpacity 85 "
" --AlbumNumber 60 --GradientSize 20 --Passes 3 ")
# Act/Assert
self.helper_run_and_assert_file(args, outfile)
def test_photo_albums(self):
""" Test photo albums """
# Arrange
outfile = "out_photo"
args = (
" -m photo --AlbumSize 200 --AlbumNumber 60"
)
# Act/Assert
self.helper_run_and_assert_file(args, outfile)
def test_tiled_artists(self):
""" Test tiled artists """
# Arrange
outfile = "out_tiled_artist"
args = " -m tile --Artist"
# Act/Assert
self.helper_run_and_assert_file(args, outfile)
if __name__ == '__main__':
if len(COVERAGE_CMD):
os.system("coverage erase")
unittest.main()
# End of file