Best Python code snippet using robotframework-pageobjects_python
benchmarker.py
Source:benchmarker.py
...538 user_options.append(arg)539 else:540 new_argv.append(arg)541 return new_argv, user_options542 def _populate_opts(self, opts, args):543 #: sets attributes according to options.544 if opts.quiet is not None: self.verbose = False545 if opts.loop is not None: self.loop = int(opts.loop)546 if opts.cycle is not None: self.cycle = int(opts.cycle)547 if opts.extra is not None: self.extra = int(opts.extra)548 if opts.exclude is not None: self.exclude = opts.exclude549 self.args = args550 #: converts patterns into regexps.551 self._exclude_rexps = opts.exclude and [re.compile(opts.exclude)] or []552 self._include_rexps = [ re.compile(_meta2rexp(arg)) for arg in self.args ]553 def _parse_user_options(self, user_options):554 d = {}555 for option in user_options:556 #: raises ValueError if user option is invalid format.557 m = re.match('^--([-\w]+)(=.*)?$', option)558 if not m:559 raise ValueError("%s: invalid format user option." % option)560 name = m.group(1)561 #: if value is not specified then uses True instead.562 value = not m.group(2) and True or m.group(2)[1:]563 d[name] = value564 #: returns a dictionary object.565 return d566 def _help_message(self, parser=None):567 #: returns help message.568 if parser is None: parser = self._new_option_parser()569 msg = parser.format_help()570 msg += r"""571 --name[=val] user-defined option572 ex.573 # get value of user-defined option574 from benchmarker import cmdopt575 print(repr(cmdopt['name'])) #=> 'val'576Examples:577 ### cycle all benchmarks 5 times with 1000,000 loop578 $ python %(file)s -c 5 -n 1000000579 ### invoke bench1, bench2, and so on580 $ python %(file)s 'bench*'581 ### invoke al benchmarks except bench1, bench2, and bench3582 $ python %(file)s -x '^bench[1-3]$'583 ### invoke all benchmarks with user-defined options584 $ python %(file)s --name1 --name2=value2585"""[1:] % {'file': sys.argv and os.path.basename(sys.argv[0]) or 'foo.py'}586 return msg587 def parse(self, argv=None):588 #: uses sys.argv when argv is not specified.589 if argv is None: argv = sys.argv590 #: parses command line options and sets attributes.591 argv, user_options = self._separate_user_options(argv)592 opts, args = self.parser.parse_args(argv)593 args = args[1:]594 self._populate_opts(opts, args)595 self._user_option_dict = self._parse_user_options(user_options)596 #: if '-h' or '--help' specified then print help message and exit.597 if opts.help:598 print(self._help_message(self.parser))599 sys.exit()600 #: if '-v' or '--version' specified then print version and exit.601 if opts.version:602 print(__version__)603 sys.exit()604 def should_skip(self, task_label):605 #: returns False if task is for empty loop.606 if task_label == '(Empty)':607 return False608 #: returns True if task label matches to exclude pattern....
optionhandler.py
Source:optionhandler.py
...22 self.parent_page = parent_page23 self._opts = {}24 self._in_robot = Context().in_robot()25 if self._new_called == 1:26 self._populate_opts(self._in_robot)27 def __repr__(self):28 return "<robotpageobjects.optionhandler.OptionHandler object at %s: %s>" % (id(self), self._opts)29 def _populate_opts(self, robot=True):30 self._opts.update(getattr(self.parent_page, 'options', {}))31 self._opts.update(self._get_opts_from_var_file())32 self._opts.update(self._get_opts_from_env_vars())33 if robot:34 self._opts.update(self._get_opts_from_robot())35 def _get_opts_from_robot(self):36 ret = {}37 robot_vars = BuiltIn().get_variables()38 for var, val in robot_vars.iteritems():39 ret[self._normalize(var)] = val40 return ret41 def _get_opts_from_var_file(self):42 ret = {}43 var_file_path = os.environ.get("PO_VAR_FILE", None)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!