HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/_pytest/__pycache__/junitxml.cpython-310.pyc
o

%wemd�@s�dZddlZddlZddlZddlZddlmmZddl	m	Z	ddl
mZddl
mZddl
m
Z
ddl
mZddl
mZdd	l
mZdd
l
mZddlZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl"m#Z#ddl$m%Z%e#d�Z&de'de(fdd�Z)dCdd�Z*iZ+dddgie+d <dgd!�ie+d"<e+d �,�e+d#<e*e+d#e+d"�e+d e+d$<Gd%d&�d&�Z-d'ed(e(ddfd)d*�Z.ej/d'edee(e'gdffd+d,��Z0ej/d'edee(e'gdffd-d.��Z1d/e(d0e(ddfd1d2�Z2ej/d3d4�d'edee(e'gdffd5d6��Z3d7eddfd8d9�Z4d:eddfd;d<�Z5d:eddfd=d>�Z6d?e(de
e(fd@dA�Z7GdBd�d�Z8dS)DaReport test results in JUnit-XML format, for use with Jenkins and build
integration servers.

Based on initial code from Ross Lawley.

Output conforms to
https://github.com/jenkinsci/xunit-plugin/blob/master/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd
�N)�datetime)�Callable)�Dict)�List)�Match)�Optional)�Tuple)�Union)�nodes)�timing)�
ExceptionRepr)�ReprFileLocation)�Config)�filename_arg)�Parser)�FixtureRequest)�
TestReport)�StashKey)�TerminalReporter�LogXML�arg�returncCs,dttdtfdd�}d}t�||t|��S)a!Visually escape invalid XML characters.

    For example, transforms
        'hello\aworld\b'
    into
        'hello#x07world#x08'
    Note that the #xABs are *not* XML escapes - missing the ampersand &#xAB.
    The idea is to escape visually for the user rather than for XML itself.
    �matchobjrcSs$t|���}|dkrd|Sd|S)N�z#x%02Xz#x%04X)�ord�group)r�i�r�I/home/arjun/projects/env/lib/python3.10/site-packages/_pytest/junitxml.py�repl3szbin_xml_escape.<locals>.replu [^	

 -~€-퟿-�က0-ჿFF])r�str�re�sub)rr�illegal_xml_rerrr�bin_xml_escape(s�r$cCsXi}|��D]\}}|��D]\}}t|t�stt|���||||<qq|�|�dS�N)�items�
isinstance�list�	TypeError�type�update)�left�right�result�kl�vl�kr�vrrrr�merge_familyCs
�r3�testcase�	classname�name�_base)�file�line�url�_base_legacy�xunit1�xunit2c	@sxeZdZdeeefddddfdd�Zdejddfd	d
�Z	dede
ddfd
d�Zdede
ddfdd�Zde
ejfdd�Zdeddfdd�Zdejfdd�Zd5dedede
eddfdd�Zdeddfdd�Zd ed!edefd"d#�Zded ed$eddfd%d&�Zdeddfd'd(�Zdeddfd)d*�Zdeddfd+d,�Zdeddfd-d.�Zdeddfd/d0�Zdeddfd1d2�Zd6d3d4�ZdS)7�
_NodeReporter�nodeid�xmlrrNcCs<||_||_|jj|_|jj|_d|_g|_g|_i|_dS)N�)�idr@�	add_stats�family�duration�
propertiesr
�attrs)�selfr?r@rrr�__init__Zs


z_NodeReporter.__init__�nodecCs|j�|j�|j�|�dSr%)r@rC�tagr
�append)rHrJrrrrLdsz_NodeReporter.appendr6�valuecCs|j�t|�t|�f�dSr%)rFrLr r$�rHr6rMrrr�add_propertyhsz_NodeReporter.add_propertycCst|�|jt|�<dSr%)r$rGr rNrrr�
add_attributek�z_NodeReporter.add_attributecC�>|jrt�d�}|jD]\}}|�tjd||d��q|SdS�z9Return a Junit node containing custom properties, if any.rF�property�r6rMN)rF�ET�ElementrL�rHrFr6rMrrr�make_properties_noden�
z"_NodeReporter.make_properties_node�
testreportcCs�t|j�}|j}|dd�}|jjr|�d|jj�d�|�t|d�|jdd�}|jddur:t	|jd�|d<t
|d�rD|j|d<||_|j�|�|j
dkrTdSi}|j��D]}|t|j
d	vrm|j|||<q[||_dS)
N���r�.)r5r6r8�r9r:r<r4)�mangle_test_addressr?rGr@�prefix�insert�joinr$�locationr �hasattrr:r+rD�keys�families)rHr[�names�existing_attrs�
classnamesrG�
temp_attrs�keyrrr�record_testreportws.

�


�
z_NodeReporter.record_testreportcCsBtjd|jd|jd�}|��}|dur|�|�|�|j�|S)Nr4�%.3f)�time)rVrWrGrErYrL�extendr
)rHr4rFrrr�to_xml�s
z_NodeReporter.to_xmlrK�message�datacCs&tj||d�}t|�|_|�|�dS)N)rq�rVrWr$�textrL)rHrKrqrrrJrrr�_add_simple�s
z_NodeReporter._add_simple�reportcCs�|jjs	|jr	dS|j}|j}|j}|jjdkrdSd}|jjdvr(|�|d�}|jjdvr?||�|d�7}|�||d�d}|jjdvrV||�|d	�7}|�||d
�d}|ra|�||d�dSdS)N�no�)�log�allz Captured Log )�
system-out�out-errrzz Captured Out r{)�
system-errr|rzz Captured Err r})	r@�log_passing_tests�passed�	capstdout�caplog�	capstderr�logging�_prepare_content�_write_content)rHrv�content_out�content_log�content_err�content_allrrr�write_captured_output�s*�z#_NodeReporter.write_captured_output�content�headercCsd�|�dd�|dg�S)N�
�P�-rx)rb�center)rHr�r�rrrr���z_NodeReporter._prepare_content�jheadercCs"t�|�}t|�|_|�|�dSr%rs)rHrvr�r�rKrrrr��s

z_NodeReporter._write_contentcCs|�d�dS)Nr)rC�rHrvrrr�append_pass��z_NodeReporter.append_passcCspt|d�r
|�dd�dS|jdusJ�t|jdd�}|dur#|j}nt|j�}t|�}|�d|t|j��dS)N�wasxfail�skippedz%xfail-marked test passes unexpectedly�	reprcrash�failure)rdru�longrepr�getattrrqr r$)rHrvr�rqrrr�append_failure�s
�
z_NodeReporter.append_failurecCs&|jdusJ�|�ddt|j��dS)N�errorzcollection failure)r�rur r�rrr�append_collect_error�sz"_NodeReporter.append_collect_errorcCs|�ddt|j��dS)Nr�zcollection skipped)rur r�r�rrr�append_collect_skipped�r�z$_NodeReporter.append_collect_skippedcCsv|jdusJ�t|jdd�}|dur|j}nt|j�}|jdkr'd|�d�}nd|�d�}|�dt|�t|j��dS)Nr��teardownzfailed on teardown with "�"zfailed on setup with "r�)r�r�rqr �whenrur$)rHrvr��reason�msgrrr�append_error�s�

z_NodeReporter.append_errorcCs�t|d�r&|j}|�d�r|dd�}t|�}tjdd|d�}|�|�dSt|jt	�s.J�|j\}}}|�d�r?|dd�}|�d	|�d
|��}tjdd|d�}t|�|_
|�|�|�|�dS)Nr�zreason: �r�zpytest.xfail)r*rqz	Skipped: �	�:z: zpytest.skip)rdr��
startswithr$rVrWrLr'r��tuplertr�)rHrv�xfailreasonr��filename�lineno�
skipreason�detailsrrr�append_skipped�s 




z_NodeReporter.append_skippedcs$|���|j���fdd�|_dS)Ncs�Sr%rr�rrrr�<lambda>sz(_NodeReporter.finalize.<locals>.<lambda>)rp�__dict__�clear�rHrr�r�finalizes
z_NodeReporter.finalizer%�rN)�__name__�
__module__�__qualname__r	r rrIrVrWrL�objectrOrPrrYrlrprur�r�r�r�r�r�r�r�r�r�rrrrr>Ys&
	 r>�request�fixture_namecCsVddlm}|jj�td�}|dur'|jdvr)|j�|dj	||jd���dSdSdS)z[Emit a PytestWarning about the given fixture being incompatible with newer xunit revisions.r)�
PytestWarningN)r<�legacyzV{fixture_name} is incompatible with junit_family '{family}' (use 'legacy' or 'xunit1'))r�rD)
�_pytest.warning_typesr��config�stash�get�xml_keyrDrJ�warn�format)r�r�r�r@rrr�!_warn_incompatibility_with_xunit2s����r�cs(t�d�dtdtddf�fdd�}|S)anAdd extra properties to the calling test.

    User properties become part of the test report and are available to the
    configured reporters, like JUnit XML.

    The fixture is callable with ``name, value``. The value is automatically
    XML-encoded.

    Example::

        def test_function(record_property):
            record_property("example_key", 1)
    �record_propertyr6rMrNcs�jj�||f�dSr%)rJ�user_propertiesrLrU�r�rr�append_property*rQz(record_property.<locals>.append_property)r�r r�)r�r�rr�rr�s
r�cCspddlm}|j�|d��t|d�dtdtddfd	d
�}|}|jj�	t
d�}|dur6|�|jj�}|j
}|S)z�Add extra xml attributes to the tag for the calling test.

    The fixture is callable with ``name, value``. The value is
    automatically XML-encoded.
    r)�PytestExperimentalApiWarningz/record_xml_attribute is an experimental feature�record_xml_attributer6rMrNcSsdSr%rrUrrr�
add_attr_noop@sz+record_xml_attribute.<locals>.add_attr_noop)r�r�rJr�r�r r�r�r�r�r��
node_reporterr?rP)r�r�r��	attr_funcr@r�rrrr�0s�
r��param�vcCs.d}t|t�sd}t|j|t|�jd���dS)zcUsed by record_testsuite_property to check that the given parameter name is of the proper
    type.Tz5{param} parameter needs to be a string, but {g} given)r��gN)r'r r)r�r*r�)r�r��__tracebackhide__r�rrr�_check_record_param_typeMs

�r��session)�scopecCs<d}dtdtddfdd�}|jj�td�}|dur|j}|S)a+Record a new ``<property>`` tag as child of the root ``<testsuite>``.

    This is suitable to writing global information regarding the entire test
    suite, and is compatible with ``xunit2`` JUnit family.

    This is a ``session``-scoped fixture which is called with ``(name, value)``. Example:

    .. code-block:: python

        def test_foo(record_testsuite_property):
            record_testsuite_property("ARCH", "PPC")
            record_testsuite_property("STORAGE_TYPE", "CEPH")

    :param name:
        The property name.
    :param value:
        The property value. Will be converted to a string.

    .. warning::

        Currently this fixture **does not work** with the
        `pytest-xdist <https://github.com/pytest-dev/pytest-xdist>`__ plugin. See
        :issue:`7767` for details.
    Tr6rMrNcSsd}td|�dS)zENo-op function in case --junitxml was not passed in the command-line.Tr6N)r�)r6rMr�rrr�record_funcssz.record_testsuite_property.<locals>.record_func)r r�r�r�r�r��add_global_property)r�r�r�r@rrr�record_testsuite_propertyVsr��parserc
Cs�|�d�}|jdddddtjtdd�ddd	�|jd
ddddd
d�|jdddd�|jdddd�|jddddd�|jdddd�|jddd d�dS)!Nzterminal reportingz
--junitxmlz--junit-xml�store�xmlpath�path)�optnamez0Create junit-xml style report file at given path)�action�dest�metavarr*�default�helpz
--junitprefixz--junit-prefixr z0Prepend prefix to classnames in junit-xml output)r�r�r�r��junit_suite_namez Test suite name for JUnit report�pytest)r��
junit_loggingz\Write captured log messages to JUnit report: one of no|log|system-out|system-err|out-err|allrw�junit_log_passing_testsz;Capture log information for passing tests to JUnit report: �boolT)r*r��junit_duration_reportz*Duration time to report: one of total|call�total�junit_familyz0Emit XML for schema: one of legacy|xunit1|xunit2r=)�getgroup�	addoption�	functools�partialr�addini)r�rrrr�pytest_addoption~sV
�
�����
�r�r�c
Cst|jj}|r6t|d�s8|�d�}t||jj|�d�|�d�|�d�||�d��|jt<|j�	|jt�dSdSdS)N�workerinputr�r�r�r�r�)
�optionr�rd�getinir�junitprefixr�r��
pluginmanager�register)r�r�r�rrr�pytest_configure�s

�	�r�cCs.|j�td�}|r|jt=|j�|�dSdSr%)r�r�r�r��
unregister)r�r@rrr�pytest_unconfigure�s
�r��addresscCs^|�d�\}}}|�d�}|d�tjd�|d<t�dd|d�|d<|d||7<|S)N�[z::rr]z\.py$rxr\)�	partition�split�replacer
�SEPr!r")r�r��possible_open_bracket�paramsrgrrrr_�s
r_c
@s&eZdZ					d/deededed	ed
eddfd
d�Zdeddfdd�Zde	eefde
fdd�Zdeddfdd�Zdede
fdd�Z
deddfdd�Zdeddfdd�Zdeddfdd�Zdeddfd d!�Zd0d"d#�Zd0d$d%�Zd&eddfd'd(�Zd)ed*eddfd+d,�Zdeejfd-d.�ZdS)1rr�rwr�r<Tr`�
suite_namer��report_durationr~rNcCs�tj�tj�|��}tj�tj�|��|_||_||_||_	||_
||_||_t
�gd�d�|_i|_g|_g|_g|_d|_|jdkrId|_dSdS)N)r�rr�r�rr�r<)�osr��
expanduser�
expandvars�normpath�abspath�logfiler`rr�r~rrD�dict�fromkeys�stats�node_reporters�node_reporters_ordered�global_properties�open_reports�cnt_double_fail_tests)rHrr`rr�rrDr~rrrrI�s(
��

�zLogXML.__init__rvcCs`t|d|�}t|dd�}|j�||f�}|jD]\}}|�|t|��q|dur.|��dSdS�Nr?rJ)r�r�popr�rOr r�)rHrvr?�
workernode�reporter�propname�	propvaluerrrr��s�zLogXML.finalizecCsXt|d|�}t|dd�}||f}||jvr|j|St||�}||j|<|j�|�|Sr)r�rr>rrL)rHrvr?rrkrrrrr�s



zLogXML.node_reporterrkcCs$||jvr|j|d7<dSdS)Nr^)r)rHrkrrrrCs
�zLogXML.add_statscCs|�|�}|�|�|Sr%)r�rl�rHrvrrrr�
_opentestcases

zLogXML._opentestcasecsrd}�jr�jdkr|���}|���nb�jrj�jdkrFt�dd��t�dd��t���fdd�|jD�d�}|rF|�|�|j	d7_	|���}�jdkrd|�
��|j���|jsc|�
��n|���n
�jrw|���}|���|����jdkr�|���}|�
��|���t�dd��t�dd��t���fd	d�|jD�d�}|r�|j�|�dSdSdS)
aHandle a setup/call/teardown report, generating the appropriate
        XML tags as necessary.

        Note: due to plugins like xdist, this hook may be called in interlaced
        order with reports from other nodes. For example:

        Usual call order:
            -> setup node1
            -> call node1
            -> teardown node1
            -> setup node2
            -> call node2
            -> teardown node2

        Possible call order in xdist:
            -> setup node1
            -> call node1
            -> setup node2
            -> call node2
            -> teardown node2
            -> teardown node1
        N�callr��	worker_id�
item_indexc3�@�|]}|j�jkrt|dd��krt|dd��kr|VqdS�rNr�r?r���.0�rep�rv�	report_ii�
report_widrr�	<genexpr>=����z2LogXML.pytest_runtest_logreport.<locals>.<genexpr>r^c3rr r!r"r%rrr(br))rr�rr��failedr��nextrr�rr�rLr~r�r�r�r��update_testcase_duration�remove)rHrv�close_reportrrr%r�pytest_runtest_logreports^


�
�	�




�






�	��zLogXML.pytest_runtest_logreportcCs>|jdks|j|jkr|�|�}|jt|dd�7_dSdS)z�Accumulate total duration for nodeid from given report and update
        the Junit.testcase with the new total if already created.r�rErAN)rr�r�rEr�rrrrr,ps
�zLogXML.update_testcase_durationcCs6|js|�|�}|jr|�|�dS|�|�dSdSr%)rrr*r�r�rrrr�pytest_collectreportws
�zLogXML.pytest_collectreport�excreprcCs0|�d�}|jjddd�|�ddt|��dS)N�internalr�)r5r6r�zinternal error)r�rGr+rur )rHr1rrrr�pytest_internalerrors
zLogXML.pytest_internalerrorcCst��|_dSr%)rrn�suite_start_timer�rrr�pytest_sessionstart�r�zLogXML.pytest_sessionstartc
CsTtj�tj�|j��}tj|dd�t|jddd���}t��}||j	}|j
d|j
d|j
d|j
d	|j}|�d
�t
jd|jt|j
d	�t|j
d�t|j
d�t|�d|t�|j	���t��d
�	}|��}|durw|�|�|jD]	}|�|���qzt
�d�}	|	�|�|�t
j|	dd��Wd�dS1s�wYdS)NT)�exist_ok�wzutf-8)�encodingrr�r�r�z&<?xml version="1.0" encoding="utf-8"?>�	testsuiterm)r6�errors�failuresr��testsrn�	timestamp�hostname�
testsuites�unicode)rr��dirnamer
r�makedirs�openrrnr4rr�writerVrWrr r�
fromtimestamp�	isoformat�platformrJ�_get_global_properties_noderLrrp�tostring)
rHrAr�suite_stop_time�suite_time_delta�numtests�
suite_noderr�r?rrr�pytest_sessionfinish�sH
�����
�



"�zLogXML.pytest_sessionfinish�terminalreportercCs|�dd|j���dS)Nr�zgenerated xml file: )�	write_sepr)rHrOrrr�pytest_terminal_summary�r�zLogXML.pytest_terminal_summaryr6rMcCs&d}td|�|j�|t|�f�dS)NTr6)r�rrLr$)rHr6rMr�rrrr��s
zLogXML.add_global_propertycCrRrS)rrVrWrLrXrrrrH�rZz"LogXML._get_global_properties_node)r�rwr�r<Tr�)r�r�r�rr r�rIrr�r	r>r�rCrr/r,r0rr3r5rNrrQr�r�rVrWrHrrrrr�s@������	
�#U

&r�)9�__doc__r�rrGr!�xml.etree.ElementTree�etree�ElementTreerVr�typingrrrrrrr	r��_pytestr
r�_pytest._code.coderr
�_pytest.configrr�_pytest.config.argparsingr�_pytest.fixturesr�_pytest.reportsr�
_pytest.stashr�_pytest.terminalrr�r�r r$r3rf�copyr>r��fixturer�r�r�r�r�r�r�r_rrrrr�<module>sp


0��
�  
	 '/