U
    òÀMf<  ã                   @   s  d dl mZ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ZdZdZed	ed
ZedƒZG dd„ de	eeef  ƒZeeee ef eeeef  dœdd„ƒZeeeeee ef f eeeef  dœdd„ƒZeeeeeef  dœdd„ƒZdd„ ZdS )é    )ÚAnyÚHashableÚMappingÚOptionalÚTypeVarÚUnionÚoverload)ÚBaseMatcher)ÚDescription)Úwrap_matcher)ÚMatcherzJon ReidzCopyright 2011 hamcrest.orgzBSD, see License.txtÚK)ÚboundÚVc                   @   s–   e Zd Zddœdd„Zeeef ee e	dœdd„Z
deeef ee e	dœdd	„Zeeef eddœd
d„Zeeeddœdd„Zeddœdd„ZdS )ÚIsDictContainingEntriesN)Úreturnc                 C   s   t | ¡ ƒ| _d S ©N)ÚsortedÚitemsÚvalue_matchers)Úselfr   © r   úX/tmp/pip-unpacked-wheel-97nlcpo6/hamcrest/library/collection/isdict_containingentries.pyÚ__init__   s    z IsDictContainingEntries.__init__)ÚitemÚmismatch_descriptionr   c                 C   s   |r|  |¡ d¡ dS )Nz is not a mapping objectF©Úappend_description_ofÚappend_text©r   r   r   r   r   r   Ú_not_a_dictionary   s    z)IsDictContainingEntries._not_a_dictionaryc              	   C   sÖ   | j D ]Ê\}}z4||kr@|r8| d¡ |¡ d¡ |¡ W  dS W n$ tk
rf   |  ||¡ Y   S X z|| }W n$ tk
r˜   |  ||¡ Y   S X | |¡s|rÊ| d¡ |¡ d¡ | ||¡  dS qdS )Nzno z key in Fz
value for ú T)r   r   r   Ú	TypeErrorr    ÚmatchesÚdescribe_mismatch)r   r   r   ÚkeyZvalue_matcherZactual_valuer   r   r   r#      s8    
ÿþþ

ÿþzIsDictContainingEntries.matchesc                 C   s   |   ||¡ d S r   )r#   r   r   r   r   r$   9   s    z)IsDictContainingEntries.describe_mismatch)ÚindexÚvalueÚdescriptionr   c                 C   s   |  |¡ d¡  |¡ dS )z(Describes key-value pair at given index.z: Nr   )r   r&   r'   r(   r   r   r   Údescribe_keyvalue<   s    z)IsDictContainingEntries.describe_keyvalue)r(   r   c                 C   sL   |  d¡ d}| jD ](\}}|s*|  d¡ |  |||¡ d}q|  d¡ d S )Nza dictionary containing {Tz, FÚ})r   r   r)   )r   r(   Úfirstr%   r'   r   r   r   Údescribe_to@   s    

z#IsDictContainingEntries.describe_to)N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r
   Úboolr    r#   r$   Úintr)   r,   r   r   r   r   r      s   
 þ ÿ
 þr   )Úkeys_valuematchersr   c                  K   s   d S r   r   ©r2   r   r   r   Úhas_entriesL   s    r4   c                 C   s   d S r   r   r3   r   r   r   r4   R   s    c                  G   s   d S r   r   r3   r   r   r   r4   X   s    c                  O   sÎ   t | ƒdkrVz*| d  ¡ }|D ]}t|| ƒ||< qW q¨ tk
rR   tdƒ‚Y q¨X nRt | ƒd rjtdƒ‚i }ttt | ƒd ƒƒD ]$}t| d| d  ƒ|| d|  < q‚| ¡ D ]\}}t|ƒ||< q°t|ƒS )a%  Matches if dictionary contains entries satisfying a dictionary of keys
    and corresponding value matchers.

    :param matcher_dict: A dictionary mapping keys to associated value matchers,
        or to expected values for
        :py:func:`~hamcrest.core.core.isequal.equal_to` matching.

    Note that the keys must be actual keys, not matchers. Any value argument
    that is not a matcher is implicitly wrapped in an
    :py:func:`~hamcrest.core.core.isequal.equal_to` matcher to check for
    equality.

    Examples::

        has_entries({'foo':equal_to(1), 'bar':equal_to(2)})
        has_entries({'foo':1, 'bar':2})

    ``has_entries`` also accepts a list of keyword arguments:

    .. function:: has_entries(keyword1=value_matcher1[, keyword2=value_matcher2[, ...]])

    :param keyword1: A keyword to look up.
    :param valueMatcher1: The matcher to satisfy for the value, or an expected
        value for :py:func:`~hamcrest.core.core.isequal.equal_to` matching.

    Examples::

        has_entries(foo=equal_to(1), bar=equal_to(2))
        has_entries(foo=1, bar=2)

    Finally, ``has_entries`` also accepts a list of alternating keys and their
    value matchers:

    .. function:: has_entries(key1, value_matcher1[, ...])

    :param key1: A key (not a matcher) to look up.
    :param valueMatcher1: The matcher to satisfy for the value, or an expected
        value for :py:func:`~hamcrest.core.core.isequal.equal_to` matching.

    Examples::

        has_entries('foo', equal_to(1), 'bar', equal_to(2))
        has_entries('foo', 1, 'bar', 2)

    é   r   zEsingle-argument calls to has_entries must pass a dict as the argumenté   z$has_entries requires key-value pairs)	ÚlenÚcopyr   ÚAttributeErrorÚ
ValueErrorÚranger1   r   r   )r2   Zkv_argsZ	base_dictr%   r&   r'   r   r   r   r4   ]   s&    .ÿÿN)Útypingr   r   r   r   r   r   r   Zhamcrest.core.base_matcherr	   Zhamcrest.core.descriptionr
   Z"hamcrest.core.helpers.wrap_matcherr   Zhamcrest.core.matcherr   Ú
__author__Ú__copyright__Ú__license__r   r   r   Ústrr4   r   r   r   r   Ú<module>   s"   $<*2