U
    n5{iÖ  ã                   @   s–  d Z dddgZddlmZmZmZmZmZ ddlm	Z	m
Z
mZmZmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ edƒZG dd„ dee ƒZedee d�Zedƒedƒedƒedƒedƒedƒfee ee ee ee ee ee ee dœdd„ZG dd„ deee  ƒZG dd„ deee  ƒZ ee! ee! dœdd„Z"e#e#eeee#e#e$ee! ee! f   dœdd„Z%dS )z5
Hamcrest matchers useful throughout the test suite.
Úmatches_resultÚHasSumÚIsSequenceOfé    )ÚAnyÚListÚSequenceÚTupleÚTypeVar)Úcontains_exactlyÚcontains_stringÚequal_toÚ
has_lengthÚhas_propertiesÚinstance_of)ÚBaseMatcher)ÚAllOf)ÚDescription)ÚMatcher)ÚProtocol)ÚFailureÚTc                   @   s    e Zd ZdZeedœdd„ZdS )Ú	Semigroupz˜
    A type with an associative binary operator.

    Common examples of a semigroup are integers with addition and strings with
    concatenation.
    )ÚotherÚreturnc                 C   s   dS )zF
        This must be associative: a + (b + c) == (a + b) + c
        N© )Úselfr   r   r   úE/tmp/pip-unpacked-wheel-mnhg7r0q/twisted/trial/_dist/test/matchers.pyÚ__add__+   s    zSemigroup.__add__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   #   s   r   ÚS)Úbound)Ú	successesÚerrorsÚfailuresÚskipsÚexpectedFailuresÚunexpectedSuccessesr   c                 C   s   t | |||||dœƒS )zA
    Match a L{TestCase} instances with matching attributes.
    ©r$   r%   r&   r'   r(   r)   )r   r*   r   r   r   r   4   s    úÿc                   @   st   e Zd ZdZee eddœdd„Zee edœdd„Zee e	d	œd
d„Z
ee eddœdd„Zeddœdd„ZdS )r   zÑ
    Match a sequence the elements of which sum to a value matched by
    another matcher.

    @ivar sumMatcher: The matcher which must match the sum.
    @ivar zero: The zero value for the matched type.
    N)Ú
sumMatcherÚzeror   c                 C   s   || _ || _d S ©N)r+   r,   )r   r+   r,   r   r   r   Ú__init__T   s    zHasSum.__init__)Úsequencer   c                 C   s&   |s
| j S | j }|D ]}|| }q|S r-   )r,   )r   r/   ÚresultÚelemr   r   r   Ú_sumX   s    
zHasSum._sum©Úitemr   c                 C   s   |   |¡}| j |¡S )zG
        Determine whether the sum of the sequence is matched.
        )r2   r+   Úmatches)r   r4   Úsr   r   r   Ú_matches`   s    
zHasSum._matches©r4   Údescriptionr   c                 C   s&   |   |¡}| | ¡ | j ||¡ dS )ú(
        Describe the mismatch.
        N)r2   Úappend_description_ofr+   Údescribe_mismatch)r   r4   r9   r6   r   r   r   r<   g   s    

zHasSum.describe_mismatch©r9   r   c                 C   s$   |  d¡ | | j¡ |  d¡ dS )ú;
        Describe this matcher for error messages.
        za sequence with sum ú, N)Úappend_textr;   r+   ©r   r9   r   r   r   Údescribe_top   s    
zHasSum.describe_to)r   r   r    r!   r   r"   r.   r   r2   Úboolr7   r   r<   rB   r   r   r   r   r   K   s   	c                   @   s^   e Zd ZdZee ddœdd„Zee edœdd„Z	ee e
dd	œd
d„Ze
ddœdd„ZdS )r   z¬
    Match a sequence where every element is matched by another matcher.

    @ivar elementMatcher: The matcher which must match every element of the
        sequence.
    N)ÚelementMatcherr   c                 C   s
   || _ d S r-   )rD   )r   rD   r   r   r   r.   �   s    zIsSequenceOf.__init__r3   c                 C   s    |D ]}| j  |¡s dS qdS )zM
        Determine whether every element of the sequence is matched.
        FT)rD   r5   )r   r4   r1   r   r   r   r7   „   s    zIsSequenceOf._matchesr8   c                 C   sB   t |ƒD ]4\}}| j |¡s| | ¡ | d|› d|›�¡ qdS )r:   znot sequence with element #ú N)Ú	enumeraterD   r5   r;   r@   )r   r4   r9   Úidxr1   r   r   r   r<   �   s    
zIsSequenceOf.describe_mismatchr=   c                 C   s$   |  d¡ | | j¡ |  d¡ dS )r>   za sequence containing only r?   N)r@   r;   rD   rA   r   r   r   rB   –   s    
zIsSequenceOf.describe_to)r   r   r    r!   r   r   r.   r   rC   r7   r   r<   rB   r   r   r   r   r   y   s
   		)Ú
propertiesr   c                  K   s   t ttƒtf | ŽƒS )zC
    Match an instance of L{Failure} with matching attributes.
    )r   r   r   r   )rH   r   r   r   Ú	isFailureŸ   s    þrI   )ÚfunctionNameÚfileNamer   c                 C   s$   t t| ƒt|ƒttƒtdƒtdƒƒS )zk
    Match a tuple representation of a frame like those used by
    L{twisted.python.failure.Failure}.
    r   )r
   r   r   r   Úintr   )rJ   rK   r   r   r   ÚsimilarFrame©   s    ùrM   N)&r!   Ú__all__Útypingr   r   r   r   r	   Zhamcrestr
   r   r   r   r   r   Zhamcrest.core.base_matcherr   Zhamcrest.core.core.allofr   Zhamcrest.core.descriptionr   Zhamcrest.core.matcherr   Ztyping_extensionsr   Ztwisted.python.failurer   r   r   r"   r   r   r   ÚobjectrI   ÚstrrL   rM   r   r   r   r   Ú<module>   sJ   ý úù.&  þ