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, default=NOT_SET) |
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) |
Definition at line 483 of file Collections.py.
|
private |
Definition at line 820 of file Collections.py.
|
private |
Definition at line 807 of file Collections.py.
|
private |
Definition at line 797 of file Collections.py.
|
private |
Definition at line 833 of file Collections.py.
|
private |
Definition at line 826 of file Collections.py.
| def 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.
Definition at line 494 of file Collections.py.
| def 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 587 of file Collections.py.
| def 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 764 of file Collections.py.
| def 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 727 of file Collections.py.
| def 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 705 of file Collections.py.
| def 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 775 of file Collections.py.
| def 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 738 of file Collections.py.
| def 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 715 of file Collections.py.
| def 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 748 of file Collections.py.
| def 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 672 of file Collections.py.
| def 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 613 of file Collections.py.
| def 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 643 of file Collections.py.
| def robot.libraries.Collections._Dictionary.get_from_dictionary | ( | self, | |
| dictionary, | |||
| key, | |||
default = NOT_SET |
|||
| ) |
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. If optional ``default`` value is given, it will be
returned instead of failing.
The given dictionary is never altered by this keyword.
Example:
| ${value} = | Get From Dictionary | ${D3} | b |
=>
| ${value} = 2
Support for ``default`` is new in Robot Framework 6.0.
Definition at line 692 of file Collections.py.
| def 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 571 of file Collections.py.
| def 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 793 of file Collections.py.
| def 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}
Definition at line 554 of file Collections.py.
| def 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 533 of file Collections.py.
| def 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 513 of file Collections.py.