o
    >h                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
 G dd dejZG dd	 d	eje	jZG d
d dejZG dd deZG dd deZdS )z,
Tests for L{twisted.words.xish.xmlstream}.
    )protocol)failure)unittest)domishutility	xmlstreamc                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )XmlStreamTestsc                 C   s0   d| _ g | _t | _| | j_| jj| jj_d S )Nz	no reason)connectionLostMsgoutlistr   	XmlStream	transportappendwriteself r   /var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/words/test/test_xmlstream.pysetUp   s
   
zXmlStreamTests.setUpc                 C   s   | j tt| j dS )zA
        Stub loseConnection because we are a transport.
        N)r   connectionLostr   Failure	Exceptionr	   r   r   r   r   loseConnection   s   zXmlStreamTests.loseConnectionc                 C   s,   | j   | j d | | jd d dS )zq
        Calling L{xmlstream.XmlStream.send} results in the data being written
        to the transport.
        s   <root>r   N)r   connectionMadesendassertEqualr
   r   r   r   r   	test_send   s   
zXmlStreamTests.test_sendc                    sJ   g   fdd}| j t j| | j   | j d | dt  dS )zU
        Receiving the starttag of the root element results in stream start.
        c                         d  d S Nr   )rootelemstreamStartedr   r   streamStartEvent.      z9XmlStreamTests.test_receiveRoot.<locals>.streamStartEvent<root>   N)r   addObserverSTREAM_START_EVENTr   dataReceivedr   len)r   r"   r   r    r   test_receiveRoot(   s   
zXmlStreamTests.test_receiveRootc                    s   g g  fdd} fdd}| j t j| | j t j| | j   | j d | dt | dt  | j d | dt | d 	t
j | dt  d	S )
zN
        Receiving malformed XML results in an L{STREAM_ERROR_EVENT}.
        c                         |  d S r   r   reason)streamErrorr   r   streamErrorEvent=   r#   z;XmlStreamTests.test_receiveBadXML.<locals>.streamErrorEventc                    r   r   r   )_	streamEndr   r   streamEndEvent@   r#   z9XmlStreamTests.test_receiveBadXML.<locals>.streamEndEventr$   r   z<child><unclosed></child>r%   N)r   r&   STREAM_ERROR_EVENTSTREAM_END_EVENTr   r(   r   r)   
assertTruecheckr   ParserError)r   r/   r3   r   )r2   r.   r   test_receiveBadXML6   s   
z!XmlStreamTests.test_receiveBadXMLc                    sn   g   fdd}| j t j| | j   |   | dt  |  d tj	 |  d 
 | j dS )z@
        Ending the stream fires a L{STREAM_END_EVENT}.
        c                    r+   r   r   r,   r1   r   r   r3   V   r#   z5XmlStreamTests.test_streamEnd.<locals>.streamEndEventr%   r   N)r   r&   r5   r   r   r   r)   assertIsInstancer   r   getErrorMessager	   )r   r3   r   r1   r   test_streamEndP   s   
zXmlStreamTests.test_streamEndN)	__name__
__module____qualname__r   r   r   r*   r9   r<   r   r   r   r   r      s    	r   c                   @   s   e Zd ZdZdd ZdS )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.
    c                 O   s"   || _ || _g | _tj|  d S r   )argskwargs	observersr   EventDispatcher__init__)r   rA   rB   r   r   r   rE   i   s   zDummyProtocol.__init__N)r=   r>   r?   __doc__rE   r   r   r   r   r@   a   s    r@   c                   @   (   e Zd ZdZdd Zdd Zdd ZdS )	BootstrapMixinTestszq
    Tests for L{xmlstream.BootstrapMixin}.

    @ivar factory: Instance of the factory or mixin under test.
    c                 C      t  | _d S r   )r   BootstrapMixinfactoryr   r   r   r   r   x   r#   zBootstrapMixinTests.setUpc                    sP   g   fdd}t  }| jd| | j| |dd | dt  dS )zL
        Dispatching an event fires registered bootstrap observers.
        c                    r+   r   r   datacalledr   r   cb   r#   z6BootstrapMixinTests.test_installBootstraps.<locals>.cb//event/myeventNr%   )r@   rK   addBootstrapinstallBootstrapsdispatchr   r)   r   rP   
dispatcherr   rN   r   test_installBootstraps{   s   z*BootstrapMixinTests.test_installBootstrapsc                    sX   g   fdd}| j d| | j d| t }| j | |dd |   dS )zI
        Test addition and removal of a bootstrap event handler.
        c                    r+   r   r   rL   rN   r   r   rP      r#   z:BootstrapMixinTests.test_addAndRemoveBootstrap.<locals>.cbrQ   N)rK   rR   removeBootstrapr@   rS   rT   assertFalserU   r   rN   r   test_addAndRemoveBootstrap   s   z.BootstrapMixinTests.test_addAndRemoveBootstrapN)r=   r>   r?   rF   r   rW   rZ   r   r   r   r   rH   q   s
    rH   c                   @   rG   )	!GenericXmlStreamFactoryTestsMixinz3
    Generic tests for L{XmlStream} factories.
    c                 C   rI   r   )r   XmlStreamFactoryrK   r   r   r   r   r      r#   z'GenericXmlStreamFactoryTestsMixin.setUpc                    sJ   g   fdd}| j d| | j d}|dd | dt  dS )zY
        The protocol factory installs bootstrap event handlers on the protocol.
        c                    r+   r   r   rL   rN   r   r   rP      r#   zRGenericXmlStreamFactoryTestsMixin.test_buildProtocolInstallsBootstraps.<locals>.cbrQ   Nr%   )rK   rR   buildProtocolrT   r   r)   )r   rP   xsr   rN   r   $test_buildProtocolInstallsBootstraps   s   zFGenericXmlStreamFactoryTestsMixin.test_buildProtocolInstallsBootstrapsc                 C   s    | j d}| | j |j  dS )z@
        The protocol factory is saved in the protocol.
        N)rK   r]   assertIdenticalr   r^   r   r   r   test_buildProtocolStoresFactory   s   zAGenericXmlStreamFactoryTestsMixin.test_buildProtocolStoresFactoryN)r=   r>   r?   rF   r   r_   rb   r   r   r   r   r[      s
    r[   c                   @   s    e Zd ZdZdd Zdd ZdS )XmlStreamFactoryMixinTestsz7
    Tests for L{xmlstream.XmlStreamFactoryMixin}.
    c                 C   s   t jd d d| _t| j_d S )N)test)r   XmlStreamFactoryMixinrK   r@   r   r   r   r   r   r      s   z XmlStreamFactoryMixinTests.setUpc                 C   s0   | j d}| d|j | ddi|j dS )zb
        Arguments passed to the factory are passed to protocol on
        instantiation.
        Nr   rd   )rK   r]   r   rA   rB   ra   r   r   r   "test_buildProtocolFactoryArguments   s   z=XmlStreamFactoryMixinTests.test_buildProtocolFactoryArgumentsN)r=   r>   r?   rF   r   rf   r   r   r   r   rc      s    rc   N)rF   twisted.internetr   twisted.pythonr   twisted.trialr   twisted.words.xishr   r   r   TestCaser   ProtocolrD   r@   rH   r[   rc   r   r   r   r   <module>   s   R. 