131
134
'type': u'video/mpeg',
132
135
'filesize': u'244700'}]
134
def testStringify(self):
135
# input, handleerror, expected output
136
# if handlerror is None, then it isn't passed in as an argument
139
( "abc", None, "abc"),
142
( u"abc", None, "abc"),
143
( u"abc\xe4", None, "abcä"),
144
( u"abc\xe4", "replace", "abc?")
137
def test_is_url_positive(self):
138
for testurl in [u"http://foo.bar.com/",
139
u"https://foo.bar.com/",
141
self.assertEqual(util.is_url(testurl), True)
143
def test_is_url_negative(self):
146
u"feed://foo.bar.com/",
147
u"http://foo.bar.com",
148
u"http:foo.bar.com/",
149
u"https:foo.bar.com/",
150
u"feed:foo.bar.com/",
151
u"http:/foo.bar.com/",
152
u"https:/foo.bar.com/",
153
u"feed:/foo.bar.com/",
154
u"http:///foo.bar.com/",
155
u"https:///foo.bar.com/",
156
u"feed:///foo.bar.com/",
159
u"crap:/foo.bar.com",
160
u"crap://foo.bar.com",
161
u"crap:///foo.bar.com",
163
u"No license (All rights reserved)",
165
self.assertEqual(util.is_url(testurl), False)
167
def test_stringify(self):
168
# input, handleerror, expected output if handlerror is None,
169
# then it isn't passed in as an argument
173
( "abc", None, "abc"),
176
( u"abc", None, "abc"),
177
( u"abc\xe4", None, "abcä"),
178
( u"abc\xe4", "replace", "abc?")
149
182
self.assertEquals(util.stringify(i), o)
151
184
self.assertEquals(util.stringify(i, h), o)
153
def testRandomString(self):
186
def test_random_string(self):
154
187
ret = util.random_string(0)
155
188
self.assertEquals(len(ret), 0)
217
250
u'http://example.org/1.ogg')
219
252
class DownloadUtilsTest(MiroTestCase):
220
def checkCleanFilename(self, filename, test_against):
221
self.assertEquals(download_utils.cleanFilename(filename),
253
def check_clean_filename(self, filename, test_against):
254
self.assertEquals(download_utils.clean_filename(filename),
224
def testCleanFilename(self):
225
self.checkCleanFilename('normalname', 'normalname')
226
self.checkCleanFilename('a:b?c>d<e|f*/g\\h"\'', 'abcdefgh')
227
self.checkCleanFilename('', '_')
228
longFilename = 'booya' * 100
229
longExtension = '.' + 'foo' * 20
230
self.checkCleanFilename(longFilename, longFilename[:100])
231
# total file length isn't over the limit, so the extension stays the
233
self.checkCleanFilename('abc' + longExtension,
234
'abc' + longExtension)
235
self.checkCleanFilename(longFilename + longExtension,
236
longFilename[:50] + longExtension[:50])
257
def test_clean_filename(self):
258
self.check_clean_filename('normalname', 'normalname')
259
self.check_clean_filename('a:b?c>d<e|f*/g\\h"\'', 'abcdefgh')
260
self.check_clean_filename('', '_')
261
long_filename = 'booya' * 100
262
long_extension = '.' + 'foo' * 20
263
self.check_clean_filename(long_filename, long_filename[:100])
264
# total file length isn't over the limit, so the extension
266
self.check_clean_filename('abc' + long_extension,
267
'abc' + long_extension)
268
self.check_clean_filename(long_filename + long_extension,
269
long_filename[:50] + long_extension[:50])
238
271
class Test_simple_config_file(MiroTestCase):
239
272
def test_read_simple_config_file(self):
348
392
self.assertEquals(m[0,0], 1)
349
393
self.assertEquals(m[0,1], None)
395
class Test_gather_subtitles_files(MiroTestCase):
397
MiroTestCase.setUp(self)
398
self.tempdir = tempfile.mkdtemp()
401
MiroTestCase.tearDown(self)
402
shutil.rmtree(self.tempdir, ignore_errors=True)
404
def create_files(self, movie_file, sub_files=None):
405
if sub_files is None:
408
movie_file = os.path.join(self.tempdir, movie_file)
409
sub_files = [os.path.join(self.tempdir, mem) for mem in sub_files]
412
all_files = [movie_file] + list(sub_files)
413
for mem in all_files:
414
dirname = os.path.dirname(mem)
415
if not os.path.exists(dirname):
418
filep = open(mem, "w")
419
filep.write("lalala")
422
return movie_file, sub_files
424
def test_no_directory(self):
425
# tests the case where the foofeed directory doesn't exist
426
movie_file = os.path.join(self.tempdir, "foofeed", "foo.mov")
427
self.assertEquals([],
428
util.gather_subtitle_files(FilenameType(movie_file)))
430
def test_no_subtitle_files(self):
431
movie_file, sub_files = self.create_files("foo.mov")
432
self.assertEquals(sub_files,
433
util.gather_subtitle_files(FilenameType(movie_file)))
435
def test_single_file(self):
436
movie_file, sub_files = self.create_files(
437
"foo.mov", ["foo.en.srt"])
438
self.assertEquals(sub_files,
439
util.gather_subtitle_files(FilenameType(movie_file)))
441
def test_multiple_files(self):
442
movie_file, sub_files = self.create_files(
443
"foo.mov", ["foo.en.srt", "foo.fr.srt", "foo.es.srt"])
444
self.assertEquals(sub_files,
445
util.gather_subtitle_files(FilenameType(movie_file)))
447
def test_lots_of_files(self):
448
movie_file, sub_files = self.create_files(
449
"foo.mov", ["foo.en.srt", "blah.ogv", "foo.ogv"])
451
# weed out the non-srt files so we can test correctly
452
sub_files = [mem for mem in sub_files if mem.endswith(".srt")]
453
self.assertEquals(sub_files,
454
util.gather_subtitle_files(FilenameType(movie_file)))
456
def test_subtitles_dir(self):
457
movie_file, sub_files = self.create_files(
458
"foo.mov", ["subtitles/foo.en.srt", "subtitles/foo.fr.srt"])
459
self.assertEquals(sub_files,
460
util.gather_subtitle_files(FilenameType(movie_file)))
462
def test_filename_possibilities(self):
463
movie_file, sub_files = self.create_files(
464
"foo.mov", ["foo.en.srt", "foo.en.sub", "foo.srt", "foo.sub"])
466
self.assertEquals(sub_files,
467
util.gather_subtitle_files(FilenameType(movie_file)))
469
class Test_copy_subtitle_file(MiroTestCase):
471
MiroTestCase.setUp(self)
472
self.tempdir = tempfile.mkdtemp()
475
MiroTestCase.tearDown(self)
476
shutil.rmtree(self.tempdir, ignore_errors=True)
478
def create_files(self, files):
480
dirname = os.path.dirname(mem)
481
if not os.path.exists(dirname):
484
filep = open(mem, "w")
485
filep.write("lalala")
488
def test_simple(self):
489
sub_path = os.path.join(self.tempdir, "otherdir/subtitle.srt")
490
video_path = os.path.join(self.tempdir, "foo.mov")
491
self.create_files([sub_path, video_path])
493
ret = util.copy_subtitle_file(sub_path, video_path)
494
expected = os.path.join(self.tempdir, "foo.srt")
495
self.assert_(os.path.exists(expected))
496
self.assertEqual(expected, ret)
498
def test_simple_with_language(self):
499
sub_path = os.path.join(self.tempdir, "otherdir/subtitle.en.srt")
500
video_path = os.path.join(self.tempdir, "foo.mov")
501
self.create_files([sub_path, video_path])
503
ret = util.copy_subtitle_file(sub_path, video_path)
504
expected = os.path.join(self.tempdir, "foo.en.srt")
505
self.assert_(os.path.exists(expected))
506
self.assertEqual(expected, ret)
508
def test_nonlanguage(self):
509
# "ex" is not a valid language code, so this should ignore
511
sub_path = os.path.join(self.tempdir, "otherdir/subtitle.ex.srt")
512
video_path = os.path.join(self.tempdir, "foo.mov")
513
self.create_files([sub_path, video_path])
515
ret = util.copy_subtitle_file(sub_path, video_path)
516
expected = os.path.join(self.tempdir, "foo.srt")
517
self.assert_(os.path.exists(expected))
518
self.assertEqual(expected, ret)