Skip to content

Commit

Permalink
xmlrunner: use TextNode when data can't be represented as single CDATA
Browse files Browse the repository at this point in the history
  • Loading branch information
vitek committed Feb 22, 2012
1 parent db8c5d5 commit e2512ea
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Cython/Tests/xmlrunner.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit e2512ea

Please sign in to comment.