8000 merge to stable by xXUnique31Xx · Pull Request #9 · crnnr/Python-TicTacToe · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

merge to stable #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 20 additions & 9 deletions tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()


Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Loading
0