U
    ôbÛVÓ  ã                   @   sP   d dl Z d dlmZ d dlmZ dZdZdZdd„ ZG d	d
„ d
eƒZ	dd„ Z
dS )é    N)ÚBaseMatcher)ÚfabszJon ReidzCopyright 2011 hamcrest.orgzBSD, see License.txtc                 C   sZ   t | ttftj ƒrdS zt| ƒd d d }W dS  tk
rH   Y dS    Y dS X dS )zKConfirm that 'value' can be treated numerically; duck-test accordingly
    Tr   é   F)Ú
isinstanceÚfloatÚcomplexÚsixZinteger_typesr   ÚArithmeticError)ÚvalueÚ_© r   úC/usr/lib/python3/dist-packages/hamcrest/library/number/iscloseto.pyÚ	isnumeric
   s    r   c                       s4   e Zd Zdd„ Zdd„ Z‡ fdd„Zdd„ Z‡  ZS )	Ú	IsCloseToc                 C   s0   t |ƒstdƒ‚t |ƒs tdƒ‚|| _|| _d S )NzIsCloseTo value must be numericzIsCloseTo delta must be numeric)r   Ú	TypeErrorr
   Údelta)Úselfr
   r   r   r   r   Ú__init__   s    zIsCloseTo.__init__c                 C   s    t |ƒsdS t|| j ƒ| jkS )NF)r   r   r
   r   )r   Úitemr   r   r   Ú_matches%   s    zIsCloseTo._matchesc                    sD   t |ƒstt| ƒ ||¡ n$t|| j ƒ}| |¡ d¡ |¡ d S )Nz differed by )r   Úsuperr   Údescribe_mismatchr   r
   Úappend_description_ofÚappend_text)r   r   Zmismatch_descriptionZactual_delta©Ú	__class__r   r   r   *   s    
ÿþzIsCloseTo.describe_mismatchc                 C   s$   |  d¡ | j¡  d¡ | j¡ d S )Nza numeric value within z of )r   r   r   r
   )r   Zdescriptionr   r   r   Údescribe_to3   s    
ÿþýzIsCloseTo.describe_to)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   Ú__classcell__r   r   r   r   r      s   		r   c                 C   s
   t | |ƒS )a²  Matches if object is a number close to a given value, within a given
    delta.

    :param value: The value to compare against as the expected value.
    :param delta: The maximum delta between the values for which the numbers
        are considered close.

    This matcher compares the evaluated object against ``value`` to see if the
    difference is within a positive ``delta``.

    Example::

        close_to(3.0, 0.25)

    )r   )r
   r   r   r   r   Úclose_to:   s    r!   )r   Zhamcrest.core.base_matcherr   Zmathr   Ú
__author__Z__copyright__Z__license__r   r   r!   r   r   r   r   Ú<module>   s    