def test_allow_java(self):
     assert_equals(is_dict_like({}, allow_java=True), True)
     assert_equals(is_dict_like([], allow_java=True), False)
     if sys.platform.startswith('java'):
         assert_equals(is_dict_like(HashMap()), False)
         assert_equals(is_dict_like(HashMap(), allow_java=True), True)
         assert_equals(is_dict_like([], allow_java=True), False)
Beispiel #2
0
 def test_allow_java(self):
     assert_equals(is_dict_like({}, allow_java=True), True)
     assert_equals(is_dict_like([], allow_java=True), False)
     if sys.platform.startswith('java'):
         assert_equals(is_dict_like(HashMap()), False)
         assert_equals(is_dict_like(HashMap(), allow_java=True), True)
         assert_equals(is_dict_like([], allow_java=True), False)
Beispiel #3
0
 def test_allow_java(self):
     assert_equals(is_dict_like({}, allow_java=True), True)
     assert_equals(is_dict_like([], allow_java=True), False)
     if sys.platform.startswith('java'):
         assert_equals(is_dict_like(HashMap()), sys.version_info >=
                       (2, 7, 0, 'beta', 4))
         assert_equals(is_dict_like(HashMap(), allow_java=True), True)
         assert_equals(is_dict_like([], allow_java=True), False)
Beispiel #4
0
 def test_allow_java(self):
     assert_equals(is_dict_like({}, allow_java=True), True)
     assert_equals(is_dict_like([], allow_java=True), False)
     if sys.platform.startswith('java'):
         assert_equals(is_dict_like(HashMap()),
                       sys.version_info >= (2, 7, 0, 'beta', 4))
         assert_equals(is_dict_like(HashMap(), allow_java=True), True)
         assert_equals(is_dict_like([], allow_java=True), False)
Beispiel #5
0
 def validate(self, types):
     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 _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)))
Beispiel #7
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()
 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()
Beispiel #9
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)))
Beispiel #10
0
 def _import(self, path):
     with io.open(path, encoding='UTF-8') as stream:
         variables = self._load_yaml(stream)
     if not is_dict_like(variables):
         raise DataError('YAML variable file must be a mapping, got %s.' %
                         type_name(variables))
     return variables.items()
 def _import(self, path):
     with io.open(path, encoding='UTF-8') as stream:
         variables = self._load_yaml(stream)
     if not is_dict_like(variables):
         raise DataError('YAML variable file must be a mapping, got %s.'
                         % type_name(variables))
     return variables.items()
Beispiel #12
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))
Beispiel #13
0
 def _handle_binary(self, value):
     if isinstance(value, xmlrpclib.Binary):
         return str(value)
     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 #14
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
 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 #16
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
Beispiel #17
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)))
Beispiel #18
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)))
Beispiel #19
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
Beispiel #20
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 #21
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 _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 #23
0
 def __init__(self, result):
     if not (is_dict_like(result) and 'status' in result):
         raise RuntimeError('Invalid remote result dictionary: %s' % result)
     self.status = result['status']
     self.output = unic(self._get(result, 'output'))
     self.return_ = self._get(result, 'return')
     self.error = unic(self._get(result, 'error'))
     self.traceback = unic(self._get(result, 'traceback'))
     self.fatal = bool(self._get(result, 'fatal', False))
     self.continuable = bool(self._get(result, 'continuable', False))
Beispiel #24
0
 def __init__(self, result):
     if not (is_dict_like(result) and 'status' in result):
         raise RuntimeError('Invalid remote result dictionary: %s' % result)
     self.status = result['status']
     self.output = unic(self._get(result, 'output'))
     self.return_ = self._get(result, 'return')
     self.error = unic(self._get(result, 'error'))
     self.traceback = unic(self._get(result, 'traceback'))
     self.fatal = bool(self._get(result, 'fatal', False))
     self.continuable = bool(self._get(result, 'continuable', False))
Beispiel #25
0
 def _get_converters(self, libcode):
     converters = getattr(libcode, 'ROBOT_LIBRARY_CONVERTERS', None)
     if not converters:
         return None
     if not is_dict_like(converters):
         self.report_error(
             f'Argument converters must be given as a dictionary, '
             f'got {type_name(converters)}.')
         return None
     return CustomArgumentConverters.from_dict(converters,
                                               self.report_error)
Beispiel #26
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 #27
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 #28
0
 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)
         return list(value)
     if identifier == '&':
         if not is_dict_like(value):
             raise VariableError("Value of variable '%s' is not dictionary "
                                 "or dictionary-like." % name)
         return DotDict(value)
     return value
 def _get_dynamical_variables(self, var_file, args):
     get_variables = getattr(var_file, "get_variables", None)
     if not get_variables:
         get_variables = getattr(var_file, "getVariables", None)
     if not get_variables:
         return None
     variables = get_variables(*args)
     if utils.is_dict_like(variables):
         return variables.items()
     if isinstance(variables, Map):
         return [(entry.key, entry.value) for entry in variables.entrySet()]
     raise DataError("Expected mapping but %s returned %s." % (get_variables.__name__, type(variables).__name__))
 def _undecorate(self, name, value):
     if not is_assign(name):
         raise DataError("Invalid variable name '%s'." % 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 #31
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 #32
0
 def _get_dynamical_variables(self, var_file, args):
     get_variables = getattr(var_file, 'get_variables', None)
     if not get_variables:
         get_variables = getattr(var_file, 'getVariables', None)
     if not get_variables:
         return None
     variables = get_variables(*args)
     if utils.is_dict_like(variables):
         return variables.items()
     if isinstance(variables, Map):
         return [(entry.key, entry.value) for entry in variables.entrySet()]
     raise DataError("Expected mapping but %s returned %s." %
                     (get_variables.__name__, type(variables).__name__))
Beispiel #33
0
 def _get_dynamical_variables(self, var_file, args):
     get_variables = getattr(var_file, 'get_variables', None)
     if not get_variables:
         get_variables = getattr(var_file, 'getVariables', None)
     if not get_variables:
         return None
     variables = get_variables(*args)
     if is_dict_like(variables):
         return variables.items()
     # TODO: This shouldn't be needed after Jython 2.7 beta 4
     if isinstance(variables, Map):
         return [(entry.key, entry.value) for entry in variables.entrySet()]
     raise DataError("Expected mapping but %s returned %s."
                     % (get_variables.__name__, type(variables).__name__))
Beispiel #34
0
 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 #35
0
 def _get_variable_item(self, match, value):
     name = match.name
     for item in match.items:
         if is_dict_like(value):
             value = self._get_dict_variable_item(name, value, item)
         elif hasattr(value, '__getitem__'):
             value = self._get_sequence_variable_item(name, value, item)
         else:
             raise VariableError(
                 "Variable '%s' is %s, which is not subscriptable, and "
                 "thus accessing item '%s' from it is not possible. To use "
                 "'[%s]' as a literal value, it needs to be escaped like "
                 "'\\[%s]'." % (name, type_name(value), item, item, item))
         name = '%s[%s]' % (name, item)
     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 #37
0
 def _get_variable_item(self, name, value, match):
     if match.identifier in '@&':
         var = '%s[%s]' % (name, match.items[0])
         logger.warn("Accessing variable items using '%s' syntax "
                     "is deprecated. Use '$%s' instead." % (var, var[1:]))
     for item in match.items:
         if is_dict_like(value):
             value = self._get_dict_variable_item(name, value, item)
         elif is_list_like(value):
             value = self._get_list_variable_item(name, value, item)
         else:
             raise VariableError(
                 "Variable '%s' is %s, not list or dictionary, and thus "
                 "accessing item '%s' from it is not possible." %
                 (name, type_name(value), item))
         name = '%s[%s]' % (name, item)
     return value
Beispiel #38
0
 def _get_variable_item(self, match, value):
     name = match.name
     if match.identifier in '@&':
         var = '%s[%s]' % (name, match.items[0])
         logger.warn("Accessing variable items using '%s' syntax "
                     "is deprecated. Use '$%s' instead." % (var, var[1:]))
     for item in match.items:
         if is_dict_like(value):
             value = self._get_dict_variable_item(name, value, item)
         elif hasattr(value, '__getitem__'):
             value = self._get_sequence_variable_item(name, value, item)
         else:
             raise VariableError(
                 "Variable '%s' is %s, which is not subscriptable, and "
                 "thus accessing item '%s' from it is not possible. To use "
                 "'[%s]' as a literal value, it needs to be escaped like "
                 "'\\[%s]'." % (name, type_name(value), item, item, item))
         name = '%s[%s]' % (name, item)
     return value
 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
Beispiel #40
0
 def _dot_dict(self, value):
     if is_dict_like(value):
         value = DotDict((n, self._dot_dict(v)) for n, v in value.items())
     return value
Beispiel #41
0
 def _validate_dictionary(self, dictionary, position=1):
     if not is_dict_like(dictionary):
         raise TypeError(
             f"Expected argument {position} to be a dictionary or "
             f"dictionary-like, got {type_name(dictionary)} instead.")
Beispiel #42
0
 def test_dict_likes(self):
     for thing in [dict(), UserDict(), MyMapping()]:
         assert_equal(is_dict_like(thing), True, thing)
 def _extra_arg_has_kwargs(self, positional, named):
     if named or len(positional) != self._maxargs + 1:
         return False
     return is_dict_like(positional[-1])
 def test_others(self):
     for thing in ['', u'', 1, None, True, object(), [], (), set()]:
         assert_equal(is_dict_like(thing), False, thing)
Beispiel #45
0
 def _dot_dict(self, value):
     if is_dict_like(value):
         value = DotDict((n, self._dot_dict(v)) for n, v in value.items())
     return value
 def test_java_maps(self):
     assert_equal(is_dict_like(HashMap()), True)
     assert_equal(is_dict_like(Hashtable()), True)
Beispiel #47
0
 def _get_list_index_name_mapping(self, names, list_length):
     if not names:
         return {}
     if is_dict_like(names):
         return dict((int(index), names[index]) for index in names)
     return dict(zip(range(list_length), names))
Beispiel #48
0
 def test_java_maps(self):
     assert_equal(is_dict_like(HashMap()), True)
     assert_equal(is_dict_like(Hashtable()), True)
 def _extra_arg_has_kwargs(self, positional, named):
     if named or len(positional) != self._maxargs + 1:
         return False
     return is_dict_like(positional[-1])
Beispiel #50
0
 def test_others(self):
     for thing in ['', u'', 1, None, True, object(), [], (), set()]:
         assert_equal(is_dict_like(thing), False, thing)
Beispiel #51
0
 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
Beispiel #52
0
 def _get_list_index_name_mapping(self, names, list_length):
     if not names:
         return {}
     if is_dict_like(names):
         return dict((int(index), names[index]) for index in names)
     return dict(zip(range(list_length), names))
 def test_dict_likes(self):
     for thing in [dict(), UserDict(), MyMapping()]:
         assert_equal(is_dict_like(thing), True, thing)