~khwalker/entertainer/config-keybindings

« back to all changes in this revision

Viewing changes to entertainerlib/tests/test_thumbnailer.py

The thumbnailers have all been consolidated into a single module.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
'''Test the thumbnailer abstract class'''
 
1
'''Thumbnailer tests.'''
 
2
# pylint: disable-msg=W0212
2
3
 
3
4
import os
4
5
 
 
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,
 
9
    VideoThumbnailer)
7
10
 
8
11
THIS_DIR = os.path.dirname(__file__)
9
12
 
 
13
 
10
14
class ThumbnailerTest(EntertainerTest):
11
15
    '''Test the thumbnailer abstract class'''
12
16
 
52
56
            THIS_DIR + '/data/ImageThumbnailer/test.jpg', 'image')
53
57
        self.assertRaises(Exception, thumbnailer_test.create_thumbnail)
54
58
 
 
59
 
 
60
class ImageThumbnailerTest(EntertainerTest):
 
61
    '''Test ImageThumbnailer'''
 
62
 
 
63
    def setUp(self):
 
64
        """See unittest.TestCase"""
 
65
        EntertainerTest.setUp(self)
 
66
        self.debug = False
 
67
        self.filename = (
 
68
            THIS_DIR + '/data/ImageThumbnailer/test.jpg')
 
69
 
 
70
    def tearDown(self):
 
71
        """Clean up after the test"""
 
72
        EntertainerTest.tearDown(self)
 
73
 
 
74
    def testThumbnailer(self):
 
75
        '''Tests the creation a file'''
 
76
        thumbnailer = ImageThumbnailer(self.filename)
 
77
        thumbnailer.create_thumbnail()
 
78
        if self.debug:
 
79
            print 'Expecting thumbnail : %s' % thumbnailer._thumb_file
 
80
        self.assertTrue(os.path.exists(thumbnailer._thumb_file))
 
81
 
 
82
 
 
83
class VideoThumbnailerTest(EntertainerTest):
 
84
    '''Tests VideoThumbnailer'''
 
85
 
 
86
    def setUp(self):
 
87
        """See unittest.TestCase"""
 
88
        EntertainerTest.setUp(self)
 
89
        self.debug = False
 
90
 
 
91
    def tearDown(self):
 
92
        """Clean up after the test"""
 
93
        EntertainerTest.tearDown(self)
 
94
 
 
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))
 
100
 
 
101
    def testThumbnailerConstructorFilenameIsFolder(self):
 
102
        '''Tests proper handling of folders instead of files'''
 
103
        self.assertRaises(ThumbnailerException,
 
104
            VideoThumbnailer, os.path.abspath('.'))
 
105
 
 
106
    def testThumbnailerConstructorFilenameExists(self):
 
107
        '''Tests existence of file to thumbnail'''
 
108
        self.assertRaises(ThumbnailerException,
 
109
            VideoThumbnailer, os.path.abspath('foo-bar-baz'))
 
110
 
 
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")
 
116
 
 
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()
 
124
        if self.debug:
 
125
            print 'Expecting thumbnail : %s' % (self.thumbnailer._thumb_file)
 
126
        self.assertTrue(os.path.exists(thumbnailer._thumb_file))
 
127
 
 
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()
 
135
        if self.debug:
 
136
            print 'Expecting thumbnail : %s' % (self.thumbnailer._thumb_file)
 
137
        self.assertTrue(os.path.exists(thumbnailer._thumb_file))
 
138