pylint tests written for gstreamer

This commit is contained in:
Thomas Adamcik 2010-05-01 21:53:52 +02:00
parent d757d6a0ec
commit d873fd62de
4 changed files with 53 additions and 46 deletions

View File

@ -77,7 +77,8 @@ class BaseCurrentPlaylistControllerTest(object):
@populate_playlist
def test_get_by_uri_raises_error_for_invalid_id(self):
self.assertRaises(LookupError, lambda: self.controller.get(uri='foobar'))
test = lambda: self.controller.get(uri='foobar')
self.assertRaises(LookupError, test)
@populate_playlist
def test_clear(self):
@ -232,7 +233,6 @@ class BaseCurrentPlaylistControllerTest(object):
@populate_playlist
def test_move_group_invalid_group(self):
tracks = len(self.controller.playlist.tracks)
test = lambda: self.controller.move(2, 1, 0)
self.assertRaises(AssertionError, test)
@ -605,11 +605,11 @@ class BasePlaybackControllerTest(object):
self.assertEqual(self.playback.playlist_position, None)
def test_new_playlist_loaded_callback_gets_called(self):
new_playlist_loaded_callback = self.playback.new_playlist_loaded_callback
callback = self.playback.new_playlist_loaded_callback
def wrapper():
wrapper.called = True
return new_playlist_loaded_callback()
return callback()
wrapper.called = False
self.playback.new_playlist_loaded_callback = wrapper
@ -627,7 +627,7 @@ class BasePlaybackControllerTest(object):
event.set()
return result
self.playback.end_of_track_callback= wrapper
self.playback.end_of_track_callback = wrapper
self.playback.play()
self.playback.seek(self.tracks[0].length - 10)
@ -977,6 +977,7 @@ class BaseStoredPlaylistsControllerTest(object):
def test_create_in_playlists(self):
playlist = self.stored.create('test')
self.assert_(self.stored.playlists)
self.assert_(playlist in self.stored.playlists)
def test_playlists_empty_to_start_with(self):
self.assert_(not self.stored.playlists)
@ -990,7 +991,7 @@ class BaseStoredPlaylistsControllerTest(object):
self.assert_(not self.stored.playlists)
def test_get_without_criteria(self):
test = lambda: self.stored.get()
test = self.stored.get
self.assertRaises(LookupError, test)
def test_get_with_wrong_cirteria(self):
@ -1064,15 +1065,15 @@ class BaseStoredPlaylistsControllerTest(object):
class BaseLibraryControllerTest(object):
tracks = []
artists = [Artist(name='artist1'), Artist(name='artist2'), Artist()]
albums = [Album(name='album1', artists=artists[:1]),
Album(name='album2', artists=artists[1:2]),
Album()]
tracks = [Track(name='track1', length=4000, artists=artists[:1], album=albums[0], uri='file://' + data_folder('uri1')),
Track(name='track2', length=4000, artists=artists[1:2], album=albums[1], uri='file://' + data_folder('uri2')),
Track()]
Album(name='album2', artists=artists[1:2]),
Album()]
tracks = [Track(name='track1', length=4000, artists=artists[:1],
album=albums[0], uri='file://' + data_folder('uri1')),
Track(name='track2', length=4000, artists=artists[1:2],
album=albums[1], uri='file://' + data_folder('uri2')),
Track()]
def setUp(self):
self.backend = self.backend_class(mixer=DummyMixer())

View File

@ -14,18 +14,22 @@ song = data_folder('song%s.wav')
generate_song = lambda i: path_to_uri(song % i)
# FIXME can be switched to generic test
class GStreamerCurrentPlaylistControllerTest(BaseCurrentPlaylistControllerTest, unittest.TestCase):
tracks = [Track(uri=generate_song(i), id=i, length=4464) for i in range(1, 4)]
class GStreamerCurrentPlaylistControllerTest(BaseCurrentPlaylistControllerTest,
unittest.TestCase):
tracks = [Track(uri=generate_song(i), id=i, length=4464)
for i in range(1, 4)]
backend_class = GStreamerBackend
class GStreamerPlaybackControllerTest(BasePlaybackControllerTest, unittest.TestCase):
tracks = [Track(uri=generate_song(i), id=i, length=4464) for i in range(1, 4)]
class GStreamerPlaybackControllerTest(BasePlaybackControllerTest,
unittest.TestCase):
tracks = [Track(uri=generate_song(i), id=i, length=4464)
for i in range(1, 4)]
backend_class = GStreamerBackend
def add_track(self, file):
uri = path_to_uri(data_folder(file))
def add_track(self, path):
uri = path_to_uri(data_folder(path))
track = Track(uri=uri, id=1, length=4464)
self.backend.current_playlist.add(track)
@ -68,8 +72,8 @@ class GStreamerStoredPlaylistsControllerTest(BaseStoredPlaylistsControllerTest,
def test_deleted_playlist_get_removed(self):
playlist = self.stored.create('test')
self.stored.delete(playlist)
file = os.path.join(settings.PLAYLIST_FOLDER, 'test.m3u')
self.assert_(not os.path.exists(file))
path = os.path.join(settings.PLAYLIST_FOLDER, 'test.m3u')
self.assert_(not os.path.exists(path))
def test_renamed_playlist_gets_moved(self):
playlist = self.stored.create('test')
@ -84,19 +88,18 @@ class GStreamerStoredPlaylistsControllerTest(BaseStoredPlaylistsControllerTest,
track = Track(uri=generate_song(1))
uri = track.uri[len('file://'):]
playlist = Playlist(tracks=[track], name='test')
file_path = os.path.join(settings.PLAYLIST_FOLDER, 'test.m3u')
path = os.path.join(settings.PLAYLIST_FOLDER, 'test.m3u')
self.stored.save(playlist)
with open(file_path) as file:
contents = file.read()
with open(path) as playlist_file:
contents = playlist_file.read()
self.assertEqual(uri, contents.strip())
def test_playlists_are_loaded_at_startup(self):
track = Track(uri=generate_song(1))
playlist = Playlist(tracks=[track], name='test')
file_path = os.path.join(settings.PLAYLIST_FOLDER, 'test.m3u')
self.stored.save(playlist)
@ -135,7 +138,7 @@ class GStreamerLibraryControllerTest(BaseLibraryControllerTest,
def tearDown(self):
settings.TAG_CACHE = self.original_tag_cache
settings.MUSIC_FOLDER= self.original_music_folder
settings.MUSIC_FOLDER = self.original_music_folder
super(GStreamerLibraryControllerTest, self).tearDown()
if __name__ == '__main__':

View File

@ -165,8 +165,10 @@ class AlbumTest(unittest.TestCase):
self.assertNotEqual(hash(album1), hash(album2))
def test_ne(self):
album1 = Album(name=u'name1', uri=u'uri1', artists=[Artist(name=u'name1')], num_tracks=1)
album2 = Album(name=u'name2', uri=u'uri2', artists=[Artist(name=u'name2')], num_tracks=2)
album1 = Album(name=u'name1', uri=u'uri1',
artists=[Artist(name=u'name1')], num_tracks=1)
album2 = Album(name=u'name2', uri=u'uri2',
artists=[Artist(name=u'name2')], num_tracks=2)
self.assertNotEqual(album1, album2)
self.assertNotEqual(hash(album1), hash(album2))
@ -221,9 +223,9 @@ class TrackTest(unittest.TestCase):
self.assertRaises(AttributeError, setattr, track, 'bitrate', None)
def test_id(self):
id = 17
track = Track(id=id)
self.assertEqual(track.id, id)
track_id = 17
track = Track(id=track_id)
self.assertEqual(track.id, track_id)
self.assertRaises(AttributeError, setattr, track, 'id', None)
def test_mpd_format_for_empty_track(self):

View File

@ -95,26 +95,26 @@ class M3UToUriTest(unittest.TestCase):
self.assertEqual([song1_uri], uris)
def test_file_with_absolute_files(self):
with tempfile.NamedTemporaryFile() as file:
file.write(song1_path)
file.flush()
uris = parse_m3u(file.name)
with tempfile.NamedTemporaryFile() as tmp:
tmp.write(song1_path)
tmp.flush()
uris = parse_m3u(tmp.name)
self.assertEqual([song1_uri], uris)
def test_file_with_multiple_absolute_files(self):
with tempfile.NamedTemporaryFile() as file:
file.write(song1_path+'\n')
file.write('# comment \n')
file.write(song2_path)
file.flush()
uris = parse_m3u(file.name)
with tempfile.NamedTemporaryFile() as tmp:
tmp.write(song1_path+'\n')
tmp.write('# comment \n')
tmp.write(song2_path)
tmp.flush()
uris = parse_m3u(tmp.name)
self.assertEqual([song1_uri, song2_uri], uris)
def test_file_with_uri(self):
with tempfile.NamedTemporaryFile() as file:
file.write(song1_uri)
file.flush()
uris = parse_m3u(file.name)
with tempfile.NamedTemporaryFile() as tmp:
tmp.write(song1_uri)
tmp.flush()
uris = parse_m3u(tmp.name)
self.assertEqual([song1_uri], uris)
def test_encoding_is_latin1(self):
@ -130,7 +130,8 @@ class URItoM3UTest(unittest.TestCase):
pass
expected_artists = [Artist(name='name')]
expected_albums = [Album(name='albumname', artists=expected_artists, num_tracks=2)]
expected_albums = [Album(name='albumname', artists=expected_artists,
num_tracks=2)]
expected_tracks = []
def generate_track(path):