<commit_before>#!/usr/bin/env python
import sys
import unittest

"""
XML Test Runner for PyUnit
"""

# Written by <NAME> <<EMAIL>> and placed in
# the Public Domain.

import os.path
import re
import time
import traceback
from StringIO import StringIO
from xml.sax.saxutils import escape

from StringIO import StringIO


class _TestInfo(object):
    """Information about a particular test.
    
    Used by _XmlTestResult."""
    def __init__(self, test, time):
        (self._class, self._method) = test.id().rsplit(".", 1)
        self._time = time
        self._error = None
        self._failure = None

    @staticmethod
    def create_success(test, time):
        """Create a _TestInfo instance for a successful test."""
        return _TestInfo(test, time)

    @staticmethod
    def create_failure(test, time, failure):
        """Create a _TestInfo instance for a failed test."""
        info = _TestInfo(test, time)
        info._failure = failure
        return info

    @staticmethod
    def create_error(test, time, error):
        """Create a _TestInfo instance for an erroneous test."""
        info = _TestInfo(test, time)
        info._error = error
        return info

    def print_report(self, stream):
        """Print information about this test case in XML format to the
        supplied stream.
        """
        stream.write('  <testcase classname="%(class)s" name="%(method)s" time="%(time).4f">' % \
            {
                "class": self._class,
                "method": self._method,
                "time": self._time,
            })
        if self._failure != None:
            self._print_error(stream, 'failure', self._failure)
        if self._error != None:
            self._print_error(stream, 'error', self._error)
        stream.write('</testcase>\n')

    def _print_error(self, stream, tagname, error):
        """Print information from a failure or error to the supplied stream."""
        text = escape(str(error[1]))
        stream.write('\n')
        stream.write('    <%s type="%s">%s\n' \
            % (tagname, str(error[0]), text))
        tb_stream = StringIO()
        traceback.print_tb(error[2], None, tb_stream)
        stream.write(escape(tb_stream.getvalue()))
        stream.write('    </%s>\n' % tagname)
        stream.write('  ')


class _XmlTestResult(unittest.TestResult):
    """A test result class that stores result as XML.
<commit_msg>Removes <> from <error> type, which breaks hudson<commit_after>#!/usr/bin/env python
import sys
import unittest

"""
XML Test Runner for PyUnit
"""

# Written by <NAME> <<EMAIL>> and placed in
# the Public Domain.

import os.path
import re
import time
import traceback
from StringIO import StringIO
from xml.sax.saxutils import escape

from StringIO import StringIO


class _TestInfo(object):
    """Information about a particular test.
    
    Used by _XmlTestResult."""
    def __init__(self, test, time):
        (self._class, self._method) = test.id().rsplit(".", 1)
        self._time = time
        self._error = None
        self._failure = None

    @staticmethod
    def create_success(test, time):
        """Create a _TestInfo instance for a successful test."""
        return _TestInfo(test, time)

    @staticmethod
    def create_failure(test, time, failure):
        """Create a _TestInfo instance for a failed test."""
        info = _TestInfo(test, time)
        info._failure = failure
        return info

    @staticmethod
    def create_error(test, time, error):
        """Create a _TestInfo instance for an erroneous test."""
        info = _TestInfo(test, time)
        info._error = error
        return info

    def print_report(self, stream):
        """Print information about this test case in XML format to the
        supplied stream.
        """
        stream.write('  <testcase classname="%(class)s" name="%(method)s" time="%(time).4f">' % \
            {
                "class": self._class,
                "method": self._method,
                "time": self._time,
            })
        if self._failure != None:
            self._print_error(stream, 'failure', self._failure)
        if self._error != None:
            self._print_error(stream, 'error', self._error)
        stream.write('</testcase>\n')

    def _print_error(self, stream, tagname, error):
        """Print information from a failure or error to the supplied stream."""
        text = escape(str(error[1]))
        stream.write('\n')
        error_type = str(error[0])
        error_type = error_type.replace("<","").replace(">","").strip()
        stream.write('    <%s type="%s">%s\n' \
            % (tagname, error_type, text))
        tb_stream = StringIO()
        traceback.print_tb(error[2], None, tb_stream)
        stream.write(escape(tb_stream.getvalue()))
        stream.write('    </%s>\n' % tagname)
        stream.write('  ')


class _XmlTestResult(unittest.TestResult):
    """A test result class that stores result as XML.

{'fraction_non_alphanumeric': 0.12570507655116842, 'fraction_numerical': 0.00201450443190975, 'mean_word_length': 2.43598615916955, 'pattern_counts': {'":': 6, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5764688', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1421, 'n_words': 422}