Revision a9a7352b

b/qa/qa_utils.py
67 67
 RETURN_VALUE) = range(1000, 1002)
68 68

  
69 69

  
70
def AssertIn(item, sequence):
70
def _RaiseWithInfo(msg, error_desc):
71
  """Raises a QA error with the given content, and adds a message if present.
72

  
73
  """
74
  if msg:
75
    output = "%s: %s" % (msg, error_desc)
76
  else:
77
    output = error_desc
78
  raise qa_error.Error(output)
79

  
80

  
81
def AssertIn(item, sequence, msg=None):
71 82
  """Raises an error when item is not in sequence.
72 83

  
73 84
  """
74 85
  if item not in sequence:
75
    raise qa_error.Error("%r not in %r" % (item, sequence))
86
    _RaiseWithInfo(msg, "%r not in %r" % (item, sequence))
76 87

  
77 88

  
78
def AssertNotIn(item, sequence):
89
def AssertNotIn(item, sequence, msg=None):
79 90
  """Raises an error when item is in sequence.
80 91

  
81 92
  """
82 93
  if item in sequence:
83
    raise qa_error.Error("%r in %r" % (item, sequence))
94
    _RaiseWithInfo(msg, "%r in %r" % (item, sequence))
84 95

  
85 96

  
86
def AssertEqual(first, second):
97
def AssertEqual(first, second, msg=None):
87 98
  """Raises an error when values aren't equal.
88 99

  
89 100
  """
90 101
  if not first == second:
91
    raise qa_error.Error("%r == %r" % (first, second))
102
    _RaiseWithInfo(msg, "%r == %r" % (first, second))
92 103

  
93 104

  
94
def AssertMatch(string, pattern):
105
def AssertMatch(string, pattern, msg=None):
95 106
  """Raises an error when string doesn't match regexp pattern.
96 107

  
97 108
  """
98 109
  if not re.match(pattern, string):
99
    raise qa_error.Error("%r doesn't match /%r/" % (string, pattern))
110
    _RaiseWithInfo(msg, "%r doesn't match /%r/" % (string, pattern))
100 111

  
101 112

  
102 113
def _GetName(entity, fn):

Also available in: Unified diff