o
    (]^<  ã                   @   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deee ef deeeef  fdd„ƒZedeeeee ef f deeeef  fdd„ƒZededeeeef  f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„Zdeeef dee de	fdd„Z
	ddeeef dee de	fd	d
„Zdeeef deddfdd„Zdedededdfdd„Zdeddfdd„ZdS )ÚIsDictContainingEntriesÚreturnNc                 C   s   t | ¡ ƒ| _d S ©N)ÚsortedÚitemsÚvalue_matchers)Úselfr   © r   úV/usr/lib/python3/dist-packages/hamcrest/library/collection/isdict_containingentries.pyÚ__init__   s   z IsDictContainingEntries.__init__ÚitemÚmismatch_descriptionc                 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 ]c\}}z||vr |r| d¡ |¡ d¡ |¡ W  dS W n ty2   |  ||¡ Y   S w z|| }W n tyJ   |  ||¡ Y   S w | |¡sf|rc| 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   ÚkeyÚvalue_matcherÚ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Údescriptionc                 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_keyvaluec                 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)r   Nr   )Ú__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   ó   d S r   r   ©r4   r   r   r   Úhas_entriesL   ó   r7   c                 C   r5   r   r   r6   r   r   r   r7   R   r8   c                  G   r5   r   r   r6   r   r   r   r7   X   r8   c                  O   sÆ   t | ƒdkr'z| d  ¡ }|D ]
}t|| ƒ||< qW n4 ty&   tdƒ‚w t | ƒd r1tdƒ‚i }ttt | ƒd ƒƒD ]}t| d| d  ƒ|| d|  < q=| ¡ D ]
\}}t|ƒ||< qTt|ƒ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Úranger3   r   r   )r4   Úkv_argsÚ	base_dictr%   r(   r)   r   r   r   r7   ]   s*   .ÿÿÿÿN)Útypingr   r   r   r   r   r   r   Úhamcrest.core.base_matcherr	   Úhamcrest.core.descriptionr
   Ú"hamcrest.core.helpers.wrap_matcherr   Úhamcrest.core.matcherr   Ú
__author__Ú__copyright__Ú__license__r   r   r   Ústrr7   r   r   r   r   Ú<module>   s$   $ <,4 