def test_hello_world(self) -> None: if platform.system() == "Windows": executor = Executor("cmd", ["/C", "echo", "hello", "world"]) else: executor = Executor("echo", ["hello", "world"]) res = executor.str_result self.assertEqual("hello world", res.strip())
def test_hello_world(self): if platform.system() == u"Windows": executor = Executor(u"cmd", [u"/C", u"echo", u"hello", u"world"]) else: executor = Executor(u"echo", [u"hello", u"world"]) res = executor.str_result self.assertEqual(u"hello world", res.strip())
def run_as_server(self): processes = {} for i in range(gconf.COCURRENCE): processes[i] = self.create_process(Executor().run) try: while True: for i, process in processes.items(): if not process.is_alive(): logger.info('process[%s] is dead, restart...', process.pid) processes[i] = self.create_process(Executor().run) time.sleep(2) except KeyboardInterrupt as e: logger.info('manage exit')
def test_create(): ex = Executor("foo") bot = Bot(ex) game = Game([bot]) assert game.state == UNINIT assert game.current_bot == 0 assert game.bots == [bot]
def __init__(self, arguments): """Initialize client. :Parameters: - `arguments`: shell arguments. """ self.args = arguments # Logger initialization. logger_file = os.path.join(CONF_ROOT, "logger.conf") logging.config.fileConfig(logger_file) self.logger = logging.getLogger('task_manager') # Config initialization. config_file = os.path.join(CONF_ROOT, "client.conf") self.config = configparser.RawConfigParser() self.config.read(config_file) # Executor initialization. self._executor = Executor(self.logger) self.__host = self.config.get('server', 'host') self.__port = self.config.get('server', 'port') # Wait time for checking jobs self.timeout = eval(self.config.get('job_executor', 'timeout')) # Length of generated random file names. self.rand_len = eval( self.config.get('shared_dir', 'random_file_length')) # Directory to save shell commands output. self.dump_dir = self.config.get('shared_dir', 'dump_dir')
def __init__(self): self.base_path = os.path.dirname(os.path.abspath(__file__)) self.config_path = os.path.abspath( os.path.join(self.base_path, "..", "config.json")) self.log_path = os.path.abspath(os.path.join(self.base_path, 'logs')) self.configuration = None self.configuration_name = None self.last_message_sent = time() self.last_ping_sent = time() self.last_received = None self.last_reconnect = None self.logger = None self.shutdown = threading.Event() self.shutdown_message = None self.reconnect_time = 5 # Seconds to wait before reconnecting, or none to not reconnect self.response_lock = threading.Lock() self.socket = None self.message_q = queue.Queue() self.executor = Executor(self, self.message_q, self.shutdown) self.header = { "User-Agent": "GorillaBot (https://github.com/molly/GorillaBot)" } self.initialize()
def testDoSubstitutionNoDefinition(self): if IGNORE_TEST: return executor = Executor() expander = Expander(executor, self.message) result = expander.do(SUBSTITUTION1) self.assertEqual(result[0], SUBSTITUTION1)
def __init__(self, name, instance_index): self.name = name self.instance_index = instance_index self.executor = Executor() self.node = Node(name, NodeDockerCommands(name, self.get_external_ip)) self.dns = Dns(name, DnsDockerCommands(name)) self.traffic = TrafficHandler(name, TrafficDockerCommands(name))
def run(instructions): # print(instructions[4].argument) global_accumulator = 0 no_repeated_instructions = True instruction_index = 0 reset_instruction_counters() while no_repeated_instructions: # increment instruction counter and check for repeats instructions[instruction_index].number_of_times_called += 1 if instructions[instruction_index].called_more_than_once(): no_repeated_instructions = False continue # load current instruction and perform operations current = Executor(instructions[instruction_index]) if current.operation == "acc": global_accumulator += current.argument print(global_accumulator) instruction_index += 1 print(f"acc {current.argument} index {instruction_index}") elif current.operation == "jmp": instruction_index += current.argument print(f"jmp {current.argument} index {instruction_index}") elif current.operation == "nop": print(f"nop, index {instruction_index}") instruction_index += 1 elif current.operation == None: print(f'current op {current}') print(f"global accumulator = {global_accumulator}")
def __init__(self, source, dest, onlyEn, imgPath, verbose, keepTmp=False, createChm=True, startpage=None): """ Parameters are documented in Main.parseArgs() """ self.createChm = createChm self.keepTmp = keepTmp self.tmp = tempfile.mkdtemp() self.style = os.path.abspath(self.style) source = os.path.abspath(source) dest = os.path.abspath(dest) if startpage is not None: startpage = os.path.abspath(startpage) self.source = source self.dest = dest self.startpage = startpage self.onlyEn = onlyEn self.imgPath = imgPath self.verbose = verbose self.ex = Executor(showErr=verbose, showOutput=True, showCmd=verbose) self.hhc = HHC(showErr=True, showOutput=verbose, showCmd=verbose) self.title = self.getTitle(self.title)
def __init__(self, port: int): sock = socket.socket() sock.bind(('localhost', port)) sock.listen(5) self._sock = SocketWrapper(sock) self._executor = Executor(self) self._aborted = False
def __init__(self): BaseEntity.__init__(self) self.isReady = False self.clubs = {} self.executor = Executor() self.loadClubs() x42.ClubStub = self
def test_double_cond(self): logging.debug("TestExec2") p = Parser(lines=cond2) e = Executor(p.program) logging.info("STARTING EXECUTION...") e.start(p.program[0]) logging.disable(logging.ERROR)
def test_cond(self): logging.basicConfig(level=logging.DEBUG) logging.debug("TestExec") p = Parser(lines=cond) e = Executor(p.program) logging.info("STARTING EXECUTION...") e.start(p.program[0])
def run(args): """Entry point function, which takes args and executes the tasks""" email = args.email master = args.master # If user hasn't passed any arguments, run the default tasks if not args.exec_tasks: tasks = [x[1] for x in TASK_REGISTER] tasks_names = "".join([x[0] for x in TASK_REGISTER]) print( "No specific tasks are given, so running default pipeline {}".format( tasks_names ) ) else: try: exec_tasks = [x.strip() for x in args.exec_tasks.split(",")] tasks = [dict(TASK_REGISTER)[task] for task in exec_tasks] except KeyError: print("Wrong task given") return try: # Call the executor ex = Executor(owner=email, tasks=tasks, master=master) ex.run() except Exception as e: print(e)
def runExperiments(cls): """ Set up logging and trigger running experiments """ cls.logger = logging.getLogger('LisaTest') cls.logger.info('Setup tests execution engine...') test_env = TestEnv(test_conf=cls._getTestConf()) experiments_conf = cls._getExperimentsConf(test_env) cls.executor = Executor(test_env, experiments_conf) # Alias tests and workloads configurations cls.wloads = cls.executor._experiments_conf["wloads"] cls.confs = cls.executor._experiments_conf["confs"] # Alias executor objects to make less verbose tests code cls.te = cls.executor.te cls.target = cls.executor.target # Execute pre-experiments code defined by the test cls._experimentsInit() cls.logger.info('Experiments execution...') cls.executor.run() cls.experiments = cls.executor.experiments # Execute post-experiments code defined by the test cls._experimentsFinalize()
def test_set_pwm_is_not_called_when_states_without_servos(self): from executor import Executor exe = Executor() states = [State([])] movement = Move(states) exe.run(movement) self._pwm.set_pwm.assert_not_called()
def main(): """comparison_test script entry point""" parser = argparse.ArgumentParser( description='vcdMaker tools comparison testing utility') parser.add_argument('--exec', '-e', required=True, help="Path to the vcdMaker executable") parser.add_argument('--testdir', '-t', required=True, help="Path to the directory containing tests") parser.add_argument('--verbose', '-v', action='store_true', default=False, help="Turns on verbose output") args = parser.parse_args() check_arguments(args) tests = Tests(args.testdir) executor = Executor(args.exec, tests.get_tests(), args.verbose) result, number_failed, number_total = executor.run() if not result: print('TEST PASSED ({})'.format(number_total)) exit_result = 0 else: print('TEST FAILED ({}/{})'.format(number_failed, number_total)) exit_result = 1 sys.exit(exit_result)
def execute(self, args): if not isinstance(args, list): raise ValueError(u'Arguments should be list, not: ' + unicode(args)) return Executor(self.settings.trace_cmd, self.settings.trace_args + args, trace_cmd_level=self.settings.debug_trace_commands)
def test_execute_sync(self, mocks): self.mock_subprocess.call.return_value = 'called' result = Executor().execute_sync(['one', 'two']) self.mock_subprocess.call.assert_called_with(['one', 'two']) assert result == 'called'
def __init__(self): KBEngine.Entity.__init__(self) GameObject.__init__(self) self.isReady = False self.clubs = {} self.executor = Executor() self.loadClubs() x42.ClubStub = self
def test_execute_async(self, mocks): self.mock_pexpect.spawn.return_value = 'spawned' result = Executor().execute_async(['run', 'with', 'some', 'args']) self.mock_pexpect.spawn.assert_called_with('run', ['with', 'some', 'args']) assert result == 'spawned'
def __init__(self, address: str, loop: AbstractEventLoop = None, iface = 0, **kwargs): BaseBleClient.__init__(self, address, loop, **kwargs) self.client = None self.iface = 0 self._execute = Executor(loop=loop) self._characteristics = None self._delegate = MyDelegate()
def test_that_position_stays_to_servo_max_when_limit_passed(self): from executor import Executor exe = Executor() servos = [Servo(1, 100)] states = [State(servos)] movement = Move(states) exe.run(movement) self._pwm.set_pwm.assert_called_once_with(1, 0, 600)
def test_set_pwm_is_called_with_the_value_of_the_servo(self): from executor import Executor exe = Executor() servos = [Servo(1, 80)] states = [State(servos)] movement = Move(states) exe.run(movement) self._pwm.set_pwm.assert_called_once_with(1, 0, 575)
def test_execute_sync_with_output(self, mocks): self.mock_subprocess.Popen.return_value.communicate.return_value = 'opened' result = Executor().execute_sync_with_output(['run', 'with', 'args']) self.mock_subprocess.Popen.assert_called_with(['run', 'with', 'args'], stdout='pipe', stderr='pipe') assert result == 'opened'
def test_that_position_is_set_for_multiple_servos(self): from executor import Executor exe = Executor() servos = [Servo(1, 100), Servo(2, 80)] states = [State(servos)] movement = Move(states) exe.run(movement) self._pwm.set_pwm.assert_has_calls( [call(1, 0, 600), call(2, 0, 575)], any_order=False)
def test_normal_run(self): def submit_callback(request): resp = json.loads(request.body.decode("utf-8")) self.assertEqual(resp['output'], "hello\n") self.assertEqual(resp['state'], "Executed") return (200, {}, "Good") setup_get_writ_resp(get_test_writ()) setup_submit_writ_resp(submit_callback) Executor(get_test_conf())._run()
def start(): config = AgentConfig() init_logging(config) logging.info('------------------------') logging.info('Starting scrapydd agent.') logging.info('config %s loaded' % config._loaded_files) logging.info('scrapydd version : %s' % scrapydd.__version__) logging.info('------------------------') executor = Executor(config) executor.start()
def __init__(self, cache=False, cache_ttl=None, refetch_prob=0, processor=None): self.cache = Cache(cache_ttl) if cache else None self.refetch_prob = refetch_prob self.processor = processor self.executor = Executor(num_workers=12) self._init_session()