o nnh!@sdZddlmZddlZddlZddlZddlZddlmZddl m Z ej Gdddej dZej Gd d d eZej Gd d d eZej Gd ddZej GdddZej GdddZdddZdddZdS)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@sfeZdZUdZdZded<dZded<dZded<ddZe e j dd d Z dddZ dddZdS) TestResultz)Base class for the result of a test case.N str | NoneoutputmessagetypecCs|jdur |j|_dSdSN)r tagselfrC/usr/local/lib/python3.10/dist-packages/ansible/utils/_junit_xml.py __post_init__s  zTestResult.__post_init__returnstrcCdS)9Tag name for the XML element created by this result type.Nrr rrrr szTestResult.tagdict[str, str]cCst|j|jdS)4Return a dictionary of attributes for this instance.)rr ) _attributesrr r rrrget_attributes#szTestResult.get_attributes ET.ElementcCst|j|}|j|_|S)1Return an XML element representing this instance.)ETElementr rrtextr elementrrrget_xml_element*szTestResult.get_xml_elementrrrrrr)__name__ __module__ __qualname____doc__r__annotations__rr rpropertyabcabstractmethodr rr rrrrrs     r) metaclassc@eZdZdZedddZdS) TestFailurezFailure info for a test case.rrcCr)rfailurerr rrrr 6zTestFailure.tagNr!r$r%r&r'r)r rrrrr.2r.c@r-) TestErrorzError info for a test case.rrcCr)rerrorrr rrrr @r0z TestError.tagNr!r1rrrrr3<r2r3c@seZdZUdZded<dZded<dZded<dZded <dZd ed <e j e d Z d ed<e j e d Z ded<dZded<dZded<dZded<dZded<ed$ddZed$ddZed$ddZd%dd Zd&d"d#ZdS)'TestCasezAn individual test case.rnameNz int | None assertionsr classnamestatuszdecimal.Decimal | Nonetimedefault_factoryzlist[TestError]errorszlist[TestFailure]failuresskipped system_out system_errFbool is_disabledrcC t|jS)z,True if the test case contains failure info.)rBr>r rrr is_failureX zTestCase.is_failurecCrD)z*True if the test case contains error info.)rBr=r rrris_error]rFzTestCase.is_errorcCrD)z"True if the test case was skipped.)rBr?r rrr is_skippedbrFzTestCase.is_skippedrcCst|j|j|j|j|jdS)r)r7r8r6r9r:)rr7r8r6r9r:r rrrrgszTestCase.get_attributesrcCstd|}|jr|jt|d_|dd|jD|dd|jD|j r4|j t|d_|j r?|j t|d_|S)rtestcaser?cSg|]}|qSrr ).0r4rrr xz,TestCase.get_xml_element..cSrJrrK)rLr/rrrrMyrN system-out system-err) rrrr? SubElementrextendr=r>r@rArrrrr qszTestCase.get_xml_element)rrBr"r#)r$r%r&r'r(r7r8r9r: dataclassesfieldlistr=r>r?r@rArCr)rErGrHrr rrrrr5Fs*              r5c@seZdZUdZded<dZded<dZded<dZded<dZd ed <e j e d Z d ed <e j e d Zded<dZded<dZded<ddZed(ddZed(ddZed(ddZed(ddZed(ddZed)d!d"Zd*d#d$Zd+d&d'ZdS), TestSuitezA collection of test cases.rr6Nrhostnameidpackagezdatetime.datetime | None timestampr;r propertieszlist[TestCase]casesr@rAcCs0|jr|jjtjjkrtdtjjdSdS)Nztimestamp.tzinfo must be )rZtzinfodatetimetimezoneutc ValueErrorr rrrrszTestSuite.__post_init__rintcCtdd|jDS)"The number of disabled test cases.cs|]}|jVqdSr )rCrLcaserrr z%TestSuite.disabled..sumr\r rrrdisabledzTestSuite.disabledcCrc)/The number of test cases containing error info.csrer )rGrfrrrrhriz#TestSuite.errors..rjr rrrr=rmzTestSuite.errorscCrc)1The number of test cases containing failure info.csrer )rErfrrrrhriz%TestSuite.failures..rjr rrrr>rmzTestSuite.failurescCrc)z1The number of test cases containing skipped info.csrer )rHrfrrrrhriz$TestSuite.skipped..rjr rrrr?rmzTestSuite.skippedcCrD)The number of test cases.)lenr\r rrrtestsrFzTestSuite.testsdecimal.DecimalcCttdd|jDS)#The total time from all test cases.css|] }|jr|jVqdSr r:rfrrrrhsz!TestSuite.time..)decimalDecimalrkr\r rrrr:zTestSuite.timecCsRt|j|j|j|j|j|j|j|j|j |j |j r%|j j ddj ddd Sdd S)rN)r]seconds)timespec) rlr=r>rWrXr6rYr?rrr:rZ)rrlr=r>rWrXr6rYr?rrr:rZreplace isoformatr rrrrs zTestSuite.get_attributesrcCs~td|}|jrt|ddd|jD|dd|jD|jr2|jt|d_ |j r=|j t|d_ |S)r testsuiter[c Ss$g|]\}}tdt||dqS)r))r6value)rrdict)rLr6rrrrrMs$z-TestSuite.get_xml_element..cSrJrrK)rL test_caserrrrMrNrOrP) rrrr[rQrRitemsr\r@rrArrrrr s"zTestSuite.get_xml_elementrrbrrsr"r#)r$r%r&r'r(rWrXrYrZrSrTrr[rUr\r@rArr)rlr=r>r?rrr:rr rrrrrVs4              rVc@seZdZUdZdZded<ejedZ ded<e dd d Z e dd d Z e dddZ e dddZe dddZd ddZd!ddZd"ddZdS)# TestSuiteszA collection of test suites.Nrr6r;zlist[TestSuite]suitesrrbcCrc)rdcsrer )rlrLsuiterrrrhriz&TestSuites.disabled..rkrr rrrrlrmzTestSuites.disabledcCrc)rncsrer )r=rrrrrhriz$TestSuites.errors..rr rrrr=rmzTestSuites.errorscCrc)rocsrer )r>rrrrrhriz&TestSuites.failures..rr rrrr>rmzTestSuites.failurescCrc)rpcsrer )rrrrrrrhriz#TestSuites.tests..rr rrrrrrmzTestSuites.testsrscCrt)rucsrer rvrrrrrhriz"TestSuites.time..)rwrxrkrr rrrr:ryzTestSuites.timercCs t|j|j|j|j|j|jdS)r)rlr=r>r6rrr:)rrlr=r>r6rrr:r rrrrszTestSuites.get_attributesrcCs*td|}|dd|jD|S)r testsuitescSrJrrKrrrrrMrNz.TestSuites.get_xml_element..)rrrrRrrrrrr szTestSuites.get_xml_elementrcCs t|S)z@Return a pretty formatted XML string representing this instance.) _pretty_xmlr r rrr to_pretty_xml s zTestSuites.to_pretty_xmlrrr"r#r!)r$r%r&r'r6r(rSrTrUrr)rlr=r>rrr:rr rrrrrrs"         rrrcKsdd|DS)zuReturn the given kwargs as a dictionary with values converted to strings. Items with a value of None will be omitted.cSs"i|] \}}|dur|t|qSr )r)rLkeyrrrr s"z_attributes..)r)kwargsrrrrsrrrrcCsttj|ddS)zDReturn a pretty formatted XML string representing the given element.unicode)encoding)r parseStringrtostring toprettyxml)rrrrrsrr")rrrr)r' __future__rr*rSr^rwxml.domr xml.etreerr dataclassABCMetarr.r3r5rVrrrrrrrs,     =R 7