from suno_utils.worker.detect_blocked_songs import ( BLOCKED_SONGS, BlockedSongClassifier, blocked_song_classifier, ) POSITIVE_LYRICS = """ [Verse] Sleigh bells ring, are you listening? (Doo) In the lane, snow is glistening A beautiful sight, we're happy tonight Walking in a winter wonderland [Chorus] Gone away is the bluebird Here to stay is a new bird (Ooo) He sings a love song as we go along Walking in a winter wonderland """ NEGATIVE_LYRICS = """ [Verse 1] Remember those walls I built? Well, baby, they're tumblin' down And they didn't even put up a fight They didn't even make a sound I found a way to let you win But I never really had a doubt Standin' in the light of your halo I got my angel now [Pre-Chorus] It's like I've been awakened Every rule, I had you breakin' It's the risk that I'm takin' I ain't never gonna shut you out """ def test_is_blocked_song_positive(): assert blocked_song_classifier.is_blocked(POSITIVE_LYRICS), blocked_song_classifier._get_score( POSITIVE_LYRICS ) def test_is_blocked_song_negative(): assert not blocked_song_classifier.is_blocked(NEGATIVE_LYRICS), blocked_song_classifier._get_score( NEGATIVE_LYRICS ) def test_threshold(): # With the default threshold, this shouldn't be enough to trigger a block snippet = "a love song as we" clf_default = BlockedSongClassifier.from_songs(BLOCKED_SONGS) assert not clf_default.is_blocked(snippet) # at threshold=0, almost everything should be blocked clf0 = BlockedSongClassifier.from_songs(BLOCKED_SONGS, threshold=0) assert clf0.is_blocked(snippet), clf0._get_score(snippet) # at threshold=1, almost nothing should be blocked clf1 = BlockedSongClassifier.from_songs(BLOCKED_SONGS, threshold=1) assert not clf1.is_blocked(POSITIVE_LYRICS) def test_singleton(): blocked_song_classifier2 = BlockedSongClassifier.from_songs(BLOCKED_SONGS, threshold=1) assert blocked_song_classifier is blocked_song_classifier2