a 5êdg¨2ã@sÔddlZddlZddlZddlmZddlmZddlm Z ddl m Z e dddZ d Z Gd d „d ejƒZGd d „d ejƒZGdd„deƒZGdd„deƒZGdd„de jƒZGdd„dejƒZedkrÐe ¡dS)éN)ÚAttributesImpl)Úfeature_external_ges)Úpulldom)Úfindfileztest.xmlZ xmltestdata)Zsubdira  Introduction to XSL

A. Namespace

c@sPeZdZdd„Zdd„Zdd„Zejdd„ƒZejd d „ƒZ d d „Z d d„Z dS)ÚPullDOMTestCasecCs\t t¡}| |jj¡t|ƒttdƒ}tt |¡ƒWdƒn1sN0YdS)z&Minimal test of DOMEventStream.parse()ÚrbN)rÚparseÚtstfileZ addCleanupÚstreamÚcloseÚlistÚopen)ÚselfÚhandlerÚfin©rú-/usr/local/lib/python3.9/test/test_pulldom.pyÚ test_parses   zPullDOMTestCase.test_parsecCsœt t¡}t|ƒ\}}| t|dƒ¡| tj|¡t|ƒ\}}| tj|¡| d|j ¡| dt |j ƒ¡| |j   d¡j d¡t|ƒ\}}| tj|¡t|ƒ\}}| tj|¡t|ƒ\}}| d|j ¡|}t|ƒ\}}| tj|¡| d|j¡t|ƒ\}}| tj|¡| d|j ¡| ||u¡t|ƒ\}}| 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|¡d S) z&Test DOMEventStream parsing semantics.Ú createElementÚhtmléz xmlns:xdczhttp://www.xml.com/booksÚtitlezIntroduction to XSLÚhrÚpz xdc:authorN)rÚ parseStringÚ SMALL_SAMPLEÚnextÚ assertTrueÚhasattrÚ assertEqualÚSTART_DOCUMENTÚ START_ELEMENTÚtagNameÚlenZ attributesZ getNamedItemÚvalueÚ CHARACTERSÚdataÚ END_ELEMENT)rÚitemsÚevtÚnodeZ title_noderrrÚtest_parse_semantics+sh   ÿ                z$PullDOMTestCase.test_parse_semanticscCs@t t¡}|D]<\}}|tjkr|jdkr| |¡| dt|jƒ¡qVq|  d¡|D]\}}|tjkrZqrqZ| d|jd¡| |¡| t |ƒdtj ¡t |ƒ\}}| |jd¡| |¡t |ƒt |ƒ\}}| |jd¡|  t ¡t |ƒWd ƒn1s0Y| ¡| |j¡| |j¡d S) z$Ensure expandItem works as expected.réz,No "title" element detected in SMALL_SAMPLE!rz=expandNode did not leave DOMEventStream in the correct state.rrrN)rrrr!r"Z expandNoderr#Ú childNodesÚfailrr%Z assertRaisesÚ StopIterationÚclearÚ assertIsNoneÚparserr )rr(r)Úitemr*rrrÚtest_expandItemis4       ÿ     ( zPullDOMTestCase.test_expandItemcCs4t t¡}|D]\}}|tjkrq0q| d¡dS)z*PullDOM does not receive "comment" events.zNo comment was encounteredN)rrrÚCOMMENTr.)rr(r)Ú_rrrÚ test_comment‰s    zPullDOMTestCase.test_commentcCspt t¡}|D] \}}|tjkr|jdkrq0qzt|ƒ\}}| tj|¡Wntyj|  d¡Yn0dS)z/PullDOM does not receive "end-document" events.rz8Ran out of events, but should have received END_DOCUMENTN) rrrr'r"rrÚ END_DOCUMENTr/r.)rr(r)r*rrrÚtest_end_document“s    ÿz!PullDOMTestCase.test_end_documentcCsPt t¡}| td¡&| |ddtj¡Wdƒn1sB0YdS)NzUse iterator protocol insteadéÿÿÿÿr)rrrZassertWarnsRegexÚDeprecationWarningrr )rr2rrrÚtest_getitem_deprecation£s  ÿz(PullDOMTestCase.test_getitem_deprecationcCs*t t¡}|j}| t¡}| |d¡dS)NF)rrrr2Z getFeaturerr)rr2Z saxparserZgesrrrÚtest_external_ges_defaultªs  z)PullDOMTestCase.test_external_ges_defaultN) Ú__name__Ú __module__Ú __qualname__rr+r4ÚunittestÚexpectedFailurer7r9r<r=rrrrrs>   rc@s8eZdZdZdd„Zejdd„ƒZdd„Zd d d „Z d S) ÚThoroughTestCasez(Test the hard-to-reach parts of pulldom.cCs| tjdtƒd¡dS)z0Test some of the hard-to-reach parts of PullDOM.N)r2)Ú_test_thoroughrrÚ SAXExerciser©rrrrÚtest_thorough_parse´sz$ThoroughTestCase.test_thorough_parsecCstdtƒdƒ}| |¡dS)z2SAX2DOM can"t handle a PI before the root element.Né )ÚSAX2DOMTestHelperrErD©rÚpdrrrÚtest_sax2dom_fail¸sz"ThoroughTestCase.test_sax2dom_failcCstdtƒdƒ}| |d¡dS)z0Test some of the hard-to-reach parts of SAX2DOM.NrHF)rIÚSAX2DOMExerciserrDrJrrrÚtest_thorough_sax2dom¾sz&ThoroughTestCase.test_thorough_sax2domTcCsÐt|ƒ\}}| tj|¡| t|dƒ¡|rŒt|ƒ\}}| tj|¡| d|j¡t|ƒ\}}| tj|¡| d|j ¡| d|j¡t|ƒ\}}| tj |¡| d|j ¡t|ƒ\}}| tj|¡| d|j¡t|ƒ\}}| tj|¡| d|j ¡| d|j¡t|ƒ\}}| tj |¡| d|j ¡t|ƒ\}}| tj |¡| d|j¡t|ƒ\}}| tj |¡| d|j ¡t|ƒ\}}| tj |¡| d|j ¡t|ƒ\}}| tj|¡dS) zPTest some of the hard-to-reach parts of the parser, using a mock parser.rú a commentÚtargetr&rrÚtextN)rrrr rrr5r&ZPROCESSING_INSTRUCTIONrPr!r"r%r'r8)rrKZ before_rootr)r*rrrrDÃsF           zThoroughTestCase._test_thoroughN)T) r>r?r@Ú__doc__rGrArBrLrNrDrrrrrC±s  rCc@s0eZdZdZdd„Zdd„Zdd„ZeZeZdS) rEznA fake sax parser that calls some of the harder-to-reach sax methods to ensure it emits the correct eventscCs ||_dS©N)Ú_handler)rrrrrÚsetContentHandleröszSAXExerciser.setContentHandlercCsˆ|j}| ¡| d¡| dd¡| dtiƒ¡| d¡| dd¡| dtddiƒ¡| d¡| d¡| d¡| ¡dS) NrOrPr&rrÚclassÚ paraclassrQ) rTÚ startDocumentÚcommentÚprocessingInstructionÚ startElementrÚ charactersÚ endElementÚ endDocument©rr6Úhrrrrùs       zSAXExerciser.parsecOsdS)zStub method. Does nothing.Nr)rÚargsÚkwargsrrrÚstub szSAXExerciser.stubN) r>r?r@rRrUrrcZ setPropertyÚ setFeaturerrrrrEòs rEc@seZdZdZdd„ZdS)rMz…The same as SAXExerciser, but without the processing instruction and comment before the root element, because S2D can"t handle itcCsr|j}| ¡| dtiƒ¡| d¡| dd¡| dtddiƒ¡| d¡| d¡| d¡| ¡dS) NrrOrPr&rrVrWrQ) rTrXr[rrYrZr\r]r^r_rrrrs     zSAX2DOMExerciser.parseN)r>r?r@rRrrrrrrMsrMc@seZdZdZdd„ZdS)rIz1Allows us to drive SAX2DOM from a DOMEventStream.cCs0t ¡|_|j tjjjd¡|j |j¡dS)Nr,) rÚSAX2DOMr2rdÚxmlÚsaxrZfeature_namespacesrUrFrrrÚreset(s zSAX2DOMTestHelper.resetN)r>r?r@rRrhrrrrrI%srIc@s&eZdZd dd„Zdd„Zdd„ZdS) ÚSAX2DOMTestCaseÚTestcCs| ||¡dSrS)r)rÚtestZtestnamerrrÚconfirm1szSAX2DOMTestCase.confirmcCs|t t¡^}t|tj ¡ttƒƒ}|D] \}}|tj kr&|j dkr&qHq&|  t|j ƒd¡Wdƒn1sn0YdS)z'Ensure SAX2DOM can parse from a stream.rrN) ÚioÚStringIOrrIrfrgZ make_parserr#rr!r"Z assertGreaterr-)rrÚsdr)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)z)Ensure SAX2DOM expands nodes as expected.ÚdocrQZsubelmrN)rrerXr[r\r]r^ZdocumentZdocumentElementr-r1ZpreviousSiblingZassertIsZ nextSiblingZ parentNodeÚunlink)rZsax2domrqÚrootZtext1Zelm1Ztext2Ztext3rrrÚ testSAX2DOM@s8             zSAX2DOMTestCase.testSAX2DOMN)rj)r>r?r@rlrprtrrrrri/s  riÚ__main__)rmrAZxml.saxrfZxml.sax.xmlreaderrZxml.sax.handlerrZxml.domrZ test.supportrr rZTestCaserrCÚobjectrErMZDOMEventStreamrIrir>ÚmainrrrrÚs"      A" 4