def _import_library(self, name, positional, named, lib): key = (name, positional, named) if self._libraries.has_key(key): LOGGER.info("Found test library '%s' with arguments %s from cache" % (name, utils.seq2str2(positional))) return self._libraries[key] lib.create_handlers() self._libraries[key] = lib libtype = lib.__class__.__name__.replace('Library', '').lower()[1:] LOGGER.info("Imported library '%s' with arguments %s (version %s, " "%s type, %s scope, %d keywords, source %s)" % (name, utils.seq2str2(positional), lib.version, libtype, lib.scope.lower(), len(lib), lib.source)) if len(lib) == 0: LOGGER.warn("Imported library '%s' contains no keywords" % name) return lib
def list_should_not_contain_value(self, list_, value, msg=None): """Fails if the `value` is not found from `list`. See `List Should Contain Value` for an explanation of `msg`. """ default = "%s contains value '%s'" % (utils.seq2str2(list_), value) _verify_condition(value not in list_, default, msg)
def _raise_creating_instance_failed(self): msg, details = get_error_details() if self.positional_args or self.named_args: args = self.positional_args + ["%s=%s" % item for item in self.named_args.items()] args_text = "arguments %s" % seq2str2(args) else: args_text = "no arguments" raise DataError("Initializing test library '%s' with %s failed: %s\n%s" % (self.name, args_text, msg, details))
def _log_imported_library(self, name, args, lib): type = lib.__class__.__name__.replace('Library', '').lower()[1:] LOGGER.info("Imported library '%s' with arguments %s " "(version %s, %s type, %s scope, %d keywords)" % (name, utils.seq2str2(args), lib.version or '<unknown>', type, lib.scope.lower(), len(lib))) if not lib: LOGGER.warn("Imported library '%s' contains no keywords" % name)
def list_should_not_contain_value(self, list_, value, msg=None): """Fails if the ``value`` is found from ``list``. Use the ``msg`` argument to override the default error message. """ self._validate_list(list_) default = "%s contains value '%s'." % (seq2str2(list_), value) _verify_condition(value not in list_, default, msg)
def _import_listener(self, name, args): listener, source = utils.import_(name, 'listener') if not inspect.ismodule(listener): listener = listener(*args) elif args: raise DataError("Listeners implemented as modules do not take arguments") LOGGER.info("Imported listener '%s' with arguments %s (source %s)" % (name, utils.seq2str2(args), source)) return listener
def _log_imported_library(self, name, args, lib): type = lib.__class__.__name__.replace('Library', '').lower()[1:] listener = ', with listener' if lib.has_listener else '' LOGGER.info("Imported library '%s' with arguments %s " "(version %s, %s type, %s scope, %d keywords%s)" % (name, seq2str2(args), lib.version or '<unknown>', type, lib.scope.lower(), len(lib), listener)) if not lib and not lib.has_listener: LOGGER.warn("Imported library '%s' contains no keywords" % name)
def list_should_contain_value(self, list_, value, msg=None): """Fails if the `value` is not found from `list`. If `msg` is not given, the default error message "[ a | b | c ] does not contain the value 'x'" is shown in case of a failure. Otherwise, the given `msg` is used in case of a failure. """ default = "%s does not contain value '%s'" % (utils.seq2str2(list_), value) _verify_condition(value in list_, default, msg)
def list_should_contain_value(self, list_, value, msg=None): """Fails if the ``value`` is not found from ``list``. If the keyword fails, the default error messages is ``<list> does not contain value '<value>'``. A custom message can be given using the ``msg`` argument. """ default = "%s does not contain value '%s'." % (seq2str2(list_), value) _verify_condition(value in list_, default, msg)
def _import_listener(self, name, args): listener, source = utils.import_(name, 'listener') if not inspect.ismodule(listener): listener = listener(*args) elif args: raise DataError( "Listeners implemented as modules do not take arguments") LOGGER.info("Imported listener '%s' with arguments %s (source %s)" % (name, utils.seq2str2(args), source)) return listener
def import_variables(self, path, args=None): LOGGER.info("Importing variable file '%s' with args %s" % (path, args)) importer = Importer('variable file').import_class_or_module_by_path var_file = importer(path, instantiate_with_args=()) try: return self._get_variables(var_file, args) except: amsg = 'with arguments %s ' % seq2str2(args) if args else '' raise DataError("Processing variable file '%s' %sfailed: %s" % (path, amsg, get_error_message()))
def _raise_creating_instance_failed(self): msg, details = get_error_details() if self.positional_args or self.named_args: args = self.positional_args \ + ['%s=%s' % item for item in self.named_args.items()] args_text = 'arguments %s' % seq2str2(args) else: args_text = 'no arguments' raise DataError("Initializing test library '%s' with %s failed: %s\n%s" % (self.name, args_text, msg, details))
def set_from_file(self, path, args=None, overwrite=False): LOGGER.info("Importing variable file '%s' with args %s" % (path, args)) var_file = self._import_variable_file(path) try: variables = self._get_variables_from_var_file(var_file, args) self._set_from_file(variables, overwrite) except: amsg = "with arguments %s " % utils.seq2str2(args) if args else "" raise DataError("Processing variable file '%s' %sfailed: %s" % (path, amsg, utils.get_error_message())) return variables
def set_from_file(self, path, args=None, overwrite=False): LOGGER.info("Importing variable file '%s' with args %s" % (path, args)) var_file = self._import_variable_file(path) try: variables = self._get_variables_from_var_file(var_file, args) self._set_from_file(variables, overwrite, path) except: amsg = 'with arguments %s ' % utils.seq2str2(args) if args else '' raise DataError("Processing variable file '%s' %sfailed: %s" % (path, amsg, utils.get_error_message())) return variables
def _import_library(self, name, positional, named, lib): args = positional + ['%s=%s' % arg for arg in named] key = (name, positional, named) if key in self._library_cache: LOGGER.info("Found library '%s' with arguments %s from cache." % (name, seq2str2(args))) return self._library_cache[key] lib.create_handlers() self._library_cache[key] = lib self._log_imported_library(name, args, lib) return lib
def _import_library(self, name, positional, named, lib): args = positional + ['%s=%s' % arg for arg in sorted(named.items())] key = (name, positional, named) if key in self._library_cache: LOGGER.info("Found test library '%s' with arguments %s from cache" % (name, utils.seq2str2(args))) return self._library_cache[key] lib.create_handlers() self._library_cache[key] = lib self._log_imported_library(name, args, lib) return lib
def _import_variables(self, import_setting, overwrite=False): path = self._resolve_name(import_setting) args = self._resolve_args(import_setting) if overwrite or (path, args) not in self._imported_variable_files: self._imported_variable_files.add((path, args)) self.variables.set_from_file(path, args, overwrite) else: msg = "Variable file '%s'" % path if args: msg += " with arguments %s" % utils.seq2str2(args) LOGGER.info("%s already imported by suite '%s'" % (msg, self.suite.longname))
def set_from_file(self, path, args, overwrite=False): LOGGER.info("Importing varible file '%s' with args %s" % (path, args)) args = args or [] try: module = utils.simple_import(path) variables = self._get_variables_from_module(module, args) self._set_from_file(variables, overwrite, path) except: amsg = args and 'with arguments %s ' % utils.seq2str2(args) or '' raise DataError("Processing variable file '%s' %sfailed: %s" % (path, amsg, utils.get_error_message())) return variables
def set_from_file(self, path, args, overwrite=False): LOGGER.info("Importing variable file '%s' with args %s" % (path, args)) args = args or [] try: module = utils.simple_import(path) variables = self._get_variables_from_module(module, args) self._set_from_file(variables, overwrite, path) except: amsg = args and 'with arguments %s ' % utils.seq2str2(args) or '' raise DataError("Processing variable file '%s' %sfailed: %s" % (path, amsg, utils.get_error_message())) return variables
def _import_variables(self, import_setting, variables, overwrite=False): path = self._resolve_name(import_setting, variables) args = self._resolve_args(import_setting, variables) if (path, args) not in self._imported_variable_files: self._imported_variable_files.append((path,args)) self.variables.set_from_file(path, args, overwrite) else: msg = "Variable file '%s'" % path if args: msg += " with arguments %s" % utils.seq2str2(args) LOGGER.info("%s already imported by suite '%s'" % (msg, self.suite.longname))
def set_from_file(self, path, args=None, overwrite=False): LOGGER.info("Importing variable file '%s' with args %s" % (path, args)) args = args or [] module = self._importer.import_class_or_module_by_path(path) try: variables = self._get_variables_from_module(module, args) self._set_from_file(variables, overwrite, path) except: amsg = 'with arguments %s ' % utils.seq2str2(args) if args else '' raise DataError("Processing variable file '%s' %sfailed: %s" % (path, amsg, utils.get_error_message())) return variables
def should_not_contain_match(self, list, pattern, msg=None, case_insensitive=False, whitespace_insensitive=False): """Fails if ``pattern`` is found in ``list``. Exact opposite of `Should Contain Match` keyword. See that keyword for information about arguments and usage in general. """ _List._validate_list(self, list) matches = _get_matches_in_iterable(list, pattern, case_insensitive, whitespace_insensitive) default = "%s contains match for pattern '%s'." \ % (seq2str2(list), pattern) _verify_condition(not matches, default, msg)
def _import_variables(self, import_setting, overwrite=False): path = self._resolve_name(import_setting) args = self._resolve_args(import_setting) if overwrite or (path, args) not in self._imported_variable_files: self._imported_variable_files.add((path, args)) self.variables.set_from_file(path, args, overwrite) LOGGER.imported( "Variables", os.path.basename(path), args=list(args), importer=import_setting.source, source=path ) else: msg = "Variable file '%s'" % path if args: msg += " with arguments %s" % seq2str2(args) LOGGER.info("%s already imported by suite '%s'" % (msg, self._suite_name))
def should_contain_match(self, list, pattern, msg=None, case_insensitive=False, whitespace_insensitive=False): """Fails if ``pattern`` is not found in ``list``. See `List Should Contain Value` for an explanation of ``msg``. By default, pattern matching is similar to matching files in a shell and is case-sensitive and whitespace-sensitive. In the pattern syntax, ``*`` matches to anything and ``?`` matches to any single character. You can also prepend ``glob=`` to your pattern to explicitly use this pattern matching behavior. If you prepend ``regexp=`` to your pattern, your pattern will be used according to the Python [http://docs.python.org/3/library/re.html|re module] regular expression syntax. Important note: Backslashes are an escape character, and must be escaped with another backslash (e.g. ``regexp=\\\\d{6}`` to search for ``\\d{6}``). See `BuiltIn.Should Match Regexp` for more details. If ``case_insensitive`` is given a true value (see `Boolean arguments`), the pattern matching will ignore case. If ``whitespace_insensitive`` is given a true value (see `Boolean arguments`), the pattern matching will ignore whitespace. Non-string values in lists are ignored when matching patterns. The given list is never altered by this keyword. See also ``Should Not Contain Match``. Examples: | Should Contain Match | ${list} | a* | | | # Match strings beginning with 'a'. | | Should Contain Match | ${list} | regexp=a.* | | | # Same as the above but with regexp. | | Should Contain Match | ${list} | regexp=\\\\d{6} | | | # Match strings containing six digits. | | Should Contain Match | ${list} | a* | case_insensitive=True | | # Match strings beginning with 'a' or 'A'. | | Should Contain Match | ${list} | ab* | whitespace_insensitive=yes | | # Match strings beginning with 'ab' with possible whitespace ignored. | | Should Contain Match | ${list} | ab* | whitespace_insensitive=true | case_insensitive=true | # Same as the above but also ignore case. | New in Robot Framework 2.8.6. """ matches = _get_matches_in_iterable(list, pattern, case_insensitive, whitespace_insensitive) default = "%s does not contain match for pattern '%s'." \ % (seq2str2(list), pattern) _verify_condition(matches, default, msg)
def should_contain_match(self, list, pattern, msg=None, case_insensitive=False, whitespace_insensitive=False): """Fails if ``pattern`` is not found in ``list``. See `List Should Contain Value` for an explanation of ``msg``. By default, pattern matching is similar to matching files in a shell and is case-sensitive and whitespace-sensitive. In the pattern syntax, ``*`` matches to anything and ``?`` matches to any single character. You can also prepend ``glob=`` to your pattern to explicitly use this pattern matching behavior. If you prepend ``regexp=`` to your pattern, your pattern will be used according to the Python [http://docs.python.org/2/library/re.html|re module] regular expression syntax. Important note: Backslashes are an escape character, and must be escaped with another backslash (e.g. ``regexp=\\\\d{6}`` to search for ``\\d{6}``). See `BuiltIn.Should Match Regexp` for more details. If ``case_insensitive`` is True, the pattern matching will ignore case. If ``whitespace_insensitive`` is True, the pattern matching will ignore whitespace. Non-string values in lists are ignored when matching patterns. The given list is never altered by this keyword. See also ``Should Not Contain Match``. Examples: | Should Contain Match | ${list} | a* | # List should contain any string beginning with 'a' | | Should Contain Match | ${list} | regexp=a.* | # List should contain any string beginning with 'a' (regexp version) | | Should Contain Match | ${list} | regexp=\\\\d{6} | # List should contain any string which contains six decimal digits | | Should Contain Match | ${list} | a* | case_insensitive=${True} | # List should contain any string beginning with 'a' or 'A' | | Should Contain Match | ${list} | ab* | whitespace_insensitive=${True} | # List should contain any string beginning with 'ab' or 'a b' or any other combination of whitespace | | Should Contain Match | ${list} | ab* | whitespace_insensitive=${True} | case_insensitive=${True} | # List should contain any string beginning with 'ab' or 'a b' or 'AB' or 'A B' or any other combination of whitespace and upper/lower case 'a' and 'b' | New in Robot Framework 2.8.6. """ default = "%s does not contain match for pattern '%s'." % ( seq2str2(list), pattern) _verify_condition( _get_matches_in_iterable(list, pattern, case_insensitive, whitespace_insensitive), default, msg)
def _import_if_needed(self, path_or_variables, args=None): if not isinstance(path_or_variables, basestring): return path_or_variables LOGGER.info("Importing variable file '%s' with args %s" % (path_or_variables, args)) if path_or_variables.lower().endswith('.yaml'): importer = YamlImporter() else: importer = PythonImporter() try: return importer.import_variables(path_or_variables, args) except: args = 'with arguments %s ' % seq2str2(args) if args else '' raise DataError("Processing variable file '%s' %sfailed: %s" % (path_or_variables, args, get_error_message()))
def _import_if_needed(self, path_or_variables, args=None): if not is_string(path_or_variables): return path_or_variables LOGGER.info("Importing variable file '%s' with args %s" % (path_or_variables, args)) if path_or_variables.lower().endswith('.yaml'): importer = YamlImporter() else: importer = PythonImporter() try: return importer.import_variables(path_or_variables, args) except: args = 'with arguments %s ' % seq2str2(args) if args else '' raise DataError("Processing variable file '%s' %sfailed: %s" % (path_or_variables, args, get_error_message()))
def should_not_contain_match(self, list, pattern, msg=None, case_insensitive=False, whitespace_insensitive=False): """Fails if ``pattern`` is found in ``list``. See `List Should Contain Value` for an explanation of ``msg``. See `Should Contain Match` for usage details and examples. New in Robot Framework 2.8.6. """ default = "%s contains match for pattern '%s'." % ( seq2str2(list), pattern) _verify_condition( not _get_matches_in_iterable(list, pattern, case_insensitive, whitespace_insensitive), default, msg)
def should_not_contain_match(self, list, pattern, msg=None, case_insensitive=False, whitespace_insensitive=False): """Fails if `pattern` is found in `list`. See `List Should Contain Value` for an explanation of `msg`. See `Should Contain Match` for usage details and examples. New in Robot Framework 2.8.6. """ default = "%s contains match for pattern '%s'." % ( seq2str2(list), pattern) _verify_condition( not _get_matches_in_iterable(list, pattern, case_insensitive, whitespace_insensitive), default, msg)
def _import_variables(self, import_setting, overwrite=False): path = self._resolve_name(import_setting) args = self._resolve_args(import_setting) if overwrite or (path, args) not in self._imported_variable_files: self._imported_variable_files.add((path, args)) self.variables.set_from_file(path, args, overwrite) LOGGER.imported("Variables", os.path.basename(path), args=list(args), importer=import_setting.source, source=path) else: msg = "Variable file '%s'" % path if args: msg += " with arguments %s" % seq2str2(args) LOGGER.info("%s already imported by suite '%s'" % (msg, self._suite_name))
def should_contain_match(self, list, pattern, msg=None, case_insensitive=False, whitespace_insensitive=False): """Fails if ``pattern`` is not found in ``list``. See `List Should Contain Value` for an explanation of ``msg``. By default, pattern matching is similar to matching files in a shell and is case-sensitive and whitespace-sensitive. In the pattern syntax, ``*`` matches to anything and ``?`` matches to any single character. You can also prepend ``glob=`` to your pattern to explicitly use this pattern matching behavior. If you prepend ``regexp=`` to your pattern, your pattern will be used according to the Python [http://docs.python.org/2/library/re.html|re module] regular expression syntax. Important note: Backslashes are an escape character, and must be escaped with another backslash (e.g. ``regexp=\\\\d{6}`` to search for ``\\d{6}``). See `BuiltIn.Should Match Regexp` for more details. If ``case_insensitive`` is given a true value (see `Boolean arguments`), the pattern matching will ignore case. If ``whitespace_insensitive`` is given a true value (see `Boolean arguments`), the pattern matching will ignore whitespace. Non-string values in lists are ignored when matching patterns. The given list is never altered by this keyword. See also ``Should Not Contain Match``. Examples: | Should Contain Match | ${list} | a* | | | # Match strings beginning with 'a'. | | Should Contain Match | ${list} | regexp=a.* | | | # Same as the above but with regexp. | | Should Contain Match | ${list} | regexp=\\\\d{6} | | | # Match strings containing six digits. | | Should Contain Match | ${list} | a* | case_insensitive=True | | # Match strings beginning with 'a' or 'A'. | | Should Contain Match | ${list} | ab* | whitespace_insensitive=yes | | # Match strings beginning with 'ab' with possible whitespace ignored. | | Should Contain Match | ${list} | ab* | whitespace_insensitive=true | case_insensitive=true | # Same as the above but also ignore case. | New in Robot Framework 2.8.6. """ matches = _get_matches_in_iterable(list, pattern, case_insensitive, whitespace_insensitive) default = "%s does not contain match for pattern '%s'." \ % (seq2str2(list), pattern) _verify_condition(matches, default, msg)
def _get_for_loop(self, kw): joiner = ' IN RANGE ' if kw.range else ' IN ' return ', '.join(kw.vars) + joiner + utils.seq2str2(kw.items)
def _get_for_loop(self, kw): joiner = ' IN RANGE ' if kw.range else ' IN ' return ', '.join(kw.variables) + joiner + seq2str2(kw.values)
def _get_for_loop(self, kw): joiner = ' %s ' % kw.flavor return ', '.join(kw.variables) + joiner + seq2str2(kw.values)
def _convert_for(self, data): name = '%s %s %s' % (', '.join( data.variables), data.flavor, seq2str2(data.values)) return {'name': self._escape(name), 'arguments': '', 'type': 'FOR'}
def _start(self, type_, name, args=''): args = ' ' + utils.seq2str2(args) self._write('+%s START %s: %s%s' % ('-'*self._indent, type_, name, args)) self._indent += 1
def run_keyword(self, name, args): return "Executed keyword '%s' with args %s" % (name, utils.seq2str2(args))
def _start(self, type_, name, args=''): args = ' ' + utils.seq2str2(args) self._write('+%s START %s: %s%s' % ('-' * self._indent, type_, name, args)) self._indent += 1