def run(self, *args): raise DataError(self.error)
def _raise(self, error): raise DataError('Cannot set variables: %s' % error)
def _raise_replacing_vars_failed(self, import_setting, err): raise DataError("Replacing variables from setting '%s' failed: %s" % (import_setting.type, err.message))
def _validate_var_name(self, name): if not is_var(name): raise DataError("Invalid variable name '%s'." % name)
def _valid_table(self, table): if table is self.testcase_table: raise DataError('Test case table not allowed in resource file.') return table
def _raise_wrong_variable_count(self, variables, values): raise DataError( 'Number of FOR IN ENUMERATE loop values should be multiple of ' 'its variables (excluding the index). Got %d variables but %d ' 'value%s.' % (variables, values, s(values)))
def validate(self, options, arguments): if ConsoleViewer.handles(arguments[1]): ConsoleViewer.validate_command(arguments[1], arguments[2:]) elif len(arguments) > 2: raise DataError('Only two arguments allowed when writing output.') return options, arguments
def _validate_not_importing_init_file(self, path): name = os.path.splitext(os.path.basename(path))[0] if name.lower() == '__init__': raise DataError("Initialization file '%s' cannot be imported as " "a resource file." % path)
def validate_command(cls, command, args): if not cls.handles(command): raise DataError("Unknown command '%s'." % command) if command.lower() == 'version' and args: raise DataError("Command 'version' does not take arguments.")
def _no_library_found(self, name, multiple=False): if multiple: raise DataError("Multiple libraries matching '%s' found." % name) raise DataError("No library '%s' found." % name)
def _raise_multiple_keywords_found(self, name, found, implicit=True): error = "Multiple keywords with name '%s' found" % name if implicit: error += ". Give the full name of the keyword you want to use" names = sorted(handler.longname for handler in found) raise DataError('\n '.join([error+':'] + names))
def _get_handler_method(self, libcode, name): method = _BaseTestLibrary._get_handler_method(self, libcode, name) if hasattr(libcode, '__all__') and name not in libcode.__all__: raise DataError('Not exposed as a keyword') return method
def _validate_handler(self, handler): if not self._is_routine(handler): raise DataError('Not a method or function') if self._is_implicit_java_or_jython_method(handler): raise DataError('Implicit methods are ignored')
def _get_handler_method(self, libcode, name): method = getattr(libcode, name) if not inspect.isroutine(method): raise DataError('Not a method or function') return method
def _raise_wrong_variable_count(self, variables, values): raise DataError( 'Number of FOR loop values should be multiple of its variables. ' 'Got %d variables but %d value%s.' % (variables, values, s(values)))
def _replace_variables(self, values, variables): try: return DotDict(self._yield_replaced(values, variables.replace_scalar)) except TypeError as err: raise DataError('Creating dictionary failed: %s' % err)
def _resolve_dict_values(self, values): raise DataError( 'FOR IN ZIP loops do not support iterating over dictionaries.')
def _raise_invalid(self, option, error): raise DataError(f"Invalid value for option '--{option.lower()}': {error}")
def __enter__(self): raise DataError(self.reason)
def _parse_args(self, args): args = [self._lowercase_long_option(a) for a in args] try: opts, args = getopt.getopt(args, self._short_opts, self._long_opts) except getopt.GetoptError, err: raise DataError(err.msg)
def _verify_format(self, type, format, valid): format = format.upper() if format not in valid: raise DataError("%s must be %s, got '%s'." % (type, seq2str(valid, lastsep=' or '), format)) return format
def _validate_format(self, format): format = format.lower() if format else '' if format and format not in self._formats: raise DataError('Invalid format: %s' % format) return format
def _validate(self): if not self.testcase_table.is_started(): raise DataError('File has no test case table.')
def _table_is_allowed(self, table): if table is self.testcase_table: raise DataError("Resource file '%s' cannot contain tests or " "tasks." % self.source) return True
def _validate_var_is_not_scalar_list(self, name, value): if is_scalar_var(name) and len(value) > 1: raise DataError("Creating a scalar variable with a list value in " "the Variable table is no longer possible. " "Create a list variable '@%s' and use it as a " "scalar variable '%s' instead." % (name[1:], name))
def _validate_mode(self, name1, name2): tasks1 = normalize(name1) in ('task', 'tasks') tasks2 = normalize(name2) in ('task', 'tasks') if tasks1 is not tasks2: raise DataError('One file cannot have both tests and tasks.')
def _validate_assign_mark(self, variable): if self._seen_assign_mark: raise DataError("Assign mark '=' can be used only with the last " "variable.") self._seen_assign_mark = variable.endswith('=') return variable.rstrip('= ')
def _map_dict_values_to_rounds(self, values, per_round): if per_round > 2: raise DataError( 'Number of FOR loop variables must be 1 or 2 when iterating ' 'over dictionaries, got %d.' % per_round) return values
def get_library(self, name_or_instance): if name_or_instance is None: raise DataError("Library can not be None.") if is_string(name_or_instance): return self._get_lib_by_name(name_or_instance) return self._get_lib_by_instance(name_or_instance)
def _table_is_allowed(self, table): if table is self.testcase_table: raise DataError("Resource file '%s' contains a test case table " "which is not allowed." % self.source) return True