Robot Framework
robot.libraries.Collections._List Class Reference
Inheritance diagram for robot.libraries.Collections._List:
robot.libraries.Collections.Collections

Public Member Functions

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...
 

Private Member Functions

def _get_list_index_name_mapping (self, names, list_length)
 
def _index_error (self, list_, index)
 
def _index_to_int (self, index, empty_to_zero=False)
 
def _log_list (self, list_)
 
def _validate_list (self, list_, position=1)
 
def _validate_lists (self, *lists)
 
def _yield_list_diffs (self, list1, list2, names)
 

Detailed Description

Definition at line 33 of file Collections.py.

Member Function Documentation

◆ _get_list_index_name_mapping()

def robot.libraries.Collections._List._get_list_index_name_mapping (   self,
  names,
  list_length 
)
private

Definition at line 411 of file Collections.py.

◆ _index_error()

def robot.libraries.Collections._List._index_error (   self,
  list_,
  index 
)
private

Definition at line 470 of file Collections.py.

◆ _index_to_int()

def robot.libraries.Collections._List._index_to_int (   self,
  index,
  empty_to_zero = False 
)
private

Definition at line 462 of file Collections.py.

◆ _log_list()

def robot.libraries.Collections._List._log_list (   self,
  list_ 
)
private

Definition at line 452 of file Collections.py.

◆ _validate_list()

def robot.libraries.Collections._List._validate_list (   self,
  list_,
  position = 1 
)
private

Definition at line 473 of file Collections.py.

◆ _validate_lists()

def robot.libraries.Collections._List._validate_lists (   self,
lists 
)
private

Definition at line 478 of file Collections.py.

◆ _yield_list_diffs()

def robot.libraries.Collections._List._yield_list_diffs (   self,
  list1,
  list2,
  names 
)
private

Definition at line 418 of file Collections.py.

◆ append_to_list()

def robot.libraries.Collections._List.append_to_list (   self,
  list_,
values 
)

Adds values to the end of list.

    Example:
    | Append To List | ${L1} | xxx |   |   |
    | Append To List | ${L2} | x   | y | z |
    =>
    | ${L1} = ['a', 'xxx']
    | ${L2} = ['a', 'b', 'x', 'y', 'z']

Definition at line 52 of file Collections.py.

◆ combine_lists()

def robot.libraries.Collections._List.combine_lists (   self,
lists 
)

Combines the given lists together and returns the result.

    The given lists are not altered by this keyword.

    Example:
    | ${x} = | Combine Lists | ${L1} | ${L2} |       |
    | ${y} = | Combine Lists | ${L1} | ${L2} | ${L1} |
    =>
    | ${x} = ['a', 'a', 'b']
    | ${y} = ['a', 'a', 'b', 'a']
    | ${L1} and ${L2} are not changed.

Definition at line 93 of file Collections.py.

◆ convert_to_list()

def robot.libraries.Collections._List.convert_to_list (   self,
  item 
)

Converts the given item to a Python list type.

    Mainly useful for converting tuples and other iterable to lists.
    Use `Create List` from the BuiltIn library for constructing new lists.

Definition at line 40 of file Collections.py.

◆ copy_list()

def robot.libraries.Collections._List.copy_list (   self,
  list_,
  deepcopy = False 
)

Returns a copy of the given list.

    If the optional ``deepcopy`` is given a true value, the returned
    list is a deep copy. New option in Robot Framework 3.1.2.

    The given list is never altered by this keyword.

Definition at line 275 of file Collections.py.

◆ count_values_in_list()

def robot.libraries.Collections._List.count_values_in_list (   self,
  list_,
  value,
  start = 0,
  end = None 
)

Returns the number of occurrences of the given value in list.

    The search can be narrowed to the selected sublist by the ``start`` and
    ``end`` indexes having the same semantics as with `Get Slice From List`
    keyword. The given list is never altered by this keyword.

    Example:
    | ${x} = | Count Values In List | ${L3} | b |
    =>
    | ${x} = 1
    | ${L3} is not changed

Definition at line 241 of file Collections.py.

◆ get_from_list()

def robot.libraries.Collections._List.get_from_list (   self,
  list_,
  index 
)

Returns the value specified with an index from list.

    The given list is never altered by this keyword.

    Index ``0`` means the first position, ``1`` the second, and so on.
    Similarly, ``-1`` is the last position, ``-2`` the second last, and so on.
    Using an index that does not exist on the list causes an error.
    The index can be either an integer or a string that can be converted
    to an integer.

    Examples (including Python equivalents in comments):
    | ${x} = | Get From List | ${L5} | 0  | # L5[0]  |
    | ${y} = | Get From List | ${L5} | -2 | # L5[-2] |
    =>
    | ${x} = 'a'
    | ${y} = 'd'
    | ${L5} is not changed

Definition at line 192 of file Collections.py.

◆ get_index_from_list()

def robot.libraries.Collections._List.get_index_from_list (   self,
  list_,
  value,
  start = 0,
  end = None 
)

Returns the index of the first occurrence of the value on the list.

    The search can be narrowed to the selected sublist by the ``start`` and
    ``end`` indexes having the same semantics as with `Get Slice From List`
    keyword. In case the value is not found, -1 is returned. The given list
    is never altered by this keyword.

    Example:
    | ${x} = | Get Index From List | ${L5} | d |
    =>
    | ${x} = 3
    | ${L5} is not changed

Definition at line 258 of file Collections.py.

◆ get_slice_from_list()

def robot.libraries.Collections._List.get_slice_from_list (   self,
  list_,
  start = 0,
  end = None 
)

Returns a slice of the given list between start and end indexes.

    The given list is never altered by this keyword.

    If both ``start`` and ``end`` are given, a sublist containing values
    from ``start`` to ``end`` is returned. This is the same as
    ``list[start:end]`` in Python. To get all items from the beginning,
    use 0 as the start value, and to get all items until and including
    the end, use ``None`` (default) as the end value.

    Using ``start`` or ``end`` not found on the list is the same as using
    the largest (or smallest) available index.

    Examples (incl. Python equivalents in comments):
    | ${x} = | Get Slice From List | ${L5} | 2      | 4 | # L5[2:4]    |
    | ${y} = | Get Slice From List | ${L5} | 1      |   | # L5[1:None] |
    | ${z} = | Get Slice From List | ${L5} | end=-2 |   | # L5[0:-2]   |
    =>
    | ${x} = ['c', 'd']
    | ${y} = ['b', 'c', 'd', 'e']
    | ${z} = ['a', 'b', 'c']
    | ${L5} is not changed

Definition at line 222 of file Collections.py.

◆ insert_into_list()

def robot.libraries.Collections._List.insert_into_list (   self,
  list_,
  index,
  value 
)

Inserts value into list to the position specified with index.

    Index ``0`` adds the value into the first position, ``1`` to the second,
    and so on. Inserting from right works with negative indices so that
    ``-1`` is the second last position, ``-2`` third last, and so on. Use
    `Append To List` to add items to the end of the list.

    If the absolute value of the index is greater than
    the length of the list, the value is added at the end
    (positive index) or the beginning (negative index). An index
    can be given either as an integer or a string that can be
    converted to an integer.

    Example:
    | Insert Into List | ${L1} | 0     | xxx |
    | Insert Into List | ${L2} | ${-1} | xxx |
    =>
    | ${L1} = ['xxx', 'a']
    | ${L2} = ['a', 'xxx', 'b']

Definition at line 77 of file Collections.py.

◆ list_should_contain_sub_list()

def robot.libraries.Collections._List.list_should_contain_sub_list (   self,
  list1,
  list2,
  msg = None,
  values = True 
)

Fails if not all elements in list2 are found in list1.

    The order of values and the number of values are not taken into
    account.

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

Definition at line 434 of file Collections.py.

◆ list_should_contain_value()

def robot.libraries.Collections._List.list_should_contain_value (   self,
  list_,
  value,
  msg = None 
)

Fails if the value is not found from list.

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

Definition at line 311 of file Collections.py.

◆ list_should_not_contain_duplicates()

def robot.libraries.Collections._List.list_should_not_contain_duplicates (   self,
  list_,
  msg = None 
)

Fails if any element in the list is found from it more than once.

    The default error message lists all the elements that were found
    from the ``list`` multiple times, but it can be overridden by giving
    a custom ``msg``. All multiple times found items and their counts are
    also logged.

    This keyword works with all iterables that can be converted to a list.
    The original iterable is never altered.

Definition at line 337 of file Collections.py.

◆ list_should_not_contain_value()

def robot.libraries.Collections._List.list_should_not_contain_value (   self,
  list_,
  value,
  msg = None 
)

Fails if the value is found from list.

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

Definition at line 321 of file Collections.py.

◆ lists_should_be_equal()

def robot.libraries.Collections._List.lists_should_be_equal (   self,
  list1,
  list2,
  msg = None,
  values = True,
  names = None,
  ignore_order = False 
)

Fails if given lists are unequal.

    The keyword first verifies that the lists have equal lengths, and then
    it checks are all their values equal. Possible differences between the
    values are listed in the default error message like ``Index 4: ABC !=
    Abc``. The types of the lists do not need to be the same. For example,
    Python tuple and list with same content are considered equal.

    The error message can be configured using ``msg`` and ``values``
    arguments:
    - If ``msg`` is not given, the default error message is used.
    - If ``msg`` is given and ``values`` gets a value considered true
      (see `Boolean arguments`), the error message starts with the given
      ``msg`` followed by a newline and the default message.
    - If ``msg`` is given and ``values``  is not given a true value,
      the error message is just the given ``msg``.

    The optional ``names`` argument can be used for naming the indices
    shown in the default error message. It can either be a list of names
    matching the indices in the lists or a dictionary where keys are
    indices that need to be named. It is not necessary to name all indices.
    When using a dictionary, keys can be either integers
    or strings that can be converted to integers.

    Examples:
    | ${names} = | Create List | First Name | Family Name | Email |
    | Lists Should Be Equal | ${people1} | ${people2} | names=${names} |
    | ${names} = | Create Dictionary | 0=First Name | 2=Email |
    | Lists Should Be Equal | ${people1} | ${people2} | names=${names} |

    If the items in index 2 would differ in the above examples, the error
    message would contain a row like ``Index 2 (email): name@foo.com !=
    name@bar.com``.

    The optional ``ignore_order`` argument can be used to ignore the order
    of the elements in the lists. Using it requires items to be sortable.
    This is new in Robot Framework 3.2.

    Example:
    | ${list1} = | Create List | apple | cherry | banana |
    | ${list2} = | Create List | cherry | banana | apple |
    | Lists Should Be Equal | ${list1} | ${list2} | ignore_order=True |

Definition at line 394 of file Collections.py.

◆ log_list()

def robot.libraries.Collections._List.log_list (   self,
  list_,
  level = 'INFO' 
)

Logs the length and contents of the list using given level.

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

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

Definition at line 448 of file Collections.py.

◆ remove_duplicates()

def robot.libraries.Collections._List.remove_duplicates (   self,
  list_ 
)

Returns a list without duplicates based on the given list.

    Creates and returns a new list that contains all items in the given
    list so that one item can appear only once. Order of the items in
    the new list is the same as in the original except for missing
    duplicates. Number of the removed duplicates is logged.

Definition at line 164 of file Collections.py.

◆ remove_from_list()

def robot.libraries.Collections._List.remove_from_list (   self,
  list_,
  index 
)

Removes and returns the value specified with an index from list.

    Index ``0`` means the first position, ``1`` the second and so on.
    Similarly, ``-1`` is the last position, ``-2`` the second last, and so on.
    Using an index that does not exist on the list causes an error.
    The index can be either an integer or a string that can be converted
    to an integer.

    Example:
    | ${x} = | Remove From List | ${L2} | 0 |
    =>
    | ${x} = 'a'
    | ${L2} = ['b']

Definition at line 150 of file Collections.py.

◆ remove_values_from_list()

def robot.libraries.Collections._List.remove_values_from_list (   self,
  list_,
values 
)

Removes all occurrences of given values from list.

    It is not an error if a value does not exist in the list at all.

    Example:
    | Remove Values From List | ${L4} | a | c | e | f |
    =>
    | ${L4} = ['b', 'd']

Definition at line 130 of file Collections.py.

◆ reverse_list()

def robot.libraries.Collections._List.reverse_list (   self,
  list_ 
)

Reverses the given list in place.

    Note that the given list is changed and nothing is returned. Use
    `Copy List` first, if you need to keep also the original order.

    | Reverse List | ${L3} |
    =>
    | ${L3} = ['c', 'b', 'a']

Definition at line 290 of file Collections.py.

◆ set_list_value()

def robot.libraries.Collections._List.set_list_value (   self,
  list_,
  index,
  value 
)

Sets the value of list specified by index to the given value.

    Index ``0`` means the first position, ``1`` the second and so on.
    Similarly, ``-1`` is the last position, ``-2`` second last, and so on.
    Using an index that does not exist on the list causes an error.
    The index can be either an integer or a string that can be converted to
    an integer.

    Example:
    | Set List Value | ${L3} | 1  | xxx |
    | Set List Value | ${L3} | -1 | yyy |
    =>
    | ${L3} = ['a', 'xxx', 'yyy']

Definition at line 114 of file Collections.py.

◆ sort_list()

def robot.libraries.Collections._List.sort_list (   self,
  list_ 
)

Sorts the given list in place.

    Sorting fails if items in the list are not comparable with each others.
    On Python 2 most objects are comparable, but on Python 3 comparing,
    for example, strings with numbers is not possible.

    Note that the given list is changed and nothing is returned. Use
    `Copy List` first, if you need to keep also the original order.

Definition at line 303 of file Collections.py.


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