U
    Mf                     @   s>  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eedee ef ee dddZeeee ef ee dddZeeeeee ef f ee dddZeeee d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                   @   s\   e Zd Zeee ddddZeedddZ	e
ddd	d
Zee
ddddZdd ZdS )IsObjectWithPropertyN)property_namevalue_matcherreturnc                 C   s   || _ || _d S N)r   r   )selfr   r    r   G/tmp/pip-unpacked-wheel-97nlcpo6/hamcrest/library/object/hasproperty.py__init__   s    zIsObjectWithProperty.__init__)itemr   c                 C   s4   |d k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)descriptionr   c                 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)r   mismatch_descriptionr   c                 C   sz   |d kr| d d S t|| jsD|| 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k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_valuematchersr   c                  K   s   d S r   r   r2   r   r   r   has_properties`   s    r4   c                 C   s   d S r   r   r3   r   r   r   r4   f   s    c                  G   s   d S r   r   r3   r   r   r   r4   l   s    c            
      O   st  t | dkrVz*| d  }|D ]}t|| ||< qW q tk
rR   tdY qX nRt | d rjtdi }ttt | d D ]$}t| d| d  || d|  < q| D ]\}}t|||< qt |dkrZt 	d}t
t| D ]<\}\}}	||	d|	 |t |d k r|	d qtt|td	d
 t| D dddS | \}}	t||	S d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)Zdescribe_all_mismatchesZdescribe_matcher_in_mismatchN)lencopyr0   AttributeError
ValueErrorrangeintitemsr   r    	enumeratesortedr!   r   r&   r
   popitemr1   )
r2   Zkv_argsZ	base_dictkeyindexr   r   ir   r8   r   r   r   r4   q   sP    .

)N) typingr   r   r   r   r   Zhamcrestr   Zhamcrest.corer   Zhamcrest.core.base_matcherr	   Zhamcrest.core.core.allofr
   Zhamcrest.core.descriptionr   Z"hamcrest.core.helpers.wrap_matcherr   r0   Zhamcrest.core.matcherr   Z hamcrest.core.string_descriptionr   
__author____copyright____license__r   r,   r   r&   r1   r4   r   r   r   r   <module>   s*   +&""*