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rt 	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,    *+"$,