def test_print_with_background_colour(self, mock_print): test_console = console.Console() test_console.background_colour = console.ConsoleColours.BACKGROUND_RED test_console.print( 'green backed output', background_colour=console.ConsoleColours.BACKGROUND_GREEN) mock_print.assert_called_once_with('\33[42mgreen backed output\33[41m')
def test_print_with_foreground_colour(self, mock_print): test_console = console.Console() test_console.foreground_colour = console.ConsoleColours.FOREGROUND_BEIGE test_console.print( 'purple text output', foreground_colour=console.ConsoleColours.FOREGROUND_PURPLE) mock_print.assert_called_once_with('\33[35mpurple text output\33[36m')
def __init__(self): #set physics variables self.clock = pygame.time.Clock() self.__physics_FPS = 100.0 self.__dt = 1.0 / self.__physics_FPS self.time_current = self.get_time() self.accumulator = 0.0 self.tile_size = 32 self.camera = camera.Camera((1280, 720)) tile_images = { "tile_grass": IMAGES.tile_grass, "tile_dirt": IMAGES.tile_dirt, "tile_wall": IMAGES.tile_wall } world = WORLD.World("level.map", tile_images) self.path_finder = pathfinder.PathFinder(world.nodes) player = entity.Player(IMAGES.player) dummy = entity.Entity(IMAGES.player, spawn_location = (16, 2)) self.entities = pygame.sprite.Group(player, dummy) self.objects = dict(world=world, player=player, dummy=dummy) self.console = console.Console() s = item.Sword(IMAGES.key) b = item.Bandage(IMAGES.key) player.hand.add(s) player.bag.add(0, b)
def test_background_colour_setter_succeeds(self): test_console = console.Console() self.assertEqual(test_console.background_colour, console.ConsoleColours.BACKGROUND_BLACK) test_console.background_colour = console.ConsoleColours.BACKGROUND_YELLOW self.assertEqual(test_console.background_colour, console.ConsoleColours.BACKGROUND_YELLOW)
def setupRocketConsole(self): """ Place a new rocket window onto a texture bound to the front of the monitor. """ self.win.setClearColor(Vec4(0.5, 0.5, 0.8, 1)) faceplate = self.monitorNP.find("**/Faceplate") assert faceplate mybuffer = self.win.makeTextureBuffer("Console Buffer", 1024, 512) tex = mybuffer.getTexture() tex.setMagfilter(Texture.FTLinear) tex.setMinfilter(Texture.FTLinear) faceplate.setTexture(tex, 1) self.rocketConsole = RocketRegion.make('console', mybuffer) self.rocketConsole.setInputHandler(self.inputHandler) self.consoleContext = self.rocketConsole.getContext() self.console = console.Console(self, self.consoleContext, 40, 13, self.handleCommand) self.console.addLine("Panda DOS") self.console.addLine("type 'help'") self.console.addLine("") self.console.allowEditing(True)
def test_parse_backcolour(self): mappings = { # lower case 'black': console.ConsoleColours.BACKGROUND_BLACK, 'red': console.ConsoleColours.BACKGROUND_RED, 'green': console.ConsoleColours.BACKGROUND_GREEN, 'yellow': console.ConsoleColours.BACKGROUND_YELLOW, 'blue': console.ConsoleColours.BACKGROUND_BLUE, 'purple': console.ConsoleColours.BACKGROUND_PURPLE, 'cyan': console.ConsoleColours.BACKGROUND_CYAN, 'white': console.ConsoleColours.BACKGROUND_WHITE, # upper case 'BLACK': console.ConsoleColours.BACKGROUND_BLACK, 'RED': console.ConsoleColours.BACKGROUND_RED, 'GREEN': console.ConsoleColours.BACKGROUND_GREEN, 'YELLOW': console.ConsoleColours.BACKGROUND_YELLOW, 'BLUE': console.ConsoleColours.BACKGROUND_BLUE, 'PURPLE': console.ConsoleColours.BACKGROUND_PURPLE, 'CYAN': console.ConsoleColours.BACKGROUND_CYAN, 'WHITE': console.ConsoleColours.BACKGROUND_WHITE, # mixed case 'BlacK': console.ConsoleColours.BACKGROUND_BLACK, 'Red': console.ConsoleColours.BACKGROUND_RED, 'gReeN': console.ConsoleColours.BACKGROUND_GREEN, 'YellOW': console.ConsoleColours.BACKGROUND_YELLOW, 'blUe': console.ConsoleColours.BACKGROUND_BLUE, 'purplE': console.ConsoleColours.BACKGROUND_PURPLE, 'CyAn': console.ConsoleColours.BACKGROUND_CYAN, 'wHITe': console.ConsoleColours.BACKGROUND_WHITE, } for key in mappings: result = console.Console().parse_backcolour(key) self.assertEqual(mappings[key], result)
def main(): pygame.mixer.pre_init(44100, -16, 2, 1024) pygame.init() engine = GameEngine() screen = engine.screen entity_mgr = EntityManager(engine) sound_bank = SoundBank() console = cmd_console.Console(engine) while 1: engine.clock.tick(60) process_input(entity_mgr, console, engine) engine.update() console.update() if not engine.game_over: if not engine.paused or engine.paused_manual_frame_tick: entity_mgr.update(engine, sound_bank) engine.paused_manual_frame_tick = False sound_bank.update(engine) entity_mgr.draw(engine) engine.draw(entity_mgr) else: engine.draw(entity_mgr) console.draw(screen) pygame.display.flip()
def test_foreground_colour_setter_succeeds(self): test_console = console.Console() self.assertEqual(test_console.foreground_colour, console.ConsoleColours.FOREGROUND_WHITE) test_console.foreground_colour = console.ConsoleColours.FOREGROUND_GREEN self.assertEqual(test_console.foreground_colour, console.ConsoleColours.FOREGROUND_GREEN)
def run(self): """ The main menu """ logging.debugv("menu/__init__.py->run(self)", []) if not self.c.getSensorID() == "Unknown": if self.c.getLock() == "Enabled": lock.Lock(self.d).run() title = "\\ZbStart\\n\\ZB" subtitle = "What do you want to do today?" title += subtitle choice = self.d.menu(title, choices=[ ("Configure", "Configure this sensor"), ("Manage", "Start/stop sensor functions"), ("Status", "View the status of this sensor"), ("Log", "View the logfile of this sensor"), #("Update", "Update the sensor scripts"), #("Console", "Open a management console"), ("About", "Learn more about the SURFids sensor"), ("Shutdown", "Shutdown the machine"), ("Lock", "Lock the sensor menu"), ], nocancel=1, width=60, colors=1) #cancel if choice[0] == 1: return elif choice[1] == "Configure": config.Config(self.d).run() elif choice[1] == "Manage": manage.Manage(self.d).run() elif choice[1] == "Status": status.Status(self.d).run() elif choice[1] == "Log": log.Log(self.d).run() elif choice[1] == "Console": console.Console(self.d).run() elif choice[1] == "About": about.About(self.d).run() elif choice[1] == "Shutdown": manage.Manage(self.d).shutdown() elif choice[1] == "Lock": lock.Lock(self.d).run() self.run()
def nse(): try: try: console.setNSE(False) while console.getNSE()!= True: banner ='\033[0;36m'+''' ================================================ _ _ _____ _____ _ | \ | |/ ___|| ___| | | | \| |\ `--. | |__ __ _ _ __ ___ | |__ | . ` | `--. \| __| / _` || '__| / __|| '_ | | |\ |/\__/ /| |___ | (_| || | | (__ | | | | \_| \_/\____/ \____/ \__,_||_| \___||_| |_| ================================================ \033[32m NSEarch \033[0;36m| Version: Monkey 0.1 @marto_nieto_g16 | [email protected] Comunidad Bytes Codes | @BytesCodes ================================================ '''+'\033[0m' print(banner) print('\033[96m''monkey >> ','\033[92m', end ='') comando = readline.get_completer_delims() readline.set_completer_delims(comando.replace('-', '')) comando = input() console.Console(comando) except NameError as es: print('\n\033[91m''Error!. Funcion getIP') except KeyboardInterrupt as e: print('\n\033[93m''\n\033[32m NSEarch - Version: Monkey:\033[93m Hasta La Proxima''\n')
def __init__(self): self.ddos_cluster = config.ddos_cluster self.database = config.database self.Max_point_tournament = config.Max_point_tournament self.username = config.user self.password = config.password self.c = console.Console(self.username, self.password)
def run_console(): if len(sys.argv) > 1: serial = sys.argv[1] else: serial = None dev = device.create_device(serial) if dev.kind == 'adb': appdb.collect_apps("../apks/") elif dev.kind == 'web': appdb.load_urls("../etc/urls.txt") ob = observer.Observer("../err/") init_state = state.State() env = environ.Environment() tlib = testlib.collect_pieces("../tlib/") tlib.assume_reached('signin', 'login', 'main') tlib.assume_reached('welcome', 'skip sign in / sign up', 'main') ob.tlib = tlib init_env = {'dev': dev, 'ob': ob, 'state': init_state, 'env': env, 'tlib': tlib} if len(sys.argv) > 2: app = sys.argv[2] load_app(app, ob, tlib, init_env) cons = console.Console(handle_console_cmd, prompt="op> ", after_cb=update_prompt, init_env=init_env) cons.start() cons.wait()
def __init__(self): self.thread = None self.reload = False # Time variables self.time_cycle = 80 self.ideal_cycle = 80 self.iteration_counter = 0 self.frequency_message = {'brain': '', 'gui': ''} self.server = None self.client = None self.host = sys.argv[1] # Initialize the GUI, HAL and Console behind the scenes self.console = console.Console() self.hal = HAL() self.gui = GUI(self.host, self.console, self.hal) # initialize Teleoperation variables self.teop = False self.speedV = 0.3 self.speedW = 0.5 self.stop = 0 self.key = None self.flag = 0 self.pattern_V = 'HAL.motors.sendV' self.pattern_W = 'HAL.motors.sendW'
def __init__(self, name="MianBot"): self.name = name # The name of chatbot. self.speech = '' # The lastest user's input self.speech_domain = '' # The domain of speech. self.speech_matchee = '' # The matchee term of speech. self.speech_path = None # The classification tree traveling path of speech. self.speech_seg = [] self.root_domain = None # The root domain of user's input. self.domain_similarity = 0.0 # The similarity between domain and speech. cur_dir = os.getcwd() os.chdir(os.path.dirname(__file__)) self.extract_attr_log = open('log/extract_arrt.log', 'w', encoding='utf-8') self.exception_log = open('log/exception.log', 'w', encoding='utf-8') os.chdir(cur_dir) # For rule matching self.console = console.Console(model_path="model/ch-corpus-3sg.bin") self.custom_rulebase = crb.CustomRuleBase() # for one time matching. self.custom_rulebase.model = self.console.rb.model # pass word2vec model # For QA self.github_qa_unupdated = True if not self.github_qa_unupdated: self.answerer = qa.Answerer() self.default_response = ["是嗎?", "我不太明白你的意思", "原來如此"]
def __init__(self, cmd=True, rest=True, port=None): print 'Starting MiniRedis Server...' super(MiniRedisServer, self).__init__() self.miniredis = MiniRedis() self.cmd = console.Console(self.miniredis) self.restServer = None if rest: print 'Starting MiniRedis API REST...' self.restServer = RestServer(cmd=self.cmd, port=port) if cmd: if self.restServer: th = threading.Thread(target=self.restServer.start_server) th.daemon = True th.start() try: self.cmd.cmdloop('Starting MiniRedis Console...') except (SystemExit, KeyboardInterrupt): if self.restServer: self.restServer.stop_server() self.restServer.miniredis = None print 'MiniRedis console closed' sys.exc_clear() else: if self.restServer: self.restServer.start_server()
def __init__(self, console_level=None, logfile=None, file_level=None): ''' This class implements the Borg pattern. @param console_level: Console log level, defaults to 'info' @type console_level: str @param logfile: Optional logfile. @type logfile: str @param file_level: File log level, defaults to 'debug'. @type file_level: str ''' self.__dict__ = self.__borg_state self.con = console.Console() self.prefs = prefs.Prefs() if console_level: self.prefs['loglevel_console'] = console_level elif not self.prefs['loglevel_console']: self.prefs['loglevel_console'] = 'info' if file_level: self.prefs['loglevel_file'] = file_level elif not self.prefs['loglevel_file']: self.prefs['loglevel_file'] = 'debug' if logfile: self.prefs['logfile'] = logfile
def __init__(self, parent, samdb, whatToPrint): super(PrintBuyerCartOrReceiptForm, self).__init__(parent) self.samdb = samdb self.parent = parent self.buyers = buyers.Buyers() self.chooserLists = chooserlists.ChooserLists() self.whatToPrint = whatToPrint self.con = console.Console() mainSizer = wx.BoxSizer(wx.VERTICAL) self.chooserPanel = wx.Panel(self, -1) self.BuildChooser(samdb) mainSizer.Add(self.chooserPanel) self.SetSizer(mainSizer) mainSizer.Fit(parent) mainSizer.SetSizeHints(parent) if self.whatToPrint == 'carts': self.message = 'Preview or print shopping cart for buyer ' else: self.message = 'Preview or print receipt for buyer '
def __init__(self, args): QMainWindow.__init__(self) self.setupUi(self) self.anim = QPropertyAnimation(self, 'windowOpacity') self.anim.setDuration(500) self.anim.setStartValue(0) self.anim.setEndValue(1) self.anim.start() self.moderat = args['moderat'] self.client = args['client'] self.module_id = args['module_id'] self.p2p = args['p2p'] self.alias = args['alias'] self.ip_address = args['ip_address'] title_prefix = self.alias if len(self.alias) > 0 else self.ip_address self.setWindowTitle(u'{}[{}] {}'.format( '(P2P)' if self.p2p else '', title_prefix, self.moderat.MString('MSHELL_TITLE'))) self.console = console.Console() self.setCentralWidget(self.console) self.connect(self.console, SIGNAL("returnPressed"), self.runCommand) self.console.connect(QShortcut(QKeySequence(Qt.Key_Escape), self), SIGNAL('activated()'), self.canceled)
def ttt3(self, bot, update): try: if update.message.text == "X": human_move = board.State.X elif update.message.text == 'O': human_move = board.State.O except: pass reply = telegram.ReplyKeyboardRemove() bot.send_message(chat_id=update.message.chat_id, text='Preparing...', reply_markup=reply) self.board_size = 3 self.games[update.message.chat_id] = [ console.Console(self.board_size), [], human_move ] for i in range(0, 9, 3): self.games[update.message.chat_id][1].append([ telegram.InlineKeyboardButton(' ', callback_data=str(i)), telegram.InlineKeyboardButton(' ', callback_data=str(i + 1)), telegram.InlineKeyboardButton(' ', callback_data=str(i + 2)) ]) reply = InlineKeyboardMarkup(self.games[update.message.chat_id][1]) if human_move == board.State.O: self.play_move(bot, update, update.message.chat_id) bot.send_message(chat_id=update.message.chat_id, text='Let\'s play, my dear opponent! ', reply_markup=reply) return 1
def __init__(self, player): self.ddos_cluster = config.ddos_cluster self.database = config.database self.Max_point_tournament = config.Max_point_tournament self.username = player.username self.password = player.password self.uhash = player.uhash self.c = console.Console(player)
def test_print_with_foreground_and_background_colour(self, mock_print): test_console = console.Console() test_console.background_colour = console.ConsoleColours.BACKGROUND_BLUE test_console.foreground_colour = console.ConsoleColours.FOREGROUND_YELLOW test_console.print('this is the output', \ background_colour=console.ConsoleColours.BACKGROUND_YELLOW, \ foreground_colour=console.ConsoleColours.FOREGROUND_BLUE) mock_print.assert_called_once_with( '\33[43m\33[34mthis is the output\33[33m\33[44m')
def test_get_pin(): console = console_library.Console() input_values = ["1111"] def input(prompt=None): return input_values.pop() console_library.input = input assert console.get_pin() == "1111"
def main(): '''main''' network_layer = route.NetworkLayer(config_data) network_layer_listener = NetworkLayerListener(network_layer) network_layer_listener.start() init_route_table() consoler = console.Console(network_layer, route) consoler.task()
def test_get_card_string(capsys): console = console_library.Console() input_values = ["123412341234"] def input(prompt=None): return input_values.pop() console_library.input = input assert console.get_card() == "123412341234" captured = capsys.readouterr() assert "Valid card ID!" in captured.out
def __init__(self): self.game_started = False self.online_flag = False self.online_game_component = OnlineGameComponent() self.consecutive_flag = False self.expected_player = 'o' self.silent_flag = False self.console = console.Console() self.input_verifier = InputVerifier() self.board = None self.online_score = {'games': 0, 'won': 0, 'losts': {}, 'ties': {}} self.score = {'games': 0, 'o': 0, 'x': 0, 'tied': 0}
def test_invalid_pin_under_four_digits_prints_string(capsys): console = console_library.Console() input_values = ["1", "1111"] def input(prompt=None): return input_values.pop(0) console_library.input = input assert console.get_pin() == "1111" captured = capsys.readouterr() assert "Invalid PIN" in captured.out
def test_console_display_menu_prints_string(capsys): console = console_library.Console() input_values = ["1", "100", "Y"] def input(prompt=None): return input_values.pop(0) console_library.input = input assert console.display_menu() == "1" captured = capsys.readouterr() assert "Deposit verified!" in captured.out
def __init__(self, name="MianBot", build_console=True, w2v_model_path="model/ch-corpus-3sg.bin"): """ # Args: - build_console: whether to construct topic matching based on word vectors console, 如果只需要 qa 模組,可將 build_console 關閉,可見 demo_qa.py """ self.name = name # The name of chatbot. self.speech = '' # The lastest user's input self.speech_domain = '' # The domain of speech. self.speech_matchee = '' # The matchee term of speech. self.speech_path = None # The classification tree traveling path of speech. self.speech_seg = [] self.root_domain = None # The root domain of user's input. self.domain_similarity = 0.0 # The similarity between domain and speech. cur_dir = os.getcwd() os.chdir(os.path.dirname(__file__)) self.extract_attr_log = open('log/extract_arrt.log', 'w', encoding='utf-8') self.exception_log = open('log/exception.log', 'w', encoding='utf-8') os.chdir(cur_dir) # For rule matching if build_console: self.console = console.Console(model_path=w2v_model_path) # self.custom_rulebase = crb.CustomRuleBase() # for one time matching. # self.custom_rulebase.model = self.console.rb.model # pass word2vec model # For Question Answering self.github_qa_unupdated = False if not self.github_qa_unupdated: try: self.answerer = qa.Answerer() except Exception as exc: print( "[QA] Please confirm the directory structure of the questions and answer data set is correct." ) print( "[QA] If you are still getting errors,s change self.github_qa_unupdated to True" ) self.default_response = [ "Say it again?", "I did not catch that.", "I do not know what you mean.", "Huh?" ]
class Atm(object): _id = "12345" _account = account.Account() _customer = None _console = console_library.Console() _card = None _pin = None @property def id(self): return self._id @property def balance(self): return self._account.balance def __init__(self): print("Atm initialized") self.display_welcome() def display_welcome(self): # This should be a console.welcome rather than a direct print. print("Welcome to our very expensive bank!") self._card = self._console.get_card() self._pin = self._console.get_pin() self.display_menu() def deposit(self, deposit): self._account.deposit(deposit) def log_in(self, card_id, pin): self._customer = customer.Customer() self._customer.validate(card_id, pin) self._account = account.Account() def withdrawal(self, withdrawal): self._account.withdrawal(withdrawal) def display_menu(self): choice = self._console.display_menu() print(choice) if (choice[0] == "1"): self.deposit(choice[1]) print("Balance:", self.balance) elif (choice[0] == "2"): self.withdrawal(choice[1]) print("Balance:", self.balance) elif (choice[0] == "3"): # self.transfer(self._choice[1]) print("Balance:", self.balance)
def __init__(self, name="阿母", build_console=True, w2v_model_path="model/ch-corpus-3sg.bin"): """ # Args: - build_console: 是否要建構依照詞向量進行主題匹配的 console, 如果只需要 qa 模組,可將 build_console 關閉,可見 demo_qa.py """ self.name = name # The name of chatbot. self.speech = '' # The lastest user's input self.speech_domain = '' # The domain of speech. self.speech_matchee = '' # The matchee term of speech. self.speech_path = None # The classification tree traveling path of speech. self.speech_seg = [] self.root_domain = None # The root domain of user's input. self.domain_similarity = 0.0 # The similarity between domain and speech. cur_dir = os.getcwd() os.chdir(os.path.dirname(__file__)) self.extract_attr_log = open('log/extract_arrt.log', 'w', encoding='utf-8') self.exception_log = open('log/exception.log', 'w', encoding='utf-8') os.chdir(cur_dir) # For rule matching if build_console: self.console = console.Console(model_path=w2v_model_path) # self.custom_rulebase = crb.CustomRuleBase() # for one time matching. # self.custom_rulebase.model = self.console.rb.model # pass word2vec model # For Question Answering self.github_qa_unupdated = False if not self.github_qa_unupdated: try: self.answerer = qa.Answerer() except Exception as exc: print("[QA] 請確認問答資料集的目錄結構是否正確") print( "[QA] 如尚未取得問答資料集, 請至 Github: zake7749/Chatbot/Readme.md 中下載, 或將 self.github_qa_unupdated 設為 true" ) self.default_response = [ "是嗎?", "我不太明白你的意思", "原來如此", "可以再說一次嗎", "不要滑手機了快去養成習慣" ]