U
    bVl                     @   sz   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G d
d deZdddZdd ZdS )    )BaseMatcher)anything)all_of)StringDescription)	hasmethod)wrap_matcherz
Chris RosezCopyright 2011 hamcrest.orgzBSD, see License.txtc                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )IsObjectWithPropertyc                 C   s   || _ || _d S N)property_namevalue_matcher)selfr
   r    r   E/usr/lib/python3/dist-packages/hamcrest/library/object/hasproperty.py__init__   s    zIsObjectWithProperty.__init__c                 C   s4   |d krdS t || jsdS t|| j}| j|S )NF)hasattrr
   getattrr   Zmatches)r   ovaluer   r   r   _matches   s    zIsObjectWithProperty._matchesc                 C   s$   | d | j d| j d S )Nzan object with a property 'z' matching )append_textr
   Zappend_description_ofr   )r   Zdescriptionr   r   r   describe_to   s    
z IsObjectWithProperty.describe_toc                 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
   Zappend_valuer   r   describe_mismatch)r   itemZmismatch_descriptionr   r   r   r   r   #   s    

z&IsObjectWithProperty.describe_mismatchc                 C   s   t  }| | t|S r	   )r   r   str)r   dr   r   r   __str__3   s    
zIsObjectWithProperty.__str__N)__name__
__module____qualname__r   r   r   r   r   r   r   r   r   r      s
   
r   Nc                 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)namematchr   r   r   has_property9   s    r#   c                  O   s   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d | 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 pairsc                 S   s   g | ]\}}t ||qS r   )r#   ).0r
   Zproperty_value_matcherr   r   r   
<listcomp>   s   z"has_properties.<locals>.<listcomp>)	lencopyr    AttributeError
ValueErrorrangeintitemsr   )Zkeys_valuematchersZkv_argsZ	base_dictkeyindexr   r   r   r   has_propertiesZ   s"    ."r1   )N)Zhamcrest.core.base_matcherr   Zhamcrest.corer   Zhamcrest.core.core.allofr   Z hamcrest.core.string_descriptionr   Zhamcrest.core.helpers.hasmethodr   Z"hamcrest.core.helpers.wrap_matcherr   r    
__author__Z__copyright__Z__license__r   r#   r1   r   r   r   r   <module>   s   ,
!