
    Vh!                       d Z ddlm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j                   G d dej                               Zej                   G d	 d
e             Zej                   G d de             Zej                   G d d             Zej                   G d d             Zej                   G d d             ZddZddZy)z
Dataclasses for creating JUnit XML files.
See: https://github.com/junit-team/junit5/blob/main/platform-tests/src/test/resources/jenkins-junit.xsd
    )annotationsN)minidom)ElementTreec                      e Zd ZU dZdZded<   dZded<   dZded<   d Ze	e
j                  dd              Zdd	Zdd
Zy)
TestResultz)Base class for the result of a test case.N
str | Noneoutputmessagetypec                @    | j                   | j                  | _         y y N)r   tagselfs    P/home/dcms/DCMS/lib/python3.12/site-packages/ansible_test/_internal/junit_xml.py__post_init__zTestResult.__post_init__   s    99DI     c                     y)9Tag name for the XML element created by this result type.N r   s    r   r   zTestResult.tag   s    r   c                D    t        | j                  | j                        S )4Return a dictionary of attributes for this instance.)r
   r   )_attributesr
   r   r   s    r   get_attributeszTestResult.get_attributes#   s    LL
 	
r   c                    t        j                  | j                  | j                               }| j                  |_        |S )1Return an XML element representing this instance.)ETElementr   r   r	   text)r   elements     r   get_xml_elementzTestResult.get_xml_element*   s/    **TXXt':':'<={{r   returnstrr#   dict[str, str]r#   
ET.Element)__name__
__module____qualname____doc__r	   __annotations__r
   r   r   propertyabcabstractmethodr   r   r!   r   r   r   r   r      sV    3FJGZD*! H  H
r   r   )	metaclassc                  "    e Zd ZdZedd       Zy)TestFailurezFailure info for a test case.c                     y)r   failurer   r   s    r   r   zTestFailure.tag6   s     r   Nr"   r)   r*   r+   r,   r.   r   r   r   r   r3   r3   2   s    ' r   r3   c                  "    e Zd ZdZedd       Zy)	TestErrorzError info for a test case.c                     y)r   errorr   r   s    r   r   zTestError.tag@   s     r   Nr"   r6   r   r   r   r8   r8   <   s    % r   r8   c                  2   e Zd ZU dZded<   dZded<   dZded<   dZded	<   dZd
ed<    e	j                  e      Zded<    e	j                  e      Zded<   dZded<   dZded<   dZded<   dZded<   edd       Zedd       Zedd       ZddZddZy)TestCasezAn individual test case.r$   nameNz
int | None
assertionsr   	classnamestatuszdecimal.Decimal | Nonetimedefault_factoryzlist[TestError]errorszlist[TestFailure]failuresskipped
system_out
system_errFboolis_disabledc                ,    t        | j                        S )z,True if the test case contains failure info.)rI   rE   r   s    r   
is_failurezTestCase.is_failureX   s     DMM""r   c                ,    t        | j                        S )z*True if the test case contains error info.)rI   rD   r   s    r   is_errorzTestCase.is_error]   s     DKK  r   c                ,    t        | j                        S )z"True if the test case was skipped.)rI   rF   r   s    r   
is_skippedzTestCase.is_skippedb   s     DLL!!r   c                    t        | j                  | j                  | j                  | j                  | j
                        S )r   )r>   r?   r=   r@   rA   )r   r>   r?   r=   r@   rA   r   s    r   r   zTestCase.get_attributesg   s2    nn;;
 	
r   c                d   t        j                  d| j                               }| j                  r%| j                  t        j                  |d      _        |j                  | j                  D cg c]  }|j                          c}       |j                  | j                  D cg c]  }|j                          c}       | j                  r%| j                  t        j                  |d      _        | j                  r%| j                  t        j                  |d      _        |S c c}w c c}w )r   testcaserF   
system-out
system-err)r   r   r   rF   
SubElementr   extendrD   r!   rE   rG   rH   )r   r    r:   r5   s       r   r!   zTestCase.get_xml_elementq   s    **Z)<)<)>?<<59\\BMM'9-2T[[IE--/IJOg//1OP??8<BMM'<05??8<BMM'<05 JOs   /D(&D-)r#   rI   r%   r'   )r)   r*   r+   r,   r-   r>   r?   r@   rA   dataclassesfieldlistrD   rE   rF   rG   rH   rJ   r.   rL   rN   rP   r   r!   r   r   r   r<   r<   F   s    "
I!J
! Iz FJ#'D
 '/k//EFOE"3+"3"3D"IHIGZ!J
!!J
!K# # ! ! " "
r   r<   c                  R   e Zd ZU dZded<   dZded<   dZded<   dZded<   dZd	ed
<    e	j                  e      Zded<    e	j                  e      Zded<   dZded<   dZded<   d Zedd       Zedd       Zedd       Zedd       Zedd       Zedd       ZddZddZy)	TestSuitezA collection of test cases.r$   r=   Nr   hostnameidpackagezdatetime.datetime | None	timestamprB   r&   
propertieszlist[TestCase]casesrG   rH   c                    | j                   rX| j                   j                  t        j                  j                  k7  r&t        dt        j                  j                        y y )Nztimestamp.tzinfo must be )r`   tzinfodatetimetimezoneutc
ValueErrorr   s    r   r   zTestSuite.__post_init__   sN    >>dnn33x7H7H7L7LL89J9J9N9N8QRSS M>r   c                :    t        d | j                  D              S )"The number of disabled test cases.c              3  4   K   | ]  }|j                     y wr   )rJ   .0cases     r   	<genexpr>z%TestSuite.disabled.<locals>.<genexpr>   s     ;4##;   sumrb   r   s    r   disabledzTestSuite.disabled   s     ;

;;;r   c                :    t        d | j                  D              S )/The number of test cases containing error info.c              3  4   K   | ]  }|j                     y wr   )rN   rl   s     r   ro   z#TestSuite.errors.<locals>.<genexpr>   s     8T4==8rp   rq   r   s    r   rD   zTestSuite.errors   s     8TZZ888r   c                :    t        d | j                  D              S )1The number of test cases containing failure info.c              3  4   K   | ]  }|j                     y wr   )rL   rl   s     r   ro   z%TestSuite.failures.<locals>.<genexpr>        :t4??:rp   rq   r   s    r   rE   zTestSuite.failures        :tzz:::r   c                :    t        d | j                  D              S )z1The number of test cases containing skipped info.c              3  4   K   | ]  }|j                     y wr   )rP   rl   s     r   ro   z$TestSuite.skipped.<locals>.<genexpr>   rz   rp   rq   r   s    r   rF   zTestSuite.skipped   r{   r   c                ,    t        | j                        S )The number of test cases.)lenrb   r   s    r   testszTestSuite.tests   s     4::r   c                `    t        j                  t        d | j                  D                    S )#The total time from all test cases.c              3  N   K   | ]  }|j                   s|j                     y wr   rA   rl   s     r   ro   z!TestSuite.time.<locals>.<genexpr>   s     "Qtyy499"Qs   %%)decimalDecimalrr   rb   r   s    r   rA   zTestSuite.time   s"     s"Q"QQRRr   c                p   t        | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  r1| j                  j                  d      j                  d            S d      S )r   N)rd   seconds)timespec)rs   rD   rE   r]   r^   r=   r_   rF   r   rA   r`   )r   rs   rD   rE   r]   r^   r=   r_   rF   r   rA   r`   replace	isoformatr   s    r   r   zTestSuite.get_attributes   s    ]];;]]]]wwLLLL**[_[i[idnn,,D,9CCYCW
 	
 pt
 	
r   c                   t        j                  d| j                               }| j                  rot        j                  |d      j                  | j                  j                         D cg c]&  \  }}t        j                  dt        ||            ( c}}       |j                  | j                  D cg c]  }|j                          c}       | j                  r%| j                  t        j                  |d      _        | j                  r%| j                  t        j                  |d      _        |S c c}}w c c}w )r   	testsuitera   r.   )r=   valuerT   rU   )r   r   r   ra   rV   rW   itemsdictrb   r!   rG   r   rH   )r   r    r=   r   	test_cases        r   r!   zTestSuite.get_xml_element   s   **[$*=*=*?@??MM'<077  BF  BQ  BQ  BW  BW  BY  9Zr}rvx}JPTZ^fkPl9m  9Z  [TZZP		113PQ??8<BMM'<05??8<BMM'<05 9ZPs   -+D;
9Er#   intr#   zdecimal.Decimalr%   r'   )r)   r*   r+   r,   r-   r]   r^   r_   r`   rX   rY   r   ra   rZ   rb   rG   rH   r   r.   rs   rD   rE   rF   r   rA   r   r!   r   r   r   r\   r\      s    %
IHjB
GZ*.I'.!2!2!24!HJH-K--dCE>C!J
!!J
!T < < 9 9 ; ; ; ;   S S
 r   r\   c                      e Zd ZU dZdZded<    ej                  e      Z	ded<   e
dd       Ze
dd	       Ze
dd
       Ze
dd       Ze
dd       ZddZddZddZy)
TestSuiteszA collection of test suites.Nr   r=   rB   zlist[TestSuite]suitesc                :    t        d | j                  D              S )rj   c              3  4   K   | ]  }|j                     y wr   )rs   rm   suites     r   ro   z&TestSuites.disabled.<locals>.<genexpr>        ;e5>>;rp   rr   r   r   s    r   rs   zTestSuites.disabled        ;t{{;;;r   c                :    t        d | j                  D              S )ru   c              3  4   K   | ]  }|j                     y wr   )rD   r   s     r   ro   z$TestSuites.errors.<locals>.<genexpr>   s     9E5<<9rp   r   r   s    r   rD   zTestSuites.errors   s     9T[[999r   c                :    t        d | j                  D              S )rx   c              3  4   K   | ]  }|j                     y wr   )rE   r   s     r   ro   z&TestSuites.failures.<locals>.<genexpr>   r   rp   r   r   s    r   rE   zTestSuites.failures   r   r   c                :    t        d | j                  D              S )r   c              3  4   K   | ]  }|j                     y wr   )r   r   s     r   ro   z#TestSuites.tests.<locals>.<genexpr>   s     855;;8rp   r   r   s    r   r   zTestSuites.tests   s     8DKK888r   c                `    t        j                  t        d | j                  D                    S )r   c              3  4   K   | ]  }|j                     y wr   r   r   s     r   ro   z"TestSuites.time.<locals>.<genexpr>   s     "G%5::"Grp   )r   r   rr   r   r   s    r   rA   zTestSuites.time   s"     s"G4;;"GGHHr   c                    t        | j                  | j                  | j                  | j                  | j
                  | j                        S )r   )rs   rD   rE   r=   r   rA   )r   rs   rD   rE   r=   r   rA   r   s    r   r   zTestSuites.get_attributes   s9    ]];;]]**
 	
r   c                    t        j                  d| j                               }|j                  | j                  D cg c]  }|j                          c}       |S c c}w )r   
testsuites)r   r   r   rW   r   r!   )r   r    r   s      r   r!   zTestSuites.get_xml_element  sJ    **\4+>+>+@AT[[IE--/IJ Js   Ac                4    t        | j                               S )z@Return a pretty formatted XML string representing this instance.)_pretty_xmlr!   r   s    r   to_pretty_xmlzTestSuites.to_pretty_xml
  s    4//122r   r   r   r%   r'   r"   )r)   r*   r+   r,   r=   r-   rX   rY   rZ   r   r.   rs   rD   rE   r   rA   r   r!   r   r   r   r   r   r      s    &D*/k//EFOE< < : : < < 9 9 I I	
3r   r   c                 n    | j                         D ci c]  \  }}|	|t        |       c}}S c c}}w )zuReturn the given kwargs as a dictionary with values converted to strings. Items with a value of None will be omitted.)r   r$   )kwargskeyr   s      r   r   r     s-    .4llnR
U@QCUORRRs   
11c                r    t        j                  t        j                  | d            j	                         S )zDReturn a pretty formatted XML string representing the given element.unicode)encoding)r   parseStringr   tostringtoprettyxml)r    s    r   r   r     s'    r{{7YGHTTVVr   r%   )r    r(   r#   r$   )r,   
__future__r   r/   rX   re   r   xml.domr   	xml.etreer   r   	dataclassABCMetar   r3   r8   r<   r\   r   r   r   r   r   r   <module>r      s    # 
     ( 3;;  > *   
   : : :z O O Od 43 43 43nS
Wr   