o
    (]^ò  ã                   @   sH  d dl 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 d dlmZ d d	lmZ d
ZdZdZedƒZG dd„ dee ƒZddededee ef dee fdd„Zedeee ef dee fdd„ƒZedeeeee ef f dee fdd„ƒZededee fdd„ƒZdd„ ZdS )é    )ÚAnyÚMappingÚTypeVarÚUnionÚoverload)Údescribed_as)Úanything)ÚBaseMatcher)ÚAllOf)ÚDescription)Úwrap_matcher)ÚMatcher)ÚStringDescriptionz
Chris RosezCopyright 2011 hamcrest.orgzBSD, see License.txtÚVc                   @   sh   e Zd Zdedee ddfdd„Zdedefdd	„Z	d
e
ddfdd„Zdede
ddfdd„Zdd„ ZdS )ÚIsObjectWithPropertyÚproperty_nameÚvalue_matcherÚreturnNc                 C   s   || _ || _d S ©N)r   r   )Úselfr   r   © r   úE/usr/lib/python3/dist-packages/hamcrest/library/object/hasproperty.pyÚ__init__   s   
zIsObjectWithProperty.__init__Úitemc                 C   s4   |d u rdS t || jƒsdS t|| jƒ}| j |¡S )NF)Úhasattrr   Úgetattrr   Úmatches)r   r   Úvaluer   r   r   Ú_matches   s   zIsObjectWithProperty._matchesÚdescriptionc                 C   s$   |  d¡  | j¡  d¡ | j¡ d S )Nzan object with a property 'z' matching )Úappend_textr   Úappend_description_ofr   )r   r   r   r   r   Údescribe_to"   s   
ÿz IsObjectWithProperty.describe_toÚmismatch_descriptionc                 C   sz   |d u r|  d¡ d S t|| jƒs"| |¡  d¡ | j¡  d¡ d S |  d¡ | j¡  d¡ t|| jƒ}| j ||¡ d S )Nzwas Nonez did not have the z	 propertyz	property ú )r    r   r   r!   r   r   Údescribe_mismatch)r   r   r#   r   r   r   r   r%   '   s   

ÿ
ÿz&IsObjectWithProperty.describe_mismatchc                 C   s   t ƒ }|  |¡ t|ƒS r   )r   r"   Ústr)r   Údr   r   r   Ú__str__8   s   
zIsObjectWithProperty.__str__)Ú__name__Ú
__module__Ú__qualname__r&   r   r   r   ÚobjectÚboolr   r   r"   r%   r(   r   r   r   r   r      s    
r   NÚnameÚmatchr   c                 C   s   |du rt ƒ }t| t|ƒƒS )a�  Matches if object has a property with a given name whose value satisfies
    a given matcher.

    :param name: The name of the property.
    :param match: Optional matcher to satisfy.

    This matcher determines if the evaluated object has a property with a given
    name. If no such property is found, ``has_property`` is not satisfied.

    If the property is found, its value is passed to a given matcher for
    evaluation. If the ``match`` argument is not a matcher, it is implicitly
    wrapped in an :py:func:`~hamcrest.core.core.isequal.equal_to` matcher to
    check for equality.

    If the ``match`` argument is not provided, the
    :py:func:`~hamcrest.core.core.isanything.anything` matcher is used so that
    ``has_property`` is satisfied if a matching property is found.

    Examples::

        has_property('name', starts_with('J'))
        has_property('name', 'Jon')
        has_property('name')

    N)r   r   Úwrap_shortcut)r.   r/   r   r   r   Úhas_property>   s   r1   Úkeys_valuematchersc                  K   ó   d S r   r   ©r2   r   r   r   Úhas_properties`   ó   r5   c                 C   r3   r   r   r4   r   r   r   r5   f   r6   c                  G   r3   r   r   r4   r   r   r   r5   l   r6   c            
      O   sf  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 |ƒdkr¨tƒ  	d¡}t
t| ¡ ƒƒD ]\}\}}	| |¡ 	d¡ |	¡ |t |ƒd k r‘| 	d¡ qstt|ƒtd	d
„ t| ¡ ƒD ƒdddœŽƒS | ¡ \}}	t||	ƒS )aX  Matches if an object has properties satisfying all of a dictionary
    of string property names 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_properties({'foo':equal_to(1), 'bar':equal_to(2)})
        has_properties({'foo':1, 'bar':2})

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

    .. function:: has_properties(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_properties(foo=equal_to(1), bar=equal_to(2))
        has_properties(foo=1, bar=2)

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

    .. function:: has_properties(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_properties('foo', equal_to(1), 'bar', equal_to(2))
        has_properties('foo', 1, 'bar', 2)

    é   r   zHsingle-argument calls to has_properties must pass a dict as the argumenté   z'has_properties requires key-value pairszan object with properties z
 matching z and c                 S   s   g | ]	\}}t ||ƒ‘qS r   )r1   )Ú.0r   Úproperty_value_matcherr   r   r   Ú
<listcomp>À   s    ÿÿz"has_properties.<locals>.<listcomp>TF)Údescribe_all_mismatchesÚdescribe_matcher_in_mismatch)ÚlenÚcopyr0   ÚAttributeErrorÚ
ValueErrorÚrangeÚintÚitemsr   r    Ú	enumerateÚsortedr!   r   r&   r
   Úpopitemr1   )
r2   Úkv_argsÚ	base_dictÚkeyÚindexr   r   Úir   r:   r   r   r   r5   q   sT   .ÿÿÿÿ
ÿ
€
þúþ
r   ) Útypingr   r   r   r   r   Úhamcrestr   Úhamcrest.corer   Úhamcrest.core.base_matcherr	   Úhamcrest.core.core.allofr
   Úhamcrest.core.descriptionr   Ú"hamcrest.core.helpers.wrap_matcherr   r0   Úhamcrest.core.matcherr   Ú hamcrest.core.string_descriptionr   Ú
__author__Ú__copyright__Ú__license__r   r,   r   r&   r1   r5   r   r   r   r   Ú<module>   s,    *+"$,