Permalink
Browse files

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

  • Loading branch information...
1 parent db8c5d5 commit e2512eaed1426ebe3146b906a5c4f1b5f0b5f56b @vitek vitek committed Feb 22, 2012
Showing with 12 additions and 5 deletions.
  1. +12 −5 Cython/Tests/xmlrunner.py
View
@@ -43,6 +43,14 @@ def test_sample(self):
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 @@ def _report_testcase(suite_name, test_result, xml_testsuite, xml_document):
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,28 +263,27 @@ def _report_output(test_runner, xml_testsuite, xml_document, stdout, stderr):
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 \
os.path.exists(test_runner.output):
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)

0 comments on commit e2512ea

Please sign in to comment.