def test_playlist_creators(): from playlist import transport as ts REFERENCE_PLAYLIST = os.path.join(TESTDIR, "reference.json") valid_song = ts.make_song("Test artist", 200, "Test song") invalid_song = {"fisk" : "sylt"} invalid_song2 = {"artist" : "Test_artist"} assert ts.valid_song(valid_song) assert not ts.valid_song(invalid_song) assert not ts.valid_song(invalid_song2) valid_playlist = ts.make_playlist([valid_song], "http://test.com/test.json", "Test playlist", ["Albin Stjerna"]) invalid_playlist = ts.make_playlist([invalid_song, invalid_song2], "http://test.com/test.json", "Test playlist", ["Albin Stjerna"]) assert ts.valid_playlist(valid_playlist) assert not ts.valid_playlist(invalid_playlist)
def match_transport(pl, songs): """Return a playlist with matches (search paths) for transport playlist pl in the song collection songs.""" found_songs = [None]*len(pl["playlist"]) if not ts.valid_playlist(pl): raise Exception("Invalid playlist format!") return [] if not ts.allowed_match("levenshtein", pl): raise Exception("Playlist requires unsupported match method!") return [] for song in songs: title, artist, location = song if not None in found_songs: # We've already found all songs! break for i in xrange(len(pl["playlist"])): if found_songs[i] != None: # Already found song continue pls_song = pl["playlist"][i] if levenshtein_ok(fl_title=title, fl_artist=artist, ls_artist=pls_song["artist"], ls_title=pls_song["title"]): found_songs[i] = location break return found_songs
def test_parse_reference_playlist(): from playlist import transport as ts from datetime import date REFERENCE_PLAYLIST = os.path.join(TESTDIR, "reference.json") playlist = ts.load(REFERENCE_PLAYLIST) assert ts.allowed_match("levenshtein", playlist) assert playlist['tags'][0] == "ebm" assert type(ts.updated(playlist)) == date assert ts.valid_playlist(playlist)
def test_transport_write(): from playlist import transport as ts from os import remove TEMP_FILE = os.path.join(TESTDIR, "transport_write_test.json") REFERENCE_PLAYLIST = os.path.join(TESTDIR, "reference.json") playlist = ts.load(REFERENCE_PLAYLIST) try: ts.write(playlist, TEMP_FILE) new_playlist = ts.load(TEMP_FILE) assert ts.valid_playlist(new_playlist) assert playlist == new_playlist finally: remove(TEMP_FILE)