U
    
W[É  ã                   @   s‚   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
e
ƒZG dd„ de
ƒZG dd„ de
ƒZG dd„ de
ƒ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
q 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 |¡ qr|sŒ|rdS dS dS )zOMove data back and forth.

        Returns whether any data was moved.
        r   é   N)r   Úseekr	   ÚreadÚtruncater   ZdataReceivedr   )r
   ZcDataZsDataZ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 )z2Take two Protocol instances and connect them.
    )r   ZmakeConnectionr   r   r   )r   r   ZcioZsior   r   r   r   ÚreturnConnected?   s    r   c                   @   s   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)ZassertEqualÚdomZparseStringZtoxml)r
   ÚfirstÚsecondr   r   r   ÚassertXMLEqualV   s    
þz XMLAssertionMixin.assertXMLEqualN)r   r   r   r   r   r   r   r   r   r   O   s   r   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú_EqualzN
    A class the instances of which are equal to anything and everything.
    c                 C   s   dS ©NTr   ©r
   Úotherr   r   r   Ú__eq__j   s    z_Equal.__eq__c                 C   s   dS ©NFr   r    r   r   r   Ú__ne__n   s    z_Equal.__ne__N©r   r   r   r   r"   r$   r   r   r   r   r   f   s   r   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú	_NotEqualz>
    A class the instances of which are equal to nothing.
    c                 C   s   dS r#   r   r    r   r   r   r"   w   s    z_NotEqual.__eq__c                 C   s   dS r   r   r    r   r   r   r$   {   s    z_NotEqual.__ne__Nr%   r   r   r   r   r&   s   s   r&   c                   @   s   e Zd ZdZdd„ ZdS )Ú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)Z
assertTrueZassertFalser   r&   )r
   ZfirstValueOneZsecondValueOneZvalueTwor   r   r   Ú"assertNormalEqualityImplementation   s    z7ComparisonTestsMixin.assertNormalEqualityImplementationN)r   r   r   r   r(   r   r   r   r   r'   €   s   r'   N)r   Úior   Zxml.domr   r   Ztwisted.internet.protocolr   r   r   Úobjectr   r   r&   r'   r   r   r   r   Ú<module>   s   (