class Ui: def __init__(self): self.input_validator = InputValidator() def greet(self): print("Welcome to the Python TicTacToe") def print_board(self, board): current_board = board.all_spots() print(""" {} | {} | {} ----------- {} | {} | {} ----------- {} | {} | {} """.format(*current_board)) def get_input(self, text): return input(text) def choose_marker(self): text = 'Choose the symbol you want to play with: X or O. Enter x or o:\n' symbol = None while not symbol: symbol = self.get_input(text).upper() if self.input_validator.valid_marker(symbol): return symbol else: symbol = None def choose_move(self, board): text = "Enter a number to make your move:\n" move = None while not move: move = self.get_input(text) if self.input_validator.valid_move(move) and int( move) in board.available_spots(): return move else: move = None def game_over(self): print("Game over!") def declare_winner(self, board, marker): if board.available_spots(): print(f'{marker} wins!') else: print("It's a tie")
def main(): level = Level() input_validator = InputValidator() display = Display() while (True): c = display.menu_select_window.getch() if c == ord('1'): display.selection_menu() elif c == ord('q') or c == ord('Q'): break display.stdscr.noutrefresh() display.menu_select_window.noutrefresh() display.main_window.noutrefresh() curses.doupdate() curses.nocbreak() curses.echo() curses.curs_set(1) curses.endwin()
try: __validate_params(input_json_path_param, output_path_param, scale_param, json_file_param) except ValueError as err: print "Error: {0}".format(err.message) print_usage() sys.exit(1) print 'input_json_path_param: ' + input_json_path_param print 'output_path_param: ' + output_path_param print 'scale: ' + (str(scale_param) if scale_param else "unspecified. Producing SVGs.") print 'json_file_param: ' + str(json_file_param) input_manifest = process_input_manifest(input_json_path_param) InputValidator.validate_input_manifest(input_manifest) mode = input_manifest["mode"] if InputValidator.MODE_PIN_SHEET in mode: PinSheetFactory.create_pin_sheet(input_manifest, output_path_param, scale_param, json_file_param) elif InputValidator.MODE_ICONS in mode: if scale_param: IconFactory.create_icons(input_manifest, output_path_param, scale_param, json_file_param) else: ScalableIconFactory.create_icons(input_manifest, output_path_param, json_file_param) else: raise ValueError("Unknown mode: " + mode)
def setUp(self): self.input_validator = InputValidator()
class GameTest(unittest.TestCase): def setUp(self): self.input_validator = InputValidator() def test_valid_marker_when_input_is_a_valid_character(self): symbol = self.input_validator.valid_marker('O') self.assertEqual(symbol, True) symbol = self.input_validator.valid_marker('X') self.assertEqual(symbol, True) def test_valid_marker_when_input_is_an_invalid_character(self): symbol = self.input_validator.valid_marker('D') self.assertEqual(symbol, None) def test_valid_marker_when_input_is_a_lowercase_character(self): symbol = self.input_validator.valid_marker('x') self.assertEqual(symbol, None) def test_valid_marker_when_input_is_a_number(self): symbol = self.input_validator.valid_marker('1') self.assertEqual(symbol, None) def test_valid_marker_when_input_is_a_special_character(self): symbol = self.input_validator.valid_marker('-') self.assertEqual(symbol, None) def test_valid_move_when_input_is_a_valid_possible_move(self): move = self.input_validator.valid_move('2') self.assertEqual(move, True) def test_valid_move_when_input_is_a_lowercase_character(self): with self.assertRaises(ValueError): self.input_validator.valid_move('x') def test_valid_move_when_input_is_an_invalid_number(self): move = self.input_validator.valid_move('100') self.assertEqual(move, None) def test_valid_move_when_input_is_a_special_character(self): with self.assertRaises(ValueError): self.input_validator.valid_move('-')
def __init__(self): self.input_validator = InputValidator()
from flask import Flask, jsonify, redirect, render_template, request, url_for from user_agents import parse # init random number generator random.seed() app = Flask(__name__) # app.logger.error("test") from db_handler import DbHandler db = DbHandler() from input_validator import InputValidator input_validator = InputValidator() domain_duplicated_error = "You already created this domain or the created domain is the same as the well-known domain. Create a different one!" @app.route( "/is_step_finished/user_id/<uuid:user_id>/step_id/<any('step1', 'step2', 'step3', 'step4', 'step5', 'questionnaire'):step_id>" ) def is_step_finished(user_id, step_id): user_id = str(user_id) input_validation = input_validator.check_input_user_id(user_id) if input_validation["result"] is False: return jsonify({ "server_error": True, "server_error_message": input_validation["message"] })