
    0VhS                        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mZm	Z	 ddl
Z
ddlmZ ddlmZ  e edd            h dz
  ZeD  ci c]  }  e|       d| d	 c} Zd
ddddddZej+                  e        ej,                  d      Zd Zd Zd Zd!dZej
                  ZdedefdZ G d d      Z  G d d      Z! G d dejD                        Z# G d d e
jH                        Z%yc c} w )"zGA Python test reporter that generates test reports in JUnit XML format.    N)AnyDict)saxutils)_pretty_print_reporter    >   	   
      z\x02xz&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    I/home/dcms/DCMS/lib/python3.12/site-packages/absl/testing/xml_reporter.py_escape_xml_attrr   9   s     
">	??    c                     t         j                         D ]  \  }}| j                  ||      }  | j                  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    ?   sA     6;;= !mdG			$ A!	
5&	!!r   c                     | | dk  ryt         j                   j                  | t         j                  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)   O   sI     )a-				(	(H%%)) 
) 
++49;7r   c                     |j                  |d|        |D ];  }t        |      dk(  s|d   |d   |j                  d|d   d|d   d       = |j                  d	       y)
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_headerr6   ^   sj     	,,+w/0 >iI!	! 8! ll1y|<=> 	,,ur   objreturnc                     	 t        |       S # t        $ r2 dt        |       j                  dt        |       j                  dcY S w xY w)z-Returns a string representation of an object.z<unprintable .z object>)str	Exceptiontype
__module____name__)r7   s    r   	_safe_strr@   s   sC    s8O	 S	S	 s   
 8AAc                   .    e Zd ZdZd Zd Zd Zd Zd Zy)_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 | _        || _        |j                         xs t        |      }t        j                  |      }|r#|j                  d      }|j                  d      }nt        j                  j                  |j                        }t        |t        j                  j                         r3t        j                  j                  |j"                  j                        }|j%                  |dz         r|t'        |      dz   d  }|}n,|j)                  dd      }|d   }t'        |      dk(  r|d   nd}t+        |      | _        t+        |      | _        y )Nr-   r,   r:   r    )run_time
start_timeskip_reasonerrorstestidr;   &_CLASS_OR_MODULE_LEVEL_TEST_DESC_REGEXmatchgroupunittestutilstrclass	__class__
isinstancecase_SubTest	test_case
startswithr0   rsplitr   namefull_class_name)selfrJ   	test_descrM   rY   rZ   
class_namepartss           r   __init__z_TestCaseResult.__init__   s0   DMDODDKDI 	&SYI288CE[[^dAo==))$..9j	D(--00	1 ]]++DNN,D,DE
			j3.	/ Z*+,$   a(Ry&)%jAo%(2 &DI+O<Dr   c                     || _         y N)rF   r[   time_in_secss     r   set_run_timez_TestCaseResult.set_run_time   s	     DMr   c                     || _         y ra   rG   rb   s     r   set_start_timez_TestCaseResult.set_start_time   s	    "DOr   c           	      0   | 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       | j                  |       |j                  d       y)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
suppressedrY   %sstatusresulttime%.3f	classnamer(   testcasez  z  </testcase>
)	rH   rY   rF   rZ   r)   rG   r6   _print_testcase_detailsr/   )r[   r3   rn   ro   test_case_attributess        r   print_xml_summaryz!_TestCaseResult.print_xml_summary   s     ffff 
		!"	4&=!	4&=!	$--'(	d**+	(9: j*>M  (
LL"#r   c                     | j                   D ]]  }|\  }}}}t        t        |            }t        t        |            }t	        |      }|j                  d|d|d|d|d|d       _ y )Nz  <z
 message="z" type="z"><![CDATA[z]]></r.   )rI   r   r@   r;   r    r/   )r[   r3   erroroutcomeexception_typemessage	error_msgs          r   rt   z'_TestCaseResult._print_testcase_details   sk     M491g~w	 7!34g'N(;<n	*illw	7L MMr   N)	r?   r>   __qualname____doc__r_   rd   rg   rv   rt    r   r   rB   rB   ~   s"    &#=J!#$>Mr   rB   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	_TestSuiteResultz)Private helper for _TextAndXMLTestResult.c                 X    i | _         i | _        i | _        d| _        d| _        i | _        y )NrD   )suitesfailure_countserror_countsoverall_start_timeoverall_end_time_testsuites_properties)r[   s    r   r_   z_TestSuiteResult.__init__   s1    DKDD DD"$Dr   c                 :   t        |j                        j                  }|dk(  r|j                  j	                  d      d   }t        |j                  t        j                  j                        r)t        |j                  j                        j                  }| j                  |       | j                  |   j                  |       |j                  D ]D  }|d   dk(  r| j                  |xx   dz  cc<    y |d   dk(  s-| j                  |xx   dz  cc<    y  y )N_ErrorHolderr:   rD   r   failurer-   rx   )r=   rJ   r?   rZ   rX   rS   rO   rT   rU   rV   _setup_test_suiter   appendrI   r   r   )r[   test_case_result
suite_namerx   s       r   add_test_case_resultz%_TestSuiteResult.add_test_case_result   s    &++,55J^# $33::3?Cj"'')?)?@ (--778AAj:&KK
""#34!((  
qY	J'1,'8w*%*%r   c                    t        d | j                  j                         D              }t        | j                  j                               }t        | j                  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|j                  d       t        | j                  j                               D ]8  \  }}|j                  dt        |      dt        t        |            d       : |j                  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 ]  }|j%                  |        |j                  d        |j                  d       y )Nc              3   2   K   | ]  }t        |        y wra   )r0   .0xs     r   	<genexpr>z5_TestSuiteResult.print_xml_summary.<locals>.<genexpr>	  s     BSVBs   )rY   rE   testsz%dfailuresrI   rp   rq   r(   
testsuitesz    <properties>
z      <property name="z	" value="z"></property>
z    </properties>
c              3   N   K   | ]  }|j                   |j                  z     y wra   )rG   rF   r   s     r   r   z5_TestSuiteResult.print_xml_summary.<locals>.<genexpr>  s     D1<<!**4Ds   #%c              3   4   K   | ]  }|j                     y wra   rf   r   s     r   r   z5_TestSuiteResult.print_xml_summary.<locals>.<genexpr>  s     9aQ\\9s   rY   rm   	testsuitec                     | j                   S ra   )rY   )ts    r   <lambda>z4_TestSuiteResult.print_xml_summary.<locals>.<lambda>.  s
    !&& r   )keyz</testsuite>
z</testsuites>
)sumr   valuesr   r   r   r   r)   r6   r   r/   sortedr   r   r;   maxminr0   rv   )r[   r3   overall_test_countoverall_failuresoverall_errorsoverall_attributesrY   valuer   suitesuite_end_timesuite_start_timer   rI   suite_attributesr   s                   r   rv   z"_TestSuiteResult.print_xml_summary  sR   BT[[-?-?-ABB4..5578**1134N	$++,	T,,-	4.()	40043J3JJKL	()@)@AB l,>G""ll'( ; ; A A CD M+$&t,.>s5z.JL 	MM ll()kk %
kk*%eDeDDn9599$$Z0h  ,f4*$
%D3u:%
&th
'TF]
#6^.>>?
@*+;<
=  -=vF %U0@A 3
**623ll#$)%* LL"#r   c                 |    || j                   v ryg | j                   |<   d| j                  |<   d| j                  |<   y)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   )r[   r   s     r   r   z"_TestSuiteResult._setup_test_suite3  sA     T[[  DKK
&'D
#$%Dj!r   c                     || _         y)zvSets the start timestamp of this test suite.

    Args:
      timestamp_in_secs: timestamp in seconds since epoch
    N)r   r[   timestamp_in_secss     r   set_end_timez_TestSuiteResult.set_end_time?  s     .Dr   c                     || _         y)ztSets the end timestamp of this test suite.

    Args:
      timestamp_in_secs: timestamp in seconds since epoch
    N)r   r   s     r   rg   z_TestSuiteResult.set_start_timeG  s     0Dr   N)
r?   r>   r}   r~   r_   r   rv   r   r   rg   r   r   r   r   r      s$    1%.)$V
&.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         |   |||       || _        i | _        | j	                         | _        |r|| j
                  _        || _        t        j                         | _
        y ra   )superr_   
xml_streampending_test_case_results_TEST_SUITE_RESULT_CLASSr   r   time_getter	threadingRLock_pending_test_case_results_lock)r[   r   r3   descriptions	verbosityr   testsuites_propertiesrR   s          r   r_   z_TextAndXMLTestResult.__init__Y  s[    	GV\95 DO%'D"..0DJ*?djj'"D ,5??+<D(r   c                 N    | j                         | _        t        |   |       y ra   )r   rG   r   	startTestr[   rJ   rR   s     r   r   z_TextAndXMLTestResult.startTestf  s     &&(DO	Gdr   c                 Z   | j                   5  t        | 	  |       | j                  |      }|sI|j	                         xs t        |      }t        j                  j                  d|z         	 d d d        y t        | dd       | j                         | _        t	        |      }| j                         | j                  z
  }|j                  |       |j                  | j                         | j                  j                  |       | j                   |= d d d        y # 1 sw Y   y xY w)NzNo pending test case: %s
rG   )r   r   stopTestget_pending_test_case_resultrK   r;   sysstderrr/   getattrr   rG   rd   rg   r   r   r   )r[   rJ   ro   	test_nametest_idrF   rR   s         r   r   z_TextAndXMLTestResult.stopTestj  s    		-	- 2gt006fGGI*T	

5	AB2 2 
|T	*	2**,4g!!#doo5h(#DOO,
jj%%f-

(
(
12 2 2s   A#D!:BD!!D*c                 t    | j                   j                  | j                                t        |           y ra   )r   rg   r   r   startTestRunr[   rR   s    r   r   z"_TextAndXMLTestResult.startTestRun}  s)    JJd..01	Gr   c                    | j                   j                  | j                                | j                  5  | j                  D ]  }| j                  |   }t        | dd       O| j                   j                  | j                  z
  }|j                  |       |j                  | j                         | j                   j                  |        | j                  j                          d d d        y # 1 sw Y   y xY w)NrG   )r   r   r   r   r   r   r   rG   rd   rg   r   clear)r[   r   ro   rF   s       r   stopTestRunz!_TextAndXMLTestResult.stopTestRun  s    JJD,,./
 
	-	- - 33 0'//84t,8ZZ004??B(


h
'



0

''/0 $$**,- - -s   B2C11C:c                 j    |rt         |   ||      S dj                  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.
    rE   )r   _exc_info_to_stringjoin	tracebackformat_exception)r[   errrJ   rR   s      r   r   z)_TextAndXMLTestResult._exc_info_to_string  s4     W(d33779--s344r   c                 4   | j                   5  t        |      }|| j                  vr| j                  |      | j                  |<   |r(| j                  |   j                  j                  |       |r|| j                  |   _        ddd       y# 1 sw Y   yxY w)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   rK   r   _TEST_CASE_RESULT_CLASSrI   r   rH   )r[   rJ   error_summaryrH   r   s        r   add_pending_test_case_resultz2_TextAndXMLTestResult.add_pending_test_case_result  s    , 
	-	- J4g	66	6262N2N3&&w/	&&w/66==mL	>I&&w/;J J Js   A8BBc                 v    | j                   5  t        |      }| j                  |= d d d        y # 1 sw Y   y xY wra   )r   rK   r   r[   rJ   r   s      r   delete_pending_test_case_resultz5_TextAndXMLTestResult.delete_pending_test_case_result  s7    		-	- 24g

(
(
12 2 2s   /8c                 P    t        |      }| j                  j                  |d       S ra   )rK   r   getr   s      r   r   z2_TextAndXMLTestResult.get_pending_test_case_result  s$    hG))--gt<<r   c                 F    t         |   |       | j                  |       y ra   )r   
addSuccessr   r   s     r   r   z _TextAndXMLTestResult.addSuccess  s    	Gt%%d+r   c                     t         |   ||       d|d   |d   | j                  ||      f}| j                  ||       y )Nrx   r   r-   rJ   r   )r   addErrorr   r   r[   rJ   r   r   rR   s       r   r   z_TextAndXMLTestResult.addError  sN    	GT3c!fc!f--c-=?M%%d-%Hr   c                     t         |   ||       d|d   |d   | j                  ||      f}| j                  ||       y )Nr   r   r-   r   r   )r   
addFailurer   r   r   s       r   r   z _TextAndXMLTestResult.addFailure  sN    	GtS!AA--c-=?M%%d-%Hr   c                 L    t         |   ||       | j                  ||       y )N)rH   )r   addSkipr   )r[   rJ   reasonrR   s      r   r   z_TextAndXMLTestResult.addSkip  s$    	GOD&!%%d%?r   c                     t         |   ||       t        t        |dd             r#|j	                  d| j                  ||             | j                  |       y )NrecordPropertyEXPECTED_FAILUREr   )r   addExpectedFailurecallabler   r   r   r   )r[   rJ   r   rR   s      r   r   z(_TextAndXMLTestResult.addExpectedFailure  sW    	GtS).56
,223T2BD%%d+r   c                     t         |   |       |j                         xs t        |      }dddd|z  f}| j	                  ||       y )Nrx   rE   z,Test case %s should have failed, but passed.r   )r   addUnexpectedSuccessrK   r;   r   )r[   rJ   r   r   rR   s       r   r   z*_TextAndXMLTestResult.addUnexpectedSuccess  sR    	G &	&SYIb"C!#$M 	%%d-%Hr   c                     t         |   |||       |Ut        |d   |j                        rd|d   |d   | j	                  ||      f}n d|d   |d   | j	                  ||      f}nd }| j                  ||       y )Nr   r   r-   r   rx   r   )r   
addSubTest
issubclassfailureExceptionr   r   )r[   rJ   subtestr   r   rR   s        r   r   z _TextAndXMLTestResult.addSubTest  s    	GtWc*
	CFD11	2"CFCF11#D1AC !#a&#a&11#D1AC m%%g]%Kr   c                     t         |           | j                  j                  d       | j                  j                  | j                         y )Nz<?xml version="1.0"?>
)r   printErrorsr   r/   r   rv   r   s    r   r   z!_TextAndXMLTestResult.printErrors   s7    	GOO34JJ  1r   ra   )NN)r?   r>   r}   r~   r   r   rB   r   
_time_copyr_   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__rR   s   @r   r   r   P  s    
 .+ &T=2&-*5" >B/3J@2
=,II@,IL2 2r   r   c                   p     e Zd ZU dZeZdZi Zee	e	f   e
d<   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.
  Nr   c                 8    t        |   |i | ||| _        yy)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_   _xml_stream)r[   r   argskwargsrR   s       r   r_   zTextAndXMLTestRunner.__init__  s*     
Gd%f%#d r   c                     || _         y)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     !COr   c                     | j                   t        | 	         S | j                  | j                   | j                  | j
                  | j                  | j                        S )N)r   )r  r   _makeResult_TEST_RESULT_CLASSr3   r   r   r   r   s    r   r
  z TextAndXMLTestRunner._makeResult0  s[    W ""$$


DKK):):DNN $ ; ; % = =r   c                 "    || j                   |<   y ra   )r   )r  r   r   s      r   set_testsuites_propertyz,TextAndXMLTestRunner.set_testsuites_property8  s    &+Cs#r   ra   )r?   r>   r}   r~   r   r  r  r   r   r   __annotations__r_   classmethodr  r
  r  r   r   s   @r   r  r    sZ     -++-$sCx.-$" 
! 
!= , ,r   r  )rE   )&r~   r#   rer   r   rp   r   typingr   r   rO   xml.saxr   absl.testingr   setrange_bad_control_character_codeschrr   r   updatecompilerL   r   r    r)   r6   r   objectr;   r@   rB   r   TextTestResultr   TextTestRunnerr  )is   0r   <module>r     s)   N  	 
       /  #5D>2_D  $@"CFc!CM"  
	


	    # #$B C *44H)I &@" 7$ YY
6 c eM eMPg0 g0Ts22AA s2l4,822 4,K"s   C.