Example #1
0
 def _validate(self, name, value):
     if name[0] == '@' and not is_list_like(value):
         raise DataError("Invalid variable '%s': Expected list-like value, "
                         "got %s." % (name, type_name(value)))
     if name[0] == '&' and not is_dict_like(value):
         raise DataError("Invalid variable '%s': Expected dict-like value, "
                         "got %s." % (name, type_name(value)))
Example #2
0
 def _validate(self, name, value):
     if name[0] == '@' and not is_list_like(value):
         raise DataError("Invalid variable '%s': Expected list-like value, "
                         "got %s." % (name, type_name(value)))
     if name[0] == '&' and not is_dict_like(value):
         raise DataError("Invalid variable '%s': Expected dict-like value, "
                         "got %s." % (name, type_name(value)))
Example #3
0
 def _import(self, path):
     with io.open(path, encoding='UTF-8') as stream:
         variables = yaml.load(stream)
     if not is_dict_like(variables):
         raise DataError('YAML variable file must be a mapping, got %s.' %
                         type_name(variables))
     return variables.items()
Example #4
0
 def _to_number_with_arithmetics(self, item):
     if is_number(item):
         return item
     number = eval(str(item), {})
     if not is_number(number):
         raise TypeError("Expected number, got %s." % type_name(item))
     return number
Example #5
0
 def __sub__(self, other):
     if isinstance(other, Date):
         return Time(self.datetime - other.datetime)
     if isinstance(other, Time):
         return Date(self.datetime - other.timedelta)
     raise TypeError('Can only subtract Date or Time from Date, got %s.' %
                     type_name(other))
Example #6
0
 def _import(self, path):
     with open(path) as stream:
         variables = yaml.load(stream)
     if not is_dict_like(variables):
         raise DataError('YAML variable file must be a mapping, got %s.'
                         % type_name(variables))
     return variables.items()
Example #7
0
 def _get_dynamic(self, var_file, args):
     get_variables = (getattr(var_file, 'get_variables', None)
                      or getattr(var_file, 'getVariables'))
     variables = get_variables(*args)
     if is_dict_like(variables):
         return variables.items()
     raise DataError("Expected '%s' to return dict-like value, got %s." %
                     (get_variables.__name__, type_name(variables)))
Example #8
0
 def _get_variable_item(self, name, variable, item):
     if is_dict_like(variable):
         return self._get_dict_variable_item(name, variable, item)
     if is_list_like(variable):
         return self._get_list_variable_item(name, variable, item)
     raise VariableError("Variable '%s' is %s, not list or dictionary, "
                         "and thus accessing item '%s' from it is not "
                         "possible." % (name, type_name(variable), item))
Example #9
0
 def _get_dynamic(self, var_file, args):
     get_variables = (getattr(var_file, 'get_variables', None) or
                      getattr(var_file, 'getVariables'))
     variables = get_variables(*args)
     if is_dict_like(variables):
         return variables.items()
     raise DataError("Expected '%s' to return dict-like value, got %s."
                     % (get_variables.__name__, type_name(variables)))
Example #10
0
 def _transform_items(self, items):
     answer = list()
     for item in items:
         if not is_list_like(item):
             raise DataError('FOR IN ZIP items must all be list-like, '
                             'got %s.' % type_name(item))
     for zipped_item in zip(*[list(item) for item in items]):
         answer.extend(zipped_item)
     return answer
Example #11
0
 def _get_variable_item(self, name, variable, item):
     if is_dict_like(variable):
         return self._get_dict_variable_item(name, variable, item)
     if is_list_like(variable):
         return self._get_list_variable_item(name, variable, item)
     raise VariableError("Variable '%s' is %s, not list or dictionary, "
                         "and thus accessing item '%s' from it is not "
                         "possible."
                         % (name, type_name(variable), item))
Example #12
0
 def _import_listener(self, listener):
     if not is_string(listener):
         # Modules have `__name__`, with others better to use `type_name`.
         name = getattr(listener, '__name__', None) or type_name(listener)
         return listener, name
     name, args = split_args_from_name_or_path(listener)
     importer = Importer('listener')
     listener = importer.import_class_or_module(os.path.normpath(name),
                                                instantiate_with_args=args)
     return listener, name
 def _import_listeners(self, listener_data):
     listeners = []
     for listener in listener_data:
         try:
             listeners.append(ListenerProxy(listener))
         except DataError as err:
             if not is_string(listener):
                 listener = type_name(listener)
             LOGGER.error("Taking listener '%s' into use failed: %s" %
                          (listener, unicode(err)))
     return listeners
Example #14
0
 def visit_suite(self, suite):
     for visitor in self._visitors:
         try:
             suite.visit(visitor)
         except:
             message, details = get_error_details()
             self._log_error("Executing model modifier '%s' failed: %s\n%s"
                             % (type_name(visitor), message, details))
     if not (suite.test_count or self._empty_suite_ok):
         raise DataError("Suite '%s' contains no tests after model "
                         "modifiers." % suite.name)
Example #15
0
 def validate(self, types):
     if types is None:
         return None
     if not types:
         return {}
     if is_dict_like(types):
         return self.validate_type_dict(types)
     if is_list_like(types):
         return self.convert_type_list_to_dict(types)
     raise DataError('Type information must be given as a dictionary or '
                     'a list, got %s.' % type_name(types))
Example #16
0
 def _import_listeners(self, listener_data):
     listeners = []
     for listener in listener_data:
         try:
             listeners.append(ListenerProxy(listener))
         except DataError as err:
             if not is_string(listener):
                 listener = type_name(listener)
             LOGGER.error("Taking listener '%s' into use failed: %s"
                          % (listener, unicode(err)))
     return listeners
 def __init__(self, listener):
     if is_string(listener):
         name, args = split_args_from_name_or_path(listener)
         listener = self._import_listener(name, args)
     else:
         name = type_name(listener)
     AbstractLoggerProxy.__init__(self, listener)
     self.name = name
     self.version = self._get_version(listener)
     if self.version == 1:
         LOGGER.warn("Listener '%s' uses deprecated API version 1. "
                     "Switch to API version 2 instead." % self.name)
Example #18
0
 def __init__(self, listener):
     if is_string(listener):
         name, args = split_args_from_name_or_path(listener)
         listener = self._import_listener(name, args)
     else:
         name = type_name(listener)
     AbstractLoggerProxy.__init__(self, listener)
     self.name = name
     self.version = self._get_version(listener)
     if self.version == 1:
         LOGGER.warn("Listener '%s' uses deprecated API version 1. "
                     "Switch to API version 2 instead." % self.name)
Example #19
0
 def _close_listener(self, listener):
     method = (getattr(listener, 'close', None) or
               getattr(listener, '_close', None))
     try:
         if method:
             method()
     except:
         message, details = get_error_details()
         name = getattr(listener, '__name__', None) or type_name(listener)
         LOGGER.error("Calling method '%s' of listener '%s' failed: %s"
                      % (method.__name__, name, message))
         LOGGER.info("Details:\n%s" % details)
Example #20
0
 def visit_suite(self, suite):
     for visitor in self._visitors:
         try:
             suite.visit(visitor)
         except:
             message, details = get_error_details()
             self._log_error(
                 "Executing model modifier '%s' failed: %s\n%s" %
                 (type_name(visitor), message, details))
     if not (suite.test_count or self._empty_suite_ok):
         raise DataError("Suite '%s' contains no tests after model "
                         "modifiers." % suite.name)
Example #21
0
 def import_listeners(cls, listeners, method_names, prefix=None,
                      raise_on_error=False):
     imported = []
     for listener in listeners:
         try:
             imported.append(cls(listener, method_names, prefix))
         except DataError as err:
             name = listener if is_string(listener) else type_name(listener)
             msg = "Taking listener '%s' into use failed: %s" % (name, err)
             if raise_on_error:
                 raise DataError(msg)
             LOGGER.error(msg)
     return imported
Example #22
0
def _get_matches_in_iterable(iterable, pattern, case_insensitive=False,
                             whitespace_insensitive=False):
    if not is_string(pattern):
        raise TypeError("Pattern must be string, got '%s'." % type_name(pattern))
    regexp = False
    if pattern.startswith('regexp='):
        pattern = pattern[7:]
        regexp = True
    elif pattern.startswith('glob='):
        pattern = pattern[5:]
    matcher = Matcher(pattern,
                      caseless=is_truthy(case_insensitive),
                      spaceless=is_truthy(whitespace_insensitive),
                      regexp=regexp)
    return [string for string in iterable
            if is_string(string) and matcher.match(string)]
Example #23
0
 def _literal_eval(self, value, expected):
     # ast.literal_eval has some issues with sets:
     if expected is set:
         # On Python 2 it doesn't handle sets at all.
         if PY2:
             raise ValueError('Sets are not supported on Python 2.')
         # There is no way to define an empty set.
         if value == 'set()':
             return set()
     try:
         value = literal_eval(value)
     except (ValueError, SyntaxError):
         # Original errors aren't too informative in these cases.
         raise ValueError('Invalid expression.')
     except TypeError as err:
         raise ValueError('Evaluating expression failed: %s' % err)
     if not isinstance(value, expected):
         raise ValueError('Value is %s, not %s.' % (type_name(value),
                                                    expected.__name__))
     return value
Example #24
0
 def _literal_eval(self, value, expected):
     # ast.literal_eval has some issues with sets:
     if expected is set:
         # On Python 2 it doesn't handle sets at all.
         if PY2:
             raise ValueError('Sets are not supported on Python 2.')
         # There is no way to define an empty set.
         if value == 'set()':
             return set()
     try:
         value = literal_eval(value)
     except (ValueError, SyntaxError):
         # Original errors aren't too informative in these cases.
         raise ValueError('Invalid expression.')
     except TypeError as err:
         raise ValueError('Evaluating expression failed: %s' % err)
     if not isinstance(value, expected):
         raise ValueError('Value is %s, not %s.' %
                          (type_name(value), expected.__name__))
     return value
Example #25
0
def _get_matches_in_iterable(iterable,
                             pattern,
                             case_insensitive=False,
                             whitespace_insensitive=False):
    if not is_string(pattern):
        raise TypeError("Pattern must be string, got '%s'." %
                        type_name(pattern))
    regexp = False
    if pattern.startswith('regexp='):
        pattern = pattern[7:]
        regexp = True
    elif pattern.startswith('glob='):
        pattern = pattern[5:]
    matcher = Matcher(pattern,
                      caseless=is_truthy(case_insensitive),
                      spaceless=is_truthy(whitespace_insensitive),
                      regexp=regexp)
    return [
        string for string in iterable
        if is_string(string) and matcher.match(string)
    ]
Example #26
0
 def __add__(self, other):
     if isinstance(other, Time):
         return Date(self.datetime + other.timedelta)
     raise TypeError('Can only add Time to Date, got %s.' %
                     type_name(other))
Example #27
0
 def __add__(self, other):
     if isinstance(other, Time):
         return Time(self.seconds + other.seconds)
     raise TypeError("Can only add Time to Time, got %s." % type_name(other))
Example #28
0
 def _validate_dictionary(self, dictionary, position=1):
     if is_string(dictionary) or is_number(dictionary):
         raise TypeError("Expected argument %d to be a dictionary or dictionary-like, "
                         "got %s instead." % (position, type_name(dictionary)))
Example #29
0
 def _validate_list(self, list_, position=1):
     if not is_list_like(list_):
         raise TypeError("Expected argument %d to be a list or list-like, "
                         "got %s instead." % (position, type_name(list_)))
Example #30
0
 def __sub__(self, other):
     if isinstance(other, Time):
         return Time(self.seconds - other.seconds)
     raise TypeError('Can only subtract Time from Time, got %s.' %
                     type_name(other))
Example #31
0
 def __add__(self, other):
     if isinstance(other, Time):
         return Time(self.seconds + other.seconds)
     raise TypeError('Can only add Time to Time, got %s.' %
                     type_name(other))
Example #32
0
 def __add__(self, other):
     if isinstance(other, Time):
         return Date(self.datetime + other.timedelta)
     raise TypeError("Can only add Time to Date, got %s." % type_name(other))
Example #33
0
File: store.py Project: Garjy/RIDE
 def _raise_cannot_set_type(self, name, value, expected):
     raise DataError("Cannot set variable '%s': Expected %s-like value, "
                     "got %s." % (name, expected, type_name(value)))
Example #34
0
 def __sub__(self, other):
     if isinstance(other, Time):
         return Time(self.seconds - other.seconds)
     raise TypeError("Can only subtract Time from Time, got %s." % type_name(other))
Example #35
0
 def _raise_cannot_set_type(self, name, value, expected):
     raise DataError("Cannot set variable '%s': Expected %s-like value, "
                     "got %s." % (name, expected, type_name(value)))
Example #36
0
 def _validate_dictionary(self, dictionary, position=1):
     if is_string(dictionary) or is_number(dictionary):
         raise TypeError(
             "Expected argument %d to be a dictionary or dictionary-like, "
             "got %s instead." % (position, type_name(dictionary)))
Example #37
0
 def _validate_list(self, list_, position=1):
     if not is_list_like(list_):
         raise TypeError("Expected argument %d to be a list or list-like, "
                         "got %s instead." % (position, type_name(list_)))
Example #38
0
 def __sub__(self, other):
     if isinstance(other, Date):
         return Time(self.datetime - other.datetime)
     if isinstance(other, Time):
         return Date(self.datetime - other.timedelta)
     raise TypeError("Can only subtract Date or Time from Date, got %s." % type_name(other))
Example #39
0
 def _get_tags_from_attribute(self, handler_method):
     tags = getattr(handler_method, 'robot_tags', ())
     if not is_list_like(tags):
         raise DataError("Expected tags to be list-like, got %s."
                         % type_name(tags))
     return tags
Example #40
0
 def _raise_expected_list(self, ret):
     self._raise('Expected list-like value, got %s.' % type_name(ret))
Example #41
0
 def _raise_expected_list(self, ret):
     self._raise('Expected list-like value, got %s.' % type_name(ret))