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 