
    RpfT                        d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ  e edd                    h dz
  Zd eD             Zdd	d
ddddZe                    e            ej        d          Zd Zd Zd ZddZej        Z eed          rej        ZneZ G d de          Z G d de          Z G d dej                   Z! G d dej"                  Z#dS )zGA Python test reporter that generates test reports in JUnit XML format.    N)saxutils)_pretty_print_reporter    >   	   
      c                 T    i | ]%}t          |          d                     |          &S )z\x{:02x})chrformat).0is     Y/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/absl/testing/xml_reporter.py
<dictcomp>r       sA     "I "I "I&'CFFKq!!"I "I "I    z&quot;z&apos;z&#xA;z&#x9;z&#xD;z&#x20;)"'
	 z^(\w+) \((\S+)\)$c                 6    t          j        | t                    S )zEscapes xml attributes.)r   escape_escape_xml_attr_conversions)contents    r   _escape_xml_attrr   7   s     
">	?	??r   c                     t                                           D ]\  }}|                     ||          } |                     dd          S )a  Escapes a string to be used as XML CDATA.

  CDATA characters are treated strictly as character data, not as XML markup,
  but there are still certain restrictions on them.

  Args:
    s: the string to be escaped.
  Returns:
    An escaped version of the input string.
  z]]>z]] >)_control_character_conversionsitemsreplace)scharescapeds      r   _escape_cdatar#   =   sL     6;;== ! !mdG			$  AA	
5&	!	!!r   c                     | | dk     rdS t           j                             | t           j        j                                                  S )zProduces an ISO8601 datetime.

  Args:
    timestamp: an Epoch based timestamp in seconds.

  Returns:
    A iso8601 format timestamp if the input is a valid timestamp, None otherwise
  Nr   )tz)datetimefromtimestamptimezoneutc	isoformat)	timestamps    r   _iso8601_timestampr,   M   sK     )a--4			(	(H%) 
) 
+ 
++49;;7r    c                    |                     |d|            |D ]M}t          |          dk    r8|d         0|d         (|                     d|d         d|d         d           N|                     d	           dS )
a+  Prints an XML header of an arbitrary element.

  Args:
    element: element name (testsuites, testsuite, testcase)
    attributes: 2-tuple list with (attributes, values) already escaped
    stream: output stream to write test report XML to
    indentation: indentation added to the element header
  <   r   N   r   z="r   >
)writelen)element
attributesstreamindentation	attributes        r   _print_xml_element_headerr:   \   s     	,,+++ww/000 > >iI!	! 8! lll1y|||<===,,ur   	_some_strc                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )_TestCaseResultaj  Private helper for _TextAndXMLTestResult that represents a test result.

  Attributes:
    test: A TestCase instance of an individual test method.
    name: The name of the individual test method.
    full_class_name: The full name of the test class.
    run_time: The duration (in seconds) it took to run the test.
    start_time: Epoch relative timestamp of when test started (in seconds)
    errors: A list of error 4-tuples. Error tuple entries are
        1) a string identifier of either "failure" or "error"
        2) an exception_type
        3) an exception_message
        4) a string version of a sys.exc_info()-style tuple of values
           ('error', err[0], err[1], self._exc_info_to_string(err))
           If the length of errors is 0, then the test is either passed or
           skipped.
    skip_reason: A string explaining why the test was skipped.
  c                 (   d| _         d| _        d | _        g | _        || _        |                                pt          |          }t                              |          }|r+|	                    d          }|	                    d          }nt          j                            |j                  }t          |t          j        j                  r)t          j                            |j        j                  }|                    |dz             r|t'          |          dz   d          }|}n;|                    dd          }|d         }t'          |          dk    r|d         nd}t+          |          | _        t+          |          | _        d S )Nr1   r0   .r   r-   )run_time
start_timeskip_reasonerrorstestidstr&_CLASS_OR_MODULE_LEVEL_TEST_DESC_REGEXmatchgroupunittestutilstrclass	__class__
isinstancecase_SubTest	test_case
startswithr4   rsplitr   namefull_class_name)selfrE   	test_descrI   rU   rV   
class_namepartss           r   __init__z_TestCaseResult.__init__   se   DMDODDKDI 		&SYYI288CCE >[[^^dAoo=))$.99j	D(-0	1	1 F ]++DN,DEE
			j3.	/	/ 
> Z*++,$   a((Ry&)%jjAoo%((2 &&DI+O<<Dr   c                     || _         d S N)rA   rW   time_in_secss     r   set_run_timez_TestCaseResult.set_run_time   s     DMMMr   c                     || _         d S r]   rB   r^   s     r   set_start_timez_TestCaseResult.set_start_time   s    "DOOOr   c           	          | j         d}d}nd}d}dd| j        z  fdd|z  fd	d|z  fd
d| j        z  fd| j        fdt	          | j                  fg}t          d||d           |                     |           |                    d           dS )aQ  Prints an XML Summary of a TestCase.

    Status and result are populated as per JUnit XML test result reporter.
    A test that has been skipped will always have a skip reason,
    as every skip method in Python's unittest requires the reason arg to be
    passed.

    Args:
      stream: output stream to write test report XML to
    Nrun	completednotrun
suppressedrU   %sstatusresulttime%.3f	classnamer+   testcasez  z  </testcase>
)	rC   rU   rA   rV   r,   rB   r:   _print_testcase_detailsr3   )rW   r7   rj   rk   test_case_attributess        r   print_xml_summaryz!_TestCaseResult.print_xml_summary   s     fffff 
	!"	4&=!	4&=!	$-'(	d*+	(99: j*>MMM  (((
LL"#####r   c                     | j         D ]u}|\  }}}}t          t          |                    }t          t          |                    }t	          |          }|                    d|d|d|d|d|d           vd S )Nz  <z
 message="z" type="z"><![CDATA[z]]></r2   )rD   r   	_safe_strrG   r#   r3   )rW   r7   erroroutcomeexception_typemessage	error_msgs          r   rp   z'_TestCaseResult._print_testcase_details   s     M M491g~w	 7!3!344g'N(;(;<<n	**illlggwww			777L M M M MM Mr   N)	__name__
__module____qualname____doc__r[   r`   rc   rr   rp    r   r   r=   r=   w   so         &#= #= #=J! ! !# # #$ $ $>M M M M Mr   r=   c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	_TestSuiteResultz)Private helper for _TextAndXMLTestResult.c                 Z    i | _         i | _        i | _        d| _        d| _        i | _        d S )Nr?   )suitesfailure_countserror_countsoverall_start_timeoverall_end_time_testsuites_properties)rW   s    r   r[   z_TestSuiteResult.__init__   s7    DKDD DD"$Dr   c                    t          |j                  j        }|dk    r |j                            d          d         }t          |j        t          j        j                  rt          |j        j	                  j        }| 
                    |           | j        |                             |           |j        D ]J}|d         dk    r| j        |xx         dz  cc<    d S |d         dk    r| j        |xx         dz  cc<    d S Kd S )N_ErrorHolderr@   r?   r   failurer1   ru   )typerE   rz   rV   rT   rO   rK   rP   rQ   rR   _setup_test_suiter   appendrD   r   r   )rW   test_case_result
suite_nameru   s       r   add_test_case_resultz%_TestSuiteResult.add_test_case_result   s0   &+,,5J^## $3::3??Cj"')?@@ B (-788Aj:&&&K
""#3444!(   
qY		J'''1,'''8w*%%%*%%%  r   c                    t          d | j                                        D                       }t          | j                                                  }t          | j                                                  }ddd|z  fdd|z  fdd|z  fdd| j        | j        z
  z  fd	t          | j                  fg}t          d
||           | j	        r|
                    d           t          | j	                                                  D ]H\  }}|
                    dt          |          dt          t          |                    d           I|
                    d           | j        D ]}| j        |         }	t          d |	D                       }
t!          d |	D                       }| j        |         }| j        |         }dd|z  fddt#          |	          z  fdd|z  fdd|z  fdd|
|z
  z  fd	t          |          fg}t          d||           t          |	d           D ]}|                    |           |
                    d           |
                    d           d S )Nc              3   4   K   | ]}t          |          V  d S r]   )r4   r   xs     r   	<genexpr>z5_TestSuiteResult.print_xml_summary.<locals>.<genexpr>  s(      BBSVVBBBBBBr   )rU   r-   testsz%dfailuresrD   rl   rm   r+   
testsuitesz    <properties>
z      <property name="z	" value="z"></property>
z    </properties>
c              3   4   K   | ]}|j         |j        z   V  d S r]   )rB   rA   r   s     r   r   z5_TestSuiteResult.print_xml_summary.<locals>.<genexpr>  s+      DD1<!*4DDDDDDr   c              3   $   K   | ]}|j         V  d S r]   rb   r   s     r   r   z5_TestSuiteResult.print_xml_summary.<locals>.<genexpr>  s$      99aQ\999999r   rU   ri   	testsuitec                     | j         S r]   )rU   )ts    r   <lambda>z4_TestSuiteResult.print_xml_summary.<locals>.<lambda>'  s    !& r   )keyz</testsuite>
z</testsuites>
)sumr   valuesr   r   r   r   r,   r:   r   r3   sortedr   r   rG   maxminr4   rr   )rW   r7   overall_test_countoverall_failuresoverall_errorsoverall_attributesrU   valuer   suitesuite_end_timesuite_start_timer   rD   suite_attributesr   s                   r   rr   z"_TestSuiteResult.print_xml_summary  s   BBT[-?-?-A-ABBBBB4.557788*113344N	$++,	T,,-	4.()	4043JJKL	()@AAB l,>GGG" *ll'((( ; A A C CDD M M+$&t,,,,.>s5zz.J.J.J.JL 	M 	M 	M 	Mll()))k % %
k*%eDDeDDDDDn99599999$Z0h ,f4*$
%D3u::%
&th
'TF]
#6^.>>?
@*+;<<
=  -=vFFF %U0@0@AAA 3 3
**62222ll#$$$$
LL"#####r   c                 X    || j         v rdS g | j         |<   d| j        |<   d| j        |<   dS )zAdds a test suite to the set of suites tracked by this test run.

    Args:
      suite_name: string, The name of the test suite being initialized.
    Nr   )r   r   r   )rW   r   s     r   r   z"_TestSuiteResult._setup_test_suite,  sB     T[  f DK
&'D
#$%Dj!!!r   c                     || _         dS )zvSets the start timestamp of this test suite.

    Args:
      timestamp_in_secs: timestamp in seconds since epoch
    N)r   rW   timestamp_in_secss     r   set_end_timez_TestSuiteResult.set_end_time8  s     .Dr   c                     || _         dS )ztSets the end timestamp of this test suite.

    Args:
      timestamp_in_secs: timestamp in seconds since epoch
    N)r   r   s     r   rc   z_TestSuiteResult.set_start_time@  s     0Dr   N)
rz   r{   r|   r}   r[   r   rr   r   r   rc   r~   r   r   r   r      su        11% % %  .)$ )$ )$V
& 
& 
&. . .0 0 0 0 0r   r   c                        e Zd ZdZeZeZedf fd	Z	 fdZ
 fdZ fdZd Zd fd	Z	 	 dd	Zd
 Zd Z fdZ fdZ fdZ fdZ fdZ fdZ fdZ fdZ xZS )_TextAndXMLTestResultzoPrivate TestResult class that produces both formatted text results and XML.

  Used by TextAndXMLTestRunner.
  Nc                    t          t          |                               |||           || _        i | _        |                                 | _        |r|| j        _        || _        t          j
                    | _        d S r]   )superr   r[   
xml_streampending_test_case_results_TEST_SUITE_RESULT_CLASSr   r   time_getter	threadingRLock_pending_test_case_results_lock)rW   r   r7   descriptions	verbosityr   testsuites_propertiesrN   s          r   r[   z_TextAndXMLTestResult.__init__R  s{    	
&&//iPPP DO%'D"..00DJ @*?dj'"D ,5?+<+<D(((r   c                     |                                  | _        t          t          |                               |           d S r]   )r   rB   r   r   	startTestrW   rE   rN   s     r   r   z_TextAndXMLTestResult.startTest_  s;    &&((DO	
&&0066666r   c                    | j         5  t          t          |                               |           |                     |          }|sS|                                pt          |          }t          j        	                    d|z             	 d d d            d S t          | dd           |                                 | _        t          |          }|                                 | j        z
  }|                    |           |                    | j                   | j                            |           | j        |= d d d            d S # 1 swxY w Y   d S )NzNo pending test case: %s
rB   )r   r   r   stopTestget_pending_test_case_resultrF   rG   sysstderrr3   getattrr   rB   r`   rc   r   r   r   )rW   rE   rk   	test_nametest_idrA   rN   s         r   r   z_TextAndXMLTestResult.stopTestc  s   		- 2 2!4((11$7770066f GGII*T	
5	ABBB2 2 2 2 2 2 2 2 
|T	*	*	2**,,4g!!##do5h(###DO,,,
j%%f---

(
12 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2s   BEB&EEEc                     | j                             |                                            t          t          |                                            d S r]   )r   rc   r   r   r   startTestRunrW   rN   s    r   r   z"_TextAndXMLTestResult.startTestRunv  sH    Jd..00111	
&&3355555r   c                    | j                             |                                            | j        5  | j        D ]}}| j        |         }t          | dd           C| j         j        | j        z
  }|                    |           |	                    | j                   | j         
                    |           ~| j                                         d d d            d S # 1 swxY w Y   d S )NrB   )r   r   r   r   r   r   r   rB   r`   rc   r   clear)rW   r   rk   rA   s       r   stopTestRunz!_TextAndXMLTestResult.stopTestRunz  s/   JD,,..///
 
	- - - 3 0 0'/84t,,8Z04?B(


h
'
'
'



0
0
0
''////
$**,,,- - - - - - - - - - - - - - - - - -s   BC  C$'C$c                     |r)t          t          |                               ||          S d                    t	          j        |           S )aW  Converts a sys.exc_info()-style tuple of values into a string.

    This method must be overridden because the method signature in
    unittest.TestResult changed between Python 2.2 and 2.4.

    Args:
      err: A sys.exc_info() tuple of values for an error.
      test: The test method.

    Returns:
      A formatted exception string.
    r-   )r   r   _exc_info_to_stringjoin	tracebackformat_exception)rW   errrE   rN   s      r   r   z)_TextAndXMLTestResult._exc_info_to_string  sI      O($//CCCNNN779-s3444r   c                 &   | j         5  t          |          }|| j        vr|                     |          | j        |<   |r%| j        |         j                            |           |r|| j        |         _        ddd           dS # 1 swxY w Y   dS )a  Adds result information to a test case result which may still be running.

    If a result entry for the test already exists, add_pending_test_case_result
    will add error summary tuples and/or overwrite skip_reason for the result.
    If it does not yet exist, a result entry will be created.
    Note that a test result is considered to have been run and passed
    only if there are no errors or skip_reason.

    Args:
      test: A test method as defined by unittest
      error_summary: A 4-tuple with the following entries:
          1) a string identifier of either "failure" or "error"
          2) an exception_type
          3) an exception_message
          4) a string version of a sys.exc_info()-style tuple of values
             ('error', err[0], err[1], self._exc_info_to_string(err))
             If the length of errors is 0, then the test is either passed or
             skipped.
      skip_reason: a string explaining why the test was skipped
    N)r   rF   r   _TEST_CASE_RESULT_CLASSrD   r   rC   )rW   rE   error_summaryrC   r   s        r   add_pending_test_case_resultz2_TextAndXMLTestResult.add_pending_test_case_result  s    , 
	- J J4g	6	6	6262N2N3 3&w/	 M&w/6==mLLL	 J>I&w/;J J J J J J J J J J J J J J J J J Js   A1BB
B
c                 t    | j         5  t          |          }| j        |= d d d            d S # 1 swxY w Y   d S r]   )r   rF   r   rW   rE   r   s      r   delete_pending_test_case_resultz5_TextAndXMLTestResult.delete_pending_test_case_result  s    		- 2 24g

(
12 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2s   -11c                 V    t          |          }| j                            |d           S r]   )rF   r   getr   s      r   r   z2_TextAndXMLTestResult.get_pending_test_case_result  s&    hhG)--gt<<<r   c                     t          t          |                               |           |                     |           d S r]   )r   r   
addSuccessr   r   s     r   r   z _TextAndXMLTestResult.addSuccess  s<    	
&&11$777%%d+++++r   c                     t          t          |                               ||           d|d         |d         |                     ||          f}|                     ||           d S )Nru   r   r1   rE   r   )r   r   addErrorr   r   rW   rE   r   r   rN   s       r   r   z_TextAndXMLTestResult.addError  so    	
&&//c:::c!fc!f--c-==?M%%d-%HHHHHr   c                     t          t          |                               ||           d|d         |d         |                     ||          f}|                     ||           d S )Nr   r   r1   r   r   )r   r   
addFailurer   r   r   s       r   r   z _TextAndXMLTestResult.addFailure  so    	
&&11$<<<AA--c-==?M%%d-%HHHHHr   c                     t          t          |                               ||           |                     ||           d S )N)rC   )r   r   addSkipr   )rW   rE   reasonrN   s      r   r   z_TextAndXMLTestResult.addSkip  sC    	
&&..tV<<<%%d%?????r   c                    t          t          |                               ||           t          t	          |dd                     r+|                    d|                     ||                     |                     |           d S )NrecordPropertyEXPECTED_FAILUREr   )r   r   addExpectedFailurecallabler   r   r   r   )rW   rE   r   rN   s      r   r   z(_TextAndXMLTestResult.addExpectedFailure  s    	
&&99$DDD.5566 D
,223T2BBD D D%%d+++++r   c                     t          t          |                               |           |                                pt	          |          }dddd|z  f}|                     ||           d S )Nru   r-   z,Test case %s should have failed, but passed.r   )r   r   addUnexpectedSuccessrF   rG   r   )rW   rE   r   r   rN   s       r   r   z*_TextAndXMLTestResult.addUnexpectedSuccess  st    	
&&;;DAAA		&SYYIb"C!#$M 	%%d-%HHHHHr   c                 h   t          t          |                               |||           |kt          |d         |j                  r(d|d         |d         |                     ||          f}n*d|d         |d         |                     ||          f}nd }|                     ||           d S )Nr   r   r1   r   ru   r   )r   r   
addSubTest
issubclassfailureExceptionr   r   )rW   rE   subtestr   r   rN   s        r   r   z _TextAndXMLTestResult.addSubTest  s    	
&&11$EEE
	CFD1	2	2 C"CFCF11#D1AAC !#a&#a&11#D1AAC m%%g]%KKKKKr   c                     t          t          |                                            | j                            d           | j                            | j                   d S )Nz<?xml version="1.0"?>
)r   r   printErrorsr   r3   r   rr   r   s    r   r   z!_TextAndXMLTestResult.printErrors  sU    	
&&22444O3444J  11111r   r]   )NN)rz   r{   r|   r}   r   r   r=   r   
_time_copyr[   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__rN   s   @r   r   r   I  s        
 .+ &T= = = = = =7 7 7 7 72 2 2 2 2&6 6 6 6 6- - -*5 5 5 5 5 5" >B/3J J J J@2 2 2
= = =, , , , ,I I I I II I I I I@ @ @ @ @, , , , ,I I I I IL L L L L2 2 2 2 2 2 2 2 2r   r   c                   f     e Zd ZdZeZdZi Zd fd	Ze	d             Z
 fdZe	d             Z xZS )TextAndXMLTestRunnerzA test runner that produces both formatted text results and XML.

  It prints out the names of tests as they are run, errors as they
  occur, and a summary of the results at the end of the test run.
  Nc                 ^     t          t          |           j        |i | |	|| _        dS dS )a  Initialize a TextAndXMLTestRunner.

    Args:
      xml_stream: file-like or None; XML-formatted test results are output
          via this object's write() method.  If None (the default), the
          new instance behaves as described in the set_default_xml_stream method
          documentation below.
      *args: passed unmodified to unittest.TextTestRunner.__init__.
      **kwargs: passed unmodified to unittest.TextTestRunner.__init__.
    N)r   r   r[   _xml_stream)rW   r   argskwargsrN   s       r   r[   zTextAndXMLTestRunner.__init__  sD     /E
%%.????#d r   c                     || _         dS )a  Sets the default XML stream for the class.

    Args:
      xml_stream: file-like or None; used for instances when xml_stream is None
          or not passed to their constructors.  If None is passed, instances
          created with xml_stream=None will act as ordinary TextTestRunner
          instances; this is the default state before any calls to this method
          have been made.
    N)r  )clsr   s     r   set_default_xml_streamz+TextAndXMLTestRunner.set_default_xml_stream  s     !COOOr   c                     | j         't          t          |                                           S |                     | j         | j        | j        | j        | j                  S )N)r   )	r  r   r   _makeResult_TEST_RESULT_CLASSr7   r   r   r   r   s    r   r	  z TextAndXMLTestRunner._makeResult)  s_    '..::<<<$$

DK):DN $ ; % = = =r   c                     || j         |<   d S r]   )r   )r  r   r   s      r   set_testsuites_propertyz,TextAndXMLTestRunner.set_testsuites_property1  s    &+Cs###r   r]   )rz   r{   r|   r}   r   r
  r  r   r[   classmethodr  r	  r  r   r   s   @r   r   r     s          -+$ $ $ $ $ $" 
! 
! ;
!= = = = = , , ;, , , , ,r   r   )r-   )$r}   r&   rer   r   rl   r   rK   xml.saxr   absl.testingr   setrange_bad_control_character_codesr   r   updatecompilerH   r   r#   r,   r:   r   hasattrr;   rt   rG   objectr=   r   TextTestResultr   TextTestRunnerr   r~   r   r   <module>r     sY   N M  				 



                 / / / / / /  #s55D>>22___D "I "I+G"I "I "I 
 
	


	      # #$B C C C *44H)I)I &@ @ @" " " 7 7 7   $ Y

79k"" !)))eM eM eM eM eMf eM eM eMPg0 g0 g0 g0 g0v g0 g0 g0Ts2 s2 s2 s2 s22A s2 s2 s2l4, 4, 4, 4, 4,82 4, 4, 4, 4, 4,r   