Author: laukpe
Date: Wed Sep 24 09:49:20 2008
New Revision: 822
Modified:
trunk/tools/statuschecker/doc/statuschecker.txt
trunk/tools/statuschecker/statuschecker.py
Log:
support for regexp log messages and checking that certain msg does not exist
Modified: trunk/tools/statuschecker/doc/statuschecker.txt
==============================================================================
--- trunk/tools/statuschecker/doc/statuschecker.txt (original)
+++ trunk/tools/statuschecker/doc/statuschecker.txt Wed Sep 24 09:49:20 2008
@@ -57,8 +57,6 @@
================= =============== =========
=============================
-
-
Defining expected log messages
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -85,6 +83,13 @@
:msg:`FAIL`, but it that case :msg:`FAIL` and the expected error must
be first.
+The log message can also be given as a regular expression pattern the
+same way as the `expected error message`__. Finally, to check that a
+keyword does not have a certain message, it is possible to use
+:msg:`NONE` in the place of the message.
+
+__ `Defining expected test status`_
+
.. table:: Examples
:class: example
@@ -110,5 +115,10 @@
\ Steps \ \
Status and Log [Documentation] FAIL Expected error message
\ ... LOG 1.2 Expected log message
+ \ Steps \ \
+ Regexp Message [Documentation] LOG 1 REGEXP: (Hello|Hi) world!
+ \ Steps \ \
+ No Message [Documentation] LOG 1:1 Test that we have only 1
msg
+ \ ... LOG 1:2 NONE
\ Steps \ \
================= =============== =========
=============================
Modified: trunk/tools/statuschecker/statuschecker.py
==============================================================================
--- trunk/tools/statuschecker/statuschecker.py (original)
+++ trunk/tools/statuschecker/statuschecker.py Wed Sep 24 09:49:20 2008
@@ -70,7 +70,7 @@
else:
test.message = ("Test was expected to FAIL but it PASSED. "
"Expected message:\n") + exp.message
- elif not _messages_match(test, exp.message):
+ elif not _message_matches(test.message, exp.message):
test.status = 'FAIL'
test.message = ("Wrong error
message.\n\nExpected:\n%s\n\nActual:\n%s\n"
% (exp.message, test.message))
@@ -78,41 +78,53 @@
test.status = 'PASS'
test.message = 'Original test failed as expected.'
-def _messages_match(test, exp_message):
- if exp_message == test.message:
+def _message_matches(actual, expected):
+ if actual == expected:
return True
- if exp_message.startswith('REGEXP:'):
- exp_pattern = '^%s$' % exp_message.replace('REGEXP:', '',
1).strip()
- if re.match(exp_pattern, test.message):
+ if expected.startswith('REGEXP:'):
+ pattern = '^%s$' % expected.replace('REGEXP:', '', 1).strip()
+ if re.match(pattern, actual, re.DOTALL):
return True
return False
def _check_logs(test, exp):
for kw_indices, msg_index, level, message in exp.logs:
- kw = _get_keyword(test, kw_indices)
try:
- msg = kw.messages[msg_index-1]
+ kw = test.keywords[kw_indices[0]]
+ for index in kw_indices[1:]:
+ kw = kw.keywords[index]
except IndexError:
+ indices = '.'.join([ str(i+1) for i in kw_indices ])
test.status = 'FAIL'
- test.message = ("Keyword '%s' should have had at least %d log
messages"\
- % (kw.name, msg_index))
- return
- if msg.level != level:
- test.status = 'FAIL'
- test.message = ("Wrong log level for keyword '%s'.\n\n"
- "Expected: %s\nActual: %s" % (kw.name, level,
msg.level))
- return
- if msg.message.strip() != message:
- test.status = 'FAIL'
- test.message = ("Wrong log message for keyword '%s'.\n\n"
- "Expected:\n%s\n\nActual:\n%s" % (kw.name,
message, msg.message))
+ test.message = ("Test '%s' does not have keyword with
index '%s'"
+ % (test.name, indices))
return
-def _get_keyword(test, kw_indices):
- kw = test.keywords[kw_indices[0]-1]
- for index in kw_indices[1:]:
- kw = kw.keywords[index-1]
- return kw
+ if len(kw.messages) <= msg_index:
+ if message != 'NONE':
+ test.status = 'FAIL'
+ test.message = ("Keyword '%s' should have had at least %d "
+ "messages" % (kw.name, msg_index+1))
+ else:
+ msg = kw.messages[msg_index]
+ if _check_log_level(msg.level, level, test, kw):
+ _check_log_message(msg.message.strip(), message, test, kw)
+
+def _check_log_level(actual, expected, test, kw):
+ if actual == expected:
+ return True
+ test.status = 'FAIL'
+ test.message = ("Wrong log level for keyword '%s'.\n\n"
+ "Expected: %s\nActual: %s" % (kw.name, expected,
actual))
+ return False
+
+def _check_log_message(actual, expected, test, kw):
+ if _message_matches(actual, expected):
+ return True
+ test.status = 'FAIL'
+ test.message = ("Wrong log message for keyword '%s'.\n\n"
+ "Expected:\n%s\n\nActual:\n%s" % (kw.name, expected,
actual))
+ return False
class _Expected:
@@ -139,9 +151,9 @@
try:
kw_indices, msg_index = index_str.split(':')
except ValueError:
- kw_indices, msg_index = index_str, '1'
- kw_indices = [ int(index) for index in kw_indices.split('.') ]
- return kw_indices, int(msg_index)
+ kw_indices, msg_index = index_str, '0'
+ kw_indices = [ int(index) - 1 for index in kw_indices.split('.') ]
+ return kw_indices, int(msg_index) - 1
def _get_log_message(self, msg_str):
try: