
    ijT                        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 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jB                        Z" G d d e	jF                        Z$yc c} w )"zGA Python test reporter that generates test reports in JUnit XML format.    N)Any)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    n/var/www/html/emotional.easysim.app/public_html/venv/lib/python3.12/site-packages/absl/testing/xml_reporter.py_escape_xml_attrr   :   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(   Q   sI     )a-				(	(H%%)) 
) 
IKr   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_headerr5   a   s{     	,,+ay)* 8iI!aL$aL$llQy|nBy|nA678 	,,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__)r6   s    r   	_safe_strr?   z   sM    Os8O	 O49//0$s)2D2D1EXNNO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+   r9   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
startswithr/   rsplitr   namefull_class_name)selfrI   	test_descrL   rX   rY   
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1,./$   a(Ry&)%jAo%(2 &DI+O<Dr   c                     || _         y N)rE   rZ   time_in_secss     r   set_run_timez_TestCaseResult.set_run_time   s	     DMr   c                     || _         y r`   rF   ra   s     r   set_start_timez_TestCaseResult.set_start_time   s	    "DOr   c           	         | j                   d}d}nd}d}d| j                  fd|fd|fd	| j                  d
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
suppressedrX   statusresulttime.3f	classnamer'   testcasez  z  </testcase>
)	rG   rX   rE   rY   r(   rF   r5   _print_testcase_detailsr.   )rZ   r2   rl   rm   test_case_attributess        r   print_xml_summaryz!_TestCaseResult.print_xml_summary   s     ffff 
	6	6	DMM#&(	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-   )rH   r   r?   r:   r   r.   )rZ   r2   erroroutcomeexception_typemessage	error_msgs          r   rr   z'_TestCaseResult._print_testcase_details   s     491g~w	 7!34g'N(;<n	*illy
7)8N3C D[gYc3r   N)	r>   r=   __qualname____doc__r^   rc   rf   rt   rr    r   r   rA   rA      s!    &#=J!#$>	r   rA   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 )NrC   )suitesfailure_countserror_countsoverall_start_timeoverall_end_time_testsuites_properties)rZ   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)	z*Adds a test case result to the test suite._ErrorHolderr9   rC   r   failurer,   rv   N)r<   rI   r>   rY   rW   rR   rN   rS   rT   rU   _setup_test_suiter   appendrH   r   r   )rZ   test_case_result
suite_namerv   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                               }| j
                  | j                  z
  }ddt        |      fdt        |      fdt        |      fd|d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                  |	   }||z
  }d|	fdt        t#        |
            fdt        |      fdt        |      fd|dfdt        |      fg}t        d||       t        |
d       D ]  }|j%                  |        |j                  d        |j                  d       y)z4Writes the test summary in XML format to the stream.c              3   2   K   | ]  }t        |        y wr`   )r/   .0xs     r   	<genexpr>z5_TestSuiteResult.print_xml_summary.<locals>.<genexpr>  s     BSVBs   )rX   rD   testsfailuresrH   rn   ro   r'   
testsuitesz    <properties>
z      <property name="z	" value="z"></property>
z    </properties>
c              3   N   K   | ]  }|j                   |j                  z     y wr`   )rF   rE   r   s     r   r   z5_TestSuiteResult.print_xml_summary.<locals>.<genexpr>+  s     D1<<!**4Ds   #%c              3   4   K   | ]  }|j                     y wr`   re   r   s     r   r   z5_TestSuiteResult.print_xml_summary.<locals>.<genexpr>,  s     9aQ\\9s   rX   	testsuitec                     | j                   S r`   )rX   )ts    r   <lambda>z4_TestSuiteResult.print_xml_summary.<locals>.<lambda><  s
    !&& r   )keyz</testsuite>
z</testsuites>
N)sumr   valuesr   r   r   r   r:   r(   r5   r   r.   sortedr   r   maxminr/   rt   )rZ   r2   overall_test_countoverall_failuresoverall_errorsoverall_timeoverall_attributesrX   valuer   suitesuite_end_timesuite_start_timer   rH   
suite_timesuite_attributesr   s                     r   rt   z"_TestSuiteResult.print_xml_summary  se    BT[[-?-?-ABB4..5578**1134N((4+B+BBL	#()*	S)*+	3~&'	L%'	()@)@AB l,>G""ll'( ; ; A A CD 
+$$%5d%;$< =&s5z23?D	


 ll()kk %
kk*%eDeDDn9599$$Z0h  ,f!$44j:
CE
O
$s8}
%S[
!j%
'*+;<
=  -=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   )rZ   r   s     r   r   z"_TestSuiteResult._setup_test_suiteA  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   rZ   timestamp_in_secss     r   set_end_timez_TestSuiteResult.set_end_timeM  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   rf   z_TestSuiteResult.set_start_timeU  s     0Dr   N)
r>   r=   r{   r|   r^   r   rt   r   r   rf   r}   r   r   r   r      s$    1%2/$b
&.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 r`   )superr^   
xml_streampending_test_case_results_TEST_SUITE_RESULT_CLASSr   r   time_getter	threadingRLock_pending_test_case_results_lock)rZ   r   r2   descriptions	verbosityr   testsuites_propertiesrQ   s          r   r^   z_TextAndXMLTestResult.__init__g  s]     
GV\95 DO%'D"..0DJ*?djj'"D ,5??+<D(r   c                 N    | j                         | _        t        |   |       y r`   )r   rF   r   	startTestrZ   rI   rQ   s     r   r   z_TextAndXMLTestResult.startTest{  s     &&(DO	Gdr   c                 \   | j                   5  t        | 	  |       | j                  |      }|sJ|j	                         xs t        |      }t        j                  j                  d| d       	 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: r   rF   )r   r   stopTestget_pending_test_case_resultrJ   r:   sysstderrr.   getattrr   rF   rc   rf   r   r   r   )rZ   rI   rm   	test_nametest_idrE   rQ   s         r   r   z_TextAndXMLTestResult.stopTest  s    		-	- 2gt006fGGI*T	

1)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 r`   )r   rf   r   r   startTestRunrZ   rQ   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)NrF   )r   r   r   r   r   r   r   rF   rc   rf   r   clear)rZ   r   rm   rE   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.
    rD   )r   _exc_info_to_stringjoin	tracebackformat_exception)rZ   errrI   rQ   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   rJ   r   _TEST_CASE_RESULT_CLASSrH   r   rG   )rZ   rI   error_summaryrG   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r`   )r   rJ   r   rZ   rI   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 r`   )rJ   r   getr   s      r   r   z2_TextAndXMLTestResult.get_pending_test_case_result  s$    hG))--gt<<r   c                 F    t         |   |       | j                  |       y r`   )r   
addSuccessr   r   s     r   r   z _TextAndXMLTestResult.addSuccess  s    	Gt%%d+r   c                     t         |   ||       d|d   |d   | j                  ||      f}| j                  ||       y )Nrv   r   r,   rI   r   )r   addErrorr   r   rZ   rI   r   r   rQ   s       r   r   z_TextAndXMLTestResult.addError  sR    	GT3AA  4 0	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  sR    	GtS!AA  4 0	M 	%%d-%Hr   c                 L    t         |   ||       | j                  ||       y )N)rG   )r   addSkipr   )rZ   rI   reasonrQ   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   )rZ   rI   r   rQ   s      r   r   z(_TextAndXMLTestResult.addExpectedFailure  sW    	GtS).56

d66s6F 	%%d+r   c                     t         |   |       |j                         xs t        |      }dddd| df}| j	                  ||       y )Nrv   rD   z
Test case z  should have failed, but passed.r   )r   addUnexpectedSuccessrJ   r:   r   )rZ   rI   r   r   rQ   s       r   r   z*_TextAndXMLTestResult.addUnexpectedSuccess  sV    	G &	&SYI


YK?@	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   rv   r   )r   
addSubTest
issubclassfailureExceptionr   r   )rZ   rI   subtestr   r   rQ   s        r   r   z _TextAndXMLTestResult.addSubTest  s    	GtWc*
	CFD11	2FF$$St$4	
 FF$$St$4	
 m%%g]%Kr   c                     t         |           | j                  j                  d       | j                  j                  | j                         y )Nz<?xml version="1.0"?>
)r   printErrorsr   r.   r   rt   r   s    r   r   z!_TextAndXMLTestResult.printErrors+  s7    	GOO34JJ  1r   r`   )NN)r>   r=   r{   r|   r   r   rA   r   
_time_copyr^   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__rQ   s   @r   r   r   ^  s    
 .+  =(2&-*5$ 37 JD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)rZ   r   argskwargsrQ   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_streamN  s     !COr   c                     | j                   t        | 	         S | j                  | j                   | j                  | j
                  | j                  | j                        S )N)r   )r  r   _makeResult_TEST_RESULT_CLASSr2   r   r   r   r   s    r   r
  z TextAndXMLTestRunner._makeResult[  s^    W ""$$



++



.. $ ; ; %  r   c                 "    || j                   |<   y r`   )r   )r  r   r   s      r   set_testsuites_propertyz,TextAndXMLTestRunner.set_testsuites_propertyg  s    &+Cs#r   r`   )r>   r=   r{   r|   r   r  r  r   dictr   __annotations__r^   classmethodr  r
  r  r   r   s   @r   r  r  1  sZ     -++-$sCx.-$" 
! 
!
 , ,r   r  )rD   )%r|   r"   rer   r   rn   r   typingr   rN   xml.saxr   absl.testingr   setrange_bad_control_character_codeschrr   r   updatecompilerK   r   r   r(   r5   r   objectr:   r?   rA   r   TextTestResultr   TextTestRunnerr  )is   0r   <module>r     s*   N  	 
       /  #5D>2_D  $@"CFc!CM"  
	


	    # #$B C *44H)I &@"" , YY
O6 Oc Og gTo0 o0dP22AA P2f8,822 8,a"s   	C,