Robot Framework Integrated Development Environment (RIDE)
robotide.lib.robot.libraries.Collections._Dictionary Class Reference
Inheritance diagram for robotide.lib.robot.libraries.Collections._Dictionary:
robotide.lib.robot.libraries.Collections.Collections

Public Member Functions

def convert_to_dictionary (self, item)
 Converts the given item to a Python dict type. More...
 
def copy_dictionary (self, dictionary, deepcopy=False)
 Returns a copy of the given dictionary. More...
 
def dictionaries_should_be_equal (self, dict1, dict2, msg=None, values=True)
 Fails if the given dictionaries are not equal. More...
 
def dictionary_should_contain_item (self, dictionary, key, value, msg=None)
 An item of key / value must be found in a dictionary. More...
 
def dictionary_should_contain_key (self, dictionary, key, msg=None)
 Fails if key is not found from dictionary. More...
 
def dictionary_should_contain_sub_dictionary (self, dict1, dict2, msg=None, values=True)
 Fails unless all items in dict2 are found from dict1. More...
 
def dictionary_should_contain_value (self, dictionary, value, msg=None)
 Fails if value is not found from dictionary. More...
 
def dictionary_should_not_contain_key (self, dictionary, key, msg=None)
 Fails if key is found from dictionary. More...
 
def dictionary_should_not_contain_value (self, dictionary, value, msg=None)
 Fails if value is found from dictionary. More...
 
def get_dictionary_items (self, dictionary, sort_keys=True)
 Returns items of the given dictionary as a list. More...
 
def get_dictionary_keys (self, dictionary, sort_keys=True)
 Returns keys of the given dictionary as a list. More...
 
def get_dictionary_values (self, dictionary, sort_keys=True)
 Returns values of the given dictionary as a list. More...
 
def get_from_dictionary (self, dictionary, key)
 Returns a value from the given dictionary based on the given key. More...
 
def keep_in_dictionary (self, dictionary, *keys)
 Keeps the given keys in the dictionary and removes all other. More...
 
def log_dictionary (self, dictionary, level='INFO')
 Logs the size and contents of the dictionary using given level. More...
 
def pop_from_dictionary (self, dictionary, key, default=NOT_SET)
 Pops the given key from the dictionary and returns its value. More...
 
def remove_from_dictionary (self, dictionary, *keys)
 Removes the given keys from the dictionary. More...
 
def set_to_dictionary (self, dictionary, *key_value_pairs, **items)
 Adds the given key_value_pairs and items to the dictionary. More...
 

Private Member Functions

def _key_values_should_be_equal (self, keys, dict1, dict2, msg, values)
 
def _keys_should_be_equal (self, dict1, dict2, msg, values)
 
def _log_dictionary (self, dictionary)
 
def _validate_dictionary (self, dictionary, position=1)
 
def _yield_dict_diffs (self, keys, dict1, dict2)
 

Detailed Description

Definition at line 466 of file Collections.py.

Member Function Documentation

◆ _key_values_should_be_equal()

def robotide.lib.robot.libraries.Collections._Dictionary._key_values_should_be_equal (   self,
  keys,
  dict1,
  dict2,
  msg,
  values 
)
private

Definition at line 800 of file Collections.py.

◆ _keys_should_be_equal()

def robotide.lib.robot.libraries.Collections._Dictionary._keys_should_be_equal (   self,
  dict1,
  dict2,
  msg,
  values 
)
private

Definition at line 785 of file Collections.py.

◆ _log_dictionary()

def robotide.lib.robot.libraries.Collections._Dictionary._log_dictionary (   self,
  dictionary 
)
private

Definition at line 775 of file Collections.py.

◆ _validate_dictionary()

def robotide.lib.robot.libraries.Collections._Dictionary._validate_dictionary (   self,
  dictionary,
  position = 1 
)
private

Definition at line 812 of file Collections.py.

◆ _yield_dict_diffs()

def robotide.lib.robot.libraries.Collections._Dictionary._yield_dict_diffs (   self,
  keys,
  dict1,
  dict2 
)
private

Definition at line 805 of file Collections.py.

◆ convert_to_dictionary()

def robotide.lib.robot.libraries.Collections._Dictionary.convert_to_dictionary (   self,
  item 
)

Converts the given item to a Python dict type.

    Mainly useful for converting other mappings to normal dictionaries.
    This includes converting Robot Framework's own ``DotDict`` instances
    that it uses if variables are created using the ``&{var}`` syntax.

    Use `Create Dictionary` from the BuiltIn library for constructing new
    dictionaries.

    New in Robot Framework 2.9.

Definition at line 479 of file Collections.py.

◆ copy_dictionary()

def robotide.lib.robot.libraries.Collections._Dictionary.copy_dictionary (   self,
  dictionary,
  deepcopy = False 
)

Returns a copy of the given dictionary.

    The ``deepcopy`` argument controls should the returned dictionary be
    a [https://docs.python.org/library/copy.html|shallow or deep copy].
    By default returns a shallow copy, but that can be changed by giving
    ``deepcopy`` a true value (see `Boolean arguments`). This is a new
    option in Robot Framework 3.1.2. Earlier versions always returned
    shallow copies.

    The given dictionary is never altered by this keyword.

Definition at line 574 of file Collections.py.

◆ dictionaries_should_be_equal()

def robotide.lib.robot.libraries.Collections._Dictionary.dictionaries_should_be_equal (   self,
  dict1,
  dict2,
  msg = None,
  values = True 
)

Fails if the given dictionaries are not equal.

    First the equality of dictionaries' keys is checked and after that all
    the key value pairs. If there are differences between the values, those
    are listed in the error message. The types of the dictionaries do not
    need to be same.

    See `Lists Should Be Equal` for more information about configuring
    the error message with ``msg`` and ``values`` arguments.

Definition at line 742 of file Collections.py.

◆ dictionary_should_contain_item()

def robotide.lib.robot.libraries.Collections._Dictionary.dictionary_should_contain_item (   self,
  dictionary,
  key,
  value,
  msg = None 
)

An item of key / value must be found in a dictionary.

    Value is converted to unicode for comparison.

    Use the ``msg`` argument to override the default error message.

Definition at line 707 of file Collections.py.

◆ dictionary_should_contain_key()

def robotide.lib.robot.libraries.Collections._Dictionary.dictionary_should_contain_key (   self,
  dictionary,
  key,
  msg = None 
)

Fails if key is not found from dictionary.

    Use the ``msg`` argument to override the default error message.

Definition at line 687 of file Collections.py.

◆ dictionary_should_contain_sub_dictionary()

def robotide.lib.robot.libraries.Collections._Dictionary.dictionary_should_contain_sub_dictionary (   self,
  dict1,
  dict2,
  msg = None,
  values = True 
)

Fails unless all items in dict2 are found from dict1.

    See `Lists Should Be Equal` for more information about configuring
    the error message with ``msg`` and ``values`` arguments.

Definition at line 753 of file Collections.py.

◆ dictionary_should_contain_value()

def robotide.lib.robot.libraries.Collections._Dictionary.dictionary_should_contain_value (   self,
  dictionary,
  value,
  msg = None 
)

Fails if value is not found from dictionary.

    Use the ``msg`` argument to override the default error message.

Definition at line 718 of file Collections.py.

◆ dictionary_should_not_contain_key()

def robotide.lib.robot.libraries.Collections._Dictionary.dictionary_should_not_contain_key (   self,
  dictionary,
  key,
  msg = None 
)

Fails if key is found from dictionary.

    Use the ``msg`` argument to override the default error message.

Definition at line 696 of file Collections.py.

◆ dictionary_should_not_contain_value()

def robotide.lib.robot.libraries.Collections._Dictionary.dictionary_should_not_contain_value (   self,
  dictionary,
  value,
  msg = None 
)

Fails if value is found from dictionary.

    Use the ``msg`` argument to override the default error message.

Definition at line 727 of file Collections.py.

◆ get_dictionary_items()

def robotide.lib.robot.libraries.Collections._Dictionary.get_dictionary_items (   self,
  dictionary,
  sort_keys = True 
)

Returns items of the given dictionary as a list.

    Uses `Get Dictionary Keys` to get keys and then returns corresponding
    items. By default keys are sorted and items returned in that order,
    but this can be changed by giving ``sort_keys`` a false value (see
    `Boolean arguments`). Notice that with Python 3.5 and earlier
    dictionary order is undefined unless using ordered dictionaries.

    Items are returned as a flat list so that first item is a key,
    second item is a corresponding value, third item is the second key,
    and so on.

    The given ``dictionary`` is never altered by this keyword.

    Example:
    | ${sorted} =   | Get Dictionary Items | ${D3} |
    | ${unsorted} = | Get Dictionary Items | ${D3} | sort_keys=False |
    =>
    | ${sorted} = ['a', 1, 'b', 2, 'c', 3]
    | ${unsorted} = ['b', 2, 'a', 1, 'c', 3]    # Order depends on Python version.

    ``sort_keys`` is a new option in Robot Framework 3.1.2. Earlier items
    were always sorted based on keys.

Definition at line 659 of file Collections.py.

◆ get_dictionary_keys()

def robotide.lib.robot.libraries.Collections._Dictionary.get_dictionary_keys (   self,
  dictionary,
  sort_keys = True 
)

Returns keys of the given dictionary as a list.

    By default keys are returned in sorted order (assuming they are
    sortable), but they can be returned in the original order by giving
    ``sort_keys``  a false value (see `Boolean arguments`). Notice that
    with Python 3.5 and earlier dictionary order is undefined unless using
    ordered dictionaries.

    The given ``dictionary`` is never altered by this keyword.

    Example:
    | ${sorted} =   | Get Dictionary Keys | ${D3} |
    | ${unsorted} = | Get Dictionary Keys | ${D3} | sort_keys=False |
    =>
    | ${sorted} = ['a', 'b', 'c']
    | ${unsorted} = ['b', 'a', 'c']   # Order depends on Python version.

    ``sort_keys`` is a new option in Robot Framework 3.1.2. Earlier keys
    were always sorted.

Definition at line 600 of file Collections.py.

◆ get_dictionary_values()

def robotide.lib.robot.libraries.Collections._Dictionary.get_dictionary_values (   self,
  dictionary,
  sort_keys = True 
)

Returns values of the given dictionary as a list.

    Uses `Get Dictionary Keys` to get keys and then returns corresponding
    values. By default keys are sorted and values returned in that order,
    but this can be changed by giving ``sort_keys`` a false value (see
    `Boolean arguments`). Notice that with Python 3.5 and earlier
    dictionary order is undefined unless using ordered dictionaries.

    The given ``dictionary`` is never altered by this keyword.

    Example:
    | ${sorted} =   | Get Dictionary Values | ${D3} |
    | ${unsorted} = | Get Dictionary Values | ${D3} | sort_keys=False |
    =>
    | ${sorted} = [1, 2, 3]
    | ${unsorted} = [2, 1, 3]    # Order depends on Python version.

    ``sort_keys`` is a new option in Robot Framework 3.1.2. Earlier values
    were always sorted based on keys.

Definition at line 630 of file Collections.py.

◆ get_from_dictionary()

def robotide.lib.robot.libraries.Collections._Dictionary.get_from_dictionary (   self,
  dictionary,
  key 
)

Returns a value from the given dictionary based on the given key.

    If the given ``key`` cannot be found from the ``dictionary``, this
    keyword fails.

    The given dictionary is never altered by this keyword.

    Example:
    | ${value} = | Get From Dictionary | ${D3} | b |
    =>
    | ${value} = 2

Definition at line 676 of file Collections.py.

◆ keep_in_dictionary()

def robotide.lib.robot.libraries.Collections._Dictionary.keep_in_dictionary (   self,
  dictionary,
keys 
)

Keeps the given keys in the dictionary and removes all other.

    If the given ``key`` cannot be found from the ``dictionary``, it
    is ignored.

    Example:
    | Keep In Dictionary | ${D5} | b | x | d |
    =>
    | ${D5} = {'b': 2, 'd': 4}

Definition at line 558 of file Collections.py.

◆ log_dictionary()

def robotide.lib.robot.libraries.Collections._Dictionary.log_dictionary (   self,
  dictionary,
  level = 'INFO' 
)

Logs the size and contents of the dictionary using given level.

    Valid levels are TRACE, DEBUG, INFO (default), and WARN.

    If you only want to log the size, use keyword `Get Length` from
    the BuiltIn library.

Definition at line 771 of file Collections.py.

◆ pop_from_dictionary()

def robotide.lib.robot.libraries.Collections._Dictionary.pop_from_dictionary (   self,
  dictionary,
  key,
  default = NOT_SET 
)

Pops the given key from the dictionary and returns its value.

    By default the keyword fails if the given ``key`` cannot be found from
    the ``dictionary``. If optional ``default`` value is given, it will be
    returned instead of failing.

    Example:
    | ${val}= | Pop From Dictionary | ${D3} | b |
    =>
    | ${val} = 2
    | ${D3} = {'a': 1, 'c': 3}

    New in Robot Framework 2.9.2.

Definition at line 541 of file Collections.py.

◆ remove_from_dictionary()

def robotide.lib.robot.libraries.Collections._Dictionary.remove_from_dictionary (   self,
  dictionary,
keys 
)

Removes the given keys from the dictionary.

    If the given ``key`` cannot be found from the ``dictionary``, it
    is ignored.

    Example:
    | Remove From Dictionary | ${D3} | b | x | y |
    =>
    | ${D3} = {'a': 1, 'c': 3}

Definition at line 518 of file Collections.py.

◆ set_to_dictionary()

def robotide.lib.robot.libraries.Collections._Dictionary.set_to_dictionary (   self,
  dictionary,
key_value_pairs,
**  items 
)

Adds the given key_value_pairs and items to the dictionary.

    Giving items as ``key_value_pairs`` means giving keys and values
    as separate arguments:

    | Set To Dictionary | ${D1} | key | value | second | ${2} |
    =>
    | ${D1} = {'a': 1, 'key': 'value', 'second': 2}

    | Set To Dictionary | ${D1} | key=value | second=${2} |

    The latter syntax is typically more convenient to use, but it has
    a limitation that keys must be strings.

    If given keys already exist in the dictionary, their values are updated.

Definition at line 498 of file Collections.py.


The documentation for this class was generated from the following file: