def create_bpm_bucket(bpm: int, length: int) -> List[shuffler.Track]: return [ shuffler.Track(title="title", artist="artist", album="album", bpm=bpm, length=1) for _ in range(length) ]
def test_create_playlist_with_single_bucket_returns_entire_library(): library = set() for i in "abcdefghijklmnopqrstuvwxyz": library.add( shuffler.Track(title=i, artist=i, album=i, bpm=100, length=1)) playlist = shuffler.create_playlist(library) for track in library: assert track in playlist
def test_create_playlist_duration_gt_than_library_length_returns_expected(): library = set() for i in range(50): library.add( shuffler.Track(title=i, artist=i, album=i, bpm=100, length=1)) duration = 100 playlist = shuffler.create_playlist(library, duration=duration) playlist_duration = sum(track.length for track in playlist) assert playlist_duration == len(library)
def test_create_playlist_with_no_overlapping_bpms_returns_entire_library(): library = set() bpm = 10 for i in "abcdefghijklmnopqrstuvwxyz": library.add( shuffler.Track(title=i, artist=i, album=i, bpm=bpm, length=1)) bpm += 10 * (1 + shuffler.THRESHOLD) playlist = shuffler.create_playlist(library) for track in library: assert track in playlist
def test_traverse_graph_creates_no_consecutive_artists(): artist_a = [] for _ in range(5): artist_a.append( shuffler.Track( title=None, artist="a", album=None, bpm=100, length=1, )) artist_b = [] for _ in range(5): artist_b.append( shuffler.Track( title=None, artist="b", album=None, bpm=100, length=1, )) artist_c = [] for _ in range(5): artist_c.append( shuffler.Track( title=None, artist="c", album=None, bpm=100, length=1, )) graph = shuffler.Graph() graph.add_vertex(100, artist_a + artist_b + artist_c) actual = shuffler.traverse_graph(graph) prev = None for track in actual: if prev: assert track.artist != prev.artist prev = track
def test_traverse_graph_single_node_with_tracks(): bpm100 = create_bpm_bucket(100, 10) graph = shuffler.Graph() graph.add_vertex(100, bpm100) expected = [ shuffler.Track(title="title", artist="artist", album="album", bpm=100, length=1) for _ in range(10) ] actual = shuffler.traverse_graph(graph) assert expected == actual
def test_smoke(): with mock.patch("music_shuffler.shuffler.create_args", autospec=True) as mock_create_args, mock.patch( "music_shuffler.shuffler.parse_file", autospec=True) as mock_parse_file, mock.patch( "music_shuffler.shuffler.write_playlist", autospec=True): mock_parser = mock.Mock() mock_parser.parse_args.return_value = mock.Mock(duration=None) mock_create_args.return_value = mock_parser library = set() for i in range(1000): library.add( shuffler.Track( title=str(i), artist=str(i), album=str(i), bpm=random.randint(10, 100), length=1, )) mock_parse_file.return_value = library shuffler.main()