fixed some bugs, more unittests
[smewt:smewt.git] / smewt / test / test_episodesubtitle.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Smewt - A smart collection manager
5 # Copyright (c) 2008 Nicolas Wack <wackou@gmail.com>
6 #
7 # Smewt is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Smewt is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 from smewttest import *
22 from smewt.media.subtitle.subtitle_tvsubtitles_provider import TVSubtitlesProvider
23
24
25 def datafile(filename):
26     return os.path.join(os.path.split(__file__)[0], 'test_episodesubtitle', filename)
27
28 class TestEpisodeSubtitle(TestCase):
29
30     def setUp(self):
31         ontology.reload_saved_ontology('media')
32
33     def testSingleSubtitle(self):
34         for subdata in yaml.load(open(datafile('subsdata.yaml')).read()):
35             query = MemoryObjectGraph()
36             resultFile = subdata['result']
37             del subdata['result']
38
39             language = subdata['language']
40             del subdata['language']
41
42             s = query.Series(title = subdata['series'])
43             del subdata['series']
44
45             ep = query.Episode(series = s, **subdata)
46
47             subprovider = TVSubtitlesProvider()
48
49             self.assert_(subprovider.canHandle(ep))
50
51             available = subprovider.getAvailableSubtitles(ep).find_all(Subtitle, language = language)
52             self.assert_(len(available) >= 1)
53
54             sub = subprovider.getSubtitle(available[0])
55             self.assertEqual(open(datafile(resultFile)).read(), sub.replace('\r\n', '\n'))
56
57
58
59 suite = allTests(TestEpisodeSubtitle)
60
61
62 if __name__ == '__main__':
63     TextTestRunner(verbosity=2).run(suite)
64     smewt.shutdown()