def test_song_from_string_errors(): """ Test the different errors that may be raised from calling Song.from_string(). """ assert Song.from_string('in flames versus terminus') is None assert Song.from_string('The sword -') is None assert Song.from_string('- Letterbomb') is None
def test_song_from_string(): """ Create a song object from an unparsed string. """ song = Song.from_string('la marea - vetusta morla', reverse=True) assert song assert song.artist == 'vetusta morla' assert song.title == 'la marea' song = Song.from_string('els amics de les arts-ja no ens passa') assert song assert song.artist == 'els amics de les arts' assert song.title == 'ja no ens passa' song = Song.from_string('immolation / epiphany', separator='/') assert song assert song.artist == 'immolation' assert song.title == 'epiphany'
def get_song_from_string(song, chat_id): """ Parse the user's input and return a song object from it. """ if not song: return None if isinstance(song, Song): return song if '-' in song: song = Song.from_string(song) else: last_res = DB.get_last_res(chat_id) if not last_res: return None song = Song(artist=last_res['artist'], title=song) return song