Ϫfl$dZddlmZddlmZddlmZddlmZddl m Z GddZ Gd d Z Gd d ejZGd dejZy)z+ Test cases for twisted.words.xish.utility ) OrderedDict)unittest)utility)Element)EventDispatcherceZdZdZdZdZy)CallbackTrackerz Test helper for tracking callbacks. Increases a counter on each call to L{call} and stores the object passed in the call. c d|_d|_y)Nrcalledobjselfs B/usr/lib/python3/dist-packages/twisted/words/test/test_xishutil.py__init__zCallbackTracker.__init__s c:|jdz|_||_y)Nr )rr s rcallzCallbackTracker.callskkAo rN)__name__ __module__ __qualname____doc__rrrrr r srr c(eZdZdZdZdZdZdZy)OrderedCallbackTrackerz= Test helper for tracking callbacks and their order. cg|_yN)callListrs rrzOrderedCallbackTracker.__init__'s  rcN|jj|jyr)rappendcall1robjects rr"zOrderedCallbackTracker.call1* TZZ(rcN|jj|jyr)rr!call2r#s rr'zOrderedCallbackTracker.call2-r%rcN|jj|jyr)rr!call3r#s rr)zOrderedCallbackTracker.call30r%rN)rrrrrr"r'r)rrrrr"s)))rrcXeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd Zy)EventDispatcherTestsz' Tests for L{EventDispatcher}. ct}t}t}t}|jd|j|jd|j|jd|j|jd|jt d}|j dt d}|j d|j ||j|jd |j|j||j|jd |j ||j|jd |j|jd |j|j||j|jd |j |d|j|jd |j|j||jd|j|j ||j|jd y) N /message/body/message /presence//event/testeventnsmessagebodyr2presencer6rr) rr addObserverrr addElementdispatch assertEqualr r removeObserver)rdcb1cb2cb3msgpress r testStuffzEventDispatcherTests.testStuff9s   osxx0 j#((+ k388, )3884'( v)*  # 3 Q' #& Q' 4 Q' Q' $' Q' 1)* Q' !$ chh/ 4 Q'rct}t}t}|jd|j|jd|j|j |d|j |j d|j |j||j |j d|j |j|y)z Test adding two observers for the same query. When the event is dispatched both of the observers need to be called. r0rN)rr r8rr:r;r r )rr=r>r?s rtest_addObserverTwicez*EventDispatcherTests.test_addObserverTwice]s   )3884 )3884 1)* Q' !$ Q' !$rcttd}tfd}jd|j ||j j dj ||j j dj ||j j dy)zG Test for registration of an observer during dispatch. r1c>jdjyNr.)r8r)_cbr=s r onMessagezBEventDispatcherTests.test_addObserverInDispatch..onMessagexs MM*bgg .rr.rrr7Nrrr addOnetimeObserverr:r;r rrArKrJr=s @@rtest_addObserverInDispatchz/EventDispatcherTests.test_addObserverInDispatchps  '(   / Z3 3 A& 3 A& 3 A&rcttd}tfd}jd|j ||j j dj ||j j dj ||j j dy)zN Test for registration of a onetime observer during dispatch. r1c>jdjyrH)rMr)rArJr=s rrKzIEventDispatcherTests.test_addOnetimeObserverInDispatch..onMessages RWW 5rr.rrNrLrNs @@r!test_addOnetimeObserverInDispatchz6EventDispatcherTests.test_addOnetimeObserverInDispatchs  '(   6 Z3 3 A& 3 A& 3 A&rc.t}td}t}|jd|j|j ||j |jd|j ||j |jdy)Nr1r.r)rrr rMrr:r;r )rr=rArJs rtestOnetimeDispatchz(EventDispatcherTests.testOnetimeDispatchso  '(   Z1 3 A& 3 A&rct}td}td}t}|jd|j|j |}|j d||j |}|j d|y)Nr1r5r/FT)rrr r8rr:r;)rr=rArBrJresults rtestDispatcherResultz)EventDispatcherTests.testDispatcherResultsu  '()*   k277+C 'D! v&rc t}t}|jd|j|jd|jd|jd|j dt d}|jd|j||j|j|j |j|jgdt|jDcgc]}|jc}zycc}w)Nr-r.rr1r4zCalls out of order: %s) rrr8r'r)r"rr9r:r;rreprr)rr=rJrAcs rtestOrderedXPathDispatchz-EventDispatcherTests.testOrderedXPathDispatchs   # % orxx0 j"((B/ orxx3'( v 3  KK XXrxx * $t,MAQZZ,M'N N -Ns$Dc`t}t}|jd|j|j dd|j d|j |jd|j|j dt|jjdy)zO Test observer clean-up after removeObserver for named events. //event/testNrr) rr r8rr:r;r r<len_eventObserverspoprr=rJs rtest_cleanUpRemoveEventObserverz4EventDispatcherTests.test_cleanUpRemoveEventObservers     nbgg. 4( BII& 1 C 1 1 5 5a 89:rctt}t}td}|jd|j|j ||j d|j|jd|j|j dt|jjdy)zO Test observer clean-up after removeObserver for XPath events. Nr3r.rrN) rr rr8rr:r;r r<r__xpathObserversrarr=rJrAs rtest_cleanUpRemoveXPathObserverz4EventDispatcherTests.test_cleanUpRemoveXPathObservers    '( j"''* 3 BII& RWW- C 1 1 5 5a 89:rc(t}t}|jd|j|j dd|j d|j |j dt|jjdy)zD Test observer clean-up after onetime named events. r^Nrr) rr rMrr:r;r r_r`rarbs r test_cleanUpOnetimeEventObserverz5EventDispatcherTests.test_cleanUpOnetimeEventObserversp     ^RWW5 4( BII& C 1 1 5 5a 89:rc<t}t}td}|jd|j|j ||j d|j|j dt|jjdy)zD Test observer clean-up after onetime XPath events. rer.rrN) rr rrMrr:r;r r_rfrargs r test_cleanUpOnetimeXPathObserverz5EventDispatcherTests.test_cleanUpOnetimeXPathObserversx    '( Z1 3 BII& C 1 1 5 5a 89:rc<Gddtj}Gddtfd}t}t }tj} |t_|j d||j d|j  |jdd|jd t|j|jd |j|t_y#$r|jdYjwxYw#|t_wxYw) z Test that exceptions in observers do not bubble up to dispatch. The exceptions raised in observers should be logged and other observers should be called as if nothing happened. ceZdZdZy)OEventDispatcherTests.test_observerRaisingException..OrderedCallbackListc"t|_yr)r callbacksrs rrzXEventDispatcherTests.test_observerRaisingException..OrderedCallbackList.__init__ s !,rN)rrrrrrrOrderedCallbackListro s /rrrc eZdZy)EEventDispatcherTests.test_observerRaisingException..TestErrorN)rrrrrr TestErrorrts rrucrr)rIrus r raiseErrorzFEventDispatcherTests.test_observerRaisingException..raiseErrors + rr^Nz2TestError raised. Should have been logged instead.r) r CallbackList Exceptionrr r8rr:failr;r_flushLoggedErrorsr )rrrrwr=rJoriginalCallbackListrus @rtest_observerRaisingExceptionz2EventDispatcherTests.test_observerRaisingExceptions /'"6"6 /        &33 8#6G MM.* 5 MM."'' 2 P 40   QD$:$:9$E F G   Q *#7G  P NO P $8G s19DC2 AD2D D D  D DN)rrrrrCrErOrRrTrWr\rcrhrjrlr}rrrr+r+4sD"(H%&',', ' ' , ; ; ; ;$8rr+c"eZdZdZdZdZdZy) XmlPipeTestsz: Tests for L{twisted.words.xish.utility.XmlPipe}. c6tj|_yr)rXmlPipepipers rsetUpzXmlPipeTests.setUp.sOO% rcfd}g|jjjd|td}|jjj ||j |gy)zO Send an element from the source and observe it from the sink. c(j|yrr!r r s rrJz,XmlPipeTests.test_sendFromSource..cb6 MM# r/test[@xmlns="testns"]testnstestN)rsinkr8rsourcesendr;rrJelementr s @rtest_sendFromSourcez XmlPipeTests.test_sendFromSource1s]   ""#;R@,- g& 'F+rcfd}g|jjjd|td}|jjj ||j |gy)zO Send an element from the sink and observe it from the source. c(j|yrrrs rrJz*XmlPipeTests.test_sendFromSink..cbDrrrrN)rrr8rrrr;rs @rtest_sendFromSinkzXmlPipeTests.test_sendFromSink?s]   $$%=rB,- G$ 'F+rN)rrrrrrrrrrrr)s& , ,rrN)r collectionsr twisted.trialrtwisted.words.xishrtwisted.words.xish.domishrtwisted.words.xish.utilityrr rTestCaser+rrrrrsV $"&-6"))$r88,,r8j",8$$",r