Robot Framework Integrated Development Environment (RIDE)
BuiltIn.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 import difflib
17 import re
18 import time
19 import token
20 from tokenize import generate_tokens, untokenize
21 
22 from robotide.lib.robot.api import logger
23 from robotide.lib.robot.errors import (ContinueForLoop, DataError, ExecutionFailed,
24  ExecutionFailures, ExecutionPassed, ExitForLoop,
25  PassExecution, ReturnFromKeyword)
26 from robotide.lib.robot.running import Keyword, RUN_KW_REGISTER
27 from robotide.lib.robot.running.context import EXECUTION_CONTEXTS
28 from robotide.lib.robot.running.usererrorhandler import UserErrorHandler
29 from robotide.lib.robot.utils import (DotDict, escape, format_assign_message,
30  get_error_message, get_time, html_escape, is_falsy, is_integer,
31  is_string, is_truthy, is_unicode, IRONPYTHON, JYTHON,
32  Matcher, normalize, NormalizedDict, parse_time, prepr,
33  plural_or_not as s, PY3, RERAISED_EXCEPTIONS, roundup,
34  secs_to_timestr, seq2str, split_from_equals, StringIO,
35  timestr_to_secs, type_name, unic, is_list_like)
36 from robotide.lib.robot.utils.asserts import assert_equal, assert_not_equal
37 from robotide.lib.robot.variables import (is_list_var, is_var, DictVariableTableValue,
38  VariableTableValue, VariableSplitter,
39  variable_not_found)
40 from robotide.lib.robot.version import get_version
41 
42 if JYTHON:
43  from java.lang import String, Number
44 
45 
46 # TODO: Clean-up registering run keyword variants in RF 3.1.
47 # https://github.com/robotframework/robotframework/issues/2190
48 
49 def run_keyword_variant(resolve):
50  def decorator(method):
51  RUN_KW_REGISTER.register_run_keyword('BuiltIn', method.__name__,
52  resolve, deprecation_warning=False)
53  return method
54  return decorator
55 
56 
57 class _BuiltInBase():
58 
59  @property
60  _context = property
61 
62  def _context(self):
63  return self._get_context_get_context()
64 
65  def _get_context(self, top=False):
66  ctx = EXECUTION_CONTEXTS.current if not top else EXECUTION_CONTEXTS.top
67  if ctx is None:
68  raise RobotNotRunningError('Cannot access execution context')
69  return ctx
70 
71  @property
72  _namespace = property
73 
74  def _namespace(self):
75  return self._get_context_get_context().namespace
76 
77  @property
78  _variables = property
79 
80  def _variables(self):
81  return self._namespace_namespace_namespace.variables
82 
83  def _matches(self, string, pattern, caseless=False):
84  # Must use this instead of fnmatch when string may contain newlines.
85  matcher = Matcher(pattern, caseless=caseless, spaceless=False)
86  return matcher.match(string)
87 
88  def _is_true(self, condition):
89  if is_string(condition):
90  condition = self.evaluate(condition, modules='os,sys')
91  return bool(condition)
92 
93  def _log_types(self, *args):
94  self._log_types_at_level_log_types_at_level('DEBUG', *args)
95 
96  def _log_types_at_level(self, level, *args):
97  msg = ["Argument types are:"] + [self._get_type_get_type(a) for a in args]
98  self.log('\n'.join(msg), level)
99 
100  def _get_type(self, arg):
101  # In IronPython type(u'x') is str. We want to report unicode anyway.
102  if is_unicode(arg):
103  return "<type 'unicode'>"
104  return str(type(arg))
105 
106 
108 
109 
134  def convert_to_integer(self, item, base=None):
135  self._log_types_log_types(item)
136  return self._convert_to_integer_convert_to_integer(item, base)
137 
138  def _convert_to_integer(self, orig, base=None):
139  try:
140  item = self._handle_java_numbers_handle_java_numbers(orig)
141  item, base = self._get_base_get_base(item, base)
142  if base:
143  return int(item, self._convert_to_integer_convert_to_integer(base))
144  return int(item)
145  except:
146  raise RuntimeError("'%s' cannot be converted to an integer: %s"
147  % (orig, get_error_message()))
148 
149  def _handle_java_numbers(self, item):
150  if not JYTHON:
151  return item
152  if isinstance(item, String):
153  return unic(item)
154  if isinstance(item, Number):
155  return item.doubleValue()
156  return item
157 
158  def _get_base(self, item, base):
159  if not is_string(item):
160  return item, base
161  item = normalize(item)
162  if item.startswith(('-', '+')):
163  sign = item[0]
164  item = item[1:]
165  else:
166  sign = ''
167  bases = {'0b': 2, '0o': 8, '0x': 16}
168  if base or not item.startswith(tuple(bases)):
169  return sign+item, base
170  return sign+item[2:], bases[item[:2]]
171 
172 
191  def convert_to_binary(self, item, base=None, prefix=None, length=None):
192  return self._convert_to_bin_oct_hex_convert_to_bin_oct_hex(item, base, prefix, length, 'b')
193 
194 
213  def convert_to_octal(self, item, base=None, prefix=None, length=None):
214  return self._convert_to_bin_oct_hex_convert_to_bin_oct_hex(item, base, prefix, length, 'o')
215 
216 
239  def convert_to_hex(self, item, base=None, prefix=None, length=None,
240  lowercase=False):
241  spec = 'x' if is_truthy(lowercase) else 'X'
242  return self._convert_to_bin_oct_hex_convert_to_bin_oct_hex(item, base, prefix, length, spec)
243 
244  def _convert_to_bin_oct_hex(self, item, base, prefix, length, format_spec):
245  self._log_types_log_types(item)
246  ret = format(self._convert_to_integer_convert_to_integer(item, base), format_spec)
247  prefix = prefix or ''
248  if ret[0] == '-':
249  prefix = '-' + prefix
250  ret = ret[1:]
251  if length:
252  ret = ret.rjust(self._convert_to_integer_convert_to_integer(length), '0')
253  return prefix + ret
254 
255 
284  def convert_to_number(self, item, precision=None):
285  self._log_types_log_types(item)
286  return self._convert_to_number_convert_to_number(item, precision)
287 
288  def _convert_to_number(self, item, precision=None):
289  number = self._convert_to_number_without_precision_convert_to_number_without_precision(item)
290  if precision is not None:
291  number = roundup(number, self._convert_to_integer_convert_to_integer(precision),
292  return_type=float)
293  return number
294 
296  try:
297  if JYTHON:
298  item = self._handle_java_numbers_handle_java_numbers(item)
299  return float(item)
300  except:
301  error = get_error_message()
302  try:
303  return float(self._convert_to_integer_convert_to_integer(item))
304  except RuntimeError:
305  raise RuntimeError("'%s' cannot be converted to a floating "
306  "point number: %s" % (item, error))
307 
308 
318  def convert_to_string(self, item):
319  self._log_types_log_types(item)
320  return self._convert_to_string_convert_to_string(item)
321 
322  def _convert_to_string(self, item):
323  return unic(item)
324 
325 
332  def convert_to_boolean(self, item):
333  self._log_types_log_types(item)
334  if is_string(item):
335  if item.upper() == 'TRUE':
336  return True
337  if item.upper() == 'FALSE':
338  return False
339  return bool(item)
340 
341 
384  def convert_to_bytes(self, input, input_type='text'):
385  try:
386  try:
387  ordinals = getattr(self, '_get_ordinals_from_%s' % input_type)
388  except AttributeError:
389  raise RuntimeError("Invalid input type '%s'." % input_type)
390  return bytes(bytearray(o for o in ordinals(input)))
391  except:
392  raise RuntimeError("Creating bytes failed: %s" % get_error_message())
393 
394  def _get_ordinals_from_text(self, input):
395  # https://github.com/IronLanguages/main/issues/1237
396  if IRONPYTHON and isinstance(input, bytearray):
397  input = bytes(input)
398  for char in input:
399  ordinal = char if is_integer(char) else ord(char)
400  yield self._test_ordinal_test_ordinal(ordinal, char, 'Character')
401 
402  def _test_ordinal(self, ordinal, original, type):
403  if 0 <= ordinal <= 255:
404  return ordinal
405  raise RuntimeError("%s '%s' cannot be represented as a byte."
406  % (type, original))
407 
408  def _get_ordinals_from_int(self, input):
409  if is_string(input):
410  input = input.split()
411  elif is_integer(input):
412  input = [input]
413  for integer in input:
414  ordinal = self._convert_to_integer_convert_to_integer(integer)
415  yield self._test_ordinal_test_ordinal(ordinal, integer, 'Integer')
416 
417  def _get_ordinals_from_hex(self, input):
418  for token in self._input_to_tokens_input_to_tokens(input, length=2):
419  ordinal = self._convert_to_integer_convert_to_integer(token, base=16)
420  yield self._test_ordinal_test_ordinal(ordinal, token, 'Hex value')
421 
422  def _get_ordinals_from_bin(self, input):
423  for token in self._input_to_tokens_input_to_tokens(input, length=8):
424  ordinal = self._convert_to_integer_convert_to_integer(token, base=2)
425  yield self._test_ordinal_test_ordinal(ordinal, token, 'Binary value')
426 
427  def _input_to_tokens(self, input, length):
428  if not is_string(input):
429  return input
430  input = ''.join(input.split())
431  if len(input) % length != 0:
432  raise RuntimeError('Expected input to be multiple of %d.' % length)
433  return (input[i:i+length] for i in range(0, len(input), length))
434 
435 
445  def create_list(self, *items):
446  return list(items)
447 
448  @run_keyword_variant(resolve=0)
449 
486  def create_dictionary(self, *items):
487  separate, combined = self._split_dict_items_split_dict_items(items)
488  result = DotDict(self._format_separate_dict_items_format_separate_dict_items(separate))
489  combined = DictVariableTableValue(combined).resolve(self._variables_variables_variables)
490  result.update(combined)
491  return result
492 
493  def _split_dict_items(self, items):
494  separate = []
495  for item in items:
496  name, value = split_from_equals(item)
497  if value is not None or VariableSplitter(item).is_dict_variable():
498  break
499  separate.append(item)
500  return separate, items[len(separate):]
501 
502  def _format_separate_dict_items(self, separate):
503  separate = self._variables_variables_variables.replace_list(separate)
504  if len(separate) % 2 != 0:
505  raise DataError('Expected even number of keys and values, got %d.'
506  % len(separate))
507  return [separate[i:i+2] for i in range(0, len(separate), 2)]
508 
509 
511 
512  def _set_and_remove_tags(self, tags):
513  set_tags = [tag for tag in tags if not tag.startswith('-')]
514  remove_tags = [tag[1:] for tag in tags if tag.startswith('-')]
515  if remove_tags:
516  self.remove_tags(*remove_tags)
517  if set_tags:
518  self.set_tags(*set_tags)
519 
520 
542  def fail(self, msg=None, *tags):
543  self._set_and_remove_tags_set_and_remove_tags(tags)
544  raise AssertionError(msg) if msg else AssertionError()
545 
546 
554  def fatal_error(self, msg=None):
555  error = AssertionError(msg) if msg else AssertionError()
556  error.ROBOT_EXIT_ON_FAILURE = True
557  raise error
558 
559 
564  def should_not_be_true(self, condition, msg=None):
565  if self._is_true_is_true(condition):
566  raise AssertionError(msg or "'%s' should not be true." % condition)
567 
568 
605  def should_be_true(self, condition, msg=None):
606  if not self._is_true_is_true(condition):
607  raise AssertionError(msg or "'%s' should be true." % condition)
608 
609 
638  def should_be_equal(self, first, second, msg=None, values=True,
639  ignore_case=False, formatter='str'):
640  self._log_types_at_info_if_different_log_types_at_info_if_different(first, second)
641  if is_truthy(ignore_case) and is_string(first) and is_string(second):
642  first = first.lower()
643  second = second.lower()
644  self._should_be_equal_should_be_equal(first, second, msg, values, formatter)
645 
646  def _should_be_equal(self, first, second, msg, values, formatter='str'):
647  include_values = self._include_values_include_values(values)
648  formatter = self._get_formatter(formatter)
649  if first == second:
650  return
651  if include_values and is_string(first) and is_string(second):
652  self._raise_multi_diff_raise_multi_diff(first, second, formatter)
653  assert_equal(first, second, msg, include_values, formatter)
654 
655  def _log_types_at_info_if_different(self, first, second):
656  level = 'DEBUG' if type(first) == type(second) else 'INFO'
657  self._log_types_at_level_log_types_at_level(level, first, second)
658 
659  def _raise_multi_diff(self, first, second, formatter):
660  first_lines = first.splitlines(True) # keepends
661  second_lines = second.splitlines(True)
662  if len(first_lines) < 3 or len(second_lines) < 3:
663  return
664  self.log("%s\n\n!=\n\n%s" % (first.rstrip(), second.rstrip()))
665  diffs = list(difflib.unified_diff(first_lines, second_lines,
666  fromfile='first', tofile='second',
667  lineterm=''))
668  diffs[3:] = [item[0] + formatter(item[1:]).rstrip()
669  for item in diffs[3:]]
670  raise AssertionError('Multiline strings are different:\n' +
671  '\n'.join(diffs))
672 
673  def _include_values(self, values):
674  return is_truthy(values) and str(values).upper() != 'NO VALUES'
675 
676 
685  def should_not_be_equal(self, first, second, msg=None, values=True,
686  ignore_case=False):
687  self._log_types_at_info_if_different_log_types_at_info_if_different(first, second)
688  if is_truthy(ignore_case) and is_string(first) and is_string(second):
689  first = first.lower()
690  second = second.lower()
691  self._should_not_be_equal_should_not_be_equal(first, second, msg, values)
692 
693  def _should_not_be_equal(self, first, second, msg, values):
694  assert_not_equal(first, second, msg, self._include_values_include_values(values))
695 
696 
706  def should_not_be_equal_as_integers(self, first, second, msg=None,
707  values=True, base=None):
708  self._log_types_at_info_if_different_log_types_at_info_if_different(first, second)
709  self._should_not_be_equal_should_not_be_equal(self._convert_to_integer(first, base),
710  self._convert_to_integer(second, base),
711  msg, values)
712 
713 
726  def should_be_equal_as_integers(self, first, second, msg=None, values=True,
727  base=None):
728  self._log_types_at_info_if_different_log_types_at_info_if_different(first, second)
729  self._should_be_equal_should_be_equal(self._convert_to_integer(first, base),
730  self._convert_to_integer(second, base),
731  msg, values)
732 
733 
743  def should_not_be_equal_as_numbers(self, first, second, msg=None,
744  values=True, precision=6):
745  self._log_types_at_info_if_different_log_types_at_info_if_different(first, second)
746  first = self._convert_to_number(first, precision)
747  second = self._convert_to_number(second, precision)
748  self._should_not_be_equal_should_not_be_equal(first, second, msg, values)
749 
750 
781  def should_be_equal_as_numbers(self, first, second, msg=None, values=True,
782  precision=6):
783  self._log_types_at_info_if_different_log_types_at_info_if_different(first, second)
784  first = self._convert_to_number(first, precision)
785  second = self._convert_to_number(second, precision)
786  self._should_be_equal_should_be_equal(first, second, msg, values)
787 
788 
801  def should_not_be_equal_as_strings(self, first, second, msg=None,
802  values=True, ignore_case=False):
803  self._log_types_at_info_if_different_log_types_at_info_if_different(first, second)
804  first = self._convert_to_string(first)
805  second = self._convert_to_string(second)
806  if is_truthy(ignore_case):
807  first = first.lower()
808  second = second.lower()
809  self._should_not_be_equal_should_not_be_equal(first, second, msg, values)
810 
811 
826  def should_be_equal_as_strings(self, first, second, msg=None, values=True,
827  ignore_case=False, formatter='str'):
828  self._log_types_at_info_if_different_log_types_at_info_if_different(first, second)
829  first = self._convert_to_string(first)
830  second = self._convert_to_string(second)
831  if is_truthy(ignore_case):
832  first = first.lower()
833  second = second.lower()
834  self._should_be_equal_should_be_equal(first, second, msg, values, formatter)
835 
836 
842  def should_not_start_with(self, str1, str2, msg=None, values=True,
843  ignore_case=False):
844  if is_truthy(ignore_case):
845  str1 = str1.lower()
846  str2 = str2.lower()
847  if str1.startswith(str2):
848  raise AssertionError(self._get_string_msg_get_string_msg(str1, str2, msg, values,
849  'starts with'))
850 
851 
857  def should_start_with(self, str1, str2, msg=None, values=True,
858  ignore_case=False):
859  if is_truthy(ignore_case):
860  str1 = str1.lower()
861  str2 = str2.lower()
862  if not str1.startswith(str2):
863  raise AssertionError(self._get_string_msg_get_string_msg(str1, str2, msg, values,
864  'does not start with'))
865 
866 
872  def should_not_end_with(self, str1, str2, msg=None, values=True,
873  ignore_case=False):
874  if is_truthy(ignore_case):
875  str1 = str1.lower()
876  str2 = str2.lower()
877  if str1.endswith(str2):
878  raise AssertionError(self._get_string_msg_get_string_msg(str1, str2, msg, values,
879  'ends with'))
880 
881 
887  def should_end_with(self, str1, str2, msg=None, values=True,
888  ignore_case=False):
889  if is_truthy(ignore_case):
890  str1 = str1.lower()
891  str2 = str2.lower()
892  if not str1.endswith(str2):
893  raise AssertionError(self._get_string_msg_get_string_msg(str1, str2, msg, values,
894  'does not end with'))
895 
896 
909  def should_not_contain(self, container, item, msg=None, values=True,
910  ignore_case=False):
911  # TODO: It is inconsistent that errors show original case in 'container'
912  # 'item' is in lower case. Should rather show original case everywhere
913  # and add separate '(case-insensitive)' not to the error message.
914  # This same logic should be used with all keywords supporting
915  # case-insensitive comparisons.
916  orig_container = container
917  if is_truthy(ignore_case) and is_string(item):
918  item = item.lower()
919  if is_string(container):
920  container = container.lower()
921  elif is_list_like(container):
922  container = set(x.lower() if is_string(x) else x for x in container)
923  if item in container:
924  raise AssertionError(self._get_string_msg_get_string_msg(orig_container, item, msg,
925  values, 'contains'))
926 
927 
946  def should_contain(self, container, item, msg=None, values=True,
947  ignore_case=False):
948  orig_container = container
949  if is_truthy(ignore_case) and is_string(item):
950  item = item.lower()
951  if is_string(container):
952  container = container.lower()
953  elif is_list_like(container):
954  container = set(x.lower() if is_string(x) else x for x in container)
955  if item not in container:
956  raise AssertionError(self._get_string_msg_get_string_msg(orig_container, item, msg,
957  values, 'does not contain'))
958 
959 
981  def should_contain_any(self, container, *items, **configuration):
982  msg = configuration.pop('msg', None)
983  values = configuration.pop('values', True)
984  ignore_case = configuration.pop('ignore_case', False)
985  if configuration:
986  raise RuntimeError("Unsupported configuration parameter%s: %s."
987  % (s(configuration),
988  seq2str(sorted(configuration))))
989  if not items:
990  raise RuntimeError('One or more items required.')
991  orig_container = container
992  if is_truthy(ignore_case):
993  items = [x.lower() if is_string(x) else x for x in items]
994  if is_string(container):
995  container = container.lower()
996  elif is_list_like(container):
997  container = set(x.lower() if is_string(x) else x for x in container)
998  if not any(item in container for item in items):
999  msg = self._get_string_msg_get_string_msg(orig_container,
1000  seq2str(items, lastsep=' or '),
1001  msg, values,
1002  'does not contain any of',
1003  quote_item2=False)
1004  raise AssertionError(msg)
1005 
1006 
1028  def should_not_contain_any(self, container, *items, **configuration):
1029  msg = configuration.pop('msg', None)
1030  values = configuration.pop('values', True)
1031  ignore_case = configuration.pop('ignore_case', False)
1032  if configuration:
1033  raise RuntimeError("Unsupported configuration parameter%s: %s."
1034  % (s(configuration),
1035  seq2str(sorted(configuration))))
1036  if not items:
1037  raise RuntimeError('One or more items required.')
1038  orig_container = container
1039  if is_truthy(ignore_case):
1040  items = [x.lower() if is_string(x) else x for x in items]
1041  if is_string(container):
1042  container = container.lower()
1043  elif is_list_like(container):
1044  container = set(x.lower() if is_string(x) else x for x in container)
1045  if any(item in container for item in items):
1046  msg = self._get_string_msg_get_string_msg(orig_container,
1047  seq2str(items, lastsep=' or '),
1048  msg, values,
1049  'contains one or more of',
1050  quote_item2=False)
1051  raise AssertionError(msg)
1052 
1053 
1069  def should_contain_x_times(self, item1, item2, count, msg=None,
1070  ignore_case=False):
1071  # TODO: Rename 'item1' and 'item2' to 'container' and 'item' in RF 3.1.
1072  # Other 'contain' keywords use these names. And 'Get Count' should too.
1073  # Cannot be done in minor release due to backwards compatibility.
1074  # Remember to update it also in the docstring!!
1075  count = self._convert_to_integer(count)
1076  orig_item1 = item1
1077  if is_truthy(ignore_case) and is_string(item2):
1078  item2 = item2.lower()
1079  if is_string(item1):
1080  item1 = item1.lower()
1081  elif is_list_like(item1):
1082  item1 = [x.lower() if is_string(x) else x for x in item1]
1083  x = self.get_countget_count(item1, item2)
1084  if not msg:
1085  msg = "'%s' contains '%s' %d time%s, not %d time%s." \
1086  % (unic(orig_item1), unic(item2), x, s(x), count, s(count))
1087  self.should_be_equal_as_integersshould_be_equal_as_integers(x, count, msg, values=False)
1088 
1089 
1098  def get_count(self, item1, item2):
1099  if not hasattr(item1, 'count'):
1100  try:
1101  item1 = list(item1)
1102  except:
1103  raise RuntimeError("Converting '%s' to list failed: %s"
1104  % (item1, get_error_message()))
1105  count = item1.count(item2)
1106  self.log('Item found from the first item %d time%s' % (count, s(count)))
1107  return count
1108 
1109 
1119  def should_not_match(self, string, pattern, msg=None, values=True,
1120  ignore_case=False):
1121  if self._matches_matches(string, pattern, caseless=is_truthy(ignore_case)):
1122  raise AssertionError(self._get_string_msg_get_string_msg(string, pattern, msg,
1123  values, 'matches'))
1124 
1125 
1135  def should_match(self, string, pattern, msg=None, values=True,
1136  ignore_case=False):
1137  if not self._matches_matches(string, pattern, caseless=is_truthy(ignore_case)):
1138  raise AssertionError(self._get_string_msg_get_string_msg(string, pattern, msg,
1139  values, 'does not match'))
1140 
1141 
1177  def should_match_regexp(self, string, pattern, msg=None, values=True):
1178  res = re.search(pattern, string)
1179  if res is None:
1180  raise AssertionError(self._get_string_msg_get_string_msg(string, pattern, msg,
1181  values, 'does not match'))
1182  match = res.group(0)
1183  groups = res.groups()
1184  if groups:
1185  return [match] + list(groups)
1186  return match
1187 
1188 
1192  def should_not_match_regexp(self, string, pattern, msg=None, values=True):
1193  if re.search(pattern, string) is not None:
1194  raise AssertionError(self._get_string_msg_get_string_msg(string, pattern, msg,
1195  values, 'matches'))
1196 
1197 
1217  def get_length(self, item):
1218  length = self._get_length_get_length(item)
1219  self.log('Length is %d' % length)
1220  return length
1221 
1222  def _get_length(self, item):
1223  try:
1224  return len(item)
1225  except RERAISED_EXCEPTIONS:
1226  raise
1227  except:
1228  try:
1229  return item.length()
1230  except RERAISED_EXCEPTIONS:
1231  raise
1232  except:
1233  try:
1234  return item.size()
1235  except RERAISED_EXCEPTIONS:
1236  raise
1237  except:
1238  try:
1239  return item.length
1240  except RERAISED_EXCEPTIONS:
1241  raise
1242  except:
1243  raise RuntimeError("Could not get length of '%s'." % item)
1244 
1245 
1250  def length_should_be(self, item, length, msg=None):
1251  length = self._convert_to_integer(length)
1252  actual = self.get_lengthget_length(item)
1253  if actual != length:
1254  raise AssertionError(msg or "Length of '%s' should be %d but is %d."
1255  % (item, length, actual))
1256 
1257 
1262  def should_be_empty(self, item, msg=None):
1263  if self.get_lengthget_length(item) > 0:
1264  raise AssertionError(msg or "'%s' should be empty." % item)
1265 
1266 
1271  def should_not_be_empty(self, item, msg=None):
1272  if self.get_lengthget_length(item) == 0:
1273  raise AssertionError(msg or "'%s' should not be empty." % item)
1274 
1275  def _get_string_msg(self, item1, item2, custom_message, include_values,
1276  delimiter, quote_item1=True, quote_item2=True):
1277  if custom_message and not self._include_values_include_values(include_values):
1278  return custom_message
1279  item1 = "'%s'" % unic(item1) if quote_item1 else unic(item1)
1280  item2 = "'%s'" % unic(item2) if quote_item2 else unic(item2)
1281  default_message = '%s %s %s' % (item1, delimiter, item2)
1282  if not custom_message:
1283  return default_message
1284  return '%s: %s' % (custom_message, default_message)
1285 
1286 
1288 
1289 
1315  def get_variables(self, no_decoration=False):
1316  return self._variables_variables_variables.as_dict(decoration=is_falsy(no_decoration))
1317 
1318  @run_keyword_variant(resolve=0)
1319 
1336  def get_variable_value(self, name, default=None):
1337  try:
1338  return self._variables_variables_variables[self._get_var_name_get_var_name(name)]
1339  except DataError:
1340  return self._variables_variables_variables.replace_scalar(default)
1341 
1342 
1343  def log_variables(self, level='INFO'):
1344  variables = self.get_variablesget_variables()
1345  for name in sorted(variables, key=lambda s: s[2:-1].lower()):
1346  msg = format_assign_message(name, variables[name], cut_long=False)
1347  self.log(msg, level)
1348 
1349  @run_keyword_variant(resolve=0)
1350 
1360  def variable_should_exist(self, name, msg=None):
1361  name = self._get_var_name_get_var_name(name)
1362  msg = self._variables_variables_variables.replace_string(msg) if msg \
1363  else "Variable %s does not exist." % name
1364  try:
1365  self._variables_variables_variables[name]
1366  except DataError:
1367  raise AssertionError(msg)
1368 
1369  @run_keyword_variant(resolve=0)
1370 
1380  def variable_should_not_exist(self, name, msg=None):
1381  name = self._get_var_name_get_var_name(name)
1382  msg = self._variables_variables_variables.replace_string(msg) if msg \
1383  else "Variable %s exists." % name
1384  try:
1385  self._variables_variables_variables[name]
1386  except DataError:
1387  pass
1388  else:
1389  raise AssertionError(msg)
1390 
1391 
1407  def replace_variables(self, text):
1408  return self._variables_variables_variables.replace_scalar(text)
1409 
1410 
1429  def set_variable(self, *values):
1430  if len(values) == 0:
1431  return ''
1432  elif len(values) == 1:
1433  return values[0]
1434  else:
1435  return list(values)
1436 
1437  @run_keyword_variant(resolve=0)
1438 
1448  def set_test_variable(self, name, *values):
1449  name = self._get_var_name_get_var_name(name)
1450  value = self._get_var_value_get_var_value(name, values)
1451  self._variables_variables_variables.set_test(name, value)
1452  self._log_set_variable_log_set_variable(name, value)
1453 
1454  @run_keyword_variant(resolve=0)
1455 
1460  def set_task_variable(self, name, *values):
1461  self.set_test_variableset_test_variable(name, *values)
1462 
1463  @run_keyword_variant(resolve=0)
1464 
1515  def set_suite_variable(self, name, *values):
1516  name = self._get_var_name_get_var_name(name)
1517  if (values and is_string(values[-1]) and
1518  values[-1].startswith('children=')):
1519  children = self._variables_variables_variables.replace_scalar(values[-1][9:])
1520  children = is_truthy(children)
1521  values = values[:-1]
1522  else:
1523  children = False
1524  value = self._get_var_value_get_var_value(name, values)
1525  self._variables_variables_variables.set_suite(name, value, children=children)
1526  self._log_set_variable_log_set_variable(name, value)
1527 
1528  @run_keyword_variant(resolve=0)
1529 
1545  def set_global_variable(self, name, *values):
1546  name = self._get_var_name_get_var_name(name)
1547  value = self._get_var_value_get_var_value(name, values)
1548  self._variables_variables_variables.set_global(name, value)
1549  self._log_set_variable_log_set_variable(name, value)
1550 
1551  # Helpers
1552 
1553  def _get_var_name(self, orig):
1554  name = self._resolve_possible_variable_resolve_possible_variable(orig)
1555  try:
1556  return self._unescape_variable_if_needed_unescape_variable_if_needed(name)
1557  except ValueError:
1558  raise RuntimeError("Invalid variable syntax '%s'." % orig)
1559 
1561  try:
1562  resolved = self._variables_variables_variables.replace_string(name)
1563  return self._unescape_variable_if_needed_unescape_variable_if_needed(resolved)
1564  except (KeyError, ValueError, DataError):
1565  return name
1566 
1568  if name.startswith('\\'):
1569  name = name[1:]
1570  if len(name) < 2:
1571  raise ValueError
1572  if name[0] in '$@&' and name[1] != '{':
1573  name = '%s{%s}' % (name[0], name[1:])
1574  if is_var(name):
1575  return name
1576  # Support for possible internal variables (issue 397)
1577  name = '%s{%s}' % (name[0], self.replace_variablesreplace_variables(name[2:-1]))
1578  if is_var(name):
1579  return name
1580  raise ValueError
1581 
1582  def _get_var_value(self, name, values):
1583  if not values:
1584  return self._variables_variables_variables[name]
1585  if name[0] == '$':
1586  # We could consider catenating values similarly as when creating
1587  # scalar variables in the variable table, but that would require
1588  # handling non-string values somehow. For details see
1589  # https://github.com/robotframework/robotframework/issues/1919
1590  if len(values) != 1 or VariableSplitter(values[0]).is_list_variable():
1591  raise DataError("Setting list value to scalar variable '%s' "
1592  "is not supported anymore. Create list "
1593  "variable '@%s' instead." % (name, name[1:]))
1594  return self._variables_variables_variables.replace_scalar(values[0])
1595  return VariableTableValue(values, name).resolve(self._variables_variables_variables)
1596 
1597  def _log_set_variable(self, name, value):
1598  self.log(format_assign_message(name, value))
1599 
1600 
1602 
1603  # If you use any of these run keyword variants from another library, you
1604  # should register those keywords with 'register_run_keyword' method. See
1605  # the documentation of that method at the end of this file. There are also
1606  # other run keyword variant keywords in BuiltIn which can also be seen
1607  # at the end of this file.
1608 
1609  @run_keyword_variant(resolve=1)
1610 
1616  def run_keyword(self, name, *args):
1617  if not is_string(name):
1618  raise RuntimeError('Keyword name must be a string.')
1619  kw = Keyword(name, args=args)
1620  return kw.run(self._context_context_context)
1621 
1622  @run_keyword_variant(resolve=0)
1623 
1653  def run_keywords(self, *keywords):
1654  self._run_keywords_run_keywords(self._split_run_keywords_split_run_keywords(list(keywords)))
1655 
1656  def _run_keywords(self, iterable):
1657  errors = []
1658  for kw, args in iterable:
1659  try:
1660  self.run_keywordrun_keyword(kw, *args)
1661  except ExecutionPassed as err:
1662  err.set_earlier_failures(errors)
1663  raise err
1664  except ExecutionFailed as err:
1665  errors.extend(err.get_errors())
1666  if not err.can_continue(self._context_context_context.in_teardown):
1667  break
1668  if errors:
1669  raise ExecutionFailures(errors)
1670 
1671  def _split_run_keywords(self, keywords):
1672  if 'AND' not in keywords:
1673  for name in self._variables_variables_variables.replace_list(keywords):
1674  yield name, ()
1675  else:
1676  for name, args in self._split_run_keywords_from_and_split_run_keywords_from_and(keywords):
1677  yield name, args
1678 
1679  def _split_run_keywords_from_and(self, keywords):
1680  while 'AND' in keywords:
1681  index = keywords.index('AND')
1682  yield self._resolve_run_keywords_name_and_args_resolve_run_keywords_name_and_args(keywords[:index])
1683  keywords = keywords[index+1:]
1684  yield self._resolve_run_keywords_name_and_args_resolve_run_keywords_name_and_args(keywords)
1685 
1687  kw_call = self._variables_variables_variables.replace_list(kw_call, replace_until=1)
1688  if not kw_call:
1689  raise DataError('Incorrect use of AND')
1690  return kw_call[0], kw_call[1:]
1691 
1692  @run_keyword_variant(resolve=2)
1693 
1761  def run_keyword_if(self, condition, name, *args):
1762  args, branch = self._split_elif_or_else_branch_split_elif_or_else_branch(args)
1763  if self._is_true_is_true(condition):
1764  return self.run_keywordrun_keyword(name, *args)
1765  return branch()
1766 
1768  if 'ELSE IF' in args:
1769  args, branch = self._split_branch_split_branch(args, 'ELSE IF', 2,
1770  'condition and keyword')
1771  return args, lambda: self.run_keyword_ifrun_keyword_if(*branch)
1772  if 'ELSE' in args:
1773  args, branch = self._split_branch_split_branch(args, 'ELSE', 1, 'keyword')
1774  return args, lambda: self.run_keywordrun_keyword(*branch)
1775  return args, lambda: None
1776 
1777  def _split_branch(self, args, control_word, required, required_error):
1778  index = list(args).index(control_word)
1779  branch = self._variables_variables_variables.replace_list(args[index+1:], required)
1780  if len(branch) < required:
1781  raise DataError('%s requires %s.' % (control_word, required_error))
1782  return args[:index], branch
1783 
1784  @run_keyword_variant(resolve=2)
1785 
1791  def run_keyword_unless(self, condition, name, *args):
1792  if not self._is_true_is_true(condition):
1793  return self.run_keywordrun_keyword(name, *args)
1794 
1795  @run_keyword_variant(resolve=1)
1796 
1811  def run_keyword_and_ignore_error(self, name, *args):
1812  try:
1813  return 'PASS', self.run_keywordrun_keyword(name, *args)
1814  except ExecutionFailed as err:
1815  if err.dont_continue:
1816  raise
1817  return 'FAIL', unic(err)
1818 
1819  @run_keyword_variant(resolve=1)
1820 
1836  def run_keyword_and_return_status(self, name, *args):
1837  status, _ = self.run_keyword_and_ignore_errorrun_keyword_and_ignore_error(name, *args)
1838  return status == 'PASS'
1839 
1840  @run_keyword_variant(resolve=1)
1841 
1853  def run_keyword_and_continue_on_failure(self, name, *args):
1854  try:
1855  return self.run_keywordrun_keyword(name, *args)
1856  except ExecutionFailed as err:
1857  if not err.dont_continue:
1858  err.continue_on_failure = True
1859  raise err
1860 
1861  @run_keyword_variant(resolve=2)
1862 
1902  def run_keyword_and_expect_error(self, expected_error, name, *args):
1903  try:
1904  self.run_keywordrun_keyword(name, *args)
1905  except ExecutionFailed as err:
1906  if err.dont_continue:
1907  raise
1908  error = err.message
1909  else:
1910  raise AssertionError("Expected error '%s' did not occur."
1911  % expected_error)
1912  if not self._error_is_expected_error_is_expected(error, expected_error):
1913  raise AssertionError("Expected error '%s' but got '%s'."
1914  % (expected_error, error))
1915  return error
1916 
1917  def _error_is_expected(self, error, expected_error):
1918  glob = self._matches_matches
1919  matchers = {'GLOB': glob,
1920  'EQUALS': lambda s, p: s == p,
1921  'STARTS': lambda s, p: s.startswith(p),
1922  'REGEXP': lambda s, p: re.match(p, s) is not None}
1923  prefixes = tuple(prefix + ':' for prefix in matchers)
1924  if not expected_error.startswith(prefixes):
1925  return glob(error, expected_error)
1926  prefix, expected_error = expected_error.split(':', 1)
1927  return matchers[prefix](error, expected_error.lstrip())
1928 
1929  @run_keyword_variant(resolve=2)
1930 
1957  def repeat_keyword(self, repeat, name, *args):
1958  try:
1959  count = self._get_repeat_count_get_repeat_count(repeat)
1960  except RuntimeError as err:
1961  timeout = self._get_repeat_timeout_get_repeat_timeout(repeat)
1962  if timeout is None:
1963  raise err
1964  keywords = self._keywords_repeated_by_timeout_keywords_repeated_by_timeout(timeout, name, args)
1965  else:
1966  keywords = self._keywords_repeated_by_count_keywords_repeated_by_count(count, name, args)
1967  self._run_keywords_run_keywords(keywords)
1968 
1969  def _get_repeat_count(self, times, require_postfix=False):
1970  times = normalize(str(times))
1971  if times.endswith('times'):
1972  times = times[:-5]
1973  elif times.endswith('x'):
1974  times = times[:-1]
1975  elif require_postfix:
1976  raise ValueError
1977  return self._convert_to_integer(times)
1978 
1979  def _get_repeat_timeout(self, timestr):
1980  try:
1981  float(timestr)
1982  except ValueError:
1983  pass
1984  else:
1985  return None
1986  try:
1987  return timestr_to_secs(timestr)
1988  except ValueError:
1989  return None
1990 
1991  def _keywords_repeated_by_count(self, count, name, args):
1992  if count <= 0:
1993  self.log("Keyword '%s' repeated zero times." % name)
1994  for i in range(count):
1995  self.log("Repeating keyword, round %d/%d." % (i + 1, count))
1996  yield name, args
1997 
1998  def _keywords_repeated_by_timeout(self, timeout, name, args):
1999  if timeout <= 0:
2000  self.log("Keyword '%s' repeated zero times." % name)
2001  repeat_round = 0
2002  maxtime = time.time() + timeout
2003  while time.time() < maxtime:
2004  repeat_round += 1
2005  self.log("Repeating keyword, round %d, %s remaining."
2006  % (repeat_round,
2007  secs_to_timestr(maxtime - time.time(), compact=True)))
2008  yield name, args
2009 
2010  @run_keyword_variant(resolve=3)
2011 
2046  def wait_until_keyword_succeeds(self, retry, retry_interval, name, *args):
2047  maxtime = count = -1
2048  try:
2049  count = self._get_repeat_count_get_repeat_count(retry, require_postfix=True)
2050  except ValueError:
2051  timeout = timestr_to_secs(retry)
2052  maxtime = time.time() + timeout
2053  message = 'for %s' % secs_to_timestr(timeout)
2054  else:
2055  if count <= 0:
2056  raise ValueError('Retry count %d is not positive.' % count)
2057  message = '%d time%s' % (count, s(count))
2058  retry_interval = timestr_to_secs(retry_interval)
2059  while True:
2060  try:
2061  return self.run_keywordrun_keyword(name, *args)
2062  except ExecutionFailed as err:
2063  if err.dont_continue:
2064  raise
2065  count -= 1
2066  if time.time() > maxtime > 0 or count == 0:
2067  raise AssertionError("Keyword '%s' failed after retrying "
2068  "%s. The last error was: %s"
2069  % (name, message, err))
2070  self._sleep_in_parts(retry_interval)
2071 
2072  @run_keyword_variant(resolve=1)
2073 
2111  def set_variable_if(self, condition, *values):
2112  values = self._verify_values_for_set_variable_if_verify_values_for_set_variable_if(list(values))
2113  if self._is_true_is_true(condition):
2114  return self._variables_variables_variables.replace_scalar(values[0])
2115  values = self._verify_values_for_set_variable_if_verify_values_for_set_variable_if(values[1:], True)
2116  if len(values) == 1:
2117  return self._variables_variables_variables.replace_scalar(values[0])
2118  return self.run_keywordrun_keyword('BuiltIn.Set Variable If', *values[0:])
2119 
2120  def _verify_values_for_set_variable_if(self, values, default=False):
2121  if not values:
2122  if default:
2123  return [None]
2124  raise RuntimeError('At least one value is required')
2125  if is_list_var(values[0]):
2126  values[:1] = [escape(item) for item in self._variables_variables_variables[values[0]]]
2127  return self._verify_values_for_set_variable_if_verify_values_for_set_variable_if(values)
2128  return values
2129 
2130  @run_keyword_variant(resolve=1)
2131 
2142  def run_keyword_if_test_failed(self, name, *args):
2143  test = self._get_test_in_teardown_get_test_in_teardown('Run Keyword If Test Failed')
2144  if not test.passed:
2145  return self.run_keywordrun_keyword(name, *args)
2146 
2147  @run_keyword_variant(resolve=1)
2148 
2159  def run_keyword_if_test_passed(self, name, *args):
2160  test = self._get_test_in_teardown_get_test_in_teardown('Run Keyword If Test Passed')
2161  if test.passed:
2162  return self.run_keywordrun_keyword(name, *args)
2163 
2164  @run_keyword_variant(resolve=1)
2165 
2173  def run_keyword_if_timeout_occurred(self, name, *args):
2174  self._get_test_in_teardown_get_test_in_teardown('Run Keyword If Timeout Occurred')
2175  if self._context_context_context.timeout_occurred:
2176  return self.run_keywordrun_keyword(name, *args)
2177 
2178  def _get_test_in_teardown(self, kwname):
2179  ctx = self._context_context_context
2180  if ctx.test and ctx.in_test_teardown:
2181  return ctx.test
2182  raise RuntimeError("Keyword '%s' can only be used in test teardown."
2183  % kwname)
2184 
2185  @run_keyword_variant(resolve=1)
2186 
2195  suite = self._get_suite_in_teardown_get_suite_in_teardown('Run Keyword If '
2196  'All Critical Tests Passed')
2197  if suite.statistics.critical.failed == 0:
2198  return self.run_keywordrun_keyword(name, *args)
2199 
2200  @run_keyword_variant(resolve=1)
2201 
2210  suite = self._get_suite_in_teardown_get_suite_in_teardown('Run Keyword If '
2211  'Any Critical Tests Failed')
2212  if suite.statistics.critical.failed > 0:
2213  return self.run_keywordrun_keyword(name, *args)
2214 
2215  @run_keyword_variant(resolve=1)
2216 
2224  def run_keyword_if_all_tests_passed(self, name, *args):
2225  suite = self._get_suite_in_teardown_get_suite_in_teardown('Run Keyword If All Tests Passed')
2226  if suite.statistics.all.failed == 0:
2227  return self.run_keywordrun_keyword(name, *args)
2228 
2229  @run_keyword_variant(resolve=1)
2230 
2238  def run_keyword_if_any_tests_failed(self, name, *args):
2239  suite = self._get_suite_in_teardown_get_suite_in_teardown('Run Keyword If Any Tests Failed')
2240  if suite.statistics.all.failed > 0:
2241  return self.run_keywordrun_keyword(name, *args)
2242 
2243  def _get_suite_in_teardown(self, kwname):
2244  if not self._context_context_context.in_suite_teardown:
2245  raise RuntimeError("Keyword '%s' can only be used in suite teardown."
2246  % kwname)
2247  return self._context_context_context.suite
2248 
2249 
2251 
2252 
2267  self.log("Continuing for loop from the next iteration.")
2268  raise ContinueForLoop()
2269 
2270 
2281  def continue_for_loop_if(self, condition):
2282  if self._is_true_is_true(condition):
2283  self.continue_for_loopcontinue_for_loop()
2284 
2285 
2298  def exit_for_loop(self):
2299  self.log("Exiting for loop altogether.")
2300  raise ExitForLoop()
2301 
2302 
2313  def exit_for_loop_if(self, condition):
2314  if self._is_true_is_true(condition):
2315  self.exit_for_loopexit_for_loop()
2316 
2317  @run_keyword_variant(resolve=0)
2318 
2361  def return_from_keyword(self, *return_values):
2362  self._return_from_keyword_return_from_keyword(return_values)
2363 
2364  def _return_from_keyword(self, return_values=None, failures=None):
2365  self.log('Returning from the enclosing user keyword.')
2366  raise ReturnFromKeyword(return_values, failures)
2367 
2368  @run_keyword_variant(resolve=1)
2369 
2389  def return_from_keyword_if(self, condition, *return_values):
2390  if self._is_true_is_true(condition):
2391  self._return_from_keyword_return_from_keyword(return_values)
2392 
2393  @run_keyword_variant(resolve=1)
2394 
2411  def run_keyword_and_return(self, name, *args):
2412  try:
2413  ret = self.run_keyword(name, *args)
2414  except ExecutionFailed as err:
2415  self._return_from_keyword_return_from_keyword(failures=[err])
2416  else:
2417  self._return_from_keyword_return_from_keyword(return_values=[escape(ret)])
2418 
2419  @run_keyword_variant(resolve=2)
2420 
2434  def run_keyword_and_return_if(self, condition, name, *args):
2435  if self._is_true_is_true(condition):
2436  self.run_keyword_and_returnrun_keyword_and_return(name, *args)
2437 
2438 
2480  def pass_execution(self, message, *tags):
2481  message = message.strip()
2482  if not message:
2483  raise RuntimeError('Message cannot be empty.')
2484  self._set_and_remove_tags(tags)
2485  log_message, level = self._get_logged_test_message_and_level(message)
2486  self.log('Execution passed with message:\n%s' % log_message, level)
2487  raise PassExecution(message)
2488 
2489  @run_keyword_variant(resolve=1)
2490 
2502  def pass_execution_if(self, condition, message, *tags):
2503  if self._is_true_is_true(condition):
2504  message = self._variables_variables_variables.replace_string(message)
2505  tags = self._variables_variables_variables.replace_list(tags)
2506  self.pass_executionpass_execution(message, *tags)
2507 
2508 
2510 
2511 
2512  def no_operation(self):
2513 
2514 
2528  def sleep(self, time_, reason=None):
2529  seconds = timestr_to_secs(time_)
2530  # Python hangs with negative values
2531  if seconds < 0:
2532  seconds = 0
2533  self._sleep_in_parts_sleep_in_parts(seconds)
2534  self.loglog('Slept %s' % secs_to_timestr(seconds))
2535  if reason:
2536  self.loglog(reason)
2537 
2538  def _sleep_in_parts(self, seconds):
2539  # time.sleep can't be stopped in windows
2540  # to ensure that we can signal stop (with timeout)
2541  # split sleeping to small pieces
2542  endtime = time.time() + float(seconds)
2543  while True:
2544  remaining = endtime - time.time()
2545  if remaining <= 0:
2546  break
2547  time.sleep(min(remaining, 0.01))
2548 
2549 
2564  def catenate(self, *items):
2565  if not items:
2566  return ''
2567  items = [unic(item) for item in items]
2568  if items[0].startswith('SEPARATOR='):
2569  sep = items[0][len('SEPARATOR='):]
2570  items = items[1:]
2571  else:
2572  sep = ' '
2573  return sep.join(items)
2574 
2575 
2625  def log(self, message, level='INFO', html=False, console=False,
2626  repr=False, formatter='str'):
2627  # TODO: Deprecate `repr` in RF 3.2 or latest in RF 3.3.
2628  if is_truthy(repr):
2629  formatter = prepr
2630  else:
2631  formatter = self._get_formatter_get_formatter(formatter)
2632  message = formatter(message)
2633  logger.write(message, level, is_truthy(html))
2634  if is_truthy(console):
2635  logger.console(message)
2636 
2637  def _get_formatter(self, formatter):
2638  try:
2639  return {'str': unic,
2640  'repr': prepr,
2641  'ascii': ascii if PY3 else repr}[formatter.lower()]
2642  except KeyError:
2643  raise ValueError("Invalid formatter '%s'. Available "
2644  "'str', 'repr' and 'ascii'." % formatter)
2645 
2646  @run_keyword_variant(resolve=0)
2647 
2658  def log_many(self, *messages):
2659  for msg in self._yield_logged_messages_yield_logged_messages(messages):
2660  self.loglog(msg)
2661 
2662  def _yield_logged_messages(self, messages):
2663  for msg in messages:
2664  var = VariableSplitter(msg)
2665  value = self._variables_variables_variables.replace_scalar(msg)
2666  if var.is_list_variable():
2667  for item in value:
2668  yield item
2669  elif var.is_dict_variable():
2670  for name, value in value.items():
2671  yield '%s=%s' % (name, value)
2672  else:
2673  yield value
2674 
2675 
2694  def log_to_console(self, message, stream='STDOUT', no_newline=False):
2695  logger.console(message, newline=is_falsy(no_newline), stream=stream)
2696 
2697  @run_keyword_variant(resolve=0)
2698 
2706  def comment(self, *messages):
2707  pass
2708 
2709 
2718  def set_log_level(self, level):
2719  try:
2720  old = self._context_context_context.output.set_log_level(level)
2721  except DataError as err:
2722  raise RuntimeError(unic(err))
2723  self._namespace_namespace_namespace.variables.set_global('${LOG_LEVEL}', level.upper())
2724  self.loglog('Log level changed from %s to %s.' % (old, level.upper()))
2725  return old
2726 
2727 
2738  def reload_library(self, name_or_instance):
2739  library = self._namespace_namespace_namespace.reload_library(name_or_instance)
2740  self.loglog('Reloaded library %s with %s keywords.' % (library.name,
2741  len(library)))
2742 
2743  @run_keyword_variant(resolve=0)
2744 
2768  def import_library(self, name, *args):
2769  try:
2770  self._namespace_namespace_namespace.import_library(name, list(args))
2771  except DataError as err:
2772  raise RuntimeError(unic(err))
2773 
2774  @run_keyword_variant(resolve=0)
2775 
2793  def import_variables(self, path, *args):
2794  try:
2795  self._namespace_namespace_namespace.import_variables(path, list(args), overwrite=True)
2796  except DataError as err:
2797  raise RuntimeError(unic(err))
2798 
2799  @run_keyword_variant(resolve=0)
2800 
2816  def import_resource(self, path):
2817  try:
2818  self._namespace_namespace_namespace.import_resource(path)
2819  except DataError as err:
2820  raise RuntimeError(unic(err))
2821 
2822 
2860  def set_library_search_order(self, *search_order):
2861  return self._namespace_namespace_namespace.set_search_order(search_order)
2862 
2863 
2873  def keyword_should_exist(self, name, msg=None):
2874  try:
2875  runner = self._namespace_namespace_namespace.get_runner(name)
2876  except DataError as error:
2877  raise AssertionError(msg or error.message)
2878  if isinstance(runner, UserErrorHandler):
2879  raise AssertionError(msg or runner.error.message)
2880 
2881 
2961  def get_time(self, format='timestamp', time_='NOW'):
2962  return get_time(format, parse_time(time_))
2963 
2964 
2994  def evaluate(self, expression, modules=None, namespace=None):
2995  if is_string(expression) and '$' in expression:
2996  expression, variables = self._handle_variables_in_expression_handle_variables_in_expression(expression)
2997  else:
2998  variables = {}
2999  namespace = self._create_evaluation_namespace_create_evaluation_namespace(namespace, modules)
3000  try:
3001  if not is_string(expression):
3002  raise TypeError("Expression must be string, got %s."
3003  % type_name(expression))
3004  if not expression:
3005  raise ValueError("Expression cannot be empty.")
3006  return eval(expression, namespace, variables)
3007  except:
3008  raise RuntimeError("Evaluating expression '%s' failed: %s"
3009  % (expression, get_error_message()))
3010 
3011  def _handle_variables_in_expression(self, expression):
3012  variables = None
3013  variable_started = False
3014  tokens = []
3015  generated = generate_tokens(StringIO(expression).readline)
3016  for toknum, tokval, _, _, _ in generated:
3017  if variable_started:
3018  if toknum == token.NAME:
3019  if variables is None:
3020  variables = self._variables_variables_variables.as_dict(decoration=False)
3021  if tokval not in variables:
3022  variable_not_found('$%s' % tokval, variables,
3023  deco_braces=False)
3024  tokval = 'RF_VAR_' + tokval
3025  else:
3026  tokens.append((token.ERRORTOKEN, '$'))
3027  variable_started = False
3028  if toknum == token.ERRORTOKEN and tokval == '$':
3029  variable_started = True
3030  else:
3031  tokens.append((toknum, tokval))
3032  if variables is None:
3033  return expression, {}
3034  decorated = [('RF_VAR_' + name, variables[name]) for name in variables]
3035  return untokenize(tokens).strip(), NormalizedDict(decorated, ignore='_')
3036 
3037  def _create_evaluation_namespace(self, namespace, modules):
3038  namespace = dict(namespace or {})
3039  modules = modules.replace(' ', '').split(',') if modules else []
3040  namespace.update((m, __import__(m)) for m in modules if m)
3041  return namespace
3042 
3043 
3063  def call_method(self, object, method_name, *args, **kwargs):
3064  try:
3065  method = getattr(object, method_name)
3066  except AttributeError:
3067  raise RuntimeError("Object '%s' does not have method '%s'."
3068  % (object, method_name))
3069  try:
3070  return method(*args, **kwargs)
3071  except:
3072  raise RuntimeError("Calling method '%s' failed: %s"
3073  % (method_name, get_error_message()))
3074 
3075 
3086  def regexp_escape(self, *patterns):
3087  if len(patterns) == 0:
3088  return ''
3089  if len(patterns) == 1:
3090  return re.escape(patterns[0])
3091  return [re.escape(p) for p in patterns]
3092 
3093 
3115  def set_test_message(self, message, append=False):
3116  test = self._context_context_context.test
3117  if not test:
3118  raise RuntimeError("'Set Test Message' keyword cannot be used in "
3119  "suite setup or teardown.")
3120  test.message = self._get_new_text_get_new_text(test.message, message,
3121  append, handle_html=True)
3122  if self._context_context_context.in_test_teardown:
3123  self._variables_variables_variables.set_test("${TEST_MESSAGE}", test.message)
3124  message, level = self._get_logged_test_message_and_level_get_logged_test_message_and_level(test.message)
3125  self.loglog('Set test message to:\n%s' % message, level)
3126 
3127  def _get_new_text(self, old, new, append, handle_html=False):
3128  if not is_unicode(new):
3129  new = unic(new)
3130  if not (is_truthy(append) and old):
3131  return new
3132  if handle_html:
3133  if new.startswith('*HTML*'):
3134  new = new[6:].lstrip()
3135  if not old.startswith('*HTML*'):
3136  old = '*HTML* %s' % html_escape(old)
3137  elif old.startswith('*HTML*'):
3138  new = html_escape(new)
3139  return '%s %s' % (old, new)
3140 
3142  if message.startswith('*HTML*'):
3143  return message[6:].lstrip(), 'HTML'
3144  return message, 'INFO'
3145 
3146 
3156  def set_test_documentation(self, doc, append=False):
3157  test = self._context_context_context.test
3158  if not test:
3159  raise RuntimeError("'Set Test Documentation' keyword cannot be "
3160  "used in suite setup or teardown.")
3161  test.doc = self._get_new_text_get_new_text(test.doc, doc, append)
3162  self._variables_variables_variables.set_test('${TEST_DOCUMENTATION}', test.doc)
3163  self.loglog('Set test documentation to:\n%s' % test.doc)
3164 
3165 
3179  def set_suite_documentation(self, doc, append=False, top=False):
3180  top = is_truthy(top)
3181  suite = self._get_context_get_context(top).suite
3182  suite.doc = self._get_new_text_get_new_text(suite.doc, doc, append)
3183  self._variables_variables_variables.set_suite('${SUITE_DOCUMENTATION}', suite.doc, top)
3184  self.loglog('Set suite documentation to:\n%s' % suite.doc)
3185 
3186 
3200  def set_suite_metadata(self, name, value, append=False, top=False):
3201  top = is_truthy(top)
3202  if not is_unicode(name):
3203  name = unic(name)
3204  metadata = self._get_context_get_context(top).suite.metadata
3205  original = metadata.get(name, '')
3206  metadata[name] = self._get_new_text_get_new_text(original, value, append)
3207  self._variables_variables_variables.set_suite('${SUITE_METADATA}', metadata.copy(), top)
3208  self.loglog("Set suite metadata '%s' to value '%s'." % (name, metadata[name]))
3209 
3210 
3224  def set_tags(self, *tags):
3225  ctx = self._context_context_context
3226  if ctx.test:
3227  ctx.test.tags.add(tags)
3228  ctx.variables.set_test('@{TEST_TAGS}', list(ctx.test.tags))
3229  elif not ctx.in_suite_teardown:
3230  ctx.suite.set_tags(tags, persist=True)
3231  else:
3232  raise RuntimeError("'Set Tags' cannot be used in suite teardown.")
3233  self.loglog('Set tag%s %s.' % (s(tags), seq2str(tags)))
3234 
3235 
3252  def remove_tags(self, *tags):
3253  ctx = self._context_context_context
3254  if ctx.test:
3255  ctx.test.tags.remove(tags)
3256  ctx.variables.set_test('@{TEST_TAGS}', list(ctx.test.tags))
3257  elif not ctx.in_suite_teardown:
3258  ctx.suite.set_tags(remove=tags, persist=True)
3259  else:
3260  raise RuntimeError("'Remove Tags' cannot be used in suite teardown.")
3261  self.loglog('Removed tag%s %s.' % (s(tags), seq2str(tags)))
3262 
3263 
3290  def get_library_instance(self, name=None, all=False):
3291  if is_truthy(all):
3292  return self._namespace_namespace_namespace.get_library_instances()
3293  try:
3294  return self._namespace_namespace_namespace.get_library_instance(name)
3295  except DataError as err:
3296  raise RuntimeError(unic(err))
3297 
3298 
3299 
3552  ROBOT_LIBRARY_SCOPE = 'GLOBAL'
3553  ROBOT_LIBRARY_VERSION = get_version()
3554 
3555 
3556 
3563  pass
3564 
3565 
3566 
3626 def register_run_keyword(library, keyword, args_to_process=None,
3627  deprecation_warning=True):
3628  RUN_KW_REGISTER.register_run_keyword(library, keyword, args_to_process,
3629  deprecation_warning)
Used by 'Continue For Loop' keyword.
Definition: errors.py:307
Used when variable does not exist.
Definition: errors.py:67
Used by 'Return From Keyword' keyword.
Definition: errors.py:311
Used by 'Pass Execution' keyword.
Definition: errors.py:300
An always available standard library with often needed keywords.
Definition: BuiltIn.py:3551
Used when something cannot be done because Robot is not running.
Definition: BuiltIn.py:3562
def _matches(self, string, pattern, caseless=False)
Definition: BuiltIn.py:83
def _log_types_at_level(self, level, *args)
Definition: BuiltIn.py:96
def continue_for_loop(self)
Skips the current for loop iteration and continues from the next.
Definition: BuiltIn.py:2266
def exit_for_loop(self)
Stops executing the enclosing for loop.
Definition: BuiltIn.py:2298
def _return_from_keyword(self, return_values=None, failures=None)
Definition: BuiltIn.py:2364
def continue_for_loop_if(self, condition)
Skips the current for loop iteration if the condition is true.
Definition: BuiltIn.py:2281
def exit_for_loop_if(self, condition)
Stops executing the enclosing for loop if the condition is true.
Definition: BuiltIn.py:2313
def pass_execution(self, message, *tags)
Skips rest of the current test, setup, or teardown with PASS status.
Definition: BuiltIn.py:2480
def return_from_keyword_if(self, condition, *return_values)
Returns from the enclosing user keyword if condition is true.
Definition: BuiltIn.py:2389
def run_keyword_and_return_if(self, condition, name, *args)
Runs the specified keyword and returns from the enclosing user keyword.
Definition: BuiltIn.py:2434
def run_keyword_and_return(self, name, *args)
Runs the specified keyword and returns from the enclosing user keyword.
Definition: BuiltIn.py:2411
def return_from_keyword(self, *return_values)
Returns from the enclosing user keyword.
Definition: BuiltIn.py:2361
def pass_execution_if(self, condition, message, *tags)
Conditionally skips rest of the current test, setup, or teardown with PASS status.
Definition: BuiltIn.py:2502
def create_dictionary(self, *items)
Creates and returns a dictionary based on the given items.
Definition: BuiltIn.py:486
def convert_to_hex(self, item, base=None, prefix=None, length=None, lowercase=False)
Converts the given item to a hexadecimal string.
Definition: BuiltIn.py:240
def convert_to_number(self, item, precision=None)
Converts the given item to a floating point number.
Definition: BuiltIn.py:284
def convert_to_bytes(self, input, input_type='text')
Converts the given input to bytes according to the input_type.
Definition: BuiltIn.py:384
def convert_to_binary(self, item, base=None, prefix=None, length=None)
Converts the given item to a binary string.
Definition: BuiltIn.py:191
def _convert_to_bin_oct_hex(self, item, base, prefix, length, format_spec)
Definition: BuiltIn.py:244
def convert_to_boolean(self, item)
Converts the given item to Boolean true or false.
Definition: BuiltIn.py:332
def convert_to_integer(self, item, base=None)
Converts the given item to an integer number.
Definition: BuiltIn.py:134
def create_list(self, *items)
Returns a list containing given items.
Definition: BuiltIn.py:445
def _input_to_tokens(self, input, length)
Definition: BuiltIn.py:427
def convert_to_string(self, item)
Converts the given item to a Unicode string.
Definition: BuiltIn.py:318
def _convert_to_integer(self, orig, base=None)
Definition: BuiltIn.py:138
def _test_ordinal(self, ordinal, original, type)
Definition: BuiltIn.py:402
def convert_to_octal(self, item, base=None, prefix=None, length=None)
Converts the given item to an octal string.
Definition: BuiltIn.py:213
def _convert_to_number(self, item, precision=None)
Definition: BuiltIn.py:288
def comment(self, *messages)
Displays the given messages in the log file as keyword arguments.
Definition: BuiltIn.py:2706
def catenate(self, *items)
Catenates the given items together and returns the resulted string.
Definition: BuiltIn.py:2564
def import_variables(self, path, *args)
Imports a variable file with the given path and optional arguments.
Definition: BuiltIn.py:2793
def call_method(self, object, method_name, *args, **kwargs)
Calls the named method of the given object with the provided arguments.
Definition: BuiltIn.py:3063
def _get_new_text(self, old, new, append, handle_html=False)
Definition: BuiltIn.py:3127
def regexp_escape(self, *patterns)
Returns each argument string escaped for use as a regular expression.
Definition: BuiltIn.py:3086
def import_library(self, name, *args)
Imports a library with the given name and optional arguments.
Definition: BuiltIn.py:2768
def set_test_documentation(self, doc, append=False)
Sets documentation for the current test case.
Definition: BuiltIn.py:3156
def _get_logged_test_message_and_level(self, message)
Definition: BuiltIn.py:3141
def set_suite_metadata(self, name, value, append=False, top=False)
Sets metadata for the current test suite.
Definition: BuiltIn.py:3200
def import_resource(self, path)
Imports a resource file with the given path.
Definition: BuiltIn.py:2816
def _create_evaluation_namespace(self, namespace, modules)
Definition: BuiltIn.py:3037
def set_log_level(self, level)
Sets the log threshold to the specified level and returns the old level.
Definition: BuiltIn.py:2718
def reload_library(self, name_or_instance)
Rechecks what keywords the specified library provides.
Definition: BuiltIn.py:2738
def evaluate(self, expression, modules=None, namespace=None)
Evaluates the given expression in Python and returns the results.
Definition: BuiltIn.py:2994
def log_to_console(self, message, stream='STDOUT', no_newline=False)
Logs the given message to the console.
Definition: BuiltIn.py:2694
def log(self, message, level='INFO', html=False, console=False, repr=False, formatter='str')
Logs the given message with the given level.
Definition: BuiltIn.py:2626
def set_library_search_order(self, *search_order)
Sets the resolution order to use when a name matches multiple keywords.
Definition: BuiltIn.py:2860
def _yield_logged_messages(self, messages)
Definition: BuiltIn.py:2662
def sleep(self, time_, reason=None)
Pauses the test executed for the given time.
Definition: BuiltIn.py:2528
def _handle_variables_in_expression(self, expression)
Definition: BuiltIn.py:3011
def log_many(self, *messages)
Logs the given messages as separate entries using the INFO level.
Definition: BuiltIn.py:2658
def set_tags(self, *tags)
Adds given tags for the current test or all tests in a suite.
Definition: BuiltIn.py:3224
def remove_tags(self, *tags)
Removes given tags from the current test or all tests in a suite.
Definition: BuiltIn.py:3252
def set_test_message(self, message, append=False)
Sets message for the current test case.
Definition: BuiltIn.py:3115
def get_time(self, format='timestamp', time_='NOW')
Returns the given time in the requested format.
Definition: BuiltIn.py:2961
def keyword_should_exist(self, name, msg=None)
Fails unless the given keyword exists in the current scope.
Definition: BuiltIn.py:2873
def set_suite_documentation(self, doc, append=False, top=False)
Sets documentation for the current test suite.
Definition: BuiltIn.py:3179
def no_operation(self)
Does absolutely nothing.
Definition: BuiltIn.py:2512
def get_library_instance(self, name=None, all=False)
Returns the currently active instance of the specified test library.
Definition: BuiltIn.py:3290
def run_keyword_if_test_passed(self, name, *args)
Runs the given keyword with the given arguments, if the test passed.
Definition: BuiltIn.py:2159
def run_keyword_if_timeout_occurred(self, name, *args)
Runs the given keyword if either a test or a keyword timeout has occurred.
Definition: BuiltIn.py:2173
def run_keyword_and_expect_error(self, expected_error, name, *args)
Runs the keyword and checks that the expected error occurred.
Definition: BuiltIn.py:1902
def _error_is_expected(self, error, expected_error)
Definition: BuiltIn.py:1917
def _split_branch(self, args, control_word, required, required_error)
Definition: BuiltIn.py:1777
def run_keyword_if_any_tests_failed(self, name, *args)
Runs the given keyword with the given arguments, if one or more tests failed.
Definition: BuiltIn.py:2238
def _keywords_repeated_by_count(self, count, name, args)
Definition: BuiltIn.py:1991
def _keywords_repeated_by_timeout(self, timeout, name, args)
Definition: BuiltIn.py:1998
def repeat_keyword(self, repeat, name, *args)
Executes the specified keyword multiple times.
Definition: BuiltIn.py:1957
def _get_repeat_count(self, times, require_postfix=False)
Definition: BuiltIn.py:1969
def run_keyword_if_all_tests_passed(self, name, *args)
Runs the given keyword with the given arguments, if all tests passed.
Definition: BuiltIn.py:2224
def run_keywords(self, *keywords)
Executes all the given keywords in a sequence.
Definition: BuiltIn.py:1653
def run_keyword_if_all_critical_tests_passed(self, name, *args)
Runs the given keyword with the given arguments, if all critical tests passed.
Definition: BuiltIn.py:2194
def run_keyword_if_test_failed(self, name, *args)
Runs the given keyword with the given arguments, if the test failed.
Definition: BuiltIn.py:2142
def run_keyword_if(self, condition, name, *args)
Runs the given keyword with the given arguments, if condition is true.
Definition: BuiltIn.py:1761
def _resolve_run_keywords_name_and_args(self, kw_call)
Definition: BuiltIn.py:1686
def _verify_values_for_set_variable_if(self, values, default=False)
Definition: BuiltIn.py:2120
def run_keyword_and_ignore_error(self, name, *args)
Runs the given keyword with the given arguments and ignores possible error.
Definition: BuiltIn.py:1811
def run_keyword_and_continue_on_failure(self, name, *args)
Runs the keyword and continues execution even if a failure occurs.
Definition: BuiltIn.py:1853
def run_keyword_unless(self, condition, name, *args)
Runs the given keyword with the given arguments if condition is false.
Definition: BuiltIn.py:1791
def wait_until_keyword_succeeds(self, retry, retry_interval, name, *args)
Runs the specified keyword and retries if it fails.
Definition: BuiltIn.py:2046
def run_keyword_if_any_critical_tests_failed(self, name, *args)
Runs the given keyword with the given arguments, if any critical tests failed.
Definition: BuiltIn.py:2209
def run_keyword_and_return_status(self, name, *args)
Runs the given keyword with given arguments and returns the status as a Boolean value.
Definition: BuiltIn.py:1836
def set_variable_if(self, condition, *values)
Sets variable based on the given condition.
Definition: BuiltIn.py:2111
def run_keyword(self, name, *args)
Executes the given keyword with the given arguments.
Definition: BuiltIn.py:1616
def set_suite_variable(self, name, *values)
Makes a variable available everywhere within the scope of the current suite.
Definition: BuiltIn.py:1515
def log_variables(self, level='INFO')
Logs all variables in the current scope with given log level.
Definition: BuiltIn.py:1343
def replace_variables(self, text)
Replaces variables in the given text with their current values.
Definition: BuiltIn.py:1407
def set_variable(self, *values)
Returns the given values which can then be assigned to a variables.
Definition: BuiltIn.py:1429
def set_task_variable(self, name, *values)
Makes a variable available everywhere within the scope of the current task.
Definition: BuiltIn.py:1460
def variable_should_exist(self, name, msg=None)
Fails unless the given variable exists within the current scope.
Definition: BuiltIn.py:1360
def set_global_variable(self, name, *values)
Makes a variable available globally in all tests and suites.
Definition: BuiltIn.py:1545
def variable_should_not_exist(self, name, msg=None)
Fails if the given variable exists within the current scope.
Definition: BuiltIn.py:1380
def set_test_variable(self, name, *values)
Makes a variable available everywhere within the scope of the current test.
Definition: BuiltIn.py:1448
def get_variable_value(self, name, default=None)
Returns variable value or default if the variable does not exist.
Definition: BuiltIn.py:1336
def get_variables(self, no_decoration=False)
Returns a dictionary containing all variables in the current scope.
Definition: BuiltIn.py:1315
def get_length(self, item)
Returns and logs the length of the given item as an integer.
Definition: BuiltIn.py:1217
def should_not_be_true(self, condition, msg=None)
Fails if the given condition is true.
Definition: BuiltIn.py:564
def fatal_error(self, msg=None)
Stops the whole test execution.
Definition: BuiltIn.py:554
def _get_string_msg(self, item1, item2, custom_message, include_values, delimiter, quote_item1=True, quote_item2=True)
Definition: BuiltIn.py:1276
def should_be_equal_as_numbers(self, first, second, msg=None, values=True, precision=6)
Fails if objects are unequal after converting them to real numbers.
Definition: BuiltIn.py:782
def should_not_be_equal_as_strings(self, first, second, msg=None, values=True, ignore_case=False)
Fails if objects are equal after converting them to strings.
Definition: BuiltIn.py:802
def should_be_empty(self, item, msg=None)
Verifies that the given item is empty.
Definition: BuiltIn.py:1262
def fail(self, msg=None, *tags)
Fails the test with the given message and optionally alters its tags.
Definition: BuiltIn.py:542
def should_be_equal_as_strings(self, first, second, msg=None, values=True, ignore_case=False, formatter='str')
Fails if objects are unequal after converting them to strings.
Definition: BuiltIn.py:827
def should_contain_x_times(self, item1, item2, count, msg=None, ignore_case=False)
Fails if item1 does not contain item2 count times.
Definition: BuiltIn.py:1070
def should_be_true(self, condition, msg=None)
Fails if the given condition is not true.
Definition: BuiltIn.py:605
def _should_be_equal(self, first, second, msg, values, formatter='str')
Definition: BuiltIn.py:646
def _raise_multi_diff(self, first, second, formatter)
Definition: BuiltIn.py:659
def get_count(self, item1, item2)
Returns and logs how many times item2 is found from item1.
Definition: BuiltIn.py:1098
def should_not_contain_any(self, container, *items, **configuration)
Fails if container contains one or more of the *items.
Definition: BuiltIn.py:1028
def should_not_be_equal_as_numbers(self, first, second, msg=None, values=True, precision=6)
Fails if objects are equal after converting them to real numbers.
Definition: BuiltIn.py:744
def should_be_equal_as_integers(self, first, second, msg=None, values=True, base=None)
Fails if objects are unequal after converting them to integers.
Definition: BuiltIn.py:727
def should_not_start_with(self, str1, str2, msg=None, values=True, ignore_case=False)
Fails if the string str1 starts with the string str2.
Definition: BuiltIn.py:843
def should_not_be_equal_as_integers(self, first, second, msg=None, values=True, base=None)
Fails if objects are equal after converting them to integers.
Definition: BuiltIn.py:707
def should_not_match_regexp(self, string, pattern, msg=None, values=True)
Fails if string matches pattern as a regular expression.
Definition: BuiltIn.py:1192
def should_match(self, string, pattern, msg=None, values=True, ignore_case=False)
Fails if the given string does not match the given pattern.
Definition: BuiltIn.py:1136
def should_end_with(self, str1, str2, msg=None, values=True, ignore_case=False)
Fails if the string str1 does not end with the string str2.
Definition: BuiltIn.py:888
def length_should_be(self, item, length, msg=None)
Verifies that the length of the given item is correct.
Definition: BuiltIn.py:1250
def should_be_equal(self, first, second, msg=None, values=True, ignore_case=False, formatter='str')
Fails if the given objects are unequal.
Definition: BuiltIn.py:639
def _log_types_at_info_if_different(self, first, second)
Definition: BuiltIn.py:655
def should_start_with(self, str1, str2, msg=None, values=True, ignore_case=False)
Fails if the string str1 does not start with the string str2.
Definition: BuiltIn.py:858
def should_match_regexp(self, string, pattern, msg=None, values=True)
Fails if string does not match pattern as a regular expression.
Definition: BuiltIn.py:1177
def should_contain(self, container, item, msg=None, values=True, ignore_case=False)
Fails if container does not contain item one or more times.
Definition: BuiltIn.py:947
def should_not_be_empty(self, item, msg=None)
Verifies that the given item is not empty.
Definition: BuiltIn.py:1271
def should_not_end_with(self, str1, str2, msg=None, values=True, ignore_case=False)
Fails if the string str1 ends with the string str2.
Definition: BuiltIn.py:873
def _should_not_be_equal(self, first, second, msg, values)
Definition: BuiltIn.py:693
def should_contain_any(self, container, *items, **configuration)
Fails if container does not contain any of the *items.
Definition: BuiltIn.py:981
def should_not_contain(self, container, item, msg=None, values=True, ignore_case=False)
Fails if container contains item one or more times.
Definition: BuiltIn.py:910
def should_not_be_equal(self, first, second, msg=None, values=True, ignore_case=False)
Fails if the given objects are equal.
Definition: BuiltIn.py:686
def should_not_match(self, string, pattern, msg=None, values=True, ignore_case=False)
Fails if the given string matches the given pattern.
Definition: BuiltIn.py:1120
def register_run_keyword(library, keyword, args_to_process=None, deprecation_warning=True)
Registers 'run keyword' so that its arguments can be handled correctly.
Definition: BuiltIn.py:3627
def assert_not_equal(first, second, msg=None, values=True, formatter=None)
Fail if given objects are equal as determined by the '==' operator.
Definition: asserts.py:192
def assert_equal(first, second, msg=None, values=True, formatter=None)
Fail if given objects are unequal as determined by the '==' operator.
Definition: asserts.py:186
def get_error_message()
Returns error message of the last occurred exception.
Definition: error.py:41
def html_escape(text, linkify=True)
Definition: markuputils.py:40
def roundup(number, ndigits=0, return_type=None)
Rounds number to the given number of digits.
Definition: misc.py:34
def seq2str(sequence, quote="'", sep=', ', lastsep=' and ')
Returns sequence in format ‘'item 1’, 'item 2' and 'item 3'`.
Definition: misc.py:115
def normalize(string, ignore=(), caseless=True, spaceless=True)
Normalizes given string according to given spec.
Definition: normalizing.py:30
def secs_to_timestr(secs, compact=False)
Converts time in seconds to a string representation.
Definition: robottime.py:126
def parse_time(timestr)
Parses the time string and returns its value as seconds since epoch.
Definition: robottime.py:246
def timestr_to_secs(timestr, round_to=3)
Parses time like '1h 10s', '01:00:10' or '42' and returns seconds.
Definition: robottime.py:45
def is_truthy(item)
Returns True or False depending is the item considered true or not.
Definition: robottypes.py:49
def is_falsy(item)
Opposite of :func:is_truthy.
Definition: robottypes.py:56
def format_assign_message(variable, value, cut_long=True)
Definition: text.py:94
def is_var(string, identifiers='$@&')
Definition: isvar.py:22
def variable_not_found(name, candidates, msg=None, deco_braces=True)
Raise DataError for missing variable name.
Definition: notfound.py:27
def VariableTableValue(value, name, error_reporter=None)
Definition: tablesetter.py:51
def get_version(naked=False)
Definition: version.py:24