def save_genres(song_id, recording): """Save the tags for recording `recording` as genres for song `song_id`.""" song_genres = [] if 'tag-list' in recording: for tag in recording['tag-list']: if int(tag['count']) == 0: # tag not applied continue genre_id = genres.find(tag['name']) if genre_id != -1 and genre_id not in song_genres: db.save('song_genre', (song_id, genre_id)) song_genres.append(genre_id) # put song in 'Other' category if no genres were found if len(song_genres) == 0: db.save('song_genre', (song_id, genres.OTHER))
def test_tag_vs_genre(self): result = find("Miles Davis. Jit") assert "jit" in result
def test_ranking(self): result = find("Benga. House") assert "benga" in result
def test_tag_vs_genre_check(self): result = find("Miles Davis. Miles Davis. Miles Davis. Techno. Techno.") assert "jazz" in result assert len(result) == 1
def test_genre_tag_occurence(self): result = find("Ska jazz. Ska jazz. The best jazz player is Miles Davis. \ Miles Davis. Miles Davis") assert "jazz" == result[0]
def test_slash_separator(self): result = find("blues/Random word test") assert "blues" in result
def test_between_words(self): result = find("Hip-hop is a genre") assert "hip hop" in result
def test_single_match(self): result = find("This is a good example of techno. Hello techno.") assert "techno" in result
def test_tag_match(self): result = find("In this text we have a Country Test Tag") assert "country" in result
def test_comment_data(self): result = find("#comment") assert "#comment" not in result
def test_highest_occurence_return_genre(self): result = find("ska, Techno, Ska") assert "ska" in result
def test_not_existing_genre(self): result = find("Lorem ipsum dolum test") assert len(result) == 0
def test_conflicting_genres(self): result = find("Dance Hall and Reggae-Techno") assert "techno" not in result
def test_multiple_and_invalid(self): result = find("KingstonDance Hall and Reggae") assert "dance hall" not in result
def test_multiple_match(self): result = find("This is Dance Hall. Sounds like a mix of Merengue") assert "dance hall" in result
def test_genre_ranking(self): result = find("In this house, we play jazz") assert "jazz" in result
def test_escaped_genre(self): result = find("For over a decade, Los Angeles singer/songwriter \ Jhené Aiko has skirted the periphery of R&B stardom") assert "r&b" in result
def test(self): result = find(review[1]) found = all((w in result for w in review[0])) self.assertTrue(found)