U
    ôbÛV0  ã                   @   sL   d dl mZ d dlmZ d dlmZ dZdZdZG dd„ deƒZ	d	d
„ Z
dS )é    )ÚBaseMatcher)Ú	hasmethod)Úwrap_matcherzJon ReidzCopyright 2011 hamcrest.orgzBSD, see License.txtc                   @   s>   e Zd Zdd„ Zdd„ Zddd„Zdd	„ Zd
d„ Zdd„ ZdS )ÚIsDictContainingEntriesc                 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__c                 C   s   |r|  |¡ d¡ dS )Nz is not a mapping objectF©Úappend_description_ofÚappend_text)r
   Ú
dictionaryÚmismatch_descriptionr   r   r   Ú_not_a_dictionary   s
    
ÿz)IsDictContainingEntries._not_a_dictionaryNc              	   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
   Úitemr   r   r   r   r   2   s    z)IsDictContainingEntries.describe_mismatchc                 C   s   |  |¡ d¡  |¡ dS )z(Describes key-value pair at given index.z: Nr   )r
   ÚindexÚvalueÚdescriptionr   r   r   Údescribe_keyvalue5   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)N)	Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r    r   r   r   r   r   
   s   
r   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ÚrangeÚintr   r   )Zkeys_valuematchersZkv_argsZ	base_dictr   r   r   r   r   r   Úhas_entriesF   s    ."r,   N)Zhamcrest.core.base_matcherr   Zhamcrest.core.helpers.hasmethodr   Z"hamcrest.core.helpers.wrap_matcherr   Ú
__author__Z__copyright__Z__license__r   r,   r   r   r   r   Ú<module>   s   <