o
    Óó·iÖ  ã                   @   s¦  d Z g d¢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dee dee dee dee dee dee dee fdd„ZG dd„ deee  ƒZG dd„ deee  ƒZ dee! dee! fdd„Z"d e#d!e#deeee#e#e$ee! ee! f   f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dedef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   úgC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\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)   N)r   r*   r   r   r   r   4   s   úÿr   c                   @   s‚   e Zd ZdZdee deddfdd„Zdee defd	d
„Zdee de	fdd„Z
dee deddfdd„Zdeddf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.
    Ú
sumMatcherÚzeror   Nc                 C   s   || _ || _d S ©N)r+   r,   )r   r+   r,   r   r   r   Ú__init__T   s   
zHasSum.__init__Úsequencec                 C   s&   |s| j S | j }|D ]}|| }q
|S r-   )r,   )r   r/   ÚresultÚelemr   r   r   Ú_sumX   s   
zHasSum._sumÚitemc                 C   s   |   |¡}| j |¡S )zG
        Determine whether the sum of the sequence is matched.
        N)r2   r+   Úmatches)r   r3   Úsr   r   r   Ú_matches`   s   
zHasSum._matchesÚdescriptionc                 C   s&   |   |¡}| | ¡ | j ||¡ dS )ú(
        Describe the mismatch.
        N)r2   Úappend_description_ofr+   Údescribe_mismatch)r   r3   r7   r5   r   r   r   r:   g   s   

zHasSum.describe_mismatchc                 C   ó$   |  d¡ | | j¡ |  d¡ dS )ú;
        Describe this matcher for error messages.
        za sequence with sum ú, N)Úappend_textr9   r+   ©r   r7   r   r   r   Údescribe_top   ó   
zHasSum.describe_to)r   r   r    r!   r   r"   r.   r   r2   Úboolr6   r   r:   r@   r   r   r   r   r   K   s    	r   c                   @   sh   e Zd ZdZdee ddfdd„Zdee defdd	„Z	dee d
e
ddfdd„Zd
e
ddf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.
    ÚelementMatcherr   Nc                 C   s
   || _ d S r-   )rC   )r   rC   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.
        FTN)rC   r4   )r   r3   r1   r   r   r   r6   „   s
   ÿzIsSequenceOf._matchesr7   c                 C   sB   t |ƒD ]\}}| j |¡s| | ¡ | d|› d|›�¡ qdS )r8   znot sequence with element #ú N)Ú	enumeraterC   r4   r9   r>   )r   r3   r7   Úidxr1   r   r   r   r:   �   s   
€ýzIsSequenceOf.describe_mismatchc                 C   r;   )r<   za sequence containing only r=   N)r>   r9   rC   r?   r   r   r   r@   –   rA   zIsSequenceOf.describe_to)r   r   r    r!   r   r   r.   r   rB   r6   r   r:   r@   r   r   r   r   r   y   s    		r   Ú
propertiesc                  K   s   t ttƒtdi | ¤ŽƒS )zC
    Match an instance of L{Failure} with matching attributes.
    Nr   )r   r   r   r   )rG   r   r   r   Ú	isFailureŸ   s   þrH   ÚfunctionNameÚfileNamec                 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   N)r
   r   r   r   Úintr   )rI   rJ   r   r   r   ÚsimilarFrame©   s   ùrL   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   ÚobjectrH   ÚstrrK   rL   r   r   r   r   Ú<module>   sX    úÿþýüûú
ù.&
ÿÿ þ