Revision: 6853e6f3f191
Author: Pekka Klärck
Date: Wed Dec 14 03:48:53 2011
Log: XUnitWriter cleanup
http://code.google.com/p/robotframework/source/detail?r=6853e6f3f191
Modified:
/src/robot/reporting/xunitwriter.py
=======================================
--- /src/robot/reporting/xunitwriter.py Wed Dec 14 02:20:42 2011
+++ /src/robot/reporting/xunitwriter.py Wed Dec 14 03:48:53 2011
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import os
+
from robot.result.visitor import ResultVisitor
from robot import utils
@@ -26,7 +28,6 @@
def __init__(self, output):
self._writer = utils.XmlWriter(output)
self._root_suite = None
- self._detail_serializer = _NopSerializer()
def start_suite(self, suite):
if self._root_suite:
@@ -49,41 +50,34 @@
'time': self._time_as_seconds(test.elapsedtime)}
self._writer.start('testcase', attrs)
if test.status == 'FAIL':
- self._detail_serializer = _FailedTestSerializer(self._writer,
test)
+ test.visit(TestFailureWriter(self._writer))
def _time_as_seconds(self, millis):
return int(round(millis, -3) / 1000)
def end_test(self, test):
- self._detail_serializer.end_test()
- self._detail_serializer = _NopSerializer()
self._writer.end('testcase')
- def start_keyword(self, kw):
+ def visit_keyword(self, kw):
pass
- def end_keyword(self, kw):
- pass
-
- def visit_message(self, msg):
- self._detail_serializer.message(msg)
-
def end_result(self, result):
self._writer.close()
-class _FailedTestSerializer:
- """Specific policy to serialize a failed test case details"""
-
- def __init__(self, writer, test):
+class TestFailureWriter(ResultVisitor):
+
+ def __init__(self, writer):
self._writer = writer
- self._writer.start('failure',
- {'message':
test.message, 'type': 'AssertionError'})
-
- def end_test(self):
+
+ def start_test(self, test):
+ self._writer.start('failure', {'message': test.message,
+ 'type': 'AssertionError'})
+
+ def end_test(self, test):
self._writer.end('failure')
- def message(self, msg):
+ def visit_message(self, msg):
"""Populates the <failure> section, normally only with
a 'Stacktrace'.
There is a weakness here because filtering is based on message
level:
@@ -92,14 +86,4 @@
- first FAIL message is already reported as <failure> attribute
"""
if msg.level == 'DEBUG':
- self._writer.content(msg.message)
-
-
-class _NopSerializer:
- """Default policy when there's no detail to serialize"""
-
- def end_test(self):
- pass
-
- def message(self, msg):
- pass
+ self._writer.content(msg.message + os.linesep)