Bug 1036392 - Add a parameter to the structured log api for stacks in test_status and test_end.;r=jgraham

This commit is contained in:
Chris Manchester 2014-07-10 09:21:22 -04:00
parent 72b3aa3d83
commit c518ffdc63
2 changed files with 41 additions and 2 deletions

View File

@ -153,7 +153,8 @@ class StructuredLogger(object):
"""
self._log_data("test_start", {"test": test})
def test_status(self, test, subtest, status, expected="PASS", message=None):
def test_status(self, test, subtest, status, expected="PASS", message=None,
stack=None, extra=None):
"""
Log a test_status message indicating a subtest result. Tests that
do not have subtests are not expected to produce test_status messages.
@ -163,6 +164,8 @@ class StructuredLogger(object):
:param status: Status string indicating the subtest result
:param expected: Status string indicating the expected subtest result.
:param message: String containing a message associated with the result.
:param stack: a stack trace encountered during test execution.
:param extra: suite-specific data associated with the test result.
"""
if status.upper() not in ["PASS", "FAIL", "TIMEOUT", "NOTRUN", "ASSERT"]:
raise ValueError("Unrecognised status %s" % status)
@ -173,9 +176,14 @@ class StructuredLogger(object):
data["message"] = message
if expected != data["status"]:
data["expected"] = expected
if stack is not None:
data["stack"] = stack
if extra is not None:
data["extra"] = extra
self._log_data("test_status", data)
def test_end(self, test, status, expected="OK", message=None, extra=None):
def test_end(self, test, status, expected="OK", message=None, stack=None,
extra=None):
"""
Log a test_end message indicating that a test completed. For tests
with subtests this indicates whether the overall test completed without
@ -186,6 +194,7 @@ class StructuredLogger(object):
:param status: Status string indicating the test result
:param expected: Status string indicating the expected test result.
:param message: String containing a message associated with the result.
:param stack: a stack trace encountered during test execution.
:param extra: suite-specific data associated with the test result.
"""
if status.upper() not in ["PASS", "FAIL", "OK", "ERROR", "TIMEOUT",
@ -197,6 +206,8 @@ class StructuredLogger(object):
data["message"] = message
if expected != data["status"] and status != "SKIP":
data["expected"] = expected
if stack is not None:
data["stack"] = stack
if extra is not None:
data["extra"] = extra
self._log_data("test_end", data)

View File

@ -86,6 +86,26 @@ class TestStructuredLog(BaseStructuredTest):
def test_status_2(self):
self.assertRaises(ValueError, self.logger.test_status, "test1", "subtest name", "XXXUNKNOWNXXX")
def test_status_extra(self):
self.logger.test_status("test1", "subtest name", "FAIL", expected="PASS", extra={"data": 42})
self.assert_log_equals({"action": "test_status",
"subtest": "subtest name",
"status": "FAIL",
"expected": "PASS",
"test": "test1",
"extra": {"data":42}
})
def test_status_stack(self):
self.logger.test_status("test1", "subtest name", "FAIL", expected="PASS", stack="many\nlines\nof\nstack")
self.assert_log_equals({"action": "test_status",
"subtest": "subtest name",
"status": "FAIL",
"expected": "PASS",
"test": "test1",
"stack": "many\nlines\nof\nstack"
})
def test_end(self):
self.logger.test_end("test1", "fail", message="Test message")
self.assert_log_equals({"action": "test_end",
@ -104,6 +124,14 @@ class TestStructuredLog(BaseStructuredTest):
def test_end_2(self):
self.assertRaises(ValueError, self.logger.test_end, "test1", "XXXUNKNOWNXXX")
def test_end_stack(self):
self.logger.test_end("test1", "PASS", expected="PASS", stack="many\nlines\nof\nstack")
self.assert_log_equals({"action": "test_end",
"status": "PASS",
"test": "test1",
"stack": "many\nlines\nof\nstack"
})
def test_process(self):
self.logger.process_output(1234, "test output")
self.assert_log_equals({"action": "process_output",