Commit a9a7352b authored by Hrvoje Ribicic's avatar Hrvoje Ribicic
Browse files

Allow QA asserts to produce more messages

This patch adds a tiny helper function that allows error messages
output by the QA asserts to be prefixed with whatever the user
Signed-off-by: default avatarHrvoje Ribicic <>
Reviewed-by: default avatarKlaus Aehlig <>
parent d65f3490
......@@ -67,36 +67,47 @@ _QA_OUTPUT = pathutils.GetLogFilename("qa-output")
RETURN_VALUE) = range(1000, 1002)
def AssertIn(item, sequence):
def _RaiseWithInfo(msg, error_desc):
"""Raises a QA error with the given content, and adds a message if present.
if msg:
output = "%s: %s" % (msg, error_desc)
output = error_desc
raise qa_error.Error(output)
def AssertIn(item, sequence, msg=None):
"""Raises an error when item is not in sequence.
if item not in sequence:
raise qa_error.Error("%r not in %r" % (item, sequence))
_RaiseWithInfo(msg, "%r not in %r" % (item, sequence))
def AssertNotIn(item, sequence):
def AssertNotIn(item, sequence, msg=None):
"""Raises an error when item is in sequence.
if item in sequence:
raise qa_error.Error("%r in %r" % (item, sequence))
_RaiseWithInfo(msg, "%r in %r" % (item, sequence))
def AssertEqual(first, second):
def AssertEqual(first, second, msg=None):
"""Raises an error when values aren't equal.
if not first == second:
raise qa_error.Error("%r == %r" % (first, second))
_RaiseWithInfo(msg, "%r == %r" % (first, second))
def AssertMatch(string, pattern):
def AssertMatch(string, pattern, msg=None):
"""Raises an error when string doesn't match regexp pattern.
if not re.match(pattern, string):
raise qa_error.Error("%r doesn't match /%r/" % (string, pattern))
_RaiseWithInfo(msg, "%r doesn't match /%r/" % (string, pattern))
def _GetName(entity, fn):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment