def test_not_equal_if_different_number_of_groups(self): manager_1 = SoundManager({"volume": 1, "groups": []}) manager_2 = SoundManager({ "volume": 1, "groups": [{ "name": "Group", "sounds": [] }] }) assert manager_1 != manager_2 assert manager_2 != manager_1
def __init__(self, config_path, host, port): with open(config_path) as config_file: config = yaml.load(config_file, Loader=CustomLoader) self.music = MusicManager(config["music"], callback_fn=self.on_music_changes) self.sound = SoundManager(config["sound"], callback_fn=self.on_sound_changes) self.app = None self.host = host self.port = port
def test_groups_are_created(self, minimal_sound_manager_config): sound_group_1_config = {"name": "Some Sound Group 1", "sounds": []} sound_group_2_config = {"name": "Some Sound Group 2", "sounds": []} minimal_sound_manager_config["groups"] = [ sound_group_1_config, sound_group_2_config ] sound_manager = SoundManager(minimal_sound_manager_config) assert len(sound_manager.groups) == 2 assert sound_manager.groups[0] == SoundGroup(sound_group_1_config) assert sound_manager.groups[1] == SoundGroup(sound_group_2_config)
def test_sort_in_config(self, minimal_sound_manager_config): name_starts_with_n_config = { "name": "Not First In The Alphabet", "sounds": [] } name_starts_with_a_config = {"name": "Alphabet", "sounds": []} minimal_sound_manager_config["sort"] = False minimal_sound_manager_config["groups"] = [ name_starts_with_n_config, name_starts_with_a_config ] sound_manager = SoundManager(minimal_sound_manager_config) assert sound_manager.groups[0] == SoundGroup(name_starts_with_n_config) assert sound_manager.groups[1] == SoundGroup(name_starts_with_a_config)
def __init__(self): # Center window on screen os.environ['SDL_VIDEO_CENTERED'] = '1' pygame.init() self.caption = 'NES Mario' size = [constants.SCREEN_WIDTH, constants.SCREEN_HEIGHT] self.screen = pygame.display.set_mode(size) self.game_info = GameInfo() self.sound_manager = SoundManager()
def test_performs_checks_on_initialization(self, monkeypatch): sound_checker_instance_mock = MagicMock() sound_checker_mock = MagicMock( return_value=sound_checker_instance_mock) monkeypatch.setattr("src.sound.sound_manager.SoundChecker", sound_checker_mock) manager = SoundManager({ "volume": 1, "directory": "default/dir/", "groups": [] }) sound_checker_mock.assert_called_once_with(manager.groups, manager.directory) sound_checker_instance_mock.do_all_checks.assert_called_once()
def test_not_equal_if_different_attributes(self): manager_1 = SoundManager({"volume": 1, "groups": []}) manager_2 = SoundManager({"volume": 0.5, "groups": []}) assert manager_1 != manager_2 assert manager_2 != manager_1
def test_equal_if_same_config(self): manager_1 = SoundManager({"volume": 1, "groups": []}) manager_2 = SoundManager({"volume": 1, "groups": []}) assert manager_1 == manager_2 assert manager_2 == manager_1
def test_sound_groups_use_tuple_instead_of_list( self, minimal_sound_manager_config): sound_manager = SoundManager(minimal_sound_manager_config) assert isinstance(sound_manager.groups, tuple)
def test_directory_in_config(self, minimal_sound_manager_config): minimal_sound_manager_config["directory"] = "/some/dir/" sound_manager = SoundManager(minimal_sound_manager_config) assert sound_manager.directory == "/some/dir/"
def test_directory_is_none_by_default(self, minimal_sound_manager_config): sound_manager = SoundManager(minimal_sound_manager_config) assert sound_manager.directory is None
def test_minimal_dict_as_config(self, minimal_sound_manager_config): sound_manager = SoundManager(minimal_sound_manager_config) assert sound_manager.volume == 1 assert len(sound_manager.groups) == 0
def example_sound_manager(self, example_config, monkeypatch): with monkeypatch.context() as m: m.setattr("src.sound.sound_manager.SoundChecker", MagicMock()) manager = SoundManager(config=example_config["sound"]) return manager
def test_not_equal_if_different_types(self): config = {"volume": 1, "groups": [{"name": "Group", "sounds": []}]} manager = SoundManager(config) assert config != manager assert manager != config
def test_minimal_server_configures_sound(self, minimal_server): minimal_sound_config = {"volume": 1, "groups": []} assert minimal_server.sound == SoundManager(minimal_sound_config)