a ze2@sddlZddlZddlZddlmZddlmZddlm Z ddl m Z e dddZ d Z Gd d d ejZGd d d ejZGdddeZGdddeZGddde jZGdddejZedkredS)N)AttributesImpl)feature_external_ges)pulldom)findfileztest.xmlZ xmltestdata)Zsubdira  Introduction to XSL

A. Namespace

c@sPeZdZddZddZddZejddZejd d Z d d Z d dZ dS)PullDOMTestCasecCs\tt}||jjt|ttd}tt|Wdn1sN0YdS)Nrb)rparsetstfileZ addCleanupstreamcloselistopen)selfhandlerfinrE/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_pulldom.py test_parses   zPullDOMTestCase.test_parsecCstt}t|\}}|t|d|tj|t|\}}|tj||d|j |dt |j ||j dj dt|\}}|tj|t|\}}|tj|t|\}}|d|j |}t|\}}|tj||d|jt|\}}|tj||d|j |||ut|\}}|tj|t|\}}|tj||d|j t|\}}|tj||d|j t|\}}|tj|t|\}}|tj||d |j t|\}}|tj||d |j t|\}}|tj|t|\}}|tj||d |j t|\}}|tj|t|\}}|tj|t|\}}|tj|dS) N createElementhtmlz xmlns:xdczhttp://www.xml.com/bookstitlezIntroduction to XSLhrpz xdc:author)r parseString SMALL_SAMPLEnext assertTruehasattr assertEqualSTART_DOCUMENT START_ELEMENTtagNamelenZ attributesZ getNamedItemvalue CHARACTERSdata END_ELEMENT)ritemsevtnodeZ title_noderrrtest_parse_semantics+sh                   z$PullDOMTestCase.test_parse_semanticscCs@tt}|D]<\}}|tjkr|jdkr|||dt|jqVq| d|D]\}}|tjkrZqrqZ|d|jd|||t |dtj t |\}}||jd||t |t |\}}||jd| t t |Wdn1s0Y|||j||jdS) Nrz,No "title" element detected in SMALL_SAMPLE!rz=expandNode did not leave DOMEventStream in the correct state.rrr)rrrr!r"Z expandNoderr# childNodesfailrr%Z assertRaises StopIterationclear assertIsNoneparserr )rr(r)itemr*rrrtest_expandItemis4            ( zPullDOMTestCase.test_expandItemcCs4tt}|D]\}}|tjkrq0q|ddS)NzNo comment was encountered)rrrCOMMENTr.)rr(r)_rrr test_comments    zPullDOMTestCase.test_commentcCsptt}|D] \}}|tjkr|jdkrq0qzt|\}}|tj|Wntyj| dYn0dS)Nrz8Ran out of events, but should have received END_DOCUMENT) rrrr'r"rr END_DOCUMENTr/r.)rr(r)r*rrrtest_end_documents    z!PullDOMTestCase.test_end_documentcCsPtt}|td&||ddtjWdn1sB0YdS)NzUse iterator protocol insteadr)rrrZassertWarnsRegexDeprecationWarningrr )rr2rrrtest_getitem_deprecations  z(PullDOMTestCase.test_getitem_deprecationcCs*tt}|j}|t}||ddS)NF)rrrr2Z getFeaturerr)rr2Z saxparserZgesrrrtest_external_ges_defaults  z)PullDOMTestCase.test_external_ges_defaultN) __name__ __module__ __qualname__rr+r4unittestexpectedFailurer7r9r<r=rrrrrs>   rc@s4eZdZddZejddZddZd dd Zd S) ThoroughTestCasecCs|tjdtddS)N)r2)_test_thoroughrr SAXExerciserrrrrtest_thorough_parsesz$ThoroughTestCase.test_thorough_parsecCstdtd}||dS)N )SAX2DOMTestHelperrErDrpdrrrtest_sax2dom_failsz"ThoroughTestCase.test_sax2dom_failcCstdtd}||ddS)NrHF)rISAX2DOMExerciserrDrJrrrtest_thorough_sax2domsz&ThoroughTestCase.test_thorough_sax2domTcCst|\}}|tj||t|d|rt|\}}|tj||d|jt|\}}|tj||d|j |d|jt|\}}|tj ||d|j t|\}}|tj||d|jt|\}}|tj||d|j |d|jt|\}}|tj ||d|j t|\}}|tj ||d|jt|\}}|tj ||d|j t|\}}|tj ||d|j t|\}}|tj|dS)Nr a commenttargetr&rrtext)rrrr rrr5r&ZPROCESSING_INSTRUCTIONrPr!r"r%r'r8)rrKZ before_rootr)r*rrrrDsF           zThoroughTestCase._test_thoroughN)T) r>r?r@rGrArBrLrNrDrrrrrCs  rCc@s,eZdZddZddZddZeZeZdS)rEcCs ||_dSN)_handler)rrrrrsetContentHandlerszSAXExerciser.setContentHandlercCs|j}||d|dd|dti|d|dd|dtddi|d|d|d|dS) NrOrPr&rrclass paraclassrQ) rS startDocumentcommentprocessingInstruction startElementr characters endElement endDocumentrr6hrrrrs       zSAXExerciser.parsecOsdSrRr)rargskwargsrrrstub szSAXExerciser.stubN)r>r?r@rTrrbZ setProperty setFeaturerrrrrEs rEc@seZdZddZdS)rMcCsr|j}||dti|d|dd|dtddi|d|d|d|dS) NrrOrPr&rrUrVrQ) rSrWrZrrXrYr[r\r]r^rrrrs     zSAX2DOMExerciser.parseN)r>r?r@rrrrrrMsrMc@seZdZddZdS)rIcCs0t|_|jtjjjd|j|jdS)Nr,) rSAX2DOMr2rcxmlsaxrZfeature_namespacesrTrFrrrreset(s zSAX2DOMTestHelper.resetN)r>r?r@rgrrrrrI%srIc@s&eZdZd ddZddZddZdS) SAX2DOMTestCaseTestcCs|||dSrR)r)rtestZtestnamerrrconfirm1szSAX2DOMTestCase.confirmcCs|tt^}t|tjtt}|D] \}}|tj kr&|j dkr&qHq&| t|j dWdn1sn0YdS)Nrr) ioStringIOrrIrerfZ make_parserr#rr!r"Z assertGreaterr-)rrsdr)r*rrr test_basic4s   zSAX2DOMTestCase.test_basiccCs>t}||di|d|di|d|d|d|d||j}|j}|j \}}}|j d}| |j | |j || |j || |j || |j || |j | |j | |j | |j|| |j|| |j|| |j|| |j||dS)NdocrQZsubelmr)rrdrWrZr[r\r]ZdocumentZdocumentElementr-r1ZpreviousSiblingZassertIsZ nextSiblingZ parentNodeunlink)rZsax2domrprootZtext1Zelm1Ztext2Ztext3rrr testSAX2DOM@s8             zSAX2DOMTestCase.testSAX2DOMN)ri)r>r?r@rkrorsrrrrrh/s  rh__main__)rlrAZxml.saxreZxml.sax.xmlreaderrZxml.sax.handlerrZxml.domrZ test.supportrr rZTestCaserrCobjectrErMZDOMEventStreamrIrhr>mainrrrrs"      A" 4