def tracks(item, formats, uri=uri): identifier = item['metadata']['identifier'] track = Track(album=album(item['metadata'])) tracks = [] for obj in files(item, formats): filename = obj.get('name') tracks.append(track.replace( uri=uri(identifier, filename), name=obj.get('title', filename), artists=artists(obj) or track.album.artists, genre=obj.get('genre'), track_no=parse_track(obj.get('track')), length=parse_length(obj.get('length')), bitrate=parse_bitrate(obj.get('bitrate')), last_modified=parse_mtime(obj.get('mtime')) )) return tracks
def test_scan(self, mock_scan): mock_scan.return_value = { 'tags': { 'image': [GIF_DATA, PNG_DATA], 'preview-image': [JPEG_DATA] } } album = Album(name='foo') track = Track(uri=b'local:track:foo.mp3', album=album) images = ['/images/' + name for name in GIF_NAME, PNG_NAME, JPEG_NAME] image_track = track.copy(album=album.copy(images=images)) self.library.add(track) mock_library.add.assert_called_with(image_track, None, None) self.assertTrue(os.path.isfile(os.path.join(self.tempdir, GIF_NAME))) self.assertTrue(os.path.isfile(os.path.join(self.tempdir, PNG_NAME))) self.assertTrue(os.path.isfile(os.path.join(self.tempdir, JPEG_NAME))) self.library.close() self.assertEqual(os.listdir(self.tempdir), [])
def setUp(self): # noqa: N802 self.tags = { "album": ["album"], "track-number": [1], "artist": ["artist"], "composer": ["composer"], "performer": ["performer"], "album-artist": ["albumartist"], "title": ["track"], "track-count": [2], "album-disc-number": [2], "album-disc-count": [3], "date": [datetime.date(2006, 1, 1)], "container-format": ["ID3 tag"], "genre": ["genre"], "comment": ["comment"], "musicbrainz-trackid": ["trackid"], "musicbrainz-albumid": ["albumid"], "musicbrainz-artistid": ["artistid"], "musicbrainz-albumartistid": ["albumartistid"], "bitrate": [1000], } artist = Artist(name="artist", musicbrainz_id="artistid") composer = Artist(name="composer") performer = Artist(name="performer") albumartist = Artist(name="albumartist", musicbrainz_id="albumartistid") album = Album(name="album", num_tracks=2, num_discs=3, musicbrainz_id="albumid", artists=[albumartist]) self.track = Track( name="track", date="2006-01-01", genre="genre", track_no=1, disc_no=2, comment="comment", musicbrainz_id="trackid", album=album, bitrate=1000, artists=[artist], composers=[composer], performers=[performer], )
def setUp(self): self.data = { 'uri': 'uri', 'duration': 4531000000, 'mtime': 1234, 'tags': { 'album': ['album'], 'track-number': [1], 'artist': ['artist'], 'composer': ['composer'], 'performer': ['performer'], 'album-artist': ['albumartist'], 'title': ['track'], 'track-count': [2], 'album-disc-number': [2], 'album-disc-count': [3], 'date': [FakeGstDate(2006, 1, 1,)], 'container-format': ['ID3 tag'], 'genre': ['genre'], 'comment': ['comment'], 'musicbrainz-trackid': ['trackid'], 'musicbrainz-albumid': ['albumid'], 'musicbrainz-artistid': ['artistid'], 'musicbrainz-albumartistid': ['albumartistid'], 'bitrate': [1000], }, } artist = Artist(name='artist', musicbrainz_id='artistid') composer = Artist(name='composer') performer = Artist(name='performer') albumartist = Artist(name='albumartist', musicbrainz_id='albumartistid') album = Album(name='album', num_tracks=2, num_discs=3, musicbrainz_id='albumid', artists=[albumartist]) self.track = Track(uri='uri', name='track', date='2006-01-01', genre='genre', track_no=1, disc_no=2, length=4531, comment='comment', musicbrainz_id='trackid', last_modified=1234, album=album, bitrate=1000, artists=[artist], composers=[composer], performers=[performer])
def setUp(self): # noqa: N802 self.tags = { 'album': ['album'], 'track-number': [1], 'artist': ['artist'], 'composer': ['composer'], 'performer': ['performer'], 'album-artist': ['albumartist'], 'title': ['track'], 'track-count': [2], 'album-disc-number': [2], 'album-disc-count': [3], 'date': ['2006-01-01'], 'container-format': ['ID3 tag'], 'genre': ['genre'], 'comment': ['comment'], 'musicbrainz-trackid': ['trackid'], 'musicbrainz-albumid': ['albumid'], 'musicbrainz-artistid': ['artistid'], 'musicbrainz-sortname': ['sortname'], 'musicbrainz-albumartistid': ['albumartistid'], 'bitrate': [1000], } artist = Artist(name='artist', musicbrainz_id='artistid', sortname='sortname') composer = Artist(name='composer') performer = Artist(name='performer') albumartist = Artist(name='albumartist', musicbrainz_id='albumartistid') album = Album(name='album', date='2006-01-01', num_tracks=2, num_discs=3, musicbrainz_id='albumid', artists=[albumartist]) self.track = Track(name='track', genre='genre', track_no=1, disc_no=2, comment='comment', musicbrainz_id='trackid', album=album, bitrate=1000, artists=[artist], composers=[composer], performers=[performer])
def test_uri(self): uri = 'an_uri' track = Track(uri=uri) self.assertEqual(track.uri, uri) with self.assertRaises(AttributeError): track.uri = None
def test_ne_artists(self): track1 = Track(artists=[Artist(name='name1')]) track2 = Track(artists=[Artist(name='name2')]) self.assertNotEqual(track1, track2) self.assertNotEqual(hash(track1), hash(track2))
def test_copying_track_with_missing_values(self): track = Track(uri='bar') copy = track.copy(name='baz') self.assertEqual('baz', copy.name) self.assertEqual('bar', copy.uri)
def test_name(self): name = 'a name' track = Track(name=name) self.assertEqual(track.name, name) self.assertRaises(AttributeError, setattr, track, 'name', None)
class TagsToTrackTest(unittest.TestCase): def setUp(self): # noqa: N802 self.tags = { 'album': ['album'], 'track-number': [1], 'artist': ['artist'], 'composer': ['composer'], 'performer': ['performer'], 'album-artist': ['albumartist'], 'title': ['track'], 'track-count': [2], 'album-disc-number': [2], 'album-disc-count': [3], 'date': ['2006-01-01'], 'container-format': ['ID3 tag'], 'genre': ['genre'], 'comment': ['comment'], 'musicbrainz-trackid': ['trackid'], 'musicbrainz-albumid': ['albumid'], 'musicbrainz-artistid': ['artistid'], 'musicbrainz-sortname': ['sortname'], 'musicbrainz-albumartistid': ['albumartistid'], 'bitrate': [1000], } artist = Artist(name='artist', musicbrainz_id='artistid', sortname='sortname') composer = Artist(name='composer') performer = Artist(name='performer') albumartist = Artist(name='albumartist', musicbrainz_id='albumartistid') album = Album(name='album', date='2006-01-01', num_tracks=2, num_discs=3, musicbrainz_id='albumid', artists=[albumartist]) self.track = Track(name='track', genre='genre', track_no=1, disc_no=2, comment='comment', musicbrainz_id='trackid', album=album, bitrate=1000, artists=[artist], composers=[composer], performers=[performer]) def check(self, expected): actual = tags.convert_tags_to_track(self.tags) self.assertEqual(expected, actual) def test_track(self): self.check(self.track) def test_missing_track_no(self): del self.tags['track-number'] self.check(self.track.replace(track_no=None)) def test_multiple_track_no(self): self.tags['track-number'].append(9) self.check(self.track) def test_missing_track_disc_no(self): del self.tags['album-disc-number'] self.check(self.track.replace(disc_no=None)) def test_multiple_track_disc_no(self): self.tags['album-disc-number'].append(9) self.check(self.track) def test_missing_track_name(self): del self.tags['title'] self.check(self.track.replace(name=None)) def test_multiple_track_name(self): self.tags['title'] = ['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.replace(musicbrainz_id=None)) def test_multiple_track_musicbrainz_id(self): self.tags['musicbrainz-trackid'].append('id') self.check(self.track) def test_missing_track_bitrate(self): del self.tags['bitrate'] self.check(self.track.replace(bitrate=None)) def test_multiple_track_bitrate(self): self.tags['bitrate'].append(1234) self.check(self.track) def test_missing_track_genre(self): del self.tags['genre'] self.check(self.track.replace(genre=None)) def test_multiple_track_genre(self): self.tags['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.replace(album=self.track.album.replace(date=None))) def test_multiple_track_date(self): self.tags['date'].append('2030-01-01') self.check(self.track) def test_datetime_instead_of_date(self): del self.tags['date'] self.tags['datetime'] = ['2006-01-01T14:13:12Z'] self.check(self.track) def test_missing_track_comment(self): del self.tags['comment'] self.check(self.track.replace(comment=None)) def test_multiple_track_comment(self): self.tags['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.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.replace(artists=artists)) def test_missing_track_artist_musicbrainz_id(self): del self.tags['musicbrainz-artistid'] 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') self.check(self.track) def test_missing_track_composer_name(self): del self.tags['composer'] 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.replace(composers=composers)) def test_missing_track_performer_name(self): del self.tags['performer'] 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.replace(performers=performers)) def test_missing_album_name(self): del self.tags['album'] self.check(self.track.replace(album=None)) def test_multiple_album_name(self): self.tags['album'].append('album2') self.check(self.track) def test_missing_album_musicbrainz_id(self): del self.tags['musicbrainz-albumid'] 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') self.check(self.track) def test_missing_album_num_tracks(self): del self.tags['track-count'] 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) self.check(self.track) def test_missing_album_num_discs(self): del self.tags['album-disc-count'] 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) self.check(self.track) def test_missing_album_artist_name(self): del self.tags['album-artist'] 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.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.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') self.check(self.track) def test_stream_organization_track_name(self): del self.tags['title'] self.tags['organization'] = ['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.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.replace(comment='location')) def test_multiple_location_track_comment(self): del self.tags['comment'] self.tags['location'] = ['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.replace(comment='copyright')) def test_multiple_copyright_track_comment(self): del self.tags['comment'] self.tags['copyright'] = ['copyright1', 'copyright2'] self.check(self.track.replace(comment='copyright1; copyright2')) def test_sortname(self): self.tags['musicbrainz-sortname'] = ['another_sortname'] artist = Artist(name='artist', sortname='another_sortname', musicbrainz_id='artistid') self.check(self.track.replace(artists=[artist])) def test_missing_sortname(self): del self.tags['musicbrainz-sortname'] artist = Artist(name='artist', sortname=None, musicbrainz_id='artistid') self.check(self.track.replace(artists=[artist]))
def test_musicbrainz_id(self): mb_id = 'mb-id' track = Track(musicbrainz_id=mb_id) self.assertEqual(track.musicbrainz_id, mb_id) with self.assertRaises(AttributeError): track.musicbrainz_id = None
def test_date(self): date = '1977-01-01' track = Track(date=date) self.assertEqual(track.date, date) with self.assertRaises(AttributeError): track.date = None
def test_bitrate(self): bitrate = 160 track = Track(bitrate=bitrate) self.assertEqual(track.bitrate, bitrate) self.assertRaises(AttributeError, setattr, track, 'bitrate', None)
def test_length(self): length = 137000 track = Track(length=length) self.assertEqual(track.length, length) self.assertRaises(AttributeError, setattr, track, 'length', None)
def test_date(self): date = '1977-01-01' track = Track(date=date) self.assertEqual(track.date, date) self.assertRaises(AttributeError, setattr, track, 'date', None)
def test_disc_no(self): disc_no = 2 track = Track(disc_no=disc_no) self.assertEqual(track.disc_no, disc_no) self.assertRaises(AttributeError, setattr, track, 'disc_no', None)
def test_track_no(self): track_no = 7 track = Track(track_no=track_no) self.assertEqual(track.track_no, track_no) self.assertRaises(AttributeError, setattr, track, 'track_no', None)
def test_album(self): album = Album() track = Track(album=album) self.assertEqual(track.album, album) self.assertRaises(AttributeError, setattr, track, 'album', None)
def test_artists(self): artists = [Artist(name='name1'), Artist(name='name2')] track = Track(artists=artists) self.assertEqual(set(track.artists), set(artists)) self.assertRaises(AttributeError, setattr, track, 'artists', None)
def test_performers(self): artists = [Artist(name='name1'), Artist(name='name2')] track = Track(performers=artists) self.assertEqual(set(track.performers), set(artists)) with self.assertRaises(AttributeError): track.performers = None
def test_track_no(self): track_no = 7 track = Track(track_no=track_no) self.assertEqual(track.track_no, track_no) with self.assertRaises(AttributeError): track.track_no = None
def test_musicbrainz_id(self): mb_id = 'mb-id' track = Track(musicbrainz_id=mb_id) self.assertEqual(track.musicbrainz_id, mb_id) self.assertRaises( AttributeError, setattr, track, 'musicbrainz_id', None)
def test_length(self): length = 137000 track = Track(length=length) self.assertEqual(track.length, length) with self.assertRaises(AttributeError): track.length = None
def test_copying_track_with_private_internal_value(self): artist1 = Artist(name='foo') artist2 = Artist(name='bar') track = Track(artists=[artist1]) copy = track.copy(artists=[artist2]) self.assertIn(artist2, copy.artists)
def test_replace_track_with_missing_values(self): track = Track(uri='bar') other = track.replace(name='baz') self.assertEqual('baz', other.name) self.assertEqual('bar', other.uri)
def test_invalid_kwarg(self): test = lambda: Track(foo='baz') self.assertRaises(TypeError, test)
class TranslatorTest(unittest.TestCase): def setUp(self): self.data = { 'uri': 'uri', 'duration': 4531000000, 'mtime': 1234, 'tags': { 'album': ['album'], 'track-number': [1], 'artist': ['artist'], 'composer': ['composer'], 'performer': ['performer'], 'album-artist': ['albumartist'], 'title': ['track'], 'track-count': [2], 'album-disc-number': [2], 'album-disc-count': [3], 'date': [FakeGstDate(2006, 1, 1,)], 'container-format': ['ID3 tag'], 'genre': ['genre'], 'comment': ['comment'], 'musicbrainz-trackid': ['trackid'], 'musicbrainz-albumid': ['albumid'], 'musicbrainz-artistid': ['artistid'], 'musicbrainz-albumartistid': ['albumartistid'], 'bitrate': [1000], }, } artist = Artist(name='artist', musicbrainz_id='artistid') composer = Artist(name='composer') performer = Artist(name='performer') albumartist = Artist(name='albumartist', musicbrainz_id='albumartistid') album = Album(name='album', num_tracks=2, num_discs=3, musicbrainz_id='albumid', artists=[albumartist]) self.track = Track(uri='uri', name='track', date='2006-01-01', genre='genre', track_no=1, disc_no=2, length=4531, comment='comment', musicbrainz_id='trackid', last_modified=1234, album=album, bitrate=1000, artists=[artist], composers=[composer], performers=[performer]) def check(self, expected): actual = scan.audio_data_to_track(self.data) self.assertEqual(expected, actual) def test_track(self): self.check(self.track) def test_none_track_length(self): self.data['duration'] = None self.check(self.track.copy(length=None)) def test_none_track_last_modified(self): self.data['mtime'] = None self.check(self.track.copy(last_modified=None)) def test_missing_track_no(self): del self.data['tags']['track-number'] self.check(self.track.copy(track_no=None)) def test_multiple_track_no(self): self.data['tags']['track-number'].append(9) self.check(self.track) def test_missing_track_disc_no(self): del self.data['tags']['album-disc-number'] self.check(self.track.copy(disc_no=None)) def test_multiple_track_disc_no(self): self.data['tags']['album-disc-number'].append(9) self.check(self.track) def test_missing_track_name(self): del self.data['tags']['title'] self.check(self.track.copy(name=None)) def test_multiple_track_name(self): self.data['tags']['title'] = ['name1', 'name2'] self.check(self.track.copy(name='name1; name2')) def test_missing_track_musicbrainz_id(self): del self.data['tags']['musicbrainz-trackid'] self.check(self.track.copy(musicbrainz_id=None)) def test_multiple_track_musicbrainz_id(self): self.data['tags']['musicbrainz-trackid'].append('id') self.check(self.track) def test_missing_track_bitrate(self): del self.data['tags']['bitrate'] self.check(self.track.copy(bitrate=None)) def test_multiple_track_bitrate(self): self.data['tags']['bitrate'].append(1234) self.check(self.track) def test_missing_track_genre(self): del self.data['tags']['genre'] self.check(self.track.copy(genre=None)) def test_multiple_track_genre(self): self.data['tags']['genre'] = ['genre1', 'genre2'] self.check(self.track.copy(genre='genre1; genre2')) def test_missing_track_date(self): del self.data['tags']['date'] self.check(self.track.copy(date=None)) def test_multiple_track_date(self): self.data['tags']['date'].append(FakeGstDate(2030, 1, 1)) self.check(self.track) def test_invalid_track_date(self): self.data['tags']['date'] = [FakeGstDate(65535, 1, 1)] self.check(self.track.copy(date=None)) def test_missing_track_comment(self): del self.data['tags']['comment'] self.check(self.track.copy(comment=None)) def test_multiple_track_comment(self): self.data['tags']['comment'] = ['comment1', 'comment2'] self.check(self.track.copy(comment='comment1; comment2')) def test_missing_track_artist_name(self): del self.data['tags']['artist'] self.check(self.track.copy(artists=[])) def test_multiple_track_artist_name(self): self.data['tags']['artist'] = ['name1', 'name2'] artists = [Artist(name='name1'), Artist(name='name2')] self.check(self.track.copy(artists=artists)) def test_missing_track_artist_musicbrainz_id(self): del self.data['tags']['musicbrainz-artistid'] artist = list(self.track.artists)[0].copy(musicbrainz_id=None) self.check(self.track.copy(artists=[artist])) def test_multiple_track_artist_musicbrainz_id(self): self.data['tags']['musicbrainz-artistid'].append('id') self.check(self.track) def test_missing_track_composer_name(self): del self.data['tags']['composer'] self.check(self.track.copy(composers=[])) def test_multiple_track_composer_name(self): self.data['tags']['composer'] = ['composer1', 'composer2'] composers = [Artist(name='composer1'), Artist(name='composer2')] self.check(self.track.copy(composers=composers)) def test_missing_track_performer_name(self): del self.data['tags']['performer'] self.check(self.track.copy(performers=[])) def test_multiple_track_performe_name(self): self.data['tags']['performer'] = ['performer1', 'performer2'] performers = [Artist(name='performer1'), Artist(name='performer2')] self.check(self.track.copy(performers=performers)) def test_missing_album_name(self): del self.data['tags']['album'] album = self.track.album.copy(name=None) self.check(self.track.copy(album=album)) def test_multiple_album_name(self): self.data['tags']['album'].append('album2') self.check(self.track) def test_missing_album_musicbrainz_id(self): del self.data['tags']['musicbrainz-albumid'] album = self.track.album.copy(musicbrainz_id=None) self.check(self.track.copy(album=album)) def test_multiple_album_musicbrainz_id(self): self.data['tags']['musicbrainz-albumid'].append('id') self.check(self.track) def test_missing_album_num_tracks(self): del self.data['tags']['track-count'] album = self.track.album.copy(num_tracks=None) self.check(self.track.copy(album=album)) def test_multiple_album_num_tracks(self): self.data['tags']['track-count'].append(9) self.check(self.track) def test_missing_album_num_discs(self): del self.data['tags']['album-disc-count'] album = self.track.album.copy(num_discs=None) self.check(self.track.copy(album=album)) def test_multiple_album_num_discs(self): self.data['tags']['album-disc-count'].append(9) self.check(self.track) def test_missing_album_artist_name(self): del self.data['tags']['album-artist'] album = self.track.album.copy(artists=[]) self.check(self.track.copy(album=album)) def test_multiple_album_artist_name(self): self.data['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)) def test_missing_album_artist_musicbrainz_id(self): del self.data['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)) def test_multiple_album_artist_musicbrainz_id(self): self.data['tags']['musicbrainz-albumartistid'].append('id') self.check(self.track) def test_stream_organization_track_name(self): del self.data['tags']['title'] self.data['tags']['organization'] = ['organization'] self.check(self.track.copy(name='organization')) def test_multiple_organization_track_name(self): del self.data['tags']['title'] self.data['tags']['organization'] = ['organization1', 'organization2'] self.check(self.track.copy(name='organization1; organization2')) # TODO: combine all comment types? def test_stream_location_track_comment(self): del self.data['tags']['comment'] self.data['tags']['location'] = ['location'] self.check(self.track.copy(comment='location')) def test_multiple_location_track_comment(self): del self.data['tags']['comment'] self.data['tags']['location'] = ['location1', 'location2'] self.check(self.track.copy(comment='location1; location2')) def test_stream_copyright_track_comment(self): del self.data['tags']['comment'] self.data['tags']['copyright'] = ['copyright'] self.check(self.track.copy(comment='copyright')) def test_multiple_copyright_track_comment(self): del self.data['tags']['comment'] self.data['tags']['copyright'] = ['copyright1', 'copyright2'] self.check(self.track.copy(comment='copyright1; copyright2'))
def test_repr_with_artists(self): self.assertEquals( "Track(artists=[Artist(name=u'foo')], composers=[], name=u'name', " "performers=[], uri=u'uri')", repr(Track(uri='uri', name='name', artists=[Artist(name='foo')])))
def test_serialize(self): track = Track(uri="uri", name="name") self.assertDictEqual( {"__model__": "TlTrack", "tlid": 123, "track": track.serialize()}, TlTrack(tlid=123, track=track).serialize(), )
def test_serialize_without_artists(self): self.assertDictEqual( {'__model__': 'Track', 'uri': 'uri', 'name': 'name'}, Track(uri='uri', name='name').serialize())
def test_ne_name(self): track1 = Track(name='name1') track2 = Track(name='name2') self.assertNotEqual(track1, track2) self.assertNotEqual(hash(track1), hash(track2))
def test_serialize_with_artists(self): artist = Artist(name='foo') self.assertDictEqual( {'__model__': 'Track', 'uri': 'uri', 'name': 'name', 'artists': [artist.serialize()]}, Track(uri='uri', name='name', artists=[artist]).serialize())
def test_different_instance_with_replace(self): t = Track(uri='test1') self.assertIsNot(t, t.replace(uri='test2'))
def test_serialize_with_album(self): album = Album(name='foo') self.assertDictEqual( {'__model__': 'Track', 'uri': 'uri', 'name': 'name', 'album': album.serialize()}, Track(uri='uri', name='name', album=album).serialize())
def test_name(self): name = 'a name' track = Track(name=name) self.assertEqual(track.name, name) with self.assertRaises(AttributeError): track.name = None
def test_eq_artists(self): artists = [Artist()] track1 = Track(artists=artists) track2 = Track(artists=artists) self.assertEqual(track1, track2) self.assertEqual(hash(track1), hash(track2))
def test_album(self): album = Album() track = Track(album=album) self.assertEqual(track.album, album) with self.assertRaises(AttributeError): track.album = None
def test_copying_track_with_invalid_key(self): test = lambda: Track().copy(invalid_key=True) self.assertRaises(TypeError, test)
def test_disc_no(self): disc_no = 2 track = Track(disc_no=disc_no) self.assertEqual(track.disc_no, disc_no) with self.assertRaises(AttributeError): track.disc_no = None
def test_eq_album(self): album = Album() track1 = Track(album=album) track2 = Track(album=album) self.assertEqual(track1, track2) self.assertEqual(hash(track1), hash(track2))
def test_replace_track(self): track = Track() self.compare(track, track.replace())
def test_eq_track_no(self): track1 = Track(track_no=1) track2 = Track(track_no=1) self.assertEqual(track1, track2) self.assertEqual(hash(track1), hash(track2))
def test_bitrate(self): bitrate = 160 track = Track(bitrate=bitrate) self.assertEqual(track.bitrate, bitrate) with self.assertRaises(AttributeError): track.bitrate = None
def test_eq_date(self): date = '1977-01-01' track1 = Track(date=date) track2 = Track(date=date) self.assertEqual(track1, track2) self.assertEqual(hash(track1), hash(track2))
def test_replace_track_with_basic_values(self): track = Track(name='foo', uri='bar') other = track.replace(name='baz') self.assertEqual('baz', other.name) self.assertEqual('bar', other.uri)
def test_eq_length(self): track1 = Track(length=100) track2 = Track(length=100) self.assertEqual(track1, track2) self.assertEqual(hash(track1), hash(track2))
def test_replace_track_with_private_internal_value(self): artist1 = Artist(name='foo') artist2 = Artist(name='bar') track = Track(artists=[artist1]) other = track.replace(artists=[artist2]) self.assertIn(artist2, other.artists)
def test_serialize_with_tracks(self): track = Track(name='foo') self.assertDictEqual( {'__model__': 'Playlist', 'uri': 'uri', 'name': 'name', 'tracks': [track.serialize()]}, Playlist(uri='uri', name='name', tracks=[track]).serialize())
def test_copying_track_with_missing_values(self): track = Track(uri="bar") copy = track.copy(name="baz") self.assertEqual("baz", copy.name) self.assertEqual("bar", copy.uri)
def test_eq_bitrate(self): track1 = Track(bitrate=100) track2 = Track(bitrate=100) self.assertEqual(track1, track2) self.assertEqual(hash(track1), hash(track2))
def test_uri(self): uri = 'an_uri' track = Track(uri=uri) self.assertEqual(track.uri, uri) self.assertRaises(AttributeError, setattr, track, 'uri', None)
def test_serialize(self): track = Track(uri='uri', name='name') self.assertDictEqual( {'__model__': 'TlTrack', 'tlid': 123, 'track': track.serialize()}, TlTrack(tlid=123, track=track).serialize())
def test_eq_musibrainz_id(self): track1 = Track(musicbrainz_id='id') track2 = Track(musicbrainz_id='id') self.assertEqual(track1, track2) self.assertEqual(hash(track1), hash(track2))
def test_copying_track(self): track = Track() self.compare(track, track.copy())
def test_eq_none(self): self.assertNotEqual(Track(), None)
def test_copying_track_with_private_internal_value(self): artist1 = Artist(name="foo") artist2 = Artist(name="bar") track = Track(artists=[artist1]) copy = track.copy(artists=[artist2]) self.assertIn(artist2, copy.artists)
def test_eq_other(self): self.assertNotEqual(Track(), 'other')
def test_serialize_with_tracks(self): track = Track(name="foo") self.assertDictEqual( {"__model__": "Playlist", "uri": "uri", "name": "name", "tracks": [track.serialize()]}, Playlist(uri="uri", name="name", tracks=[track]).serialize(), )
def test_ne_uri(self): track1 = Track(uri='uri1') track2 = Track(uri='uri2') self.assertNotEqual(track1, track2) self.assertNotEqual(hash(track1), hash(track2))