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