From efad50c253dbf4c53feb4fe81addcdea8d392e0d Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Thu, 16 Apr 2015 00:25:01 +0200 Subject: [PATCH] cleanup: Stop using deprecated copy() --- mopidy/core/playlists.py | 2 +- mopidy/local/commands.py | 2 +- mopidy/m3u/playlists.py | 2 +- mopidy/m3u/translator.py | 6 +-- mopidy/mpd/protocol/music_db.py | 2 +- mopidy/stream/actor.py | 2 +- tests/audio/test_utils.py | 80 ++++++++++++++--------------- tests/core/test_events.py | 2 +- tests/m3u/test_playlists.py | 18 +++---- tests/m3u/test_translator.py | 6 +-- tests/mpd/protocol/test_music_db.py | 2 +- tests/mpd/test_translator.py | 16 +++--- 12 files changed, 70 insertions(+), 70 deletions(-) diff --git a/mopidy/core/playlists.py b/mopidy/core/playlists.py index 9be5efa7..aa5befaf 100644 --- a/mopidy/core/playlists.py +++ b/mopidy/core/playlists.py @@ -92,7 +92,7 @@ class PlaylistsController(object): # Use the playlist name from as_list() because it knows about any # playlist folder hierarchy, which lookup() does not. return [ - playlists[r.uri].copy(name=r.name) + playlists[r.uri].replace(name=r.name) for r in playlist_refs if playlists[r.uri] is not None] else: return [ diff --git a/mopidy/local/commands.py b/mopidy/local/commands.py index 486e205f..c8c70216 100644 --- a/mopidy/local/commands.py +++ b/mopidy/local/commands.py @@ -143,7 +143,7 @@ class ScanCommand(commands.Command): uri, MIN_DURATION_MS) else: mtime = file_mtimes.get(os.path.join(media_dir, relpath)) - track = utils.convert_tags_to_track(tags).copy( + track = utils.convert_tags_to_track(tags).replace( uri=uri, length=duration, last_modified=mtime) if library.add_supports_tags_and_duration: library.add(track, tags=tags, duration=duration) diff --git a/mopidy/m3u/playlists.py b/mopidy/m3u/playlists.py index eaa3d980..bfb27dc0 100644 --- a/mopidy/m3u/playlists.py +++ b/mopidy/m3u/playlists.py @@ -126,4 +126,4 @@ class M3UPlaylistsProvider(backend.PlaylistsProvider): file_handle.write(track.uri + '\n') # assert playlist name matches file name/uri - return playlist.copy(uri=uri, name=name) + return playlist.replace(uri=uri, name=name) diff --git a/mopidy/m3u/translator.py b/mopidy/m3u/translator.py index 4eefce9d..177ab6c3 100644 --- a/mopidy/m3u/translator.py +++ b/mopidy/m3u/translator.py @@ -98,13 +98,13 @@ def parse_m3u(file_path, media_dir=None): continue if urlparse.urlsplit(line).scheme: - tracks.append(track.copy(uri=line)) + tracks.append(track.replace(uri=line)) elif os.path.normpath(line) == os.path.abspath(line): path = path_to_uri(line) - tracks.append(track.copy(uri=path)) + tracks.append(track.replace(uri=path)) elif media_dir is not None: path = path_to_uri(os.path.join(media_dir, line)) - tracks.append(track.copy(uri=path)) + tracks.append(track.replace(uri=path)) track = Track() return tracks diff --git a/mopidy/mpd/protocol/music_db.py b/mopidy/mpd/protocol/music_db.py index 541fcd6d..83dab871 100644 --- a/mopidy/mpd/protocol/music_db.py +++ b/mopidy/mpd/protocol/music_db.py @@ -486,7 +486,7 @@ def searchaddpl(context, *args): if not playlist: playlist = context.core.playlists.create(playlist_name).get() tracks = list(playlist.tracks) + _get_tracks(results) - playlist = playlist.copy(tracks=tracks) + playlist = playlist.replace(tracks=tracks) context.core.playlists.save(playlist) diff --git a/mopidy/stream/actor.py b/mopidy/stream/actor.py index 81e07b6d..4b81f60e 100644 --- a/mopidy/stream/actor.py +++ b/mopidy/stream/actor.py @@ -48,7 +48,7 @@ class StreamLibraryProvider(backend.LibraryProvider): try: result = self._scanner.scan(uri) - track = utils.convert_tags_to_track(result.tags).copy( + track = utils.convert_tags_to_track(result.tags).replace( uri=uri, length=result.duration) except exceptions.ScannerError as e: logger.warning('Problem looking up %s: %s', uri, e) diff --git a/tests/audio/test_utils.py b/tests/audio/test_utils.py index a49ead90..200d7729 100644 --- a/tests/audio/test_utils.py +++ b/tests/audio/test_utils.py @@ -59,7 +59,7 @@ class TagsToTrackTest(unittest.TestCase): def test_missing_track_no(self): del self.tags['track-number'] - self.check(self.track.copy(track_no=None)) + self.check(self.track.replace(track_no=None)) def test_multiple_track_no(self): self.tags['track-number'].append(9) @@ -67,7 +67,7 @@ class TagsToTrackTest(unittest.TestCase): def test_missing_track_disc_no(self): del self.tags['album-disc-number'] - self.check(self.track.copy(disc_no=None)) + self.check(self.track.replace(disc_no=None)) def test_multiple_track_disc_no(self): self.tags['album-disc-number'].append(9) @@ -75,15 +75,15 @@ class TagsToTrackTest(unittest.TestCase): def test_missing_track_name(self): del self.tags['title'] - self.check(self.track.copy(name=None)) + self.check(self.track.replace(name=None)) def test_multiple_track_name(self): self.tags['title'] = ['name1', 'name2'] - self.check(self.track.copy(name='name1; name2')) + self.check(self.track.replace(name='name1; name2')) def test_missing_track_musicbrainz_id(self): del self.tags['musicbrainz-trackid'] - self.check(self.track.copy(musicbrainz_id=None)) + self.check(self.track.replace(musicbrainz_id=None)) def test_multiple_track_musicbrainz_id(self): self.tags['musicbrainz-trackid'].append('id') @@ -91,7 +91,7 @@ class TagsToTrackTest(unittest.TestCase): def test_missing_track_bitrate(self): del self.tags['bitrate'] - self.check(self.track.copy(bitrate=None)) + self.check(self.track.replace(bitrate=None)) def test_multiple_track_bitrate(self): self.tags['bitrate'].append(1234) @@ -99,15 +99,15 @@ class TagsToTrackTest(unittest.TestCase): def test_missing_track_genre(self): del self.tags['genre'] - self.check(self.track.copy(genre=None)) + self.check(self.track.replace(genre=None)) def test_multiple_track_genre(self): self.tags['genre'] = ['genre1', 'genre2'] - self.check(self.track.copy(genre='genre1; genre2')) + self.check(self.track.replace(genre='genre1; genre2')) def test_missing_track_date(self): del self.tags['date'] - self.check(self.track.copy(date=None)) + self.check(self.track.replace(date=None)) def test_multiple_track_date(self): self.tags['date'].append(datetime.date(2030, 1, 1)) @@ -115,25 +115,25 @@ class TagsToTrackTest(unittest.TestCase): def test_missing_track_comment(self): del self.tags['comment'] - self.check(self.track.copy(comment=None)) + self.check(self.track.replace(comment=None)) def test_multiple_track_comment(self): self.tags['comment'] = ['comment1', 'comment2'] - self.check(self.track.copy(comment='comment1; comment2')) + self.check(self.track.replace(comment='comment1; comment2')) def test_missing_track_artist_name(self): del self.tags['artist'] - self.check(self.track.copy(artists=[])) + self.check(self.track.replace(artists=[])) def test_multiple_track_artist_name(self): self.tags['artist'] = ['name1', 'name2'] artists = [Artist(name='name1'), Artist(name='name2')] - self.check(self.track.copy(artists=artists)) + self.check(self.track.replace(artists=artists)) def test_missing_track_artist_musicbrainz_id(self): del self.tags['musicbrainz-artistid'] - artist = list(self.track.artists)[0].copy(musicbrainz_id=None) - self.check(self.track.copy(artists=[artist])) + artist = list(self.track.artists)[0].replace(musicbrainz_id=None) + self.check(self.track.replace(artists=[artist])) def test_multiple_track_artist_musicbrainz_id(self): self.tags['musicbrainz-artistid'].append('id') @@ -141,25 +141,25 @@ class TagsToTrackTest(unittest.TestCase): def test_missing_track_composer_name(self): del self.tags['composer'] - self.check(self.track.copy(composers=[])) + self.check(self.track.replace(composers=[])) def test_multiple_track_composer_name(self): self.tags['composer'] = ['composer1', 'composer2'] composers = [Artist(name='composer1'), Artist(name='composer2')] - self.check(self.track.copy(composers=composers)) + self.check(self.track.replace(composers=composers)) def test_missing_track_performer_name(self): del self.tags['performer'] - self.check(self.track.copy(performers=[])) + self.check(self.track.replace(performers=[])) def test_multiple_track_performe_name(self): self.tags['performer'] = ['performer1', 'performer2'] performers = [Artist(name='performer1'), Artist(name='performer2')] - self.check(self.track.copy(performers=performers)) + self.check(self.track.replace(performers=performers)) def test_missing_album_name(self): del self.tags['album'] - self.check(self.track.copy(album=None)) + self.check(self.track.replace(album=None)) def test_multiple_album_name(self): self.tags['album'].append('album2') @@ -167,9 +167,9 @@ class TagsToTrackTest(unittest.TestCase): def test_missing_album_musicbrainz_id(self): del self.tags['musicbrainz-albumid'] - album = self.track.album.copy(musicbrainz_id=None, - images=[]) - self.check(self.track.copy(album=album)) + album = self.track.album.replace(musicbrainz_id=None, + images=[]) + self.check(self.track.replace(album=album)) def test_multiple_album_musicbrainz_id(self): self.tags['musicbrainz-albumid'].append('id') @@ -177,8 +177,8 @@ class TagsToTrackTest(unittest.TestCase): def test_missing_album_num_tracks(self): del self.tags['track-count'] - album = self.track.album.copy(num_tracks=None) - self.check(self.track.copy(album=album)) + album = self.track.album.replace(num_tracks=None) + self.check(self.track.replace(album=album)) def test_multiple_album_num_tracks(self): self.tags['track-count'].append(9) @@ -186,8 +186,8 @@ class TagsToTrackTest(unittest.TestCase): def test_missing_album_num_discs(self): del self.tags['album-disc-count'] - album = self.track.album.copy(num_discs=None) - self.check(self.track.copy(album=album)) + album = self.track.album.replace(num_discs=None) + self.check(self.track.replace(album=album)) def test_multiple_album_num_discs(self): self.tags['album-disc-count'].append(9) @@ -195,21 +195,21 @@ class TagsToTrackTest(unittest.TestCase): def test_missing_album_artist_name(self): del self.tags['album-artist'] - album = self.track.album.copy(artists=[]) - self.check(self.track.copy(album=album)) + album = self.track.album.replace(artists=[]) + self.check(self.track.replace(album=album)) def test_multiple_album_artist_name(self): self.tags['album-artist'] = ['name1', 'name2'] artists = [Artist(name='name1'), Artist(name='name2')] - album = self.track.album.copy(artists=artists) - self.check(self.track.copy(album=album)) + album = self.track.album.replace(artists=artists) + self.check(self.track.replace(album=album)) def test_missing_album_artist_musicbrainz_id(self): del self.tags['musicbrainz-albumartistid'] albumartist = list(self.track.album.artists)[0] - albumartist = albumartist.copy(musicbrainz_id=None) - album = self.track.album.copy(artists=[albumartist]) - self.check(self.track.copy(album=album)) + albumartist = albumartist.replace(musicbrainz_id=None) + album = self.track.album.replace(artists=[albumartist]) + self.check(self.track.replace(album=album)) def test_multiple_album_artist_musicbrainz_id(self): self.tags['musicbrainz-albumartistid'].append('id') @@ -218,30 +218,30 @@ class TagsToTrackTest(unittest.TestCase): def test_stream_organization_track_name(self): del self.tags['title'] self.tags['organization'] = ['organization'] - self.check(self.track.copy(name='organization')) + self.check(self.track.replace(name='organization')) def test_multiple_organization_track_name(self): del self.tags['title'] self.tags['organization'] = ['organization1', 'organization2'] - self.check(self.track.copy(name='organization1; organization2')) + self.check(self.track.replace(name='organization1; organization2')) # TODO: combine all comment types? def test_stream_location_track_comment(self): del self.tags['comment'] self.tags['location'] = ['location'] - self.check(self.track.copy(comment='location')) + self.check(self.track.replace(comment='location')) def test_multiple_location_track_comment(self): del self.tags['comment'] self.tags['location'] = ['location1', 'location2'] - self.check(self.track.copy(comment='location1; location2')) + self.check(self.track.replace(comment='location1; location2')) def test_stream_copyright_track_comment(self): del self.tags['comment'] self.tags['copyright'] = ['copyright'] - self.check(self.track.copy(comment='copyright')) + self.check(self.track.replace(comment='copyright')) def test_multiple_copyright_track_comment(self): del self.tags['comment'] self.tags['copyright'] = ['copyright1', 'copyright2'] - self.check(self.track.copy(comment='copyright1; copyright2')) + self.check(self.track.replace(comment='copyright1; copyright2')) diff --git a/tests/core/test_events.py b/tests/core/test_events.py index e916b670..67dc91f0 100644 --- a/tests/core/test_events.py +++ b/tests/core/test_events.py @@ -111,7 +111,7 @@ class BackendEventsTest(unittest.TestCase): def test_playlists_save_sends_playlist_changed_event(self, send): playlist = self.core.playlists.create('foo').get() - playlist = playlist.copy(name='bar') + playlist = playlist.replace(name='bar') send.reset_mock() self.core.playlists.save(playlist).get() diff --git a/tests/m3u/test_playlists.py b/tests/m3u/test_playlists.py index a294e6cf..5b5eaa33 100644 --- a/tests/m3u/test_playlists.py +++ b/tests/m3u/test_playlists.py @@ -70,7 +70,7 @@ class M3UPlaylistsProviderTest(unittest.TestCase): self.assertTrue(os.path.exists(path1)) self.assertFalse(os.path.exists(path2)) - playlist = self.core.playlists.save(playlist.copy(name='test2')) + playlist = self.core.playlists.save(playlist.replace(name='test2')) self.assertEqual('test2', playlist.name) self.assertEqual(uri2, playlist.uri) self.assertFalse(os.path.exists(path1)) @@ -93,7 +93,7 @@ class M3UPlaylistsProviderTest(unittest.TestCase): def test_playlist_contents_is_written_to_disk(self): track = Track(uri=generate_song(1)) playlist = self.core.playlists.create('test') - playlist = self.core.playlists.save(playlist.copy(tracks=[track])) + playlist = self.core.playlists.save(playlist.replace(tracks=[track])) path = playlist_uri_to_path(playlist.uri, self.playlists_dir) with open(path) as f: @@ -104,7 +104,7 @@ class M3UPlaylistsProviderTest(unittest.TestCase): def test_extended_playlist_contents_is_written_to_disk(self): track = Track(uri=generate_song(1), name='Test', length=60000) playlist = self.core.playlists.create('test') - playlist = self.core.playlists.save(playlist.copy(tracks=[track])) + playlist = self.core.playlists.save(playlist.replace(tracks=[track])) path = playlist_uri_to_path(playlist.uri, self.playlists_dir) with open(path) as f: @@ -115,7 +115,7 @@ class M3UPlaylistsProviderTest(unittest.TestCase): def test_playlists_are_loaded_at_startup(self): track = Track(uri='dummy:track:path2') playlist = self.core.playlists.create('test') - playlist = playlist.copy(tracks=[track]) + playlist = playlist.replace(tracks=[track]) playlist = self.core.playlists.save(playlist) self.assertEqual(len(self.core.playlists.as_list()), 1) @@ -191,7 +191,7 @@ class M3UPlaylistsProviderTest(unittest.TestCase): playlist1 = self.core.playlists.create('test1') self.assertEqual(playlist1, self.core.playlists.lookup(playlist1.uri)) - playlist2 = playlist1.copy(name='test2') + playlist2 = playlist1.replace(name='test2') playlist2 = self.core.playlists.save(playlist2) self.assertIsNone(self.core.playlists.lookup(playlist1.uri)) self.assertEqual(playlist2, self.core.playlists.lookup(playlist2.uri)) @@ -199,7 +199,7 @@ class M3UPlaylistsProviderTest(unittest.TestCase): def test_create_replaces_existing_playlist_with_updated_playlist(self): track = Track(uri=generate_song(1)) playlist1 = self.core.playlists.create('test') - playlist1 = self.core.playlists.save(playlist1.copy(tracks=[track])) + playlist1 = self.core.playlists.save(playlist1.replace(tracks=[track])) self.assertEqual(playlist1, self.core.playlists.lookup(playlist1.uri)) playlist2 = self.core.playlists.create('test') @@ -220,7 +220,7 @@ class M3UPlaylistsProviderTest(unittest.TestCase): def test_playlist_with_unknown_track(self): track = Track(uri='file:///dev/null') playlist = self.core.playlists.create('test') - playlist = playlist.copy(tracks=[track]) + playlist = playlist.replace(tracks=[track]) playlist = self.core.playlists.save(playlist) self.assertEqual(len(self.core.playlists.as_list()), 1) @@ -244,7 +244,7 @@ class M3UPlaylistsProviderTest(unittest.TestCase): check_order(self.core.playlists.as_list(), ['a', 'b', 'c']) playlist = self.core.playlists.lookup('m3u:a.m3u') - playlist = playlist.copy(name='d') + playlist = playlist.replace(name='d') playlist = self.core.playlists.save(playlist) check_order(self.core.playlists.as_list(), ['b', 'c', 'd']) @@ -256,7 +256,7 @@ class M3UPlaylistsProviderTest(unittest.TestCase): def test_get_items_returns_item_refs(self): track = Track(uri='dummy:a', name='A', length=60000) playlist = self.core.playlists.create('test') - playlist = self.core.playlists.save(playlist.copy(tracks=[track])) + playlist = self.core.playlists.save(playlist.replace(tracks=[track])) item_refs = self.core.playlists.get_items(playlist.uri) diff --git a/tests/m3u/test_translator.py b/tests/m3u/test_translator.py index c84f12bf..32eb9f3b 100644 --- a/tests/m3u/test_translator.py +++ b/tests/m3u/test_translator.py @@ -22,9 +22,9 @@ encoded_uri = path.path_to_uri(encoded_path) song1_track = Track(uri=song1_uri) song2_track = Track(uri=song2_uri) encoded_track = Track(uri=encoded_uri) -song1_ext_track = song1_track.copy(name='song1') -song2_ext_track = song2_track.copy(name='song2', length=60000) -encoded_ext_track = encoded_track.copy(name='æøå') +song1_ext_track = song1_track.replace(name='song1') +song2_ext_track = song2_track.replace(name='song2', length=60000) +encoded_ext_track = encoded_track.replace(name='æøå') # FIXME use mock instead of tempfile.NamedTemporaryFile diff --git a/tests/mpd/protocol/test_music_db.py b/tests/mpd/protocol/test_music_db.py index ca043d3c..73c3b300 100644 --- a/tests/mpd/protocol/test_music_db.py +++ b/tests/mpd/protocol/test_music_db.py @@ -103,7 +103,7 @@ class MusicDatabaseHandlerTest(protocol.BaseTestCase): def test_searchaddpl_appends_to_existing_playlist(self): playlist = self.core.playlists.create('my favs').get() - playlist = playlist.copy(tracks=[ + playlist = playlist.replace(tracks=[ Track(uri='dummy:x', name='X'), Track(uri='dummy:y', name='y'), ]) diff --git a/tests/mpd/test_translator.py b/tests/mpd/test_translator.py index 4e1baf0e..055932fc 100644 --- a/tests/mpd/test_translator.py +++ b/tests/mpd/test_translator.py @@ -80,26 +80,26 @@ class TrackMpdFormatTest(unittest.TestCase): self.assertEqual(len(result), 14) def test_track_to_mpd_format_musicbrainz_trackid(self): - track = self.track.copy(musicbrainz_id='foo') + track = self.track.replace(musicbrainz_id='foo') result = translator.track_to_mpd_format(track) self.assertIn(('MUSICBRAINZ_TRACKID', 'foo'), result) def test_track_to_mpd_format_musicbrainz_albumid(self): - album = self.track.album.copy(musicbrainz_id='foo') - track = self.track.copy(album=album) + album = self.track.album.replace(musicbrainz_id='foo') + track = self.track.replace(album=album) result = translator.track_to_mpd_format(track) self.assertIn(('MUSICBRAINZ_ALBUMID', 'foo'), result) def test_track_to_mpd_format_musicbrainz_albumartistid(self): - artist = list(self.track.artists)[0].copy(musicbrainz_id='foo') - album = self.track.album.copy(artists=[artist]) - track = self.track.copy(album=album) + artist = list(self.track.artists)[0].replace(musicbrainz_id='foo') + album = self.track.album.replace(artists=[artist]) + track = self.track.replace(album=album) result = translator.track_to_mpd_format(track) self.assertIn(('MUSICBRAINZ_ALBUMARTISTID', 'foo'), result) def test_track_to_mpd_format_musicbrainz_artistid(self): - artist = list(self.track.artists)[0].copy(musicbrainz_id='foo') - track = self.track.copy(artists=[artist]) + artist = list(self.track.artists)[0].replace(musicbrainz_id='foo') + track = self.track.replace(artists=[artist]) result = translator.track_to_mpd_format(track) self.assertIn(('MUSICBRAINZ_ARTISTID', 'foo'), result)