def test_sort_in_config(self, minimal_music_manager_config): name_starts_with_n_config = { "name": "Not First In The Alphabet", "track_lists": [] } name_starts_with_a_config = {"name": "Alphabet", "track_lists": []} minimal_music_manager_config["sort"] = False minimal_music_manager_config["groups"] = [ name_starts_with_n_config, name_starts_with_a_config ] music_manager = MusicManager(minimal_music_manager_config) assert music_manager.groups[0] == MusicGroup(name_starts_with_n_config) assert music_manager.groups[1] == MusicGroup(name_starts_with_a_config)
def test_music_tuple_generator(self): """ Test that calling `music_tuple_generator()` returns an iterator over all tuples of the form (group, track_list, track). """ group_config = { "name": "Group 1", "track_lists": [ { "name": "Track List 1", "shuffle": False, "tracks": ["track_1.mp3"] }, { "name": "Track List 2", "shuffle": False, "tracks": ["track_2.mp3", "track_3.mp3"] }, ], } groups = [MusicGroup(group_config)] generator = utils.music_tuple_generator(groups) first_tuple = (groups[0], groups[0].track_lists[0], groups[0].track_lists[0].tracks[0]) second_tuple = (groups[0], groups[0].track_lists[1], groups[0].track_lists[1].tracks[0]) third_tuple = (groups[0], groups[0].track_lists[1], groups[0].track_lists[1].tracks[1]) assert first_tuple == next(generator) assert second_tuple == next(generator) assert third_tuple == next(generator) with pytest.raises(StopIteration): next(generator)
def test_groups_are_created(self, minimal_music_manager_config): music_group_1_config = { "name": "Some Music Group 1", "track_lists": [] } music_group_2_config = { "name": "Some Music Group 2", "track_lists": [] } minimal_music_manager_config["groups"] = [ music_group_1_config, music_group_2_config ] music_manager = MusicManager(minimal_music_manager_config) assert len(music_manager.groups) == 2 assert music_manager.groups[0] == MusicGroup(music_group_1_config) assert music_manager.groups[1] == MusicGroup(music_group_2_config)
def example_group(self): group_config = { "name": "Group 1", "track_lists": [{ "name": "Track List", "tracks": [] }] } return MusicGroup(group_config)
def test_check_tracks_do_exist(self, monkeypatch): """ Test that the `check_tracks_do_exist()` method uses `utils.get_track_path()` to determine whether a file exists. """ get_track_path_mock = MagicMock() monkeypatch.setattr("src.music.music_checker.utils.get_track_path", get_track_path_mock) group_1 = MusicGroup({ "name": "Group 1", "track_lists": [{ "name": "Track List 1", "tracks": ["track-1.mp3", "track-2.mp3"] }] }) group_2 = MusicGroup({ "name": "Group 2", "track_lists": [{ "name": "Track List 2", "tracks": ["track-3.mp3"] }] }) expected_calls = [ call(group_1, group_1.track_lists[0], group_1.track_lists[0]._tracks[0], default_dir="default/dir/"), call(group_1, group_1.track_lists[0], group_1.track_lists[0]._tracks[1], default_dir="default/dir/"), call(group_2, group_2.track_lists[0], group_2.track_lists[0]._tracks[0], default_dir="default/dir/"), ] MusicChecker().check_tracks_do_exist([group_1, group_2], "default/dir/") assert get_track_path_mock.call_count == 3 # There are three tracks in total to check get_track_path_mock.assert_has_calls(expected_calls, any_order=True)
def test_check_tracks_do_exist_raises_error_if_file_does_not_exist(self): """ Test that `check_tracks_do_exist()´ re-raises the `ValueError` raised by `get_track_path()` if the track is not a valid file. """ group = MusicGroup({ "name": "Group 1", "track_lists": [{ "name": "Track List 1", "tracks": ["this-does-not-exist.mp3"] }] }) with pytest.raises(ValueError): MusicChecker().check_tracks_do_exist([group], None)
def test_check_track_list_names_raises_error_if_next_invalid_name(self): """ If the `next` attribute of a tracklist is not the name of an existing tracklist, raise a `RuntimeError`. """ group_config = { "name": "Group 1", "track_lists": [{ "name": "Track List", "next": "Non-existing Track List", "tracks": [] }], } groups = [MusicGroup(group_config)] with pytest.raises(RuntimeError): MusicChecker().check_track_list_names(groups)
def test_check_tracks_do_exist_raises_on_invalid_youtube_video(self): """ Test that the `check_tracks_do_exist()` method raises an error for non-existing YouTube videos. """ group = MusicGroup({ "name": "Group 1", "track_lists": [{ "name": "Track List 1", "tracks": ["https://www.youtube.com/watch?v=l1111111111" ], # Some non-existent video }], }) with pytest.raises(RuntimeError): MusicChecker().check_tracks_do_exist([group], None)
def test_check_tracks_do_exist_raises_on_private_youtube_video(self): """ Test that the `check_tracks_do_exist()` method raises an error for private YouTube videos. """ group = MusicGroup({ "name": "Group 1", "track_lists": [{ "name": "Track List 1", "tracks": ["https://www.youtube.com/watch?v=lTutay89N6Q" ], # Some private video }], }) with pytest.raises(RuntimeError): MusicChecker().check_tracks_do_exist([group], None)
def test_check_tracks_do_exist_does_not_raise_on_valid_youtube_video(self): """ Test that the `check_tracks_do_exist()` method does not raise an error on existing YouTube videos. """ group = MusicGroup({ "name": "Group 1", "track_lists": [{ "name": "Track List 1", "tracks": ["https://www.youtube.com/watch?v=hKRUPYrAQoE" ], # Some existing video }], }) MusicChecker().check_tracks_do_exist([group], None) assert True # Success if no error was raised
def test_check_track_list_names_raises_error_if_duplicate_name(self): """ If two tracklists have the same name, raise a `RuntimeError`. """ group_config = { "name": "Group 1", "track_lists": [{ "name": "Track List", "tracks": [] }, { "name": "Track List", "tracks": [] }], } groups = [MusicGroup(group_config)] with pytest.raises(RuntimeError): MusicChecker().check_track_list_names(groups)
def test_check_track_list_names(self): """ If all names are unique and the `next` attributes are names of existing tracklists, no error should be raised. """ group_config = { "name": "Group 1", "track_lists": [{ "name": "First", "next": "Second", "tracks": [] }, { "name": "Second", "tracks": [] }], } groups = [MusicGroup(group_config)] MusicChecker().check_track_list_names(groups) assert True # No error occurred