Commit e2512eae authored by Vitja Makarov's avatar Vitja Makarov

xmlrunner: use TextNode when data can't be represented as single CDATA

parent db8c5d5a
......@@ -43,6 +43,14 @@ import sys
import time
from unittest import TestResult, _TextTestResult, TextTestRunner
from cStringIO import StringIO
import xml.dom.minidom
class XMLDocument(xml.dom.minidom.Document):
def createCDATAOrText(self, data):
if ']]>' in data:
return self.createTextNode(data)
return self.createCDATASection(data)
class _TestInfo(object):
......@@ -245,7 +253,7 @@ class _XMLTestResult(_TextTestResult):
failure.setAttribute('message', str(test_result.err[1]))
error_info = test_result.get_error_info()
failureText = xml_document.createCDATASection(error_info)
failureText = xml_document.createCDATAOrText(error_info)
failure.appendChild(failureText)
_report_testcase = staticmethod(_report_testcase)
......@@ -255,20 +263,19 @@ class _XMLTestResult(_TextTestResult):
systemout = xml_document.createElement('system-out')
xml_testsuite.appendChild(systemout)
systemout_text = xml_document.createCDATASection(stdout)
systemout_text = xml_document.createCDATAOrText(stdout)
systemout.appendChild(systemout_text)
systemerr = xml_document.createElement('system-err')
xml_testsuite.appendChild(systemerr)
systemerr_text = xml_document.createCDATASection(stderr)
systemerr_text = xml_document.createCDATAOrText(stderr)
systemerr.appendChild(systemerr_text)
_report_output = staticmethod(_report_output)
def generate_reports(self, test_runner):
"Generates the XML reports to a given XMLTestRunner object."
from xml.dom.minidom import Document
all_results = self._get_info_by_testcase()
if type(test_runner.output) == str and not \
......@@ -276,7 +283,7 @@ class _XMLTestResult(_TextTestResult):
os.makedirs(test_runner.output)
for suite, tests in all_results.items():
doc = Document()
doc = XMLDocument()
# Build the XML file
testsuite = _XMLTestResult._report_testsuite(suite, tests, doc)
......
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