20 seq2str, seq2str2, type_name, unic, Matcher)
131 while value
in list_:
168 removed = len(list_) - len(ret)
169 logger.info(
'%d duplicate%s removed.' % (removed,
plural_or_not(removed)))
225 return list_[start:end]
262 return int(start) + list_.index(value)
276 return copy.deepcopy(list_)
311 default =
"%s does not contain value '%s'." % (
seq2str2(list_), value)
320 default =
"%s contains value '%s'." % (
seq2str2(list_), value)
335 if not isinstance(list_, list):
339 if item
not in dupes:
340 count = list_.count(item)
342 logger.info(
"'%s' found %d times." % (item, count))
346 '%s found multiple times.' %
seq2str(dupes))
387 default =
'Lengths are different: %d != %d' % (len1, len2)
391 default =
'Lists are different:\n' +
'\n'.join(diffs)
398 return dict((
int(index), names[index])
for index
in names)
399 return dict(zip(range(list_length), names))
402 for index, (item1, item2)
in enumerate(zip(list1, list2)):
403 name =
' (%s)' % names[index]
if index
in names
else ''
405 assert_equal(item1, item2, msg=
'Index %d%s' % (index, name))
406 except AssertionError
as err:
419 diffs =
', '.join(
unic(item)
for item
in list2
if item
not in list1)
420 default =
'Following values were not found from first list: ' + diffs
432 logger.write(
'\n'.join(self.
_log_list_log_list(list_)), level)
436 yield 'List is empty.'
437 elif len(list_) == 1:
438 yield 'List has one item:\n%s' % list_[0]
440 yield 'List length is %d and it contains following items:' % len(list_)
441 for index, item
in enumerate(list_):
442 yield '%s: %s' % (index, item)
445 if empty_to_zero
and not index:
450 raise ValueError(
"Cannot convert index '%s' to an integer." % index)
453 raise IndexError(
'Given index %s is out of the range 0-%d.'
454 % (index, len(list_)-1))
458 raise TypeError(
"Expected argument %d to be a list or list-like, "
459 "got %s instead." % (position,
type_name(list_)))
462 for index, item
in enumerate(lists, start=1):
500 if len(key_value_pairs) % 2 != 0:
501 raise ValueError(
"Adding data to a dictionary failed. There "
502 "should be even number of key-value-pairs.")
503 for i
in range(0, len(key_value_pairs), 2):
504 dictionary[key_value_pairs[i]] = key_value_pairs[i+1]
505 dictionary.update(items)
521 if key
in dictionary:
522 value = dictionary.pop(key)
523 logger.info(
"Removed item with key '%s' and value '%s'." % (key, value))
525 logger.info(
"Key '%s' not found." % key)
543 if default
is NOT_SET:
545 return dictionary.pop(key)
546 return dictionary.pop(key, default)
560 remove_keys = [k
for k
in dictionary
if k
not in keys]
577 return copy.deepcopy(dictionary)
578 return dictionary.copy()
602 keys = dictionary.keys()
633 return [dictionary[k]
for k
in keys]
662 return [i
for key
in keys
for i
in (key, dictionary[key])]
679 return dictionary[key]
681 raise RuntimeError(
"Dictionary does not contain key '%s'." % key)
689 default =
"Dictionary does not contain key '%s'." % key
698 default =
"Dictionary contains key '%s'." % key
710 actual, expected =
unic(dictionary[key]),
unic(value)
711 default =
"Value of dictionary key '%s' does not match: %s != %s" % (key, actual, expected)
720 default =
"Dictionary does not contain value '%s'." % value
729 default =
"Dictionary contains value '%s'." % value
758 diffs = [
unic(k)
for k
in keys
if k
not in dict1]
759 default =
"Following keys missing from first dictionary: %s" \
773 logger.write(
'\n'.join(self.
_log_dictionary_log_dictionary(dictionary)), level)
777 yield 'Dictionary is empty.'
778 elif len(dictionary) == 1:
779 yield 'Dictionary has one item:'
781 yield 'Dictionary size is %d and it contains following items:' % len(dictionary)
783 yield '%s: %s' % (key, dictionary[key])
788 miss1 = [
unic(k)
for k
in keys2
if k
not in dict1]
789 miss2 = [
unic(k)
for k
in keys1
if k
not in dict2]
792 error += [
'Following keys missing from first dictionary: %s'
795 error += [
'Following keys missing from second dictionary: %s'
802 default =
'Following keys have different values:\n' +
'\n'.join(diffs)
808 assert_equal(dict1[key], dict2[key], msg=
'Key %s' % (key,))
809 except AssertionError
as err:
814 raise TypeError(
"Expected argument %d to be a dictionary or dictionary-like, "
815 "got %s instead." % (position,
type_name(dictionary)))
894 ROBOT_LIBRARY_SCOPE =
'GLOBAL'
933 case_insensitive=False,
934 whitespace_insensitive=False):
935 _List._validate_list(self, list)
937 whitespace_insensitive)
938 default =
"%s does not contain match for pattern '%s'." \
948 case_insensitive=False,
949 whitespace_insensitive=False):
950 _List._validate_list(self, list)
952 whitespace_insensitive)
953 default =
"%s contains match for pattern '%s'." \
968 whitespace_insensitive=False):
969 _List._validate_list(self, list)
971 whitespace_insensitive)
984 whitespace_insensitive=False):
985 _List._validate_list(self, list)
986 return len(self.
get_matchesget_matches(list, pattern, case_insensitive,
987 whitespace_insensitive))
995 elif is_truthy(values)
and str(values).upper() !=
'NO VALUES':
996 msg +=
'\n' + default_msg
1001 whitespace_insensitive=False):
1003 raise TypeError(
"Pattern must be string, got '%s'." %
type_name(pattern))
1005 if pattern.startswith(
'regexp='):
1006 pattern = pattern[7:]
1008 elif pattern.startswith(
'glob='):
1009 pattern = pattern[5:]
1010 matcher = Matcher(pattern,
1012 spaceless=
is_truthy(whitespace_insensitive),
1014 return [string
for string
in iterable
1015 if is_string(string)
and matcher.match(string)]
A test library providing keywords for handling lists and dictionaries.
def get_match_count(self, list, pattern, case_insensitive=False, whitespace_insensitive=False)
Returns the count of matches to pattern in list.
def should_not_contain_match(self, list, pattern, msg=None, case_insensitive=False, whitespace_insensitive=False)
Fails if pattern is found in list.
def get_matches(self, list, pattern, case_insensitive=False, whitespace_insensitive=False)
Returns a list of matches to pattern in list.
def should_contain_match(self, list, pattern, msg=None, case_insensitive=False, whitespace_insensitive=False)
Fails if pattern is not found in list.
def _log_dictionary(self, dictionary)
def convert_to_dictionary(self, item)
Converts the given item to a Python dict type.
def keep_in_dictionary(self, dictionary, *keys)
Keeps the given keys in the dictionary and removes all other.
def dictionary_should_not_contain_value(self, dictionary, value, msg=None)
Fails if value is found from dictionary.
def get_from_dictionary(self, dictionary, key)
Returns a value from the given dictionary based on the given key.
def get_dictionary_values(self, dictionary, sort_keys=True)
Returns values of the given dictionary as a list.
def get_dictionary_items(self, dictionary, sort_keys=True)
Returns items of the given dictionary as a list.
def copy_dictionary(self, dictionary, deepcopy=False)
Returns a copy of the given dictionary.
def log_dictionary(self, dictionary, level='INFO')
Logs the size and contents of the dictionary using given level.
def _key_values_should_be_equal(self, keys, dict1, dict2, msg, values)
def _keys_should_be_equal(self, dict1, dict2, msg, values)
def dictionary_should_contain_key(self, dictionary, key, msg=None)
Fails if key is not found from dictionary.
def dictionary_should_not_contain_key(self, dictionary, key, msg=None)
Fails if key is found from dictionary.
def dictionary_should_contain_sub_dictionary(self, dict1, dict2, msg=None, values=True)
Fails unless all items in dict2 are found from dict1.
def pop_from_dictionary(self, dictionary, key, default=NOT_SET)
Pops the given key from the dictionary and returns its value.
def _validate_dictionary(self, dictionary, position=1)
def remove_from_dictionary(self, dictionary, *keys)
Removes the given keys from the dictionary.
def set_to_dictionary(self, dictionary, *key_value_pairs, **items)
Adds the given key_value_pairs and items to the dictionary.
def dictionary_should_contain_item(self, dictionary, key, value, msg=None)
An item of key / value must be found in a dictionary.
def _yield_dict_diffs(self, keys, dict1, dict2)
def dictionary_should_contain_value(self, dictionary, value, msg=None)
Fails if value is not found from dictionary.
def get_dictionary_keys(self, dictionary, sort_keys=True)
Returns keys of the given dictionary as a list.
def dictionaries_should_be_equal(self, dict1, dict2, msg=None, values=True)
Fails if the given dictionaries are not equal.
def list_should_contain_value(self, list_, value, msg=None)
Fails if the value is not found from list.
def append_to_list(self, list_, *values)
Adds values to the end of list.
def log_list(self, list_, level='INFO')
Logs the length and contents of the list using given level.
def _yield_list_diffs(self, list1, list2, names)
def sort_list(self, list_)
Sorts the given list in place.
def _log_list(self, list_)
def get_from_list(self, list_, index)
Returns the value specified with an index from list.
def remove_values_from_list(self, list_, *values)
Removes all occurrences of given values from list.
def remove_from_list(self, list_, index)
Removes and returns the value specified with an index from list.
def remove_duplicates(self, list_)
Returns a list without duplicates based on the given list.
def _index_to_int(self, index, empty_to_zero=False)
def reverse_list(self, list_)
Reverses the given list in place.
def count_values_in_list(self, list_, value, start=0, end=None)
Returns the number of occurrences of the given value in list.
def _validate_lists(self, *lists)
def convert_to_list(self, item)
Converts the given item to a Python list type.
def list_should_contain_sub_list(self, list1, list2, msg=None, values=True)
Fails if not all of the elements in list2 are found in list1.
def get_slice_from_list(self, list_, start=0, end=None)
Returns a slice of the given list between start and end indexes.
def _validate_list(self, list_, position=1)
def copy_list(self, list_, deepcopy=False)
Returns a copy of the given list.
def _get_list_index_name_mapping(self, names, list_length)
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.
def combine_lists(self, *lists)
Combines the given lists together and returns the result.
def list_should_not_contain_duplicates(self, list_, msg=None)
Fails if any element in the list is found from it more than once.
def insert_into_list(self, list_, index, value)
Inserts value into list to the position specified with index.
def lists_should_be_equal(self, list1, list2, msg=None, values=True, names=None)
Fails if given lists are unequal.
def _index_error(self, list_, index)
def list_should_not_contain_value(self, list_, value, msg=None)
Fails if the value is found from list.
def set_list_value(self, list_, index, value)
Sets the value of list specified by index to the given value.
def _verify_condition(condition, default_msg, msg, values=False)
def _get_matches_in_iterable(iterable, pattern, case_insensitive=False, whitespace_insensitive=False)
def assert_equal(first, second, msg=None, values=True, formatter=None)
Fail if given objects are unequal as determined by the '==' operator.
def seq2str2(sequence)
Returns sequence in format [ item 1 | item 2 | ...
def seq2str(sequence, quote="'", sep=', ', lastsep=' and ')
Returns sequence in format ‘'item 1’, 'item 2' and 'item 3'`.
def is_truthy(item)
Returns True or False depending is the item considered true or not.
def get_version(naked=False)