A library providing keywords for handling lists and dictionaries. More...
Public Member Functions | |
| def | get_match_count (self, list, pattern, case_insensitive=False, whitespace_insensitive=False) |
Returns the count of matches to pattern in list. More... | |
| def | get_matches (self, list, pattern, case_insensitive=False, whitespace_insensitive=False) |
Returns a list of matches to pattern in list. More... | |
| def | should_contain_match (self, list, pattern, msg=None, case_insensitive=False, whitespace_insensitive=False) |
Fails if pattern is not found in list. More... | |
| def | should_not_contain_match (self, list, pattern, msg=None, case_insensitive=False, whitespace_insensitive=False) |
Fails if pattern is found in list. More... | |
Public Member Functions inherited from robot.libraries.Collections._List | |
| def | append_to_list (self, list_, *values) |
Adds values to the end of list. More... | |
| def | combine_lists (self, *lists) |
Combines the given lists together and returns the result. More... | |
| def | convert_to_list (self, item) |
Converts the given item to a Python list type. More... | |
| def | copy_list (self, list_, deepcopy=False) |
| Returns a copy of the given list. More... | |
| def | count_values_in_list (self, list_, value, start=0, end=None) |
Returns the number of occurrences of the given value in list. More... | |
| def | get_from_list (self, list_, index) |
Returns the value specified with an index from list. More... | |
| def | get_index_from_list (self, list_, value, start=0, end=None) |
Returns the index of the first occurrence of the value on the list. More... | |
| def | get_slice_from_list (self, list_, start=0, end=None) |
Returns a slice of the given list between start and end indexes. More... | |
| def | insert_into_list (self, list_, index, value) |
Inserts value into list to the position specified with index. More... | |
| def | list_should_contain_sub_list (self, list1, list2, msg=None, values=True) |
Fails if not all elements in list2 are found in list1. More... | |
| def | list_should_contain_value (self, list_, value, msg=None) |
Fails if the value is not found from list. More... | |
| def | list_should_not_contain_duplicates (self, list_, msg=None) |
Fails if any element in the list is found from it more than once. More... | |
| def | list_should_not_contain_value (self, list_, value, msg=None) |
Fails if the value is found from list. More... | |
| def | lists_should_be_equal (self, list1, list2, msg=None, values=True, names=None, ignore_order=False) |
| Fails if given lists are unequal. More... | |
| def | log_list (self, list_, level='INFO') |
Logs the length and contents of the list using given level. More... | |
| def | remove_duplicates (self, list_) |
Returns a list without duplicates based on the given list. More... | |
| def | remove_from_list (self, list_, index) |
Removes and returns the value specified with an index from list. More... | |
| def | remove_values_from_list (self, list_, *values) |
Removes all occurrences of given values from list. More... | |
| def | reverse_list (self, list_) |
| Reverses the given list in place. More... | |
| def | set_list_value (self, list_, index, value) |
Sets the value of list specified by index to the given value. More... | |
| def | sort_list (self, list_) |
| Sorts the given list in place. More... | |
Public Member Functions inherited from robot.libraries.Collections._Dictionary | |
| 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... | |
Static Public Attributes | |
| string | ROBOT_LIBRARY_SCOPE = 'GLOBAL' |
| ROBOT_LIBRARY_VERSION = get_version() | |
A library providing keywords for handling lists and dictionaries.
``Collections`` is Robot Framework's standard library that provides a
set of keywords for handling Python lists and dictionaries. This
library has keywords, for example, for modifying and getting
values from lists and dictionaries (e.g. `Append To List`, `Get
From Dictionary`) and for verifying their contents (e.g. `Lists
Should Be Equal`, `Dictionary Should Contain Value`).
== Table of contents ==
%TOC%
= Related keywords in BuiltIn =
Following keywords in the BuiltIn library can also be used with
lists and dictionaries:
| = Keyword Name = | = Applicable With = |
| `Create List` | lists |
| `Create Dictionary` | dicts |
| `Get Length` | both |
| `Length Should Be` | both |
| `Should Be Empty` | both |
| `Should Not Be Empty` | both |
| `Should Contain` | both |
| `Should Not Contain` | both |
| `Should Contain X Times` | lists |
| `Should Not Contain X Times` | lists |
| `Get Count` | lists |
= Using with list-like and dictionary-like objects =
List keywords that do not alter the given list can also be used
with tuples, and to some extend also with other iterables.
`Convert To List` can be used to convert tuples and other iterables
to Python ``list`` objects.
Similarly dictionary keywords can, for most parts, be used with other
mappings. `Convert To Dictionary` can be used if real Python ``dict``
objects are needed.
= Boolean arguments =
Some keywords accept arguments that are handled as Boolean values true or
false. If such an argument is given as a string, it is considered false if
it is an empty string or equal to ``FALSE``, ``NONE``, ``NO``, ``OFF`` or
``0``, case-insensitively. Keywords verifying something that allow dropping
actual and expected values from the possible error message also consider
string ``no values`` to be false. Other strings are considered true
regardless their value, and other argument types are tested using the same
[http://docs.python.org/library/stdtypes.html#truth|rules as in Python].
True examples:
| `Should Contain Match` | ${list} | ${pattern} | case_insensitive=True | # Strings are generally true. |
| `Should Contain Match` | ${list} | ${pattern} | case_insensitive=yes | # Same as the above. |
| `Should Contain Match` | ${list} | ${pattern} | case_insensitive=${TRUE} | # Python ``True`` is true. |
| `Should Contain Match` | ${list} | ${pattern} | case_insensitive=${42} | # Numbers other than 0 are true. |
False examples:
| `Should Contain Match` | ${list} | ${pattern} | case_insensitive=False | # String ``false`` is false. |
| `Should Contain Match` | ${list} | ${pattern} | case_insensitive=no | # Also string ``no`` is false. |
| `Should Contain Match` | ${list} | ${pattern} | case_insensitive=${EMPTY} | # Empty string is false. |
| `Should Contain Match` | ${list} | ${pattern} | case_insensitive=${FALSE} | # Python ``False`` is false. |
| `Lists Should Be Equal` | ${x} | ${y} | Custom error | values=no values | # ``no values`` works with ``values`` argument |
Considering ``OFF`` and ``0`` false is new in Robot Framework 3.1.
= Data in examples =
List related keywords use variables in format ``${Lx}`` in their examples.
They mean lists with as many alphabetic characters as specified by ``x``.
For example, ``${L1}`` means ``['a']`` and ``${L3}`` means
``['a', 'b', 'c']``.
Dictionary keywords use similar ``${Dx}`` variables. For example, ``${D1}``
means ``{'a': 1}`` and ``${D3}`` means ``{'a': 1, 'b': 2, 'c': 3}``.
Definition at line 917 of file Collections.py.
| def robot.libraries.Collections.Collections.get_match_count | ( | self, | |
| list, | |||
| pattern, | |||
case_insensitive = False, |
|||
whitespace_insensitive = False |
|||
| ) |
Returns the count of matches to pattern in list.
For more information on ``pattern``, ``case_insensitive``, and
``whitespace_insensitive``, see `Should Contain Match`.
Examples:
| ${count}= | Get Match Count | ${list} | a* | # ${count} will be the count of strings beginning with 'a' |
| ${count}= | Get Match Count | ${list} | regexp=a.* | # ${matches} will be the count of strings beginning with 'a' (regexp version) |
| ${count}= | Get Match Count | ${list} | a* | case_insensitive=${True} | # ${matches} will be the count of strings beginning with 'a' or 'A' |
Definition at line 1005 of file Collections.py.
| def robot.libraries.Collections.Collections.get_matches | ( | self, | |
| list, | |||
| pattern, | |||
case_insensitive = False, |
|||
whitespace_insensitive = False |
|||
| ) |
Returns a list of matches to pattern in list.
For more information on ``pattern``, ``case_insensitive``, and
``whitespace_insensitive``, see `Should Contain Match`.
Examples:
| ${matches}= | Get Matches | ${list} | a* | # ${matches} will contain any string beginning with 'a' |
| ${matches}= | Get Matches | ${list} | regexp=a.* | # ${matches} will contain any string beginning with 'a' (regexp version) |
| ${matches}= | Get Matches | ${list} | a* | case_insensitive=${True} | # ${matches} will contain any string beginning with 'a' or 'A' |
Definition at line 989 of file Collections.py.
| def robot.libraries.Collections.Collections.should_contain_match | ( | self, | |
| list, | |||
| pattern, | |||
msg = None, |
|||
case_insensitive = False, |
|||
whitespace_insensitive = False |
|||
| ) |
Fails if pattern is not found in list.
By default, pattern matching is similar to matching files in a shell
and is case-sensitive and whitespace-sensitive. In the pattern syntax,
``*`` matches to anything and ``?`` matches to any single character. You
can also prepend ``glob=`` to your pattern to explicitly use this pattern
matching behavior.
If you prepend ``regexp=`` to your pattern, your pattern will be used
according to the Python
[http://docs.python.org/library/re.html|re module] regular expression
syntax. Important note: Backslashes are an escape character, and must
be escaped with another backslash (e.g. ``regexp=\\\\d{6}`` to search for
``\\d{6}``). See `BuiltIn.Should Match Regexp` for more details.
If ``case_insensitive`` is given a true value (see `Boolean arguments`),
the pattern matching will ignore case.
If ``whitespace_insensitive`` is given a true value (see `Boolean
arguments`), the pattern matching will ignore whitespace.
Non-string values in lists are ignored when matching patterns.
Use the ``msg`` argument to override the default error message.
See also ``Should Not Contain Match``.
Examples:
| Should Contain Match | ${list} | a* | | | # Match strings beginning with 'a'. |
| Should Contain Match | ${list} | regexp=a.* | | | # Same as the above but with regexp. |
| Should Contain Match | ${list} | regexp=\\\\d{6} | | | # Match strings containing six digits. |
| Should Contain Match | ${list} | a* | case_insensitive=True | | # Match strings beginning with 'a' or 'A'. |
| Should Contain Match | ${list} | ab* | whitespace_insensitive=yes | | # Match strings beginning with 'ab' with possible whitespace ignored. |
| Should Contain Match | ${list} | ab* | whitespace_insensitive=true | case_insensitive=true | # Same as the above but also ignore case. |
Definition at line 956 of file Collections.py.
| def robot.libraries.Collections.Collections.should_not_contain_match | ( | self, | |
| list, | |||
| pattern, | |||
msg = None, |
|||
case_insensitive = False, |
|||
whitespace_insensitive = False |
|||
| ) |
Fails if pattern is found in list.
Exact opposite of `Should Contain Match` keyword. See that keyword
for information about arguments and usage in general.
Definition at line 970 of file Collections.py.
|
static |
Definition at line 918 of file Collections.py.
|
static |
Definition at line 919 of file Collections.py.