def get_input(self, board): """ Prompts user for their command. If the command is a move it decomposes it into its relevant components and Returns them: active_piece, active_piece_type, target_location, is_capture, promotion_type, castle_direction """ while True: print('<cmd> for a list of commands.') user_input = input(' Your move: ') print('\n') # MOVE PARSING AND PACKAGING if main.validate_san(user_input): try: active_piece, active_piece_type, target_location, is_capture, \ promotion_type, castle_direction = main.decompose_and_assess(board, user_input) except Exceptions.InvalidInput as II: # if it flags inform the agent and re-ask for a move print( f"Apologies, '{user_input}' failed to identify a unique, legal move." ) print(f' : {II}') continue # In case promotion identifier forgotten.. if (active_piece.__class__.__name__ == 'Pawn' and # Moving piece is pawn.. (target_location[0] == 0 or target_location[0] == 7) and # and target square is final rank promotion_type == ''): # .. and no promotion type is designated.. print( "\nThis move will promote the pawn! What to promote to?" ) print("k<N>ight <B>ishop <R>ook <Q>ueen" ) # prompt user for info. choice = input(" : ").upper() if choice in ['N', 'B', 'R', 'Q']: promotion_type = Globals.LETTERS[choice] return active_piece, active_piece_type, target_location, is_capture, promotion_type, castle_direction # COMMAND PARSING AND ACTION elif user_input.isalpha(): user_input = user_input.lower() if user_input == 'cmd': main.in_game_commands() elif user_input == 'resign': main.not_implemented('resign') elif user_input == 'save': print(f'FEN: {main.convert_board2fen(board)}') main.not_implemented('save') elif user_input == 'tmp': with open('tmp.txt', 'r') as tmp: lines = tmp.readlines() print(''.join(lines)) elif user_input in ('close', 'quit', 'exit', 'no'): main.exit_program() else: print( f"Apologies, '{user_input}' failed to identify recognisable move or command." )
def test_exit_program(self): """Tests if program exits properly""" with self.assertRaises(SystemExit): exit_program()
def test_exit_program(self): """Tests the program quit function in main.py.""" with self.assertRaises(SystemExit): main.exit_program()
def test_exit(self): ''' Testing the exit function for clean exiting of program. ''' with self.assertRaises(SystemExit): main.exit_program()
def test_system_exit(self): """ Tests main.exit_program.""" with self.assertRaises(SystemExit): main.exit_program()
def test_main_menu(self): user_input = ["q"] with patch('builtins.input', side_effect=user_input): menu = main_menu() with self.assertRaises(SystemExit): exit_program()
def test_exit_program(self): with self.assertRaises(SystemExit): exit_program()
def test_exit_program(self): """Test function to test the system exit""" with self.assertRaises(SystemExit): main.exit_program()
def test_exit_program(self): """Tests that exit_program calls sys.exit() properly""" with self.assertRaises(SystemExit): exit_program()
def test_exit_program(self, sys_exit_mock): main.exit_program() self.assertTrue(sys_exit_mock.assert_called)
def test_exit_program(): """Tests that exit_program calls sys.exit() properly""" with pytest.raises(SystemExit): exit_program()
def test_exit_program(self): """Test the exit_program() method""" with self.assertRaises(SystemExit): main.exit_program()
def test_exit2(self): with self.assertRaises(SystemExit) as cm: main.exit_program() self.assertEqual(cm.exception, "Error")
def test_exit_program(self): """ Verify that exit_program properly exits program """ with self.assertRaises(SystemExit): exit_program()
def test_exit_program(self): """Tests exit program causes system exit""" with self.assertRaises(SystemExit): exit_program()