diff --git a/controller.py b/controller.py index ec89cc2..beef81d 100644 --- a/controller.py +++ b/controller.py @@ -47,10 +47,10 @@ def start_menu(self): GameView.display_message("Loading game failed.") self.load_game_state() break - elif choice == '3': + if choice == '3': GameView.display_message("Thank you for playing. Goodbye!") sys.exit(0) - elif choice.lower() == 'secret': + if choice.lower() == 'secret': try: self.binary_rain() except KeyboardInterrupt: diff --git a/tests/test_controller.py b/tests/test_controller.py index b2d5fec..9b663e1 100644 --- a/tests/test_controller.py +++ b/tests/test_controller.py @@ -186,10 +186,10 @@ def test_post_game_draw(self, mock_display_message, mock_start_menu): """ Test that post_game displays the correct message when the game is a draw """ with patch('view.GameView.input_prompt', return_value='1') as mock_input_prompt: self.game_manager.post_game() - calls = [unittest.mock.call("It's a draw."), + calls = [unittest.mock.call("It's a draw!"), unittest.mock.call("\n1. Return to Main Menu\n2. Exit")] - mock_display_message.call_args_list == calls + self.assertTrue(mock_display_message.call_args_list == calls) mock_input_prompt.assert_called_once_with("Enter your choice: ") mock_start_menu.assert_called_once() @@ -201,10 +201,10 @@ def test_post_game_draw_invalid_choice(self, mock_input_prompt, mock_start_menu) self.game_manager.post_game() mock_input_prompt.assert_called_once_with("Enter your choice: ") - calls = [unittest.mock.call("It's a draw."), + calls = [unittest.mock.call("It's a draw!"), unittest.mock.call("\n1. Return to Main Menu\n2. Exit"), unittest.mock.call("Invalid choice. Returning to main menu.")] - mock_display_message.call_args_list == calls + self.assertTrue(mock_display_message.call_args_list == calls) mock_start_menu.assert_called_once() @@ -246,6 +246,17 @@ def test_game_loop_apply_action(self, mock_choose_move, mock_post_game.assert_called_once() + + +class TestSerialization(unittest.TestCase): + """ This class contains tests for the serialization module. """ + + def setUp(self): + """ Set up the GameManager object for unittests """ + self.game_manager = GameManager() + self.game_manager.players = [MagicMock(), MagicMock()] + self.game_manager.board = GameBoard() + @patch('controller.GameManager.start_menu') @patch('builtins.open', new_callable=unittest.mock.mock_open) def test_save_game_with_savename(self, mock_open, mock_start_menu): @@ -400,22 +411,22 @@ def test_load_game_state_no_saved_games_directory(self, mock_game_view, mock_os_ @patch('os.listdir', return_value=['game1.json', 'game2.json']) @patch('view.GameView.input_prompt', return_value='3') @patch('view.GameView.display_message') - def test_invalid_selection_save_game(self, mock_input_prompt, - mock_listdir, - mock_display_message): + def test_invalid_selection_save_game(self, mock_display_message, + mock_input_prompt, + mock_listdir,): """ Test that load_game_state handles invalid selection""" result = self.game_manager.load_game_state() self.assertFalse(result) # display_message is used more than one time - calls = [unittest.mock.call("Please select a game to load"), + calls = [unittest.mock.call("Please select a game to load:"), unittest.mock.call("1. game1.json"), unittest.mock.call("2. game2.json"), unittest.mock.call("Invalid selection.")] mock_input_prompt.assert_called() mock_listdir.assert_called_once() - mock_display_message.call_args_list == calls + self.assertTrue(mock_display_message.call_args_list == calls) if __name__ == '__main__': unittest.main()