def test__given_command_processor__when_command_processor_invoked_with_new_peer_join__then_invoke_add_peer_and_data_upload( self, mock_websocket): calls_for_get_peer = [ mock.call('peer_id_1'), mock.call('peer_id_2'), mock.call('peer_id_3'), mock.call('SAMPLE_PEER_ID') ] calls_for_send_data_to_peer = [ mock.call('peer_id_1'), mock.call('peer_id_2'), mock.call('peer_id_3'), mock.call('SAMPLE_PEER_ID') ] mock_websocket.return_value = self.mock_websocket_instance command_processor = CommandProcessor(self.mock_chain_instance) actual_output = command_processor.command_processor( TestCommandProcessor.NEW_PEER_JOIN) expected_output = 'ACK' self.assertEqual(mock_websocket.call_count, 1) self.assertEqual(expected_output, actual_output) self.mock_chain_instance.add_new_peer.assert_called_once_with( 'SAMPLE_PEER_ID', { 'host': '0.0.0.0', 'port': '1234' }) self.mock_chain_instance.get_peer_id_list.assert_called_once() self.mock_chain_instance.get_peer.assert_has_calls(calls_for_get_peer) self.mock_chain_instance.get_block_data.assert_called_once() self.mock_websocket_instance.send.assert_called_once_with( json.dumps(TestCommandProcessor.UPLOAD_DICT))
def processRequest(): try: form_data_dict = request.form logger.info("request team_id : %s" % form_data_dict['team_id']) cmdProcessor = CommandProcessor() response = cmdProcessor.processCommand(form_data_dict['text'], form_data_dict) return response except: return "Oops, could not process request."
def test__given_command_processor__when_command_processor_invoked_with_ping__then_return_pong_as_message( self): command_processor = CommandProcessor(self.mock_chain_instance) actual_output = command_processor.command_processor( TestCommandProcessor.PING_COMMAND) expected_output = {'CMD': 'PONG'} self.assertEqual(expected_output, actual_output) self.assertIsInstance(actual_output, dict)
def test__given_command_processor__when_command_processor_invoked_with_add_block_comand__then_add_block( self): command_processor = CommandProcessor(self.mock_chain_instance) actual_output = command_processor.command_processor( TestCommandProcessor.ADD_BLOCK_COMMAND) expected_output = 'ACK' self.assertEqual(expected_output, actual_output) self.mock_chain_instance.add_block.assert_called_once_with('TEST_DATA')
def test__given_command_processor__when_command_processor_invoked_with_validate_block_comand__then_validate_block( self): command_processor = CommandProcessor(self.mock_chain_instance) actual_output = command_processor.command_processor( TestCommandProcessor.VALIDATE_COMMAND_BLOCK) expected_output = 'ACK' self.assertEqual(expected_output, actual_output) self.mock_chain_instance.validate_block.assert_called_once_with( {'data': 'Test Data'})
def test__given_command_processor__when_command_processor_invoked_with_add_peer__then_invoke_add_peer_on_chain_instance( self): command_processor = CommandProcessor(self.mock_chain_instance) actual_output = command_processor.command_processor( TestCommandProcessor.ADD_PEER_COMMAND) expected_output = 'ACK' self.mock_chain_instance.add_new_peer.assert_called_once_with( 'SAMPLE_PEER_ID', { 'host': '0.0.0.0', 'port': '1234' }) self.assertEqual(expected_output, actual_output)
def setUp(self): self.command_processor = CommandProcessor() command = "Create_parking_lot 5" self.command_processor.process(command) command = "Park KA-01 driver_age 21" output = self.command_processor.process(command) command = "Park KA-02 driver_age 18" output = self.command_processor.process(command) command = "Park KA-03 driver_age 18" output = self.command_processor.process(command) command = "Park KA-04 driver_age 21" output = self.command_processor.process(command)
def __init__(self, client): self.manually_overriden = False self.configuration_manager = ConfigurationManager(self.CONFIGURATION_FILENAME) self.repost_manager = RepostManager(self.HASHES_FILENAME) self.command_processor = CommandProcessor(self) self.configuration_manager.load_configuration() self.TOKEN = self.configuration_manager.configuration['token'] self.MASTER_ADMIN_ID = self.configuration_manager.configuration['admin'] self.ABOUT_MESSAGE = self.configuration_manager.configuration['about'] self.client = client
def __init__(self, websocket_port, *args, **kwargs): """ Function for intializing the block chain server. Initializes the BlockChain as well as the HTTP server for interacting with the blockchain """ bc_logger('Setting up naive chain server') self.peer_id = str(uuid.uuid4()) self.age = datetime.datetime.now() self.websocket_port = websocket_port bc_logger('Intializing websocket RPC') self.initialize_blockhain_rpc() bc_logger('Intializing websocket RPC') bc_logger('Intializing protocol processing') self.protocol_processor = CommandProcessor(self) self.peer_list = [] self.peer_connect_dict = {} self.block_data = [] # replace with a thread safe implementation # will run this in the background as a future that never returns!! self.rpc_server.start_websocket() bc_logger('Node {} live on {}:{}'.format(self.peer_id, '0.0.0.0', self.websocket_port)) if kwargs.get('existing_peer'): bc_logger('Peer Discovered') epeer_id = kwargs.get('peer_id') epeer_host = kwargs.get('peer_host') epeer_port = kwargs.get('peer_port') self.join_existing_peer_on_startup(epeer_id, epeer_host, epeer_port) else: bc_logger( 'No Peer Specified. Intializing genesis block for standalone operation' ) self.configure_genesis() # will block on this self.intialize_http_server() self.http_server.start_server()
def __init__(self, config): """ Initialize :param config: configuration :type config: Config """ self.command_processor = CommandProcessor( self._command_handlers(config.command_handlers)) self.robot = Robot(config.apiai.client_access_token, config.apiai.language, self.command_processor.commands) self.speech_to_text = SpeechToText( config.speechkit.key, "", config.speechkit.recognition.language) self.text_to_speech = TextToSpeech( config.speechkit.synthesis.cache_size, config.speechkit.key, config.speechkit.synthesis.language, config.speechkit.synthesis.speaker, config.speechkit.synthesis.emotion, config.speechkit.synthesis.speed) self.record = SpeechCapture(config.record.silence_calculation_chunks, config.record.speech_level_coefficient, config.record.start_wait_chunks, config.record.finish_wait_chunks)
def test_file_reading(self, mockPrint): command_processor = CommandProcessor() input_consumer = FileInputConsumer(command_processor) file_name = os.path.join(os.path.dirname(__file__), "./data/test1.txt") input_consumer.consume(file_name) mockPrint.write.assert_has_calls( [ call("Created parking of 6 slots"), call("\n"), call( 'Car with vehicle registration number "KA-01-HH-1234" has been parked at slot number 1' ), call("\n"), call( 'Car with vehicle registration number "PB-01-HH-1234" has been parked at slot number 2' ), call("\n"), call("1,2"), call("\n"), call( 'Car with vehicle registration number "PB-01-TG-2341" has been parked at slot number 3' ), call("\n"), call("2"), call("\n"), call( 'Slot number 2 vacated, the car with vehicle registration number "PB-01-HH-1234" left the space, the driver of the car was of age 21' ), call("\n"), call( 'Car with vehicle registration number "HR-29-TG-3098" has been parked at slot number 2' ), call("\n"), call(""), call("\n"), ] )
def test__given_command_processor__when_command_processor_invoked_with_new_peer_join_then_raise_websocket_exception__then_remove_added_from_block_chain( self, mock_websocket): calls_for_get_peer = [ mock.call('peer_id_1'), mock.call('peer_id_2'), mock.call('peer_id_3'), mock.call('SAMPLE_PEER_ID') ] calls_for_send_data_to_peer = [ mock.call('peer_id_1'), mock.call('peer_id_2'), mock.call('peer_id_3'), mock.call('SAMPLE_PEER_ID') ] mock_websocket.return_value = self.mock_websocket_instance mock_websocket.side_effect = websocket_client.WebSocketTimeoutException command_processor = CommandProcessor(self.mock_chain_instance) actual_output = command_processor.command_processor( TestCommandProcessor.NEW_PEER_JOIN) expected_output = 'ACK' self.assertEqual(expected_output, actual_output) self.mock_chain_instance.add_new_peer.assert_called_once_with( 'SAMPLE_PEER_ID', { 'host': '0.0.0.0', 'port': '1234' }) self.assertEqual(mock_websocket.call_count, 1) self.mock_chain_instance.get_peer_id_list.assert_called_once() self.mock_chain_instance.get_peer.assert_has_calls(calls_for_get_peer) self.mock_chain_instance.get_block_data.assert_called_once() self.mock_chain_instance.remove_peer.assert_called_once_with( 'SAMPLE_PEER_ID')
def setUp(self, daoMock, serviceMock): self.command_processor = CommandProcessor() self.parking_lot_service_mock = serviceMock.return_value
def setUp(self): self.command_processor = CommandProcessor()
def main(stdscr): holdstdout = StdOutWrapper() sys.stdout = holdstdout sys.stderr = holdstdout #stdscr = curses.initscr() screen_size = stdscr.getmaxyx() height = screen_size[0] width = screen_size[1] hincrement = int(height / 3) wincrement = int(width / 3) upper_left = (0, 0) upper_middle = (0, wincrement) upper_right = (0, 2 * wincrement) middle_left = (hincrement, 0) middle_middle = (hincrement, wincrement) middle_right = (hincrement, 2 * wincrement) lower_left = (2 * hincrement, 0) lower_middle = (2 * hincrement, wincrement) #lower_right= (2 * hincrement, 2 * wincrement) # Skills | Spells | Loadout # HUD | Map | Inventory # Terminal | Status | Inventory # Terminal green curses.init_pair(1, 46, curses.COLOR_BLACK) # Dull red curses.init_pair(2, 196, curses.COLOR_BLACK) # Dull Teal curses.init_pair(3, curses.COLOR_CYAN, curses.COLOR_BLACK) # Black on Grey curses.init_pair(4, curses.COLOR_BLACK, 244) # bronze curses.init_pair(5, 208, curses.COLOR_BLACK) curses.init_pair(6, 208, 130) # steel curses.init_pair(7, 252, curses.COLOR_BLACK) curses.init_pair(8, 253, 247) # mithril curses.init_pair(9, 117, curses.COLOR_BLACK) curses.init_pair(10, 117, 33) # adamant curses.init_pair(11, 99, curses.COLOR_BLACK) curses.init_pair(12, 52, 99) # demon curses.init_pair(13, 92, curses.COLOR_BLACK) curses.init_pair(14, 52, 99) # spark curses.init_pair(15, 92, curses.COLOR_BLACK) curses.init_pair(16, 52, 99) # night curses.init_pair(17, 92, curses.COLOR_BLACK) curses.init_pair(18, 52, 99) # cooked meat curses.init_pair(19, 124, curses.COLOR_BLACK) # leather curses.init_pair(20, 130, curses.COLOR_BLACK) # oak curses.init_pair(21, 172, curses.COLOR_BLACK) # maple curses.init_pair(22, 167, curses.COLOR_BLACK) # willow curses.init_pair(23, 137, curses.COLOR_BLACK) # flax curses.init_pair(100, 100, curses.COLOR_BLACK) # gold curses.init_pair(253, 220, curses.COLOR_BLACK) # white curses.init_pair(254, 252, curses.COLOR_BLACK) # box color, dull grey curses.init_pair(255, 240, curses.COLOR_BLACK) terwin = curses.newwin(hincrement, wincrement, lower_left[0], lower_left[1]) terwin.attron(curses.color_pair(255)) terwin.box() ter_panel = curses.panel.new_panel(terwin) ter_panel.top() hudwin = curses.newwin(hincrement, wincrement, middle_left[0], middle_left[1]) hudwin.attron(curses.color_pair(255)) hudwin.box() hud_panel = curses.panel.new_panel(hudwin) hud_panel.top() invwin = curses.newwin(hincrement * 2, wincrement, middle_right[0], middle_right[1]) invwin.attron(curses.color_pair(255)) invwin.box() inv_panel = curses.panel.new_panel(invwin) inv_panel.top() stswin = curses.newwin(hincrement, wincrement, lower_middle[0], lower_middle[1]) stswin.attron(curses.color_pair(255)) stswin.box() sts_panel = curses.panel.new_panel(stswin) sts_panel.top() sklwin = curses.newwin(hincrement, wincrement, upper_left[0], upper_left[1]) sklwin.attron(curses.color_pair(255)) sklwin.box() skl_panel = curses.panel.new_panel(sklwin) skl_panel.top() eqpwin = curses.newwin(hincrement, wincrement, upper_right[0], upper_right[1]) eqpwin.attron(curses.color_pair(255)) eqpwin.box() eqp_panel = curses.panel.new_panel(eqpwin) eqp_panel.top() mapwin = curses.newwin(hincrement, wincrement, middle_middle[0], middle_middle[1]) mapwin.attron(curses.color_pair(255)) mapwin.box() map_panel = curses.panel.new_panel(mapwin) map_panel.top() splwin = curses.newwin(hincrement, wincrement, upper_middle[0], upper_middle[1]) splwin.attron(curses.color_pair(255)) splwin.box() spl_panel = curses.panel.new_panel(splwin) spl_panel.top() curses.start_color() curses.cbreak() curses.noecho() terwin.keypad(1) terwin.idcok(False) try: var_handler = VarHandler() command_processor = CommandProcessor(var_handler) var_handler.bind('command_processor', command_processor) io_handler = IOHandler(terwin, var_handler) var_handler.bind('io_handler', io_handler) hud_handler = HUDHandler(hudwin, var_handler) var_handler.bind('hud_handler', hud_handler) status_handler = StatusHandler(stswin) var_handler.bind('status_handler', status_handler) player = Player(sklwin, var_handler) var_handler.bind('player', player) inventory_handler = InventoryHandler(invwin, eqpwin, var_handler) var_handler.bind('inventory_handler', inventory_handler) location_handler = LocationHandler(mapwin, var_handler) var_handler.bind('location_handler', location_handler) time_handler = TimeHandler() var_handler.bind('time_handler', time_handler) spell_handler = SpellHander(splwin, var_handler) var_handler.bind('spell_handler', spell_handler) combat_handler = CombatHandler(var_handler) var_handler.bind('combat_handler', combat_handler) start = location_handler.spawn_location('entervale') location_handler.spawn_location('forest') start.move("mine") io_handler.output("Welcome to pyscape", curses.color_pair(3), curses.A_BOLD) hud_handler.text_update() hud_panel.top() inventory_handler.update_inv_window() curses.panel.update_panels() while True: curses.curs_set(1) input = io_handler.get_input("~~~~~~~:", curses.color_pair(1)) output = command_processor.receive_command(input) io_handler.output(output[0], output[1]) hud_handler.text_update() hud_panel.top() #inventory_handler.draw_bank() curses.panel.update_panels() except KeyboardInterrupt: terwin.addstr("exiting") exit(0) finally: terwin.keypad(0) curses.nocbreak() curses.echo() curses.endwin() sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ sys.stdout.write(holdstdout.get_text())
def main(): input_file = args[1] file_input_consumer = FileInputConsumer(CommandProcessor()) file_input_consumer.consume(input_file)