-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_test.py
executable file
·129 lines (95 loc) · 3.64 KB
/
video_test.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
#!/usr/bin/python
# Copyright (C) Michael Still ([email protected]) 2006, 2007, 2008
# Released under the terms of the GNU GPL v2
# Unit tests for mythnettv's video module
import gflags
import os
import sys
import unittest
import database
import testsetup
import video
FLAGS = gflags.FLAGS
class VideoTest(unittest.TestCase):
def setUp(self):
""" Download required testing files """
for filename in ['video_length_fail.mov', 'video_length_works.avi',
'video_notavideo.mp4']:
testsetup.DownloadTestData(filename)
def testVideoInit(self):
vid = video.MythNetTvVideo(None, '/tmp/testdata/video_length_fail.mov')
def testVideoLengthError(self):
""" Make sure the right thing happens when we fail to get the length
of a video
"""
try:
vid = video.MythNetTvVideo(None, '/tmp/testdata/video_length_fail.mov')
vid.Length()
except video.LengthException, e:
# This is the exception we want
return
self.fail()
def testVideoLengthNotAVideo(self):
""" Some sites don't return a video file, for example when your IP isn't
in the country they allow downloads from. Make sure the right thing.
"""
try:
vid = video.MythNetTvVideo(None, '/tmp/testdata/video_notavideo.mp4')
vid.Length()
except video.LengthException, e:
# This is the exception we want
return
self.fail()
def testVideoLengthWorks(self):
""" This one should work """
vid = video.MythNetTvVideo(None, '/tmp/testdata/video_length_works.avi')
len = vid.Length()
self.assertEquals(int(len), 161)
def testNeedsTranscode(self):
""" A very simple test of whether to transcode a file """
vid = video.MythNetTvVideo(None, '/tmp/testdata/video_length_works.avi')
needs = vid.NeedsTranscode()
self.assertEquals(needs, False)
def testNewNeedsTranscode(self):
""" Ensure that the new algorithm for deciding to transcode is consistent
with the old one.
"""
db = database.MythNetTvDatabase(dbname='mythnettv_tests',
dbuser='test',
dbpassword='test',
dbhost='localhost')
vid = video.MythNetTvVideo(db, '/tmp/testdata/video_length_works.avi')
# Doesn't need transcoding
return_false = ['mp4v', '0x10000002', 'divx', 'DIVX', 'XVID',
'DX50']
# Does need transcoding
# Note that some avc1 videos work, and some don't -- so all get transcoded
return_true = ['avc1', 'theo', 'WMV2', 'FLV1']
for format in return_false:
vid.values['ID_VIDEO_FORMAT'] = format
self.assertEquals(vid.NeedsTranscode(), False,
'%s should not be transcoded' % format)
for format in return_true:
vid.values['ID_VIDEO_FORMAT'] = format
self.assertEquals(vid.NeedsTranscode(), True,
'%s should not be transcoded' % format)
def testEnsureNewFilenameUnique(self):
""" When we generate a new filename, it should not be the same as an
existing filename
"""
vid = video.MythNetTvVideo(None, '/tmp/testdata/video_length_works.avi')
new_name = vid.NewFilename('/tmp/testdata', 'avi')
if os.path.exists('/tmp/testdata/%s' % new_name):
self.fail()
def testTranscode(self):
""" Do a sample transcode """
vid = video.MythNetTvVideo(None, '/tmp/testdata/video_length_works.avi')
vid.Transcode('/tmp/testdata')
if __name__ == "__main__":
# Parse flags
try:
argv = FLAGS(sys.argv)
except gflags.FlagsError, e:
out.write('%s\n' % e)
Usage(out)
unittest.main()