
    F-Phjx                    p   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	Z	d dl
mZ d dlZd dlZd d	lmZ d d
lmZ erd dlmZ d1dZ G d d          Zd Z G d de          Z G d d e          Z G d! d"e          Z G d# d$e          Z G d% d&e          Zd2d3d*Zd4d,Zd5d.Zd6d0ZdS )7    )annotations)
Collection)Mapping)Sequence)Sized)DecimalN)Complex)Any)TYPE_CHECKING)ndarrayfull_objectobjectmessage_dataSequence[tuple[str, str, str]]number_of_elementsintdifferent_idsSequence[object]max_abs_difffloatmax_rel_diffreturn	list[str]c                   t          |          }|                    dd           g d|D ]x\  }}}	t          d         t          |                    d<   t          d         t          |                    d<   t          d         t          |	                    d<   ydt          |           d| dd	| d
| gfd|D             z   }
|
S )Nr   )IndexObtainedExpected)r   r   r         z(comparison failed. Mismatched elements: z / :zMax absolute difference: zMax relative difference: c           
     h    g | ].\  }}}|d d          d|d d          d|d d          /S )<r   z | r   r    ).0indexesobtainedexpected	max_sizess       R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/_pytest/python_api.py
<listcomp>z#_compare_approx.<locals>.<listcomp>(   ss     	 	 	'GXx ^Yq\^^^^x^)A,^^^^H^yYZ|^^^^	 	 	    )listinsertmaxlen)r   r   r   r   r   r   message_listindexr&   r'   explanationr(   s              @r)   _compare_approxr3      s    %%L<===		I%1 8 8!x9Q<U44	!9Q<X77	!9Q<X77	!_3}3E3E__J\___2L222L22	 	 	 	+7	 	 		K r+   c                  d    e Zd ZdZdZdZddd	ZddZddZddZ	d Z
dZddZddZd ZddZdS )
ApproxBasezhProvide shared utilities for making approximate comparisons between
    numbers or sequences of numbers.Nd   Fnan_okboolr   Nonec                j    d}|| _         || _        || _        || _        |                                  d S )NT)r'   absrelr7   _check_type)selfr'   r<   r;   r7   __tracebackhide__s         r)   __init__zApproxBase.__init__:   s<      r+   strc                    t           NNotImplementedErrorr>   s    r)   __repr__zApproxBase.__repr__B   s    !!r+   
other_sider
   r   c                    dd| d|  gS )Nzcomparison failedz
Obtained: z
Expected: r#   )r>   rH   s     r)   _repr_comparezApproxBase._repr_compareE   s%    %%%
 	
r+   c                `     t           fd                     |          D                       S )Nc              3  P   K   | ] \  }}|                     |          k    V  !d S rC   _approx_scalar)r$   axr>   s      r)   	<genexpr>z$ApproxBase.__eq__.<locals>.<genexpr>M   sK       
 
,0AqA$$Q'''
 
 
 
 
 
r+   )all_yield_comparisonsr>   actuals   ` r)   __eq__zApproxBase.__eq__L   sI     
 
 
 
484K4KF4S4S
 
 
 
 
 	
r+   c                $    d}t          d          )NTzVapprox() is not supported in a boolean context.
Did you mean: `assert a == approx(b)`?)AssertionError)r>   r?   s     r)   __bool__zApproxBase.__bool__Q   s     e
 
 	
r+   c                    || k     S rC   r#   rT   s     r)   __ne__zApproxBase.__ne__Z   s    dN##r+   ApproxScalarc                    t          |t                    r"t          || j        | j        | j                  S t          || j        | j        | j                  S )N)r<   r;   r7   )
isinstancer   ApproxDecimalr<   r;   r7   r\   )r>   rP   s     r)   rN   zApproxBase._approx_scalar]   sO    a!! 	T dht{SSSSA48$+NNNNr+   c                    t           )zoYield all the pairs of numbers to be compared.

        This is used to implement the `__eq__` method.
        rD   rT   s     r)   rS   zApproxBase._yield_comparisonsb   s
    
 "!r+   c                    dS )z<Raise a TypeError if the expected value is not a valid type.Nr#   rF   s    r)   r=   zApproxBase._check_typei   s      r+   NNF)r7   r8   r   r9   r   rA   )rH   r
   r   r   r   r8   )r   r\   r   r9   )__name__
__module____qualname____doc____array_ufunc____array_priority__r@   rG   rJ   rV   rY   __hash__r[   rN   rS   r=   r#   r+   r)   r5   r5   2   s        ( ( O    " " " "
 
 
 

 
 
 


 
 
 H$ $ $ $O O O O
" " "K K K K K Kr+   r5   c                     t          |t          t          f          r&t          |          } | fd|D                       S t	          |          r fd|D             S   |          S )z=Recursively map a function over a sequence of arbitrary depthc              3  8   K   | ]}t          |          V  d S rC   _recursive_sequence_mapr$   xifs     r)   rQ   z*_recursive_sequence_map.<locals>.<genexpr>v   s.      CC2/266CCCCCCr+   c                0    g | ]}t          |          S r#   ro   rq   s     r)   r*   z+_recursive_sequence_map.<locals>.<listcomp>x   s$    ;;;2'2..;;;r+   )r^   r,   tupletype_is_sequence_like)rs   rP   seq_types   `  r)   rp   rp   r   s    !dE]## 77xCCCCCCCCCC	1		 ;;;;;;;;qttr+   c                  :     e Zd ZdZddZddZd fd
Zd Z xZS )ApproxNumpyzHPerform approximate comparisons where the expected value is numpy array.r   rA   c                f    t          | j        | j                                                  }d|dS )Napprox())rp   rN   r'   tolist)r>   list_scalarss     r)   rG   zApproxNumpy.__repr__   s:    .!5!5!7!7
 
 +****r+   rH   ndarray | list[Any]r   c                   dd l }dd l}dd| j        j        }t	          | j        | j                                                  t          |          J |j        k    rd	d
| dj         gS | j        j        }|j	         }|j	         }g } |j
        d |D              D ]}	 |	          }
 |	          }|
|k    rjt          |
j        |z
            }t          ||          }|dk    r|j	        }n t          ||t          |          z            }|                    |	           fd|D             }t          | j        |||||          S )Nr   nested_list	list[Any]nd_indextuple[Any, ...]r   r
   c                $    | }|D ]
}||         }|S )z
            Helper function to get the value out of a nested list, given an n-dimensional index.
            This mimics numpy's indexing, but for raw nested python lists.
            r#   )r   r   valueis       r)   get_value_from_nested_listz=ApproxNumpy._repr_compare.<locals>.get_value_from_nested_list   s(     %E ! !aLr+   z3Impossible to compare arrays with different shapes.zShapes:  and c              3  4   K   | ]}t          |          V  d S rC   )range)r$   r   s     r)   rQ   z,ApproxNumpy._repr_compare.<locals>.<genexpr>   s(      (J(Jaq(J(J(J(J(J(Jr+           c           
         g | ]B}t          |          t           |                    t           |                    fCS r#   rA   )r$   r1   approx_side_as_seqr   other_side_as_arrays     r)   r*   z-ApproxNumpy._repr_compare.<locals>.<listcomp>   sj     
 
 
 	 E

../BEJJKK../A5IIJJ
 
 
r+   )r   r   r   r   r   r
   )	itertoolsmathr'   shaperp   rN   r~   _as_numpy_arraysizeinfproductr;   r.   appendr3   )r>   rH   r   r   np_array_shaper   r   r   r   r1   approx_valueother_valueabs_diffr   r   r   r   s                 @@@r)   rJ   zApproxNumpy._repr_compare   s   
	 
	 
	 
	 ,4!5!5!7!7
 

 .j99"...0666EK>KK0C0IKK 
 "]/yy&Y&(J(J>(J(J(JK 
	, 
	,E556H%PPL445H%PPK{**|4{BCC"<::#%%#'8LL#&|XK@P@P5P#Q#QL$$U+++
 
 
 
 
 
 '
 
 
 M
 
 	
r+   r8   c                J   dd l }|                    |          s=	 |                    |          }n&# t          $ r}t	          d| d          |d }~ww xY w|                    |          s|j        | j        j        k    rdS t                                          |          S )Nr   zcannot compare 'z' to numpy.ndarrayF)	numpyisscalarasarray	Exception	TypeErrorr   r'   superrV   )r>   rU   npe	__class__s       r)   rV   zApproxNumpy.__eq__   s     {{6"" 	VVF++ V V V M6 M M MNNTUUV {{6"" 	v|t}7J'J'J5ww~~f%%%s   2 
AAAc              #    K   dd l }|                    |          rG|                    | j        j                  D ]%}|| j        |                                         fV  &d S |                    | j        j                  D ]=}||                                         | j        |                                         fV  >d S )Nr   )r   r   ndindexr'   r   item)r>   rU   r   r   s       r)   rS   zApproxNumpy._yield_comparisons   s       ;;v 	@ZZ 344 6 6dmA.3355555556 6 ZZ 344 @ @Qinn&&a(8(=(=(?(??????@ @r+   rc   )rH   r   r   r   rd   )	rf   rg   rh   ri   rG   rJ   rV   rS   __classcell__r   s   @r)   rz   rz   }   s        RR+ + + +>
 >
 >
 >
@& & & & & & @ @ @ @ @ @ @r+   rz   c                  B     e Zd ZdZddZddZd fd
Zd ZddZ xZ	S )ApproxMappingzyPerform approximate comparisons where the expected value is a mapping
    with numeric values (the keys can be anything).r   rA   c                V     d fd j                                         D             dS )Nr|   c                B    i | ]\  }}|                     |          S r#   rM   r$   kvr>   s      r)   
<dictcomp>z*ApproxMapping.__repr__.<locals>.<dictcomp>   s-    XXX$!QAt22155XXXr+   r}   )r'   itemsrF   s   `r)   rG   zApproxMapping.__repr__   s7    ^XXXX$-BUBUBWBWXXX^^^^r+   rH   Mapping[object, float]r   c                    dd l } fd j                                        D             t                    }|j         }|j         }g }t                                                                                    D ]\  \  }}}	||	k    r|j        y|	w	 t          |t          |j        |	z
                      }|j        dk    r|j        }n-t          |t          |j        |	z
  |j        z                      }n# t          $ r Y nw xY w|
                    |           fd|D             }
t           j        |
||||          S )Nr   c                B    i | ]\  }}|                     |          S r#   rM   r   s      r)   r   z/ApproxMapping._repr_compare.<locals>.<dictcomp>   s:     
 
 
*.!QAt""1%%
 
 
r+   r   c                    g | ]:}t          |          t          |                   t          |                   f;S r#   r   )r$   keyapprox_side_as_maprH   s     r)   r*   z/ApproxMapping._repr_compare.<locals>.<listcomp>  sP     
 
 
 XXs:c?++S1CC1H-I-IJ
 
 
r+   )r   r'   r   r/   r   zipvaluesr.   r;   ZeroDivisionErrorr   r3   )r>   rH   r   r   r   r   r   
approx_keyr   r   r   r   s   ``         @r)   rJ   zApproxMapping._repr_compare   s   
 
 
 
26-2E2E2G2G
 
 
 !!344yy7:$$&&
(9(9(;(;8
 8
 	1 	13&Z {**(49P'*(#l.Ck.Q*R*R( ( (0C77+/8LL+. , #%1%:[%H&2&;%<!" !", ,L -   $$Z000
 
 
 
 
$
 
 

 M
 
 	
s   A%D  
DDr8   c                   	 t          |                                          t          | j                                                  k    rdS n# t          $ r Y dS w xY wt	                                          |          S NF)setkeysr'   AttributeErrorr   rV   r>   rU   r   s     r)   rV   zApproxMapping.__eq__  s}    	6;;==!!S););)=)=%>%>>>u ? 	 	 	55	 ww~~f%%%s   A	A 
AAc              #  p   K   | j                                         D ]}||         | j         |         fV  d S rC   )r'   r   )r>   rU   r   s      r)   rS   z ApproxMapping._yield_comparisons%  sL      ##%% 	. 	.A)T]1------	. 	.r+   r9   c           
        d}| j                                         D ]d\  }}t          |t          | j                             r=d}t	          |                    ||t          j        | j                                       ed S )NTz[pytest.approx() does not support nested dictionaries: key={!r} value={!r}
  full mapping={})r'   r   r^   rv   r   formatpprintpformat)r>   r?   r   r   msgs        r)   r=   zApproxMapping._check_type)  s     ---// 	W 	WJC%dm!4!455 Wt

3v~dm7T7T U UVVVW	W 	Wr+   rc   )rH   r   r   r   rd   re   
rf   rg   rh   ri   rG   rJ   rV   rS   r=   r   r   s   @r)   r   r      s        7 7_ _ _ _.
 .
 .
 .
`& & & & & &. . .W W W W W W W Wr+   r   c                  B     e Zd ZdZddZddZd fd
Zd ZddZ xZ	S )ApproxSequenceLikezRPerform approximate comparisons where the expected value is a sequence of numbers.r   rA   c                     t           j                  }|t          t          fvrt          }d | fd j        D                       dS )Nr|   c              3  B   K   | ]}                     |          V  d S rC   rM   )r$   rP   r>   s     r)   rQ   z.ApproxSequenceLike.__repr__.<locals>.<genexpr>8  s1      !P!PQ$"5"5a"8"8!P!P!P!P!P!Pr+   r}   )rv   r'   ru   r,   )r>   rx   s   ` r)   rG   zApproxSequenceLike.__repr__4  sX    &&E4=((HU!P!P!P!P$-!P!P!PPPUUUUr+   rH   Sequence[float]r   c                   dd l }t          | j                  t                    k    r)ddt          | j                   dt                     gS t          | j        | j                  t                    }|j         }|j         }g }t          t                              D ]\  }\  }}	||	k    r|	 t          |j        |	z
            }
t          ||
          }|	dk    r|j        }n1t          ||
t          |	          z            }n# t          $ r Y nw xY w|                    |           fd|D             }t          | j        |||||          S )Nr   z1Impossible to compare lists with different sizes.z	Lengths: r   r   c                    g | ]:}t          |          t          |                   t          |                   f;S r#   r   )r$   r   r   rH   s     r)   r*   z4ApproxSequenceLike._repr_compare.<locals>.<listcomp>Y  sP     
 
 
 VVSA''-?-B)C)CD
 
 
r+   )r   r/   r'   rp   rN   r   	enumerater   r;   r.   r   r   r3   )r>   rH   r   r   r   r   r   r   r   r   r   r   r   s    `          @r)   rJ   z ApproxSequenceLike._repr_compare:  s   t}Z00CFC..FFS__FF 
 5T5H$-XX !344yy.7"J///
 /
 	( 	(*A*k {**
V"<#8;#FGGH#&|X#>#>L
 #c))'+x'*<CDTDT9T'U'U !   D $$Q'''
 
 
 
 
"
 
 

 M
 
 	
s   <'D
DDr8   c                    	 t          |          t          | j                  k    rdS n# t          $ r Y dS w xY wt                                          |          S r   )r/   r'   r   r   rV   r   s     r)   rV   zApproxSequenceLike.__eq__g  se    	6{{c$-0000u 1 	 	 	55	ww~~f%%%s   %+ 
99c                ,    t          || j                  S rC   )r   r'   rT   s     r)   rS   z%ApproxSequenceLike._yield_comparisonso  s    64=)))r+   r9   c           
         d}t          | j                  D ]d\  }}t          |t          | j                            r=d}t	          |                    ||t          j        | j                                      ed S )NTz]pytest.approx() does not support nested data structures: {!r} at index {}
  full sequence: {})r   r'   r^   rv   r   r   r   r   )r>   r?   r1   rP   r   s        r)   r=   zApproxSequenceLike._check_typer  s     !$-00 	U 	UHE1!T$-0011 Uv

1eV^DM5R5R S STTTU	U 	Ur+   rc   )rH   r   r   r   rd   re   r   r   s   @r)   r   r   1  s        \\V V V V+
 +
 +
 +
Z& & & & & &* * *U U U U U U U Ur+   r   c                  Z    e Zd ZU dZdZded<   dZded<   dd	ZddZdZ	e
d             ZdS )r\   zLPerform approximate comparisons where the expected value is a single number.g-q=zfloat | DecimalDEFAULT_ABSOLUTE_TOLERANCEgư>DEFAULT_RELATIVE_TOLERANCEr   rA   c                8   t          | j        t                    sat          | j        t          t          f          r@t          j        t          | j                  pt          | j        t                              rt          | j                  S 	 d| j	        cxk    rdk     rn n
| j	        d}n	| j	        d}t          | j        t                    r*| j        j
        rt          j        | j	                  s|dz  }n# t          $ r d}Y nw xY w| j         d| S )u   Return a string communicating both the expected value and the
        tolerance for the comparison being made.

        For example, ``1.0 ± 1e-6``, ``(3+4j) ± 5e-6 ∠ ±180°``.
        gMbP?g     @@nz.1eu    ∠ ±180°z???u    ± )r^   r'   r8   r	   r   r   isinfr;   rA   	toleranceimag
ValueError)r>   vetted_tolerances     r)   rG   zApproxScalar.__repr__  sA    t}d++	&t}w.@AA	& z#dm,,O
4=$0O0OPP	&
 t}%%%	%t~+++++++++&*n#8#8  &*n#:#:  4='223M&3 
4>223
 !N2  	% 	% 	%$	% -77%5777s   A,C> >DDr8   c                    d
d}t          |          }| t           fd|j        D                       S  | j                  r ||          sdS | j        k    rd	S  | j                  s=t	           j        t
          t          f          rt	          |t
          t          f          sdS t          j        t           j                            r( j
        o t          j        t          |                    S t          j        t           j                            rdS t           j        |z
             j        k    }|S )ziReturn whether the given value is equal to the expected value
        within the pre-specified tolerance.valr
   r   r8   c                    t          | t                    rdS 	 dd l}t          | |j                  S # t          $ r Y dS w xY w)NTr   F)r^   r8   r   bool_ImportError)r   r   s     r)   is_boolz$ApproxScalar.__eq__.<locals>.is_bool  s^    #t$$ t""""!#rx000   uus   2 
A A Nc              3  B   K   | ]}                     |          V  d S rC   )rV   )r$   rO   r>   s     r)   rQ   z&ApproxScalar.__eq__.<locals>.<genexpr>  s-      <<!t{{1~~<<<<<<r+   FT)r   r
   r   r8   )r   rR   flatr'   r^   r	   r   r   isnanr;   r7   r   r   )r>   rU   r   r   results   `    r)   rV   zApproxScalar.__eq__  s\   		 		 		 		 "&)) <<<<w|<<<<<< 74=!! 	''&// 	5t}$$4 74=!! 	t}w&899	6GW#566	 5
 :c$-(()) 	;;:4:c&kk#:#:: :c$-(()) 	5 4=6122dnDr+   Nc                   d } || j         | j                  }|dk     rt          d|           t          j        |          rt          d          | j        	| j         |S  || j        | j                  t          | j                  z  }|dk     rt          d|           t          j        |          rt          d          t          ||          S )zReturn the tolerance for the comparison.

        This could be either an absolute tolerance or a relative tolerance,
        depending on what the user specified or which would be larger.
        c                    | | n|S rC   r#   )rP   defaults     r)   set_defaultz+ApproxScalar.tolerance.<locals>.set_default  s    1172r+   r   z&absolute tolerance can't be negative: z absolute tolerance can't be NaN.Nz&relative tolerance can't be negative: z relative tolerance can't be NaN.)	r;   r   r   r   r   r<   r   r'   r.   )r>   r   absolute_tolerancerelative_tolerances       r)   r   zApproxScalar.tolerance  s$   	3 	3 	3
 )[43RSS!!M9KMM   :()) 	A?@@@ 8x#)) )[Hd5
 
 !!M9KMM   :()) 	A?@@@ %'9:::r+   rc   rd   )rf   rg   rh   ri   r   __annotations__r   rG   rV   rl   propertyr   r#   r+   r)   r\   r\   z  s         VV 387777266666!8 !8 !8 !8F6 6 6 6r H,; ,; X,; ,; ,;r+   r\   c                  >    e Zd ZdZ ed          Z ed          ZdS )r_   zFPerform approximate comparisons where the expected value is a Decimal.z1e-12z1e-6N)rf   rg   rh   ri   r   r   r   r#   r+   r)   r_   r_     s4        PP!(!1!1!(r+   r_   Fr7   r8   c                   d}t          | t                    rt          }nt          | t                    rt          }nt          |           rt          |           } t          }nct          |           rt          }nLt          | t                    r0t          | t          t          f          sd| }t          |          t          } || |||          S )a!  Assert that two numbers (or two ordered sequences of numbers) are equal to each other
    within some tolerance.

    Due to the :doc:`python:tutorial/floatingpoint`, numbers that we
    would intuitively expect to be equal are not always so::

        >>> 0.1 + 0.2 == 0.3
        False

    This problem is commonly encountered when writing tests, e.g. when making
    sure that floating-point values are what you expect them to be.  One way to
    deal with this problem is to assert that two floating-point numbers are
    equal to within some appropriate tolerance::

        >>> abs((0.1 + 0.2) - 0.3) < 1e-6
        True

    However, comparisons like this are tedious to write and difficult to
    understand.  Furthermore, absolute comparisons like the one above are
    usually discouraged because there's no tolerance that works well for all
    situations.  ``1e-6`` is good for numbers around ``1``, but too small for
    very big numbers and too big for very small ones.  It's better to express
    the tolerance as a fraction of the expected value, but relative comparisons
    like that are even more difficult to write correctly and concisely.

    The ``approx`` class performs floating-point comparisons using a syntax
    that's as intuitive as possible::

        >>> from pytest import approx
        >>> 0.1 + 0.2 == approx(0.3)
        True

    The same syntax also works for ordered sequences of numbers::

        >>> (0.1 + 0.2, 0.2 + 0.4) == approx((0.3, 0.6))
        True

    ``numpy`` arrays::

        >>> import numpy as np                                                          # doctest: +SKIP
        >>> np.array([0.1, 0.2]) + np.array([0.2, 0.4]) == approx(np.array([0.3, 0.6])) # doctest: +SKIP
        True

    And for a ``numpy`` array against a scalar::

        >>> import numpy as np                                         # doctest: +SKIP
        >>> np.array([0.1, 0.2]) + np.array([0.2, 0.1]) == approx(0.3) # doctest: +SKIP
        True

    Only ordered sequences are supported, because ``approx`` needs
    to infer the relative position of the sequences without ambiguity. This means
    ``sets`` and other unordered sequences are not supported.

    Finally, dictionary *values* can also be compared::

        >>> {'a': 0.1 + 0.2, 'b': 0.2 + 0.4} == approx({'a': 0.3, 'b': 0.6})
        True

    The comparison will be true if both mappings have the same keys and their
    respective values match the expected tolerances.

    **Tolerances**

    By default, ``approx`` considers numbers within a relative tolerance of
    ``1e-6`` (i.e. one part in a million) of its expected value to be equal.
    This treatment would lead to surprising results if the expected value was
    ``0.0``, because nothing but ``0.0`` itself is relatively close to ``0.0``.
    To handle this case less surprisingly, ``approx`` also considers numbers
    within an absolute tolerance of ``1e-12`` of its expected value to be
    equal.  Infinity and NaN are special cases.  Infinity is only considered
    equal to itself, regardless of the relative tolerance.  NaN is not
    considered equal to anything by default, but you can make it be equal to
    itself by setting the ``nan_ok`` argument to True.  (This is meant to
    facilitate comparing arrays that use NaN to mean "no data".)

    Both the relative and absolute tolerances can be changed by passing
    arguments to the ``approx`` constructor::

        >>> 1.0001 == approx(1)
        False
        >>> 1.0001 == approx(1, rel=1e-3)
        True
        >>> 1.0001 == approx(1, abs=1e-3)
        True

    If you specify ``abs`` but not ``rel``, the comparison will not consider
    the relative tolerance at all.  In other words, two numbers that are within
    the default relative tolerance of ``1e-6`` will still be considered unequal
    if they exceed the specified absolute tolerance.  If you specify both
    ``abs`` and ``rel``, the numbers will be considered equal if either
    tolerance is met::

        >>> 1 + 1e-8 == approx(1)
        True
        >>> 1 + 1e-8 == approx(1, abs=1e-12)
        False
        >>> 1 + 1e-8 == approx(1, rel=1e-6, abs=1e-12)
        True

    **Non-numeric types**

    You can also use ``approx`` to compare non-numeric types, or dicts and
    sequences containing non-numeric types, in which case it falls back to
    strict equality. This can be useful for comparing dicts and sequences that
    can contain optional values::

        >>> {"required": 1.0000005, "optional": None} == approx({"required": 1, "optional": None})
        True
        >>> [None, 1.0000005] == approx([None,1])
        True
        >>> ["foo", 1.0000005] == approx([None,1])
        False

    If you're thinking about using ``approx``, then you might want to know how
    it compares to other good ways of comparing floating-point numbers.  All of
    these algorithms are based on relative and absolute tolerances and should
    agree for the most part, but they do have meaningful differences:

    - ``math.isclose(a, b, rel_tol=1e-9, abs_tol=0.0)``:  True if the relative
      tolerance is met w.r.t. either ``a`` or ``b`` or if the absolute
      tolerance is met.  Because the relative tolerance is calculated w.r.t.
      both ``a`` and ``b``, this test is symmetric (i.e.  neither ``a`` nor
      ``b`` is a "reference value").  You have to specify an absolute tolerance
      if you want to compare to ``0.0`` because there is no tolerance by
      default.  More information: :py:func:`math.isclose`.

    - ``numpy.isclose(a, b, rtol=1e-5, atol=1e-8)``: True if the difference
      between ``a`` and ``b`` is less that the sum of the relative tolerance
      w.r.t. ``b`` and the absolute tolerance.  Because the relative tolerance
      is only calculated w.r.t. ``b``, this test is asymmetric and you can
      think of ``b`` as the reference value.  Support for comparing sequences
      is provided by :py:func:`numpy.allclose`.  More information:
      :std:doc:`numpy:reference/generated/numpy.isclose`.

    - ``unittest.TestCase.assertAlmostEqual(a, b)``: True if ``a`` and ``b``
      are within an absolute tolerance of ``1e-7``.  No relative tolerance is
      considered , so this function is not appropriate for very large or very
      small numbers.  Also, it's only available in subclasses of ``unittest.TestCase``
      and it's ugly because it doesn't follow PEP8.  More information:
      :py:meth:`unittest.TestCase.assertAlmostEqual`.

    - ``a == pytest.approx(b, rel=1e-6, abs=1e-12)``: True if the relative
      tolerance is met w.r.t. ``b`` or if the absolute tolerance is met.
      Because the relative tolerance is only calculated w.r.t. ``b``, this test
      is asymmetric and you can think of ``b`` as the reference value.  In the
      special case that you explicitly specify an absolute tolerance but not a
      relative tolerance, only the absolute tolerance is considered.

    .. note::

        ``approx`` can handle numpy arrays, but we recommend the
        specialised test helpers in :std:doc:`numpy:reference/routines.testing`
        if you need support for comparisons, NaNs, or ULP-based tolerances.

        To match strings using regex, you can use
        `Matches <https://github.com/asottile/re-assert#re_assertmatchespattern-str-args-kwargs>`_
        from the
        `re_assert package <https://github.com/asottile/re-assert>`_.


    .. note::

        Unlike built-in equality, this function considers
        booleans unequal to numeric zero or one. For example::

           >>> 1 == approx(True)
           False

    .. warning::

       .. versionchanged:: 3.2

       In order to avoid inconsistent behavior, :py:exc:`TypeError` is
       raised for ``>``, ``>=``, ``<`` and ``<=`` comparisons.
       The example below illustrates the problem::

           assert approx(0.1) > 0.1 + 1e-10  # calls approx(0.1).__gt__(0.1 + 1e-10)
           assert 0.1 + 1e-10 > approx(0.1)  # calls approx(0.1).__lt__(0.1 + 1e-10)

       In the second example one expects ``approx(0.1).__le__(0.1 + 1e-10)``
       to be called. But instead, ``approx(0.1).__lt__(0.1 + 1e-10)`` is used to
       comparison. This is because the call hierarchy of rich comparisons
       follows a fixed behavior. More information: :py:meth:`object.__ge__`

    .. versionchanged:: 3.7.1
       ``approx`` raises ``TypeError`` when it encounters a dict value or
       sequence element of non-numeric type.

    .. versionchanged:: 6.1.0
       ``approx`` falls back to strict equality for non-numeric types instead
       of raising ``TypeError``.
    Tz:pytest.approx() only supports ordered sequences, but got: )r^   r   r_   r   r   _is_numpy_arrayr   rz   rw   r   r   rA   bytesr   r\   )r'   r<   r;   r7   r?   clsr   s          r)   approxr     s    ` (G$$  -	Hg	&	& 		"	" 	"8,,	8	$	$  	Hj	)	) *XU|2T2T W8WWnn3xc6***r+   r'   c                    t          | d          o1t          | t                    ot          | t          t          f           S )N__getitem__)hasattrr^   r   rA   r   )r'   s    r)   rw   rw     s?    -(( 	3x''	38c5\222r+   objc                $    t          |           duS )zr
    Return true if the given object is implicitly convertible to ndarray,
    and numpy is already imported.
    N)r   )r   s    r)   r   r     s    
 3t++r+   ndarray | Nonec                   t           j                            d          }|c|                    |           rdS t	          | |j                  r| S t          | d          st          dd          r|                    |           S dS )z
    Return an ndarray if the given object is implicitly convertible to ndarray,
    and numpy is already imported, otherwise None.
    r   N	__array__r   __array_interface__)sysmodulesgetr   r^   r   r   r   )r   r   s     r)   r   r     s    
 koog&&B	~;;s 	#4RZ(( 	#JS+&& 	#'%9N*O*O 	#::c??"4r+   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   rb   )r7   r8   r   r5   )r'   r   r   r8   )r   r   r   r8   )r   r   r   r   )
__future__r   collections.abcr   r   r   r   decimalr   r   numbersr	   r   r  typingr
   r   r   r   r3   r5   rp   rz   r   r   r\   r_   r   rw   r   r   r#   r+   r)   <module>r     s   " " " " " " & & & & & & # # # # # # $ $ $ $ $ $ ! ! ! ! ! !               



                       :8K 8K 8K 8K 8K 8K 8K 8K@  e@ e@ e@ e@ e@* e@ e@ e@PIW IW IW IW IWJ IW IW IWXFU FU FU FU FU FU FU FURS; S; S; S; S;: S; S; S;l1 1 1 1 1L 1 1 1a+ a+ a+ a+ a+H   , , , ,     r+   