1
'''Test the thumbnailer abstract class'''
1
'''Thumbnailer tests.'''
2
# pylint: disable-msg=W0212
6
from entertainerlib.exceptions import ThumbnailerException
5
7
from entertainerlib.tests import EntertainerTest
6
from entertainerlib.utils.thumbnailer import Thumbnailer, ThumbnailerException
8
from entertainerlib.thumbnailer import (ImageThumbnailer, Thumbnailer,
8
11
THIS_DIR = os.path.dirname(__file__)
10
14
class ThumbnailerTest(EntertainerTest):
11
15
'''Test the thumbnailer abstract class'''
52
56
THIS_DIR + '/data/ImageThumbnailer/test.jpg', 'image')
53
57
self.assertRaises(Exception, thumbnailer_test.create_thumbnail)
60
class ImageThumbnailerTest(EntertainerTest):
61
'''Test ImageThumbnailer'''
64
"""See unittest.TestCase"""
65
EntertainerTest.setUp(self)
68
THIS_DIR + '/data/ImageThumbnailer/test.jpg')
71
"""Clean up after the test"""
72
EntertainerTest.tearDown(self)
74
def testThumbnailer(self):
75
'''Tests the creation a file'''
76
thumbnailer = ImageThumbnailer(self.filename)
77
thumbnailer.create_thumbnail()
79
print 'Expecting thumbnail : %s' % thumbnailer._thumb_file
80
self.assertTrue(os.path.exists(thumbnailer._thumb_file))
83
class VideoThumbnailerTest(EntertainerTest):
84
'''Tests VideoThumbnailer'''
87
"""See unittest.TestCase"""
88
EntertainerTest.setUp(self)
92
"""Clean up after the test"""
93
EntertainerTest.tearDown(self)
95
def testThumbnailerConstructor(self):
96
'''Tests instantiation of thumbnailer class'''
97
self.thumbnailer = VideoThumbnailer(
98
THIS_DIR + '/data/VideoThumbnailer/test.avi', src='video')
99
self.assertTrue(isinstance(self.thumbnailer, VideoThumbnailer))
101
def testThumbnailerConstructorFilenameIsFolder(self):
102
'''Tests proper handling of folders instead of files'''
103
self.assertRaises(ThumbnailerException,
104
VideoThumbnailer, os.path.abspath('.'))
106
def testThumbnailerConstructorFilenameExists(self):
107
'''Tests existence of file to thumbnail'''
108
self.assertRaises(ThumbnailerException,
109
VideoThumbnailer, os.path.abspath('foo-bar-baz'))
111
def testThumbnailerConstructorSrc(self):
112
'''Tests valid source types'''
113
self.assertRaises(ThumbnailerException,
114
VideoThumbnailer, os.path.abspath('.') +
115
'/data/VideoThumbnailer/test.avi', src="foo")
117
def testThumbnailAvi(self):
118
'''Tests thumbnailing of Avi file'''
119
thumbnailer = VideoThumbnailer(
120
THIS_DIR + '/data/VideoThumbnailer/test.avi', src='video')
121
if os.path.exists(thumbnailer._thumb_file):
122
os.remove(thumbnailer._thumb_file)
123
thumbnailer.create_thumbnail()
125
print 'Expecting thumbnail : %s' % (self.thumbnailer._thumb_file)
126
self.assertTrue(os.path.exists(thumbnailer._thumb_file))
128
def testThumbnailFlv(self):
129
'''Tests thumbnailing of a flash file'''
130
thumbnailer = VideoThumbnailer(
131
THIS_DIR + '/data/VideoThumbnailer/test.avi', src='video')
132
if os.path.exists(thumbnailer._thumb_file):
133
os.remove(thumbnailer._thumb_file)
134
thumbnailer.create_thumbnail()
136
print 'Expecting thumbnail : %s' % (self.thumbnailer._thumb_file)
137
self.assertTrue(os.path.exists(thumbnailer._thumb_file))