ϪfdZddlmZddlmZddlmZddlmZm Z m Z GddejZ Gdd eje jZGd d ejZGd d eZGddeZy)z, Tests for L{twisted.words.xish.xmlstream}. )protocol)failure)unittest)domishutility xmlstreamc0eZdZdZdZdZdZdZdZy)XmlStreamTestscd|_g|_tj|_||j_|jj |jj_y)Nz no reason)connectionLostMsgoutlistr XmlStream transportappendwriteselfs C/usr/lib/python3/dist-packages/twisted/words/test/test_xmlstream.pysetUpzXmlStreamTests.setUpsI!, ",,.#' )-)<)<  &c|jjtjt |j y)zA Stub loseConnection because we are a transport. N)rconnectionLostrFailure Exceptionr rs rloseConnectionzXmlStreamTests.loseConnections- %% OOId&<&<= > rc|jj|jjd|j|jddy)zq Calling L{xmlstream.XmlStream.send} results in the data being written to the transport. srN)rconnectionMadesend assertEqualr rs r test_sendzXmlStreamTests.test_sends> %%' I& a)4rcgfd}|jjtj||jj|jj d|j dt y)zU Receiving the starttag of the root element results in stream start. c(jdyNr)rootelem streamStarteds rstreamStartEventz9XmlStreamTests.test_receiveRoot..streamStartEvent.s   &rN)r addObserverSTREAM_START_EVENTr dataReceivedrlen)rr'r&s @rtest_receiveRootzXmlStreamTests.test_receiveRoot(sc  ' ""9#?#?AQR %%' ##H- C ./rcggfd}fd}|jjtj||jjtj||jj |jj d|j dt|j dt|jj d|j dt|jdjtj|j dty)zN Receiving malformed XML results in an L{STREAM_ERROR_EVENT}. c(j|yr#r$)reason streamErrors rstreamErrorEventz;XmlStreamTests.test_receiveBadXML..streamErrorEvent=s   v &rc(jdyr#r$)_ streamEnds rstreamEndEventz9XmlStreamTests.test_receiveBadXML..streamEndEvent@s   T "rr(rzr)N) rr*STREAM_ERROR_EVENTSTREAM_END_EVENTrr,rr- assertTruecheckr ParserError)rr3r7r6r2s @@rtest_receiveBadXMLz!XmlStreamTests.test_receiveBadXML6s   ' # ""9#?#?AQR ""9#=#=~N %%' ##H- C ,- C N+ ##$?@ C ,-  A,,V-?-?@A C N+rcgfd}|jjtj||jj|j |j dt |jdtj|j dj|jy)z@ Ending the stream fires a L{STREAM_END_EVENT}. c(j|yr#r$)r1r6s rr7z5XmlStreamTests.test_streamEnd..streamEndEventVs   V $rr)rN) rr*r9rrrr-assertIsInstancerrgetErrorMessager )rr7r6s @rtest_streamEndzXmlStreamTests.test_streamEndPs  % ""9#=#=~N %%'  C N+ ilGOO< 15579O9OPrN) __name__ __module__ __qualname__rrr r.r=rBrrr r s!= 5 0,4Qrr ceZdZdZdZy) DummyProtocolz I am a protocol with an event dispatcher without further processing. This protocol is only used for testing XmlStreamFactoryMixin to make sure the bootstrap observers are added to the protocol instance. cl||_||_g|_tjj |yr#)argskwargs observersrEventDispatcher__init__)rrJrKs rrNzDummyProtocol.__init__is+  ((.rN)rCrDrE__doc__rNrFrrrHrHas /rrHc"eZdZdZdZdZdZy)BootstrapMixinTestszq Tests for L{xmlstream.BootstrapMixin}. @ivar factory: Instance of the factory or mixin under test. c6tj|_yr#)rBootstrapMixinfactoryrs rrzBootstrapMixinTests.setUpxs //1 rcgfd}t}|jjd||jj||j dd|j dt y)zL Dispatching an event fires registered bootstrap observers. c(j|yr#r$datacalleds rcbz6BootstrapMixinTests.test_installBootstraps..cb MM$ r//event/myeventNr))rHrT addBootstrapinstallBootstrapsdispatchrr-rrZ dispatcherrYs @rtest_installBootstrapsz*BootstrapMixinTests.test_installBootstraps{sd #_  !!"3R8 &&z2D"34 CK(rcgfd}|jjd||jjd|t}|jj ||j dd|j y)zI Test addition and removal of a bootstrap event handler. c(j|yr#r$rWs rrZz:BootstrapMixinTests.test_addAndRemoveBootstrap..cbr[rr\N)rTr]removeBootstraprHr^r_ assertFalser`s @rtest_addAndRemoveBootstrapz.BootstrapMixinTests.test_addAndRemoveBootstrapss   !!"3R8 $$%6;"_  &&z2D"34  rN)rCrDrErOrrbrgrFrrrQrQqs 2) !rrQc"eZdZdZdZdZdZy)!GenericXmlStreamFactoryTestsMixinz3 Generic tests for L{XmlStream} factories. c6tj|_yr#)rXmlStreamFactoryrTrs rrz'GenericXmlStreamFactoryTestsMixin.setUps 113 rcgfd}|jjd||jjd}|jdd|j dt y)zY The protocol factory installs bootstrap event handlers on the protocol. c(j|yr#r$rWs rrZzRGenericXmlStreamFactoryTestsMixin.test_buildProtocolInstallsBootstraps..cbr[rr\Nr))rTr] buildProtocolr_rr-)rrZxsrYs @r$test_buildProtocolInstallsBootstrapszFGenericXmlStreamFactoryTestsMixin.test_buildProtocolInstallsBootstrapss]  !!"3R8 \\ ' ' - D+, CK(rc|jjd}|j|j|jy)z@ The protocol factory is saved in the protocol. N)rTrnassertIdenticalrros rtest_buildProtocolStoresFactoryzAGenericXmlStreamFactoryTestsMixin.test_buildProtocolStoresFactorys0\\ ' ' - T\\2::6rN)rCrDrErOrrprtrFrrriris4) 7rriceZdZdZdZdZy)XmlStreamFactoryMixinTestsz7 Tests for L{xmlstream.XmlStreamFactoryMixin}. cftjdd|_t|j_y)N)test)rXmlStreamFactoryMixinrTrHrrs rrz XmlStreamFactoryMixinTests.setUps" 66t$G - rc|jjd}|jd|j|jddi|jy)zb Arguments passed to the factory are passed to protocol on instantiation. Nr#rx)rTrnrrJrKrss r"test_buildProtocolFactoryArgumentsz=XmlStreamFactoryMixinTests.test_buildProtocolFactoryArgumentssD \\ ' ' - "''* &$3rN)rCrDrErOrr{rFrrrvrvs.4rrvN)rOtwisted.internetrtwisted.pythonr twisted.trialrtwisted.words.xishrrrTestCaser ProtocolrMrHrQrirvrFrrrsz &""99OQX&&OQd /H%%w'>'> / +!(+++!\7(;7@4!B4r