def test_argv_from_file(monkeypatch, tmpdir, mp3file): """ Check that the `--from_file` argument can read a text file containing a list of filenames, and return a list with all of them. """ mp3_files = [ tmpdir / 'first.mp3', tmpdir / 'second.mp3', tmpdir / 'third.mp3', ] song_tags = [ ('white wizzard', 'the sun also rises'), ('mastodon', 'andromeda'), ('megadeth', 'dawn patrol'), ] songs = [] for filename, tag in zip(mp3_files, song_tags): artist, title = tag shutil.copyfile(mp3file, filename) tag_mp3(filename, artist=artist, title=title) songs.append(Song(artist=artist, title=title)) filelist = tmpdir / 'filelist' with open(filelist, 'w') as file: for filename in mp3_files: file.write(str(filename) + '\n') file.flush() monkeypatch.setattr(sys, 'argv', [__file__, '--from-file', str(filelist)]) parsed_songs = parse_argv() assert parsed_songs == set(parsed_songs)
def test_getlyrics_from_song(mp3file): """ Check that the main method can find the lyrics for a song and write them as ID3 metadata. """ tag_mp3(mp3file, artist='YOB', title='Our raw heart') song = Song.from_filename(mp3file) result = get_lyrics(song) assert 'my restless ghost' in result.song.lyrics.lower()
def test_getlyrics_dont_overwrite(mp3file): """ Check that we skip a song if the mp3 file already has embedded lyrics. """ placeholder = 'Some lyrics' tag_mp3(mp3file, lyrics=placeholder) song = Song.from_filename(mp3file) CONFIG['overwrite'] = False assert get_lyrics(song) is None assert song.lyrics == placeholder
def test_getlyrics_overwrite(mp3file): """ Check that we can overwrite the lyrics of a song if it already has them. """ placeholder = 'Some lyrics' tag_mp3(mp3file, artist='Baroness', title='Eula', lyrics=placeholder) song = Song.from_filename(mp3file) CONFIG['overwrite'] = True result = get_lyrics(song) assert result.song.lyrics != placeholder assert 'forget the taste of my own tongue' in result.song.lyrics.lower()
def test_song_from_filename(mp3file): """ Create a song object from an mp3 file. """ tag_mp3(mp3file, artist='Kataklysm', title='Born to kill and destined to die', album='Meditations') song = Song.from_filename(mp3file) assert song assert song.filename == mp3file assert song.artist == 'Kataklysm' assert song.title == 'Born to kill and destined to die' assert song.album == 'Meditations'
def test_process_result(mp3file): """ Check that the `process_result()` function can write the lyrics to the corresponding mp3 and return wheter or not they were found. """ artist = 'lör' title = 'requiem' song_lyrics = 'hello world' tag_mp3(mp3file, artist=artist, title=title) song = Song.from_filename(mp3file) song.lyrics = song_lyrics result_notfound = Result(song=song, source=None, runtimes={}) assert not process_result(result_notfound) assert not Song.from_filename(mp3file).lyrics result_found = Result(song=song, source='whatever', runtimes={}) assert process_result(result_found) assert Song.from_filename(mp3file).lyrics == song_lyrics
def fake_runmp(songs): for i, song in enumerate(songs): tag_mp3(song.filename, lyrics=f'lyrics{i}') return Stats()