def test_emit_game_window_signal(self): game_controller = GameController(1, "username") game_controller.game = mc.MagicMock().return_value game_controller.game.hide = mc.MagicMock() game_controller.level_window = mc.MagicMock().return_value game_controller.level_window.hide = mc.MagicMock() game_controller.game_menu_signal = mc.MagicMock().return_value game_controller.game_menu_signal.emit = mc.MagicMock() game_controller.emit_game_menu_signal() game_controller.game_menu_signal.emit.assert_called_once_with( "username")
def test_start_the_game_no_level_provided(self): game_controller = GameController(1, "username") mocked_game = mc.MagicMock() game_controller.create_game = mc.MagicMock(return_value=mocked_game) game_controller._connect_signals_to_game = mc.MagicMock() game_controller.select_level = mc.MagicMock() game_controller.start_the_game() game_controller._connect_signals_to_game.assert_called_once_with( mocked_game) game_controller.select_level.assert_called()
def test_start_the_game_with_level_inserted(self): game_controller = GameController(1, "username") mocked_game = mc.MagicMock().return_value mocked_game.hide = mc.MagicMock() game_controller.create_game = mc.MagicMock(return_value=mocked_game) game_controller._connect_signals_to_game = mc.MagicMock() game_controller.level_window = mc.MagicMock().return_value game_controller.level_window.hide = mc.MagicMock() game_controller._play_selected_level = mc.MagicMock() game_controller.start_the_game(1) game_controller._connect_signals_to_game.assert_called_once_with( mocked_game) game_controller.level_window.hide.assert_called() game_controller.game.hide.assert_called() game_controller._play_selected_level.assert_called_once_with(1)
def test_start_again(self): game_controller = GameController(1, "username") game_controller.game = mc.MagicMock() game_controller.game.hide = mc.MagicMock() game_controller.start_the_game = mc.MagicMock() game_controller.start_again(1) game_controller.game.hide.assert_called() game_controller.start_the_game.assert_called_once_with(1)
def test_play_selected_level(self): game_controller = GameController(1, "username") game_controller.game = mc.MagicMock() game_controller.game.play_game = mc.MagicMock() game_controller._play_selected_level(1) game_controller.game.play_game.assert_called_once_with(1)
def test_create_game(self, mock_method): hangman_instance = GameController.create_game(Game.Hangman.value, "hello") self.assertIsInstance(hangman_instance, hangman.HangmanWindow)
def start_selected_game(self, selected_game, username): self.game_controller = GameController(selected_game, username) self.game_controller.game_menu_signal.connect( self.show_game_menu_window) self.game_menu_window.hide() self.game_controller.start_the_game()
class GameLauncher: __instance__ = None def __init__(self): if GameLauncher.__instance__ is None: GameLauncher.__instance__ = self self.account = AccountManagement() self.game_controller = None self.game_menu_window = None self.login_window = None self.main_menu_window = None self.signup_window = None else: raise Exception("Only one instance of GameLauncher is allowed!") @staticmethod def clear_instance(): GameLauncher.__instance__ = None @staticmethod def get_instance(): if not GameLauncher.__instance__: GameLauncher() return GameLauncher.__instance__ def show_main_menu_window(self): self.main_menu_window = MainMenu() self.main_menu_window.log_in_signal.connect(self.show_login_window) self.main_menu_window.signup_signal.connect(self.show_signup_window) if self.game_menu_window is not None: self.game_menu_window.hide() if self.login_window is not None: self.login_window.hide() if self.signup_window is not None: self.signup_window.hide() self.main_menu_window.show() def show_signup_window(self): self.signup_window = SignUpWindow(self.account) self.signup_window.next_window_signal.connect( self.show_game_menu_window) self.signup_window.previous_window_signal.connect( self.show_main_menu_window) if self.login_window is not None: self.login_window.hide() self.main_menu_window.hide() self.signup_window.show() def show_login_window(self): self.login_window = LogInWindow(self.account) self.login_window.next_window_signal.connect( self.show_game_menu_window) self.login_window.previous_window_signal.connect( self.show_main_menu_window) self.main_menu_window.hide() self.login_window.show() def show_game_menu_window(self, username): self.game_menu_window = GameMenuWindow(username=username) self.game_menu_window.game_signal.connect(self.start_selected_game) self.game_menu_window.main_menu_signal.connect( self.show_main_menu_window) if self.login_window is not None: self.login_window.hide() if self.signup_window is not None: self.signup_window.hide() self.main_menu_window.hide() self.game_menu_window.show() def start_selected_game(self, selected_game, username): self.game_controller = GameController(selected_game, username) self.game_controller.game_menu_signal.connect( self.show_game_menu_window) self.game_menu_window.hide() self.game_controller.start_the_game()