def test_generators_are_not_consumed(self):
     g = generator()
     assert_equal(is_list_like(g), True)
     assert_equal(is_list_like(g), True)
     assert_equal(list(g), ['generated'])
     assert_equal(list(g), [])
     assert_equal(is_list_like(g), True)
Beispiel #2
0
 def _process_cli_opts(self, opts):
     for name, (cli_name, default) in self._cli_opts.items():
         value = opts[cli_name] if cli_name in opts else default
         if default == [] and not is_list_like(value):
             value = [value]
         self[name] = self._process_value(name, value)
     self['TestNames'] += self['ReRunFailed']
 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)))
 def test_other_iterables_are_list_like(self):
     try:
         xrange
     except NameError:
         xrange = range
     for thing in [[], (), set(), xrange(1), generator(), array('i'), UserList()]:
         assert_equal(is_list_like(thing), True, thing)
Beispiel #5
0
 def _validate_variables(self, variables):
     for name, value in variables:
         if name.startswith('LIST__') and not is_list_like(value):
             # TODO: what to do with this error
             name = '@{%s}' % name[len('LIST__'):]
             raise DataError("List variable '%s' cannot get a non-list "
                             "value '%s'" % (name, unic(value)))
 def _handle_binary(self, value):
     if isinstance(value, xmlrpclib.Binary):
         return value.data
     if is_list_like(value):
         return [self._handle_binary(v) for v in value]
     if is_dict_like(value):
         return dict((k, self._handle_binary(v)) for k, v in value.items())
     return value
Beispiel #7
0
 def _convert(self, value):
     if isinstance(value, xmlrpclib.Binary):
         return bytes(value.data)
     if is_dict_like(value):
         return DotDict((k, self._convert(v)) for k, v in value.items())
     if is_list_like(value):
         return [self._convert(v) for v in value]
     return value
 def _process_cli_opts(self, opts):
     for name, (cli_name, default) in self._cli_opts.items():
         value = opts[cli_name] if cli_name in opts else default
         if isinstance(default, list):
             # Copy mutable values and support list values as scalars.
             value = list(value) if is_list_like(value) else [value]
         self[name] = self._process_value(name, value)
     self['TestNames'] += self['ReRunFailed']
Beispiel #9
0
 def _decorate(self, name, value):
     if is_dict_like(value):
         name = '&{%s}' % name
     elif is_list_like(value):
         name = '@{%s}' % name
     else:
         name = '${%s}' % name
     return name, value
Beispiel #10
0
 def validate(self, types):
     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))
 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
 def get_listeners(self, libinst=None):
     if not libinst:
         libinst = self.get_instance()
     listeners = getattr(libinst, 'ROBOT_LIBRARY_LISTENER', None)
     if listeners is None:
         return []
     if is_list_like(listeners):
         return listeners
     return [listeners]
 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))
Beispiel #14
0
 def _undecorate(self, name, value):
     validate_var(name)
     if name[0] == '@':
         if not is_list_like(value):
             self._raise_cannot_set_type(name, value, 'list')
         value = list(value)
     if name[0] == '&':
         if not is_dict_like(value):
             self._raise_cannot_set_type(name, value, 'dictionary')
         value = DotDict(value)
     return name[2:-1], value
Beispiel #15
0
 def _validate_value(self, value, identifier, name):
     if identifier == '@':
         if not is_list_like(value):
             raise DataError("Value of variable '%s' is not list or "
                             "list-like." % name)
         return list(value)
     if identifier == '&':
         if not is_dict_like(value):
             raise DataError("Value of variable '%s' is not dictionary "
                             "or dictionary-like." % name)
         return DotDict(value)
     return value
Beispiel #16
0
 def _get_scalar_var_as_list(self, name):
     if not is_list_var(name):
         raise ValueError
     name = '$'+name[1:]
     try:
         value = self._find_variable(name)
     except KeyError:
         value = self._get_extended_var(name)
     if not utils.is_list_like(value):
         raise DataError("Using scalar variable '%s' as list variable '@%s' "
                         "requires its value to be list or list-like."
                         % (name, name[1:]))
     return value
 def _validate_value(self, value, identifier, name):
     if identifier == '@':
         if not is_list_like(value):
             raise VariableError("Value of variable '%s' is not list or "
                                 "list-like." % name)
         # TODO: Is converting to list needed or would checking be enough?
         # TODO: Check this and DotDict usage below in RF 3.1.
         return list(value)
     if identifier == '&':
         if not is_dict_like(value):
             raise VariableError("Value of variable '%s' is not dictionary "
                                 "or dictionary-like." % name)
         # TODO: Is converting to DotDict needed? Check in RF 3.1.
         return DotDict(value)
     return value
Beispiel #18
0
    def join_command_line(self, *args):
        """Joins arguments into one command line string.

        In resulting command line string arguments are delimited with a space,
        arguments containing spaces are surrounded with quotes, and possible
        quotes are escaped with a backslash.

        If this keyword is given only one argument and that is a list like
        object, then the values of that list are joined instead.

        Example:
        | ${cmd} = | Join Command Line | --option | value with spaces |
        | Should Be Equal | ${cmd} | --option "value with spaces" |

        New in Robot Framework 2.9.2.
        """
        if len(args) == 1 and is_list_like(args[0]):
            args = args[0]
        return subprocess.list2cmdline(args)
Beispiel #19
0
 def __getitem__(self, name):
     validate_var(name, '$@%')
     stored = StoredFinder(self.store)
     extended = ExtendedFinder(self)
     for finder in (EnvironmentFinder(),
                    stored,
                    EmptyFinder(),
                    NumberFinder(),
                    extended):
         try:
             value = finder.find(name)
         except (KeyError, ValueError):
             continue
         if name[0] == '@':
             if not is_list_like(value):
                 raise DataError("Value of variable '%s' is not list or "
                                 "list-like." % name)
             return list(value)
         return value
     raise_not_found(name, self.store.store)
Beispiel #20
0
 def test_dict_likes_are_list_like(self):
     for thing in [dict(), UserDict(), MyMapping()]:
         assert_equal(is_list_like(thing), True, thing)
Beispiel #21
0
 def _log_start(self, command, config):
     if is_list_like(command):
         command = self.join_command_line(command)
     logger.info('Starting process:\n%s' % command)
     logger.debug('Process configuration:\n%s' % config)
 def test_others_are_not_list_like(self):
     for thing in [1, None, True, object()]:
         assert_equal(is_list_like(thing), False, thing)
 def test_object_raising_exception_are_not_list_like(self):
     class O(object):
         def __iter__(self):
             1/0
     assert_equal(is_list_like(O()), False)
 def test_java_dict_likes_are_list_like(self):
     assert_equal(is_list_like(HashMap()), True)
     assert_equal(is_list_like(Hashtable()), True)
Beispiel #25
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_)))
 def __init__(self, flatten):
     if not is_list_like(flatten):
         flatten = [flatten]
     flatten = [f.lower() for f in flatten]
     self._types = [f for f in flatten if f in ('for', 'foritem')]
Beispiel #27
0
 def test_iter_makes_object_iterable_regardless_implementation(self):
     class Example(object):
         def __iter__(self):
             1/0
     assert_equal(is_list_like(Example()), True)
Beispiel #28
0
 def test_only_getitem_does_not_make_object_iterable(self):
     class Example(object):
         def __getitem__(self, item):
             return "I'm not iterable!"
     assert_equal(is_list_like(Example()), False)
Beispiel #29
0
 def test_files_are_not_list_like(self):
     with open(__file__) as f:
         assert_equal(is_list_like(f), False)
     assert_equal(is_list_like(f), False)
Beispiel #30
0
 def test_java_dict_likes_are_list_like(self):
     assert_equal(is_list_like(HashMap()), True)
     assert_equal(is_list_like(Hashtable()), True)
Beispiel #31
0
 def test_java_strings_are_not_list_like(self):
     assert_equal(is_list_like(String()), False)
Beispiel #32
0
 def test_others_are_not_list_like(self):
     for thing in [1, None, True, object()]:
         assert_equal(is_list_like(thing), False, thing)
 def __init__(self, flatten):
     if not is_list_like(flatten):
         flatten = [flatten]
     names = [n[5:] for n in flatten if n[:5].lower() == 'name:']
     self._matcher = MultiMatcher(names)
Beispiel #34
0
 def test_iterables_in_general_are_list_like(self):
     for thing in [[], (), set(), xrange(1), generator(), array('i'), UserList()]:
         assert_equal(is_list_like(thing), True, thing)
Beispiel #35
0
 def test_strings_are_not_list_like(self):
     for thing in ['str', u'unicode', UserString('user')]:
         assert_equal(is_list_like(thing), False, thing)
Beispiel #36
0
 def test_java_dict_likes_are_not_list_like(self):
     assert_equals(is_list_like(HashMap()), False)
Beispiel #37
0
 def _log_start(self, command, config):
     if is_list_like(command):
         command = self.join_command_line(command)
     logger.info("Starting process:\n%s" % command)
     logger.debug("Process configuration:\n%s" % config)
 def test_java_strings_are_not_list_like(self):
     assert_equal(is_list_like(String()), False)
 def _take_copy_of_mutable_value(self, value):
     if is_dict_like(value):
         return dict(value)
     if is_list_like(value):
         return list(value)
     return value
 def test_files_are_not_list_like(self):
     with open(__file__) as f:
         assert_equal(is_list_like(f), False)
     assert_equal(is_list_like(f), False)
 def _passing_list(self, arguments):
     return self._correct_count(arguments) and is_list_like(arguments[-1])
Beispiel #42
0
 def replace_list(self, items, replace_until=None):
     if not is_list_like(items):
         raise ValueError("'replace_list' requires list-like input.")
     return self._replacer.replace_list(items, replace_until)
Beispiel #43
0
 def _get_listeners(self, inst):
     if not hasattr(inst, "ROBOT_LIBRARY_LISTENER"):
         return None
     listeners = inst.ROBOT_LIBRARY_LISTENER
     return listeners if is_list_like(listeners) else [listeners]
Beispiel #44
0
 def _log_start(self, command, config):
     if is_list_like(command):
         command = self.join_command_line(command)
     logger.info(u'Starting process:\n%s' % system_decode(command))
     logger.debug(u'Process configuration:\n%s' % config)
 def replace_list(self, items, replace_until=None, ignore_errors=False):
     if not is_list_like(items):
         raise ValueError("'replace_list' requires list-like input, "
                          "got %s." % type_name(items))
     return self._replacer.replace_list(items, replace_until, ignore_errors)
Beispiel #46
0
 def _resolve_setting(self, value):
     if is_list_like(value):
         return self._variables.replace_list(value, ignore_errors=True)
     return self._variables.replace_string(value, ignore_errors=True)
Beispiel #47
0
 def test_bytes_are_not_list_like(self):
     for thing in [b'bytes', bytearray(b'bytes')]:
         assert_equal(is_list_like(thing), False, thing)
Beispiel #48
0
 def _get_tags_from_attribute(self, handler_method):
     tags = getattr(handler_method, 'robot_tags', ())
     if not utils.is_list_like(tags):
         raise DataError("Expected tags to list like, got %s." %
                         utils.type_name(tags))
     return Tags(tags)
 def _resolve_setting(self, value):
     if is_list_like(value):
         return self._variables.replace_list(value, ignore_errors=True)
     return self._variables.replace_string(value, ignore_errors=True)
Beispiel #50
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
Beispiel #51
0
 def __setitem__(self, name, value):
     validate_var(name)
     if name[0] == '@' and not is_list_like(value):
         raise DataError('TODO')
     self.store.add(name[2:-1], value)
Beispiel #52
0
 def _to_list(self, value):
     if value is None:
         return ()
     if not is_list_like(value):
         raise DataError
     return value
Beispiel #53
0
 def _get_listeners(self, inst):
     if not hasattr(inst, 'ROBOT_LIBRARY_LISTENER'):
         return None
     listeners = inst.ROBOT_LIBRARY_LISTENER
     return listeners if is_list_like(listeners) else [listeners]
 def __init__(self, flatten):
     if not is_list_like(flatten):
         flatten = [flatten]
     patterns = [p[4:] for p in flatten if p[:4].lower() == 'tag:']
     self._matcher = TagPatterns(patterns)
 def test_object_raising_exception_are_not_list_like(self):
     class O(object):
         def __iter__(self):
             1/0
     assert_equals(is_list_like(O()), False)
 def _passing_list(self, arguments):
     return self._correct_count(arguments) and is_list_like(arguments[-1])
Beispiel #57
0
 def _validate_variables(self, variables):
     for name, value in variables:
         if name.startswith('LIST__') and not is_list_like(value):
             name = '@{%s}' % name[len('LIST__'):]
             raise DataError("List variable '%s' cannot get a non-list "
                             "value '%s'" % (name, unic(value)))