20 from tokenize
import generate_tokens, untokenize
24 ExecutionFailures, ExecutionPassed, ExitForLoop,
25 PassExecution, ReturnFromKeyword)
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)
38 VariableTableValue, VariableSplitter,
43 from java.lang
import String, Number
50 def decorator(method):
51 RUN_KW_REGISTER.register_run_keyword(
'BuiltIn', method.__name__,
52 resolve, deprecation_warning=
False)
66 ctx = EXECUTION_CONTEXTS.current
if not top
else EXECUTION_CONTEXTS.top
83 def _matches(self, string, pattern, caseless=False):
85 matcher = Matcher(pattern, caseless=caseless, spaceless=
False)
86 return matcher.match(string)
90 condition = self.evaluate(condition, modules=
'os,sys')
91 return bool(condition)
97 msg = [
"Argument types are:"] + [self.
_get_type_get_type(a)
for a
in args]
98 self.log(
'\n'.join(msg), level)
103 return "<type 'unicode'>"
104 return str(
type(arg))
141 item, base = self.
_get_base_get_base(item, base)
146 raise RuntimeError(
"'%s' cannot be converted to an integer: %s"
152 if isinstance(item, String):
154 if isinstance(item, Number):
155 return item.doubleValue()
162 if item.startswith((
'-',
'+')):
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]]
241 spec =
'x' if is_truthy(lowercase)
else 'X'
247 prefix = prefix
or ''
249 prefix =
'-' + prefix
290 if precision
is not None:
305 raise RuntimeError(
"'%s' cannot be converted to a floating "
306 "point number: %s" % (item, error))
335 if item.upper() ==
'TRUE':
337 if item.upper() ==
'FALSE':
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)))
396 if IRONPYTHON
and isinstance(input, bytearray):
399 ordinal = char
if is_integer(char)
else ord(char)
400 yield self.
_test_ordinal_test_ordinal(ordinal, char,
'Character')
403 if 0 <= ordinal <= 255:
405 raise RuntimeError(
"%s '%s' cannot be represented as a byte."
410 input = input.split()
413 for integer
in input:
415 yield self.
_test_ordinal_test_ordinal(ordinal, integer,
'Integer')
420 yield self.
_test_ordinal_test_ordinal(ordinal, token,
'Hex value')
425 yield self.
_test_ordinal_test_ordinal(ordinal, token,
'Binary value')
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))
448 @run_keyword_variant(resolve=0)
490 result.update(combined)
499 separate.append(item)
500 return separate, items[len(separate):]
504 if len(separate) % 2 != 0:
505 raise DataError(
'Expected even number of keys and values, got %d.'
507 return [separate[i:i+2]
for i
in range(0, len(separate), 2)]
513 set_tags = [tag
for tag
in tags
if not tag.startswith(
'-')]
514 remove_tags = [tag[1:]
for tag
in tags
if tag.startswith(
'-')]
516 self.remove_tags(*remove_tags)
518 self.set_tags(*set_tags)
542 def fail(self, msg=None, *tags):
556 error.ROBOT_EXIT_ON_FAILURE =
True
565 if self.
_is_true_is_true(condition):
566 raise AssertionError(msg
or "'%s' should not be true." % condition)
606 if not self.
_is_true_is_true(condition):
639 ignore_case=False, formatter='str'):
642 first = first.lower()
643 second = second.lower()
644 self.
_should_be_equal_should_be_equal(first, second, msg, values, formatter)
648 formatter = self._get_formatter(formatter)
653 assert_equal(first, second, msg, include_values, formatter)
656 level =
'DEBUG' if type(first) ==
type(second)
else 'INFO'
660 first_lines = first.splitlines(
True)
661 second_lines = second.splitlines(
True)
662 if len(first_lines) < 3
or len(second_lines) < 3:
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',
668 diffs[3:] = [item[0] + formatter(item[1:]).rstrip()
669 for item
in diffs[3:]]
674 return is_truthy(values)
and str(values).upper() !=
'NO VALUES'
689 first = first.lower()
690 second = second.lower()
707 values=True, base=None):
710 self._convert_to_integer(second, base),
729 self.
_should_be_equal_should_be_equal(self._convert_to_integer(first, base),
730 self._convert_to_integer(second, base),
744 values=True, precision=6):
746 first = self._convert_to_number(first, precision)
747 second = self._convert_to_number(second, precision)
784 first = self._convert_to_number(first, precision)
785 second = self._convert_to_number(second, precision)
802 values=True, ignore_case=False):
804 first = self._convert_to_string(first)
805 second = self._convert_to_string(second)
807 first = first.lower()
808 second = second.lower()
827 ignore_case=False, formatter='str'):
829 first = self._convert_to_string(first)
830 second = self._convert_to_string(second)
832 first = first.lower()
833 second = second.lower()
834 self.
_should_be_equal_should_be_equal(first, second, msg, values, formatter)
847 if str1.startswith(str2):
862 if not str1.startswith(str2):
864 'does not start with'))
877 if str1.endswith(str2):
892 if not str1.endswith(str2):
894 'does not end with'))
916 orig_container = container
920 container = container.lower()
922 container = set(x.lower()
if is_string(x)
else x
for x
in container)
923 if item
in container:
948 orig_container = container
952 container = container.lower()
954 container = set(x.lower()
if is_string(x)
else x
for x
in container)
955 if item
not in container:
957 values,
'does not contain'))
982 msg = configuration.pop(
'msg',
None)
983 values = configuration.pop(
'values',
True)
984 ignore_case = configuration.pop(
'ignore_case',
False)
986 raise RuntimeError(
"Unsupported configuration parameter%s: %s."
988 seq2str(sorted(configuration))))
990 raise RuntimeError(
'One or more items required.')
991 orig_container = container
993 items = [x.lower()
if is_string(x)
else x
for x
in items]
995 container = container.lower()
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):
1000 seq2str(items, lastsep=
' or '),
1002 'does not contain any of',
1029 msg = configuration.pop(
'msg',
None)
1030 values = configuration.pop(
'values',
True)
1031 ignore_case = configuration.pop(
'ignore_case',
False)
1033 raise RuntimeError(
"Unsupported configuration parameter%s: %s."
1034 % (s(configuration),
1035 seq2str(sorted(configuration))))
1037 raise RuntimeError(
'One or more items required.')
1038 orig_container = container
1040 items = [x.lower()
if is_string(x)
else x
for x
in items]
1042 container = container.lower()
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):
1047 seq2str(items, lastsep=
' or '),
1049 'contains one or more of',
1075 count = self._convert_to_integer(count)
1078 item2 = item2.lower()
1080 item1 = item1.lower()
1082 item1 = [x.lower()
if is_string(x)
else x
for x
in item1]
1083 x = self.
get_countget_count(item1, item2)
1085 msg =
"'%s' contains '%s' %d time%s, not %d time%s." \
1086 % (
unic(orig_item1),
unic(item2), x, s(x), count, s(count))
1099 if not hasattr(item1,
'count'):
1103 raise RuntimeError(
"Converting '%s' to list failed: %s"
1105 count = item1.count(item2)
1106 self.log(
'Item found from the first item %d time%s' % (count, s(count)))
1139 values,
'does not match'))
1178 res = re.search(pattern, string)
1181 values,
'does not match'))
1182 match = res.group(0)
1183 groups = res.groups()
1185 return [match] + list(groups)
1193 if re.search(pattern, string)
is not None:
1219 self.log(
'Length is %d' % length)
1225 except RERAISED_EXCEPTIONS:
1229 return item.length()
1230 except RERAISED_EXCEPTIONS:
1235 except RERAISED_EXCEPTIONS:
1240 except RERAISED_EXCEPTIONS:
1243 raise RuntimeError(
"Could not get length of '%s'." % item)
1251 length = self._convert_to_integer(length)
1253 if actual != length:
1254 raise AssertionError(msg
or "Length of '%s' should be %d but is %d."
1255 % (item, length, actual))
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)
1318 @run_keyword_variant(resolve=0)
1345 for name
in sorted(variables, key=
lambda s: s[2:-1].
lower()):
1347 self.log(msg, level)
1349 @run_keyword_variant(resolve=0)
1363 else "Variable %s does not exist." % name
1369 @run_keyword_variant(resolve=0)
1383 else "Variable %s exists." % name
1430 if len(values) == 0:
1432 elif len(values) == 1:
1437 @run_keyword_variant(resolve=0)
1454 @run_keyword_variant(resolve=0)
1463 @run_keyword_variant(resolve=0)
1517 if (values
and is_string(values[-1])
and
1518 values[-1].startswith(
'children=')):
1521 values = values[:-1]
1528 @run_keyword_variant(resolve=0)
1558 raise RuntimeError(
"Invalid variable syntax '%s'." % orig)
1564 except (KeyError, ValueError, DataError):
1568 if name.startswith(
'\\'):
1572 if name[0]
in '$@&' and name[1] !=
'{':
1573 name =
'%s{%s}' % (name[0], name[1:])
1577 name =
'%s{%s}' % (name[0], self.
replace_variablesreplace_variables(name[2:-1]))
1591 raise DataError(
"Setting list value to scalar variable '%s' "
1592 "is not supported anymore. Create list "
1593 "variable '@%s' instead." % (name, name[1:]))
1609 @run_keyword_variant(resolve=1)
1618 raise RuntimeError(
'Keyword name must be a string.')
1619 kw = Keyword(name, args=args)
1622 @run_keyword_variant(resolve=0)
1658 for kw, args
in iterable:
1661 except ExecutionPassed
as err:
1662 err.set_earlier_failures(errors)
1664 except ExecutionFailed
as err:
1665 errors.extend(err.get_errors())
1672 if 'AND' not in keywords:
1680 while 'AND' in keywords:
1681 index = keywords.index(
'AND')
1683 keywords = keywords[index+1:]
1690 return kw_call[0], kw_call[1:]
1692 @run_keyword_variant(resolve=2)
1763 if self.
_is_true_is_true(condition):
1768 if 'ELSE IF' in args:
1769 args, branch = self.
_split_branch_split_branch(args,
'ELSE IF', 2,
1770 'condition and keyword')
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
1778 index = list(args).index(control_word)
1780 if len(branch) < required:
1781 raise DataError(
'%s requires %s.' % (control_word, required_error))
1782 return args[:index], branch
1784 @run_keyword_variant(resolve=2)
1792 if not self.
_is_true_is_true(condition):
1795 @run_keyword_variant(resolve=1)
1813 return 'PASS', self.
run_keywordrun_keyword(name, *args)
1814 except ExecutionFailed
as err:
1815 if err.dont_continue:
1817 return 'FAIL',
unic(err)
1819 @run_keyword_variant(resolve=1)
1838 return status ==
'PASS'
1840 @run_keyword_variant(resolve=1)
1856 except ExecutionFailed
as err:
1857 if not err.dont_continue:
1858 err.continue_on_failure =
True
1861 @run_keyword_variant(resolve=2)
1905 except ExecutionFailed
as err:
1906 if err.dont_continue:
1914 % (expected_error, error))
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())
1929 @run_keyword_variant(resolve=2)
1960 except RuntimeError
as err:
1971 if times.endswith(
'times'):
1973 elif times.endswith(
'x'):
1975 elif require_postfix:
1977 return self._convert_to_integer(times)
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))
2000 self.log(
"Keyword '%s' repeated zero times." % name)
2002 maxtime = time.time() + timeout
2003 while time.time() < maxtime:
2005 self.log(
"Repeating keyword, round %d, %s remaining."
2010 @run_keyword_variant(resolve=3)
2047 maxtime = count = -1
2052 maxtime = time.time() + timeout
2056 raise ValueError(
'Retry count %d is not positive.' % count)
2057 message =
'%d time%s' % (count, s(count))
2062 except ExecutionFailed
as err:
2063 if err.dont_continue:
2066 if time.time() > maxtime > 0
or count == 0:
2068 "%s. The last error was: %s"
2069 % (name, message, err))
2070 self._sleep_in_parts(retry_interval)
2072 @run_keyword_variant(resolve=1)
2113 if self.
_is_true_is_true(condition):
2116 if len(values) == 1:
2118 return self.
run_keywordrun_keyword(
'BuiltIn.Set Variable If', *values[0:])
2124 raise RuntimeError(
'At least one value is required')
2130 @run_keyword_variant(resolve=1)
2147 @run_keyword_variant(resolve=1)
2164 @run_keyword_variant(resolve=1)
2180 if ctx.test
and ctx.in_test_teardown:
2182 raise RuntimeError(
"Keyword '%s' can only be used in test teardown."
2185 @run_keyword_variant(resolve=1)
2196 'All Critical Tests Passed')
2197 if suite.statistics.critical.failed == 0:
2200 @run_keyword_variant(resolve=1)
2211 'Any Critical Tests Failed')
2212 if suite.statistics.critical.failed > 0:
2215 @run_keyword_variant(resolve=1)
2226 if suite.statistics.all.failed == 0:
2229 @run_keyword_variant(resolve=1)
2240 if suite.statistics.all.failed > 0:
2245 raise RuntimeError(
"Keyword '%s' can only be used in suite teardown."
2267 self.log(
"Continuing for loop from the next iteration.")
2282 if self.
_is_true_is_true(condition):
2299 self.log(
"Exiting for loop altogether.")
2314 if self.
_is_true_is_true(condition):
2317 @run_keyword_variant(resolve=0)
2365 self.log(
'Returning from the enclosing user keyword.')
2368 @run_keyword_variant(resolve=1)
2390 if self.
_is_true_is_true(condition):
2393 @run_keyword_variant(resolve=1)
2413 ret = self.run_keyword(name, *args)
2414 except ExecutionFailed
as err:
2419 @run_keyword_variant(resolve=2)
2435 if self.
_is_true_is_true(condition):
2481 message = message.strip()
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)
2489 @run_keyword_variant(resolve=1)
2503 if self.
_is_true_is_true(condition):
2542 endtime = time.time() + float(seconds)
2544 remaining = endtime - time.time()
2547 time.sleep(min(remaining, 0.01))
2567 items = [
unic(item)
for item
in items]
2568 if items[0].startswith(
'SEPARATOR='):
2569 sep = items[0][len(
'SEPARATOR='):]
2573 return sep.join(items)
2625 def log(self, message, level='INFO', html=False, console=False,
2626 repr=False, formatter='str'):
2632 message = formatter(message)
2633 logger.write(message, level,
is_truthy(html))
2635 logger.console(message)
2639 return {
'str': unic,
2641 'ascii': ascii
if PY3
else repr}[formatter.lower()]
2643 raise ValueError(
"Invalid formatter '%s'. Available "
2644 "'str', 'repr' and 'ascii'." % formatter)
2646 @run_keyword_variant(resolve=0)
2663 for msg
in messages:
2664 var = VariableSplitter(msg)
2666 if var.is_list_variable():
2669 elif var.is_dict_variable():
2670 for name, value
in value.items():
2671 yield '%s=%s' % (name, value)
2695 logger.console(message, newline=
is_falsy(no_newline), stream=stream)
2697 @run_keyword_variant(resolve=0)
2721 except DataError
as err:
2722 raise RuntimeError(
unic(err))
2724 self.
loglog(
'Log level changed from %s to %s.' % (old, level.upper()))
2740 self.
loglog(
'Reloaded library %s with %s keywords.' % (library.name,
2743 @run_keyword_variant(resolve=0)
2771 except DataError
as err:
2772 raise RuntimeError(
unic(err))
2774 @run_keyword_variant(resolve=0)
2796 except DataError
as err:
2797 raise RuntimeError(
unic(err))
2799 @run_keyword_variant(resolve=0)
2819 except DataError
as err:
2820 raise RuntimeError(
unic(err))
2876 except DataError
as error:
2878 if isinstance(runner, UserErrorHandler):
2994 def evaluate(self, expression, modules=None, namespace=None):
2995 if is_string(expression)
and '$' in expression:
3002 raise TypeError(
"Expression must be string, got %s."
3005 raise ValueError(
"Expression cannot be empty.")
3006 return eval(expression, namespace, variables)
3008 raise RuntimeError(
"Evaluating expression '%s' failed: %s"
3013 variable_started =
False
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:
3021 if tokval
not in variables:
3024 tokval =
'RF_VAR_' + tokval
3026 tokens.append((token.ERRORTOKEN,
'$'))
3027 variable_started =
False
3028 if toknum == token.ERRORTOKEN
and tokval ==
'$':
3029 variable_started =
True
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=
'_')
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)
3065 method = getattr(object, method_name)
3066 except AttributeError:
3067 raise RuntimeError(
"Object '%s' does not have method '%s'."
3068 % (object, method_name))
3070 return method(*args, **kwargs)
3072 raise RuntimeError(
"Calling method '%s' failed: %s"
3087 if len(patterns) == 0:
3089 if len(patterns) == 1:
3090 return re.escape(patterns[0])
3091 return [re.escape(p)
for p
in patterns]
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)
3125 self.
loglog(
'Set test message to:\n%s' % message, level)
3133 if new.startswith(
'*HTML*'):
3134 new = new[6:].lstrip()
3135 if not old.startswith(
'*HTML*'):
3137 elif old.startswith(
'*HTML*'):
3139 return '%s %s' % (old, new)
3142 if message.startswith(
'*HTML*'):
3143 return message[6:].lstrip(),
'HTML'
3144 return message,
'INFO'
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)
3163 self.
loglog(
'Set test documentation to:\n%s' % test.doc)
3182 suite.doc = self.
_get_new_text_get_new_text(suite.doc, doc, append)
3184 self.
loglog(
'Set suite documentation to:\n%s' % suite.doc)
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)
3208 self.
loglog(
"Set suite metadata '%s' to value '%s'." % (name, metadata[name]))
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)
3232 raise RuntimeError(
"'Set Tags' cannot be used in suite teardown.")
3233 self.
loglog(
'Set tag%s %s.' % (s(tags),
seq2str(tags)))
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)
3260 raise RuntimeError(
"'Remove Tags' cannot be used in suite teardown.")
3261 self.
loglog(
'Removed tag%s %s.' % (s(tags),
seq2str(tags)))
3295 except DataError
as err:
3296 raise RuntimeError(
unic(err))
3552 ROBOT_LIBRARY_SCOPE =
'GLOBAL'
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.
Used when variable does not exist.
Used by 'Return From Keyword' keyword.
Used by 'Pass Execution' keyword.
An always available standard library with often needed keywords.
Used when something cannot be done because Robot is not running.
def _matches(self, string, pattern, caseless=False)
def _log_types(self, *args)
def _get_context(self, top=False)
def _log_types_at_level(self, level, *args)
def _is_true(self, condition)
def continue_for_loop(self)
Skips the current for loop iteration and continues from the next.
def exit_for_loop(self)
Stops executing the enclosing for loop.
def _return_from_keyword(self, return_values=None, failures=None)
def continue_for_loop_if(self, condition)
Skips the current for loop iteration if the condition is true.
def exit_for_loop_if(self, condition)
Stops executing the enclosing for loop if the condition is true.
def pass_execution(self, message, *tags)
Skips rest of the current test, setup, or teardown with PASS status.
def return_from_keyword_if(self, condition, *return_values)
Returns from the enclosing user keyword if condition is true.
def run_keyword_and_return_if(self, condition, name, *args)
Runs the specified keyword and returns from the enclosing user keyword.
def run_keyword_and_return(self, name, *args)
Runs the specified keyword and returns from the enclosing user keyword.
def return_from_keyword(self, *return_values)
Returns from the enclosing user keyword.
def pass_execution_if(self, condition, message, *tags)
Conditionally skips rest of the current test, setup, or teardown with PASS status.
def create_dictionary(self, *items)
Creates and returns a dictionary based on the given items.
def convert_to_hex(self, item, base=None, prefix=None, length=None, lowercase=False)
Converts the given item to a hexadecimal string.
def _split_dict_items(self, items)
def _handle_java_numbers(self, item)
def convert_to_number(self, item, precision=None)
Converts the given item to a floating point number.
def _format_separate_dict_items(self, separate)
def convert_to_bytes(self, input, input_type='text')
Converts the given input to bytes according to the input_type.
def _get_ordinals_from_hex(self, input)
def convert_to_binary(self, item, base=None, prefix=None, length=None)
Converts the given item to a binary string.
def _convert_to_bin_oct_hex(self, item, base, prefix, length, format_spec)
def convert_to_boolean(self, item)
Converts the given item to Boolean true or false.
def convert_to_integer(self, item, base=None)
Converts the given item to an integer number.
def create_list(self, *items)
Returns a list containing given items.
def _input_to_tokens(self, input, length)
def _convert_to_number_without_precision(self, item)
def convert_to_string(self, item)
Converts the given item to a Unicode string.
def _get_ordinals_from_int(self, input)
def _convert_to_integer(self, orig, base=None)
def _test_ordinal(self, ordinal, original, type)
def _convert_to_string(self, item)
def _get_ordinals_from_bin(self, input)
def convert_to_octal(self, item, base=None, prefix=None, length=None)
Converts the given item to an octal string.
def _get_base(self, item, base)
def _get_ordinals_from_text(self, input)
def _convert_to_number(self, item, precision=None)
def comment(self, *messages)
Displays the given messages in the log file as keyword arguments.
def catenate(self, *items)
Catenates the given items together and returns the resulted string.
def import_variables(self, path, *args)
Imports a variable file with the given path and optional arguments.
def _get_formatter(self, formatter)
def call_method(self, object, method_name, *args, **kwargs)
Calls the named method of the given object with the provided arguments.
def _get_new_text(self, old, new, append, handle_html=False)
def regexp_escape(self, *patterns)
Returns each argument string escaped for use as a regular expression.
def import_library(self, name, *args)
Imports a library with the given name and optional arguments.
def set_test_documentation(self, doc, append=False)
Sets documentation for the current test case.
def _get_logged_test_message_and_level(self, message)
def set_suite_metadata(self, name, value, append=False, top=False)
Sets metadata for the current test suite.
def import_resource(self, path)
Imports a resource file with the given path.
def _create_evaluation_namespace(self, namespace, modules)
def set_log_level(self, level)
Sets the log threshold to the specified level and returns the old level.
def reload_library(self, name_or_instance)
Rechecks what keywords the specified library provides.
def evaluate(self, expression, modules=None, namespace=None)
Evaluates the given expression in Python and returns the results.
def log_to_console(self, message, stream='STDOUT', no_newline=False)
Logs the given message to the console.
def _sleep_in_parts(self, seconds)
def log(self, message, level='INFO', html=False, console=False, repr=False, formatter='str')
Logs the given message with the given level.
def set_library_search_order(self, *search_order)
Sets the resolution order to use when a name matches multiple keywords.
def _yield_logged_messages(self, messages)
def sleep(self, time_, reason=None)
Pauses the test executed for the given time.
def _handle_variables_in_expression(self, expression)
def log_many(self, *messages)
Logs the given messages as separate entries using the INFO level.
def set_tags(self, *tags)
Adds given tags for the current test or all tests in a suite.
def remove_tags(self, *tags)
Removes given tags from the current test or all tests in a suite.
def set_test_message(self, message, append=False)
Sets message for the current test case.
def get_time(self, format='timestamp', time_='NOW')
Returns the given time in the requested format.
def keyword_should_exist(self, name, msg=None)
Fails unless the given keyword exists in the current scope.
def set_suite_documentation(self, doc, append=False, top=False)
Sets documentation for the current test suite.
def no_operation(self)
Does absolutely nothing.
def get_library_instance(self, name=None, all=False)
Returns the currently active instance of the specified test library.
def run_keyword_if_test_passed(self, name, *args)
Runs the given keyword with the given arguments, if the test passed.
def _get_repeat_timeout(self, timestr)
def _split_run_keywords(self, keywords)
def _split_run_keywords_from_and(self, keywords)
def _split_elif_or_else_branch(self, args)
def run_keyword_if_timeout_occurred(self, name, *args)
Runs the given keyword if either a test or a keyword timeout has occurred.
def run_keyword_and_expect_error(self, expected_error, name, *args)
Runs the keyword and checks that the expected error occurred.
def _error_is_expected(self, error, expected_error)
def _split_branch(self, args, control_word, required, required_error)
def run_keyword_if_any_tests_failed(self, name, *args)
Runs the given keyword with the given arguments, if one or more tests failed.
def _keywords_repeated_by_count(self, count, name, args)
def _keywords_repeated_by_timeout(self, timeout, name, args)
def repeat_keyword(self, repeat, name, *args)
Executes the specified keyword multiple times.
def _get_repeat_count(self, times, require_postfix=False)
def run_keyword_if_all_tests_passed(self, name, *args)
Runs the given keyword with the given arguments, if all tests passed.
def run_keywords(self, *keywords)
Executes all the given keywords in a sequence.
def run_keyword_if_all_critical_tests_passed(self, name, *args)
Runs the given keyword with the given arguments, if all critical tests passed.
def run_keyword_if_test_failed(self, name, *args)
Runs the given keyword with the given arguments, if the test failed.
def _get_test_in_teardown(self, kwname)
def run_keyword_if(self, condition, name, *args)
Runs the given keyword with the given arguments, if condition is true.
def _get_suite_in_teardown(self, kwname)
def _run_keywords(self, iterable)
def _resolve_run_keywords_name_and_args(self, kw_call)
def _verify_values_for_set_variable_if(self, values, default=False)
def run_keyword_and_ignore_error(self, name, *args)
Runs the given keyword with the given arguments and ignores possible error.
def run_keyword_and_continue_on_failure(self, name, *args)
Runs the keyword and continues execution even if a failure occurs.
def run_keyword_unless(self, condition, name, *args)
Runs the given keyword with the given arguments if condition is false.
def wait_until_keyword_succeeds(self, retry, retry_interval, name, *args)
Runs the specified keyword and retries if it fails.
def run_keyword_if_any_critical_tests_failed(self, name, *args)
Runs the given keyword with the given arguments, if any critical tests failed.
def run_keyword_and_return_status(self, name, *args)
Runs the given keyword with given arguments and returns the status as a Boolean value.
def set_variable_if(self, condition, *values)
Sets variable based on the given condition.
def run_keyword(self, name, *args)
Executes the given keyword with the given arguments.
def set_suite_variable(self, name, *values)
Makes a variable available everywhere within the scope of the current suite.
def log_variables(self, level='INFO')
Logs all variables in the current scope with given log level.
def _resolve_possible_variable(self, name)
def replace_variables(self, text)
Replaces variables in the given text with their current values.
def set_variable(self, *values)
Returns the given values which can then be assigned to a variables.
def set_task_variable(self, name, *values)
Makes a variable available everywhere within the scope of the current task.
def _log_set_variable(self, name, value)
def variable_should_exist(self, name, msg=None)
Fails unless the given variable exists within the current scope.
def set_global_variable(self, name, *values)
Makes a variable available globally in all tests and suites.
def variable_should_not_exist(self, name, msg=None)
Fails if the given variable exists within the current scope.
def _get_var_value(self, name, values)
def set_test_variable(self, name, *values)
Makes a variable available everywhere within the scope of the current test.
def _unescape_variable_if_needed(self, name)
def get_variable_value(self, name, default=None)
Returns variable value or default if the variable does not exist.
def get_variables(self, no_decoration=False)
Returns a dictionary containing all variables in the current scope.
def _get_var_name(self, orig)
def get_length(self, item)
Returns and logs the length of the given item as an integer.
def should_not_be_true(self, condition, msg=None)
Fails if the given condition is true.
def fatal_error(self, msg=None)
Stops the whole test execution.
def _get_string_msg(self, item1, item2, custom_message, include_values, delimiter, quote_item1=True, quote_item2=True)
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.
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.
def should_be_empty(self, item, msg=None)
Verifies that the given item is empty.
def fail(self, msg=None, *tags)
Fails the test with the given message and optionally alters its tags.
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.
def should_contain_x_times(self, item1, item2, count, msg=None, ignore_case=False)
Fails if item1 does not contain item2 count times.
def should_be_true(self, condition, msg=None)
Fails if the given condition is not true.
def _should_be_equal(self, first, second, msg, values, formatter='str')
def _raise_multi_diff(self, first, second, formatter)
def get_count(self, item1, item2)
Returns and logs how many times item2 is found from item1.
def should_not_contain_any(self, container, *items, **configuration)
Fails if container contains one or more of the *items.
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.
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.
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.
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.
def should_not_match_regexp(self, string, pattern, msg=None, values=True)
Fails if string matches pattern as a regular expression.
def should_match(self, string, pattern, msg=None, values=True, ignore_case=False)
Fails if the given string does not match the given pattern.
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.
def length_should_be(self, item, length, msg=None)
Verifies that the length of the given item is correct.
def should_be_equal(self, first, second, msg=None, values=True, ignore_case=False, formatter='str')
Fails if the given objects are unequal.
def _log_types_at_info_if_different(self, first, second)
def _get_length(self, item)
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.
def _include_values(self, values)
def _set_and_remove_tags(self, tags)
def should_match_regexp(self, string, pattern, msg=None, values=True)
Fails if string does not match pattern as a regular expression.
def should_contain(self, container, item, msg=None, values=True, ignore_case=False)
Fails if container does not contain item one or more times.
def should_not_be_empty(self, item, msg=None)
Verifies that the given item is not empty.
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.
def _should_not_be_equal(self, first, second, msg, values)
def should_contain_any(self, container, *items, **configuration)
Fails if container does not contain any of the *items.
def should_not_contain(self, container, item, msg=None, values=True, ignore_case=False)
Fails if container contains item one or more times.
def should_not_be_equal(self, first, second, msg=None, values=True, ignore_case=False)
Fails if the given objects are equal.
def should_not_match(self, string, pattern, msg=None, values=True, ignore_case=False)
Fails if the given string matches the given pattern.
def run_keyword_variant(resolve)
def register_run_keyword(library, keyword, args_to_process=None, deprecation_warning=True)
Registers 'run keyword' so that its arguments can be handled correctly.
def assert_not_equal(first, second, msg=None, values=True, formatter=None)
Fail if given objects are equal as determined by the '==' operator.
def assert_equal(first, second, msg=None, values=True, formatter=None)
Fail if given objects are unequal as determined by the '==' operator.
def get_error_message()
Returns error message of the last occurred exception.
def split_from_equals(string)
def html_escape(text, linkify=True)
def roundup(number, ndigits=0, return_type=None)
Rounds number to the given number of digits.
def seq2str(sequence, quote="'", sep=', ', lastsep=' and ')
Returns sequence in format ‘'item 1’, 'item 2' and 'item 3'`.
def normalize(string, ignore=(), caseless=True, spaceless=True)
Normalizes given string according to given spec.
def secs_to_timestr(secs, compact=False)
Converts time in seconds to a string representation.
def parse_time(timestr)
Parses the time string and returns its value as seconds since epoch.
def timestr_to_secs(timestr, round_to=3)
Parses time like '1h 10s', '01:00:10' or '42' and returns seconds.
def is_truthy(item)
Returns True or False depending is the item considered true or not.
def is_falsy(item)
Opposite of :func:is_truthy.
def format_assign_message(variable, value, cut_long=True)
def is_var(string, identifiers='$@&')
def variable_not_found(name, candidates, msg=None, deco_braces=True)
Raise DataError for missing variable name.
def VariableTableValue(value, name, error_reporter=None)
def get_version(naked=False)
def is_dict_variable(value)
def is_list_variable(value)