PK APOCALYPSE V1

APOCALYPSE V1

Current Path : /opt/hc_python/lib/python3.12/site-packages/nose/plugins/__pycache__/
Upload File :
Current File : //opt/hc_python/lib/python3.12/site-packages/nose/plugins/__pycache__/xunit.cpython-312.pyc

�

���g}-���dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
m
Z
ddlmZddl
mZddlmZddlmZmZej(d	�Zej(d
�Zd�Zd�Zd
�Zd�Zd�ZGd�de�ZGd�de�Zy)aUThis plugin provides test results in the standard XUnit XML format.

It's designed for the `Jenkins`_ (previously Hudson) continuous build
system, but will probably work for anything else that understands an
XUnit-formatted XML representation of test results.

Add this shell command to your builder ::

    nosetests --with-xunit

And by default a file named nosetests.xml will be written to the
working directory.

In a Jenkins builder, tick the box named "Publish JUnit test result report"
under the Post-build Actions and enter this value for Test report XMLs::

    **/nosetests.xml

If you need to change the name or location of the file, you can set the
``--xunit-file`` option.

If you need to change the name of the test suite, you can set the
``--xunit-testsuite-name`` option.

Here is an abbreviated version of what an XML test report might look like::

    <?xml version="1.0" encoding="UTF-8"?>
    <testsuite name="nosetests" tests="1" errors="1" failures="0" skip="0">
        <testcase classname="path_to_test_suite.TestSomething"
                  name="test_it" time="0">
            <error type="exceptions.TypeError" message="oops, wrong type">
            Traceback (most recent call last):
            ...
            TypeError: oops, wrong type
            </error>
        </testcase>
    </testsuite>

.. _Jenkins: http://jenkins-ci.org/

�N)�StringIO)�time)�saxutils)�Plugin)�SkipTest)�
force_unicode�format_exceptionz[\000-\010\013\014\016-\037]z^(.*?)(\(.*\))$c�.�tjd|�S)z)Replaces invalid XML characters with '?'.�?)�CONTROL_CHARACTERS�sub)�values �A/opt/hc_python/lib/python3.12/site-packages/nose/plugins/xunit.py�xml_safer>s���!�!�#�u�-�-�c�8�t|�jdd�S)z)Escape a string for an XML CDATA section.z]]>z]]>]]&gt;<![CDATA[)r�replace)�cdatas r�escape_cdatarBs���E�?�"�"�5�*>�?�?rc��tj|�}|r/|j�\}}|jdd�\}}|||zgS|jdd�S)N�.�)�TEST_ID�match�groups�rsplit)�idval�m�name�fargs�head�tails      r�id_splitr#FsV���
�
�e��A���h�h�j���e��[�[��a�(�
��d��d�5�j�!�!��|�|�C��#�#rc��tj|�r
|j}n|jj}tj|�}|r2|j}|jd�r|t
d�d}|�d|��S|S)z�Returns a nice name for class object or class instance.

        >>> nice_classname(Exception()) # doctest: +ELLIPSIS
        '...Exception'
        >>> nice_classname(Exception) # doctest: +ELLIPSIS
        '...Exception'

    zorg.python.core.Nr)�inspect�isclass�__name__�	__class__�	getmodule�
startswith�len)�obj�cls_name�modrs    r�nice_classnamer/Ost�����s���<�<���=�=�)�)��
�
�
�C�
 �C�
��|�|���?�?�-�.���.�/�0�1�D���)�)��rc���|d}|�|d}n	t|�}t	|d�}t|�S#t$r.	t|�}n#t$r|jd}YnwxYwY�MwxYw)zReturn the exception's message.rr�UTF-8)�str�UnicodeEncodeError�UnicodeError�argsrr)�exc_info�exc�results   r�exc_messager9fs}��
�1�+�C�
�{��!���	%���X�F��6�7�
+�F��F����"�	%�
%��S�����
%����!���
%��	%�s2�1�	A(�A�A(�A"�A(�!A"�"A(�'A(c�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�Teec� �||_||_y�N)�	_encoding�_streams)�self�encodingr5s   r�__init__zTee.__init__zs��!�����
rc�t�t||j�}|jD]}|j|��yr=)rr>r?�write)r@�data�ss   rrDz	Tee.write~s+���T�4�>�>�2�����A�
�G�G�D�M�rc�4�|D]}|j|��yr=)rD)r@�lines�lines   r�
writelineszTee.writelines�s���D��J�J�t��rc�F�|jD]}|j��yr=)r?�flush)r@rFs  rrLz	Tee.flush�s�����A�
�G�G�I�rc��y)NF��r@s r�isattyz
Tee.isatty�s��rN)r'�
__module__�__qualname__rBrDrJrLrPrNrrr;r;ys����
��rr;c���eZdZdZdZdZdZdZ�fd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zdd�Zdd�Zdd�Z�xZS)�XunitzCThis plugin provides test results in the standard XUnit XML format.�xuniti�r1Nc�T��tt|��g|_d|_d|_yr=)�superrTrB�_capture_stack�_currentStdout�_currentStderr)r@r(s �rrBzXunit.__init__�s(���
�e�T�#�%� ���"���"��rc�T�t|d�rt�|jz
}|Sd}|S)N�_timerg)�hasattrrr\)r@�takens  r�
_timeTakenzXunit._timeTaken�s/���4��"��F�T�[�[�(�E����E��rc�B�t|�}tj|�S)z.Escape an XML attribute. Value can be unicode.)rr�	quoteattr)r@�attrs  r�
_quoteattrzXunit._quoteattr�s����~���!�!�$�'�'rc
���tj|||�|jdddd|jdd�d��|jd	dd
d|jdd
�d��y)z%Sets additional command line options.z--xunit-file�store�
xunit_file�FILE�NOSE_XUNIT_FILEz
nosetests.xmlzrPath to xml file to store the xunit report in. Default is nosetests.xml in the working directory [NOSE_XUNIT_FILE])�action�dest�metavar�default�helpz--xunit-testsuite-name�xunit_testsuite_name�PACKAGE�NOSE_XUNIT_TESTSUITE_NAME�	nosetestszbName of the testsuite in the xunit xml, generated by plugin. Default test suite name is nosetests.N)r�options�
add_option�get)r@�parser�envs   rrrz
Xunit.options�sv�����t�V�S�)�����7��v��G�G�-��?�&�		�	(�	���$�W�'���G�G�7��E�:�		�	<rc��tj|||�||_|jrSddddd�|_g|_tjj|j�|_
|j|_yy)zConfigures the xunit plugin.r)�errors�failures�passes�skippedN)r�	configure�config�enabled�stats�	errorlist�os�path�realpathrf�error_report_file_namern)r@rrr}s   rr|zXunit.configure�sp������w��/�����<�<�$%�&'�$%�%&��D�J�
 �D�N�*,�'�'�*:�*:�7�;M�;M�*N�D�'�(/�(D�(D�D�%�rc�x�tj|jd|jd�|_|j|j
d<|j|j
d<|j
d|j
dz|j
dz|j
dz|j
d	<|jjd
|j
z�|jjdj|jD�cgc]}t||j���c}��|jjd�|jj�|jjd
kDr:|jd�|jd|jjz�yycc}w)zmWrites an Xunit-formatted XML file

        The file includes a report of test errors and failures.

        �wrrA�testsuite_namerxryrzr{�totalz�<?xml version="1.0" encoding="%(encoding)s"?><testsuite name="%(testsuite_name)s" tests="%(total)d" errors="%(errors)d" failures="%(failures)d" skip="%(skipped)d">�z</testsuite>rzF----------------------------------------------------------------------zXML: %sN)�codecs�openr�rA�error_report_filerrnrD�joinr�r�closer}�	verbosity�writelnr)r@�stream�es   r�reportzXunit.report�sz��"(���T�-H�-H�#�-1�]�]�I�"G���!%����
�
�:��'+�'@�'@��
�
�#�$�#�z�z�(�3�d�j�j��6L�L�!%���H�!5� 6�8<�
�
�9�8M� N��
�
�7�����$�$�
"�%)�J�J�
/�	0�
	
���$�$�R�W�W�8<���.H�8F�1�/<�A�t�}�}�.M�8F�.H�&I�	J����$�$�^�4����$�$�&��;�;� � �1�$��N�N�8�$��N�N�9�t�'=�'=�'B�'B�B�C�%��	.Hs�F7c��|jjtjtjf�t�|_t�|_t|j|jtj�t_t|j|jtj�t_yr=)
rX�append�sys�stdout�stderrrrYrZr;rArOs r�
_startCapturezXunit._startCapture�ss�����"�"�C�J�J��
�
�#;�<�&�j���&�j��������(;�(;�S�Z�Z�H��
������(;�(;�S�Z�Z�H��
rc�$�|j�yr=)r��r@�contexts  r�startContextzXunit.startContext�s�����rc�$�|j�yr=)�_endCapturer�s  r�stopContextzXunit.stopContext�s�����rc�B�t�|_|j�y)z+Initializes a timer before starting a test.N)rr\r��r@�tests  r�
beforeTestzXunit.beforeTest�s���f������rc�|�|jr0|jj�\t_t_yyr=)rX�popr�r�r�rOs rr�zXunit._endCapture�s-�����%)�%8�%8�%<�%<�%>�"�C�J��
�rc�@�|j�d|_d|_yr=)r�rYrZr�s  r�	afterTestzXunit.afterTest�s������"���"��rc�X�|jr|j�|jr�yyr=)rXr�r�s  r�finalizezXunit.finalize�s"���!�!������!�!rc�p�|jr*|jj�}|rdt|�zSy)Nz'<system-out><![CDATA[%s]]></system-out>r�)rY�getvaluer�r@rs  r�_getCapturedStdoutzXunit._getCapturedStdout�=������'�'�0�0�2�E��@�<��D���rc�p�|jr*|jj�}|rdt|�zSy)Nz'<system-err><![CDATA[%s]]></system-err>r�)rZr�rr�s  r�_getCapturedStderrzXunit._getCapturedStderrr�rc
�h�|j�}t|dt�rd}|jdxxdz
cc<nd}|jdxxdz
cc<t	||j
�}|j
�}|jjd|jt|�d�|jt|�d�|||jt|d��|jt|��t|�|j�|j�d�	z�y	)
z*Add error output to Xunit report.
        rr{r�errorrxz�<testcase classname=%(cls)s name=%(name)s time="%(taken).3f"><%(type)s type=%(errtype)s message=%(message)s><![CDATA[%(tb)s]]></%(type)s>%(systemout)s%(systemerr)s</testcase>���)	�clsrr^�type�errtype�message�tb�	systemout�	systemerrN)r_�
issubclassrrr	rA�idr�r�rcr#r/r9rr�r�)r@r��err�captr^r�r�r�s        r�addErrorzXunit.addErrors�����!���c�!�f�h�'��D��J�J�y�!�Q�&�!��D��J�J�x� �A�%� �
�c�4�=�=�
1��
�W�W�Y�������
?��O�O�H�R�L��O�4��_�_�X�b�\�"�%5�6�������s�1�v�(>�?�����C�(8�9���#��1�1�3��1�1�3�	
�
�
	rc��|j�}t||j�}|jdxxdz
cc<|j	�}|j
j
d|jt|�d�|jt|�d�||jt|d��|jt|��t|�|j�|j�d�z�y)z,Add failure output to Xunit report.
        ryrz�<testcase classname=%(cls)s name=%(name)s time="%(taken).3f"><failure type=%(errtype)s message=%(message)s><![CDATA[%(tb)s]]></failure>%(systemout)s%(systemerr)s</testcase>rr�)r�rr^r�r�r�r�r�N)r_r	rArr�r�r�rcr#r/r9rr�r�)r@r�r�r��tb_infor^r�r�s        r�
addFailurezXunit.addFailure1s������!��
�c�4�=�=�
1���
�
�:��!�#��
�W�W�Y�������
>��O�O�H�R�L��O�4��_�_�X�b�\�"�%5�6������s�1�v�(>�?�����C�(8�9���#��1�1�3��1�1�3�
�
�	rc	�^�|j�}|jdxxdz
cc<|j�}|jj	d|jt
|�d�|jt
|�d�||j�|j�d�z�y)z,Add success output to Xunit report.
        rzrzb<testcase classname=%(cls)s name=%(name)s time="%(taken).3f">%(systemout)s%(systemerr)s</testcase>rr�)r�rr^r�r�N)	r_rr�r�r�rcr#r�r�)r@r�r�r^r�s     r�
addSuccesszXunit.addSuccessGs������!���
�
�8���!��
�W�W�Y�������
G��O�O�H�R�L��O�4��_�_�X�b�\�"�%5�6���1�1�3��1�1�3�	
�
�	rr=)NN)r'rQrR�__doc__r�scorerAr�rBr_rcrrr|r�r�r�r�r�r�r�r�r�r�r�r�r��
__classcell__)r(s@rrTrT�sx���M��D��E��H���#��(�
<�$E�D�2I����
?�#�
����<�,rrT)r�r��doctestr�r��	traceback�rer%�iorr�xml.saxr�nose.plugins.baser�nose.excr�nose.pyversionrr	�compilerrrrr#r/r9�objectr;rTrNrr�<module>r�s���(�R��	�
��	�����$��:� �R�Z�Z� ?�@��
�"�*�*�'�
(��.�@�$��.�&�&��,F�F�Fr

if you don't want to be vaporized in a nuclear explosion, i simply have to become nuclear myself… i am atomic