41
41
parser.add_argument("files", metavar="file", nargs="*",
42
42
help="document, spreadsheet or presentation to be tested")
44
parser.add_argument("-m","--unoconv_max_size", type=int, metavar="MAX_SIZE",
45
help="OOOTHUMBNAILER_UNOCONV_MAX_SIZE environment variable to be used")
47
parser.add_argument("-t", "--timeout", type=int,
48
help="OOOTHUMBNAILER_TIMEOUT environment variable to be used")
44
parser.add_argument("-t", "--timeout", type=float,
45
help="maximum time allowed to make a thumbnail")
50
47
parser.add_argument("-d", "--debug", action="store_const", const=True,
51
48
default=False, help="print debugging information on failed tests")
71
68
files = list_of_files()
74
if args.unoconv_max_size is None and args.timeout is None:
75
out = os.path.join(os.path.dirname(__file__), "output/")
76
# If no options are specified, run these tests
77
errors = test_files(files, out + "1", 4000000)
78
errors += test_files(files, out + "2", timeout=3)
79
errors += test_files(files, out + "3", 4000000, 3)
80
errors += test_files(files, out + "4")
81
num_of_files = len(files) * 4
71
if args.timeout is None:
72
errors = test_files(files)
84
if args.unoconv_max_size:
85
kwargs["unoconv_max_size"] = args.unoconv_max_size
87
kwargs["timeout"] = args.timeout
88
errors = test_files(files, **kwargs)
89
num_of_files = len(files)
74
errors = test_files(files, timeout=args.timeout)
93
78
print "Tests were successful"
95
80
print red("%d test%s failed out of %d" % \
96
(errors, "s" if errors != 1 else "", num_of_files))
81
(errors, "s" if errors != 1 else "", len(files)))
98
84
except KeyboardInterrupt:
162
147
output_directory = os.path.join(os.path.dirname(__file__), "output")
163
148
if not os.path.isdir(output_directory):
164
149
os.mkdir(output_directory)
165
151
# Print title of test
166
print green("Testing %d file%s with unoconv_max_size=%d and timeout=%d" \
167
% (len(files), "s" if len(files) != 1 else "", unoconv_max_size,
152
print green("Testing %d file%s with timeout=%f" \
153
% (len(files), "s" if len(files) != 1 else "", timeout))
169
155
# Get maximum length of filenames
171
157
for file in files:
214
199
if os.path.exists(output):
215
200
os.remove(output)
217
# Run ooo-thumbnailer with specified file and options, timed with
220
env["OOOTHUMBNAILER_UNOCONV_MAX_SIZE"] = str(int(unoconv_max_size))
221
env["OOOTHUMBNAILER_TIMEOUT"] = str(int(timeout))
202
# Run ooo-thumbnailer with specified file and options
224
command.extend(["/usr/bin/timeout", str(timeout)])
227
206
command.extend(["bash", "-x"])
228
207
command.append(SCRIPT)
229
if unoconv_max_size > 0:
230
command.extend(["-m", str(unoconv_max_size)])
231
208
command.extend([file, output, "128"])
233
210
time1 = get_time()
234
211
process = subprocess.Popen(command,
235
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
212
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
238
214
stdout, stderr = process.communicate()
246
223
# Determine results
248
225
if process.returncode == 0 and os.path.exists(output):
249
# Check to see if unoconv_max_size was obeyed or not
250
if unoconv_max_size > 0 and is_file_in_microsoft_format(file) \
251
and not is_file_with_thumbnail(file) \
252
and os.path.getsize(file) > unoconv_max_size:
253
outcome = red("Ignored unoconv_max_size")
254
# Check to see if timeout was obeyed or not
255
elif timeout > 0 and time > timeout + 0.05:
256
outcome = red("Ignored timeout")
226
# Successful error code and thumbnail has been created
228
# Check to see if result was unexpectedly slow
229
if time > timeout and is_file_with_thumbnail(file):
230
outcome = red("Thumbnail created, but unexpectedly slow")
258
# Successful error code and thumbnail has been created
259
# Check to see if result was unexpectedly slow
260
if time > 3 and is_file_with_thumbnail(file):
261
outcome = red("Thumbnail created, but unexpectedly slow")
263
outcome = green("Success: thumbnail created")
232
outcome = green("Success: thumbnail created")
265
235
elif process.returncode == 0:
266
236
# Successful error code but thumbnail file does not exist
267
237
outcome = red("Thumbnail not found, but errorcode is 0")
268
elif unoconv_max_size > 0 and process.returncode == 9:
269
# Error code 9 indicates that file was too large
270
if is_file_in_microsoft_format(file) \
271
and not is_file_with_thumbnail(file) \
272
and os.path.getsize(file) >= unoconv_max_size:
273
outcome = green("Success: skipped because too large")
276
outcome = red("Skipped when it shouldn't have")
277
elif timeout > 0 and process.returncode == 137 or process.returncode == -9:
278
# Error code 8 indicates that the script timed out
280
if time >= 3 and is_file_with_thumbnail(file):
281
outcome = red("Timed out, but this operation should have been quick")
283
outcome = green("Success: timed out")
286
outcome = red("Timed out too early")
288
240
outcome = red("Failed (code:%d)" % process.returncode)
289
242
if debug and not success:
290
243
outcome = outcome + "\n" + str(command) + "\n" + stdout + "\n" + stderr
291
245
return "%0.2f seconds" % time, outcome, success
293
247
def is_file_in_microsoft_format(file):