o
    ¯b:  ã                   @   sz   d Z ddlmZ ddlmZ ddlmZ G dd„ dƒZdd„ Z	G d	d
„ d
ƒZ
G dd„ dƒZG dd„ dƒZG dd„ dƒZdS )a¼  
I{Private} test utilities for use throughout Twisted's test suite.  Unlike
C{proto_helpers}, this is no exception to the
don't-use-it-outside-Twisted-we-won't-maintain-compatibility rule!

@note: Maintainers be aware: things in this module should be gradually promoted
    to more full-featured test helpers and exposed as public API as your
    maintenance time permits.  In order to be public API though, they need
    their own test cases.
é    )ÚBytesIO)Úminidom)ÚFileWrapperc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚIOPumpzŠUtility to pump data between clients and servers for protocol testing.

    Perhaps this is a utility worthy of being in protocol.py?
    c                 C   s   || _ || _|| _|| _d S )N)ÚclientÚserverÚclientIOÚserverIO)Úselfr   r   r   r	   © r   ú8/usr/lib/python3/dist-packages/twisted/test/testutils.pyÚ__init__   s   
zIOPump.__init__c                 C   s   |   ¡ r	 |   ¡ sdS dS )z,Pump until there is no more input or output.N)Úpump)r
   r   r   r   Úflush!   s   ÿzIOPump.flushc                 C   s”   | j  d¡ | j d¡ | j  ¡ }| j ¡ }| j  d¡ | j d¡ | j  ¡  | j ¡  |D ]}| j |¡ q.|D ]}| j |¡ q9|sF|rHdS dS )zOMove data back and forth.

        Returns whether any data was moved.
        r   é   )r   Úseekr	   ÚreadÚtruncater   ÚdataReceivedr   )r
   ÚcDataÚsDataÚbyter   r   r   r   &   s   



zIOPump.pumpN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r      s
    r   c                 C   sJ   t ƒ }t ƒ }| t|ƒ¡ |  t|ƒ¡ t|| ||ƒ}| ¡  | ¡  |S )z-Take two Protocol instances and connect them.)r   ÚmakeConnectionr   r   r   )r   r   ÚcioÚsior   r   r   r   ÚreturnConnected=   s   r   c                   @   ó   e Zd ZdZdd„ ZdS )ÚXMLAssertionMixinzŠ
    Test mixin defining a method for comparing serialized XML documents.

    Must be mixed in to a L{test case<unittest.TestCase>}.
    c                 C   s$   |   t |¡ ¡ t |¡ ¡ ¡ dS )zï
        Verify that two strings represent the same XML document.

        @param first: An XML string.
        @type first: L{bytes}

        @param second: An XML string that should match C{first}.
        @type second: L{bytes}
        N)ÚassertEqualÚdomÚparseStringÚtoxml)r
   ÚfirstÚsecondr   r   r   ÚassertXMLEqualR   s   
ÿz XMLAssertionMixin.assertXMLEqualN)r   r   r   r   r(   r   r   r   r   r!   K   s    r!   c                   @   ó"   e Zd ZdZdedefdd„ZdS )Ú_EqualzN
    A class the instances of which are equal to anything and everything.
    ÚotherÚreturnc                 C   ó   dS )NTr   ©r
   r+   r   r   r   Ú__eq__f   ó   z_Equal.__eq__N©r   r   r   r   ÚobjectÚboolr/   r   r   r   r   r*   a   ó    r*   c                   @   r)   )Ú	_NotEqualz>
    A class the instances of which are equal to nothing.
    r+   r,   c                 C   r-   )NFr   r.   r   r   r   r/   o   r0   z_NotEqual.__eq__Nr1   r   r   r   r   r5   j   r4   r5   c                   @   r    )ÚComparisonTestsMixina¾  
    A mixin which defines a method for making assertions about the correctness
    of an implementation of C{==} and C{!=}.

    Use this to unit test objects which follow the common convention for C{==}
    and C{!=}:

        - The object compares equal to itself
        - The object cooperates with unrecognized types to allow them to
          implement the comparison
        - The object implements not-equal as the opposite of equal
    c                 C   s˜   |   ||k¡ |   ||k¡ |  ||k¡ |  ||k¡ |  ||k¡ |   ||k¡ |   |tƒ k¡ |  |tƒ k¡ |  |tƒ k¡ |   |tƒ k¡ dS )aU  
        Assert that C{firstValueOne} is equal to C{secondValueOne} but not
        equal to C{valueOne} and that it defines equality cooperatively with
        other types it doesn't know about.

        @param firstValueOne: An object which is expected to compare as equal
            to C{secondValueOne} and not equal to C{valueTwo}.

        @param secondValueOne: A different object than C{firstValueOne} but
            which is expected to compare equal to that object.

        @param valueTwo: An object which is expected to compare as not equal to
            C{firstValueOne}.
        N)Ú
assertTrueÚassertFalser*   r5   )r
   ÚfirstValueOneÚsecondValueOneÚvalueTwor   r   r   Ú"assertNormalEqualityImplementation   s   z7ComparisonTestsMixin.assertNormalEqualityImplementationN)r   r   r   r   r<   r   r   r   r   r6   s   s    r6   N)r   Úior   Úxml.domr   r#   Útwisted.internet.protocolr   r   r   r!   r*   r5   r6   r   r   r   r   Ú<module>   s   (		