
    ?g                       S SK Jr  S SKJr  S SKJr  S SKJr  S SKrS SKJ	r	  S SK
r
S SKrS SKJr  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKrS SKJr  \(       a  S SK J!r!                S2S jr" " S S5      r#S r$ " S S\#5      r% " S S\#5      r& " S S \#5      r' " S! S"\#5      r( " S# S$\(5      r)S3S4S% jjr*S5S& jr+S6S' jr,S7S( jr-\" S)\.S*9r/\S+S,.     S8S- jj5       r0\          S9S. j5       r0        S:S/ jr0\Rb                  \0l1        \ " S0 S1\\Rd                  Rf                  \/      5      5       r4g);    )annotations)
Collection)Sized)DecimalN)Complex)TracebackType)Any)Callable)cast)ContextManager)final)Mapping)overload)Pattern)Sequence)Tuple)Type)TYPE_CHECKING)TypeVar)fail)ndarrayc                   [        U5      nUR                  SS5        / SQnU HW  u  pn
[        US   [        U5      5      US'   [        US   [        U	5      5      US'   [        US   [        U
5      5      US'   MY     S[        U5       SU S3S	U 3S
U 3/U VV	V
s/ s H%  u  pn
USUS    3 SU	SUS    3 SU
SUS    3 3PM'     sn
n	n-   nU$ s  sn
n	nf )Nr   )IndexObtainedExpected)r   r   r         z(comparison failed. Mismatched elements: z / :zMax absolute difference: zMax relative difference: <z | )listinsertmaxlen)full_objectmessage_datanumber_of_elementsdifferent_idsmax_abs_diffmax_rel_diffmessage_list	max_sizesindexobtainedexpectedindexesexplanations                4/usr/lib/python3/dist-packages/_pytest/python_api.py_compare_approxr2   "   s#    %L<=I%1!9Q<U4	!9Q<X7	!9Q<X7	! &2
 33}3E2FcJ\I]]^_
#L>2
#L>2 ,8	+7'Gx 1Yq\N"
#3x)A,/?&@HQyYZ|nL\C]^+7		K 		s   ,C
c                  z    \ rS rSrSrSrSrSSS jjrSS jrSS jr	SS jr
S	 rSrSS
 jrSS jrS rSS jrSrg)
ApproxBase?   zdProvide shared utilities for making approximate comparisons between
numbers or sequences of numbers.Nd   c                X    SnXl         X0l        X l        X@l        U R	                  5         g )NT)r.   absrelnan_ok_check_type)selfr.   r9   r8   r:   __tracebackhide__s         r1   __init__ApproxBase.__init__G   s(          c                    [         eNNotImplementedErrorr<   s    r1   __repr__ApproxBase.__repr__O   s    !!r@   c                    SSU 3SU  3/$ )Nzcomparison failedz
Obtained: z
Expected:  )r<   
other_sides     r1   _repr_compareApproxBase._repr_compareR   s#    %
 	
r@   c                L   ^  [        U 4S jT R                  U5       5       5      $ )Nc              3  P   >#    U  H  u  pUTR                  U5      :H  v   M     g 7frB   _approx_scalar).0axr<   s      r1   	<genexpr>$ApproxBase.__eq__.<locals>.<genexpr>Z   s'      
4SDAA$$Q''4Ss   #&)all_yield_comparisonsr<   actuals   ` r1   __eq__ApproxBase.__eq__Y   s(     
484K4KF4S
 
 	
r@   c                    Sn[        S5      e)NTzVapprox() is not supported in a boolean context.
Did you mean: `assert a == approx(b)`?)AssertionError)r<   r=   s     r1   __bool__ApproxBase.__bool__^   s     e
 	
r@   c                    X:X  + $ rB   rI   rX   s     r1   __ne__ApproxBase.__ne__g   s    ##r@   c                    [        U[        5      (       a)  [        XR                  U R                  U R
                  S9$ [        XR                  U R                  U R
                  S9$ )N)r9   r8   r:   )
isinstancer   ApproxDecimalr9   r8   r:   ApproxScalar)r<   rS   s     r1   rP   ApproxBase._approx_scalarj   sE    a!! dhht{{SSA88$++NNr@   c                    [         e)z_Yield all the pairs of numbers to be compared.

This is used to implement the `__eq__` method.
rC   rX   s     r1   rW   ApproxBase._yield_comparisonso   s
    
 "!r@   c                    g)z<Raise a TypeError if the expected value is not a valid type.NrI   rE   s    r1   r;   ApproxBase._check_typev   s    r@   )r8   r.   r:   r9   NNF)r:   boolreturnNonern   str)rJ   r	   rn   	list[str]rn   rm   )rn   rf   rn   ro   )__name__
__module____qualname____firstlineno____doc____array_ufunc____array_priority__r>   rF   rK   rZ   r^   __hash__ra   rP   rW   r;   __static_attributes__rI   r@   r1   r4   r4   ?   sJ    ( O"



 H$O
"Kr@   r4   c                   ^  [        U[        [        45      (       a  [        U5      nU" U 4S jU 5       5      $ [	        U5      (       a  U Vs/ s H  n[        T U5      PM     sn$ T " U5      $ s  snf )z=Recursively map a function over a sequence of arbitrary depthc              3  <   >#    U  H  n[        TU5      v   M     g 7frB   )_recursive_sequence_map)rQ   xifs     r1   rT   *_recursive_sequence_map.<locals>.<genexpr>   s     C2/266s   )rd   r    tupletype_is_sequence_liker   )r   rS   seq_typer   s   `   r1   r   r      sd    !dE]##7CCCC	1		9:;2'2.;;t <s   A/c                  J   ^  \ rS rSrSrSS jrS	S jrS
U 4S jjrS rSr	U =r
$ )ApproxNumpy   zHPerform approximate comparisons where the expected value is numpy array.c                l    [        U R                  U R                  R                  5       5      nSU< S3$ Napprox())r   rP   r.   tolist)r<   list_scalarss     r1   rF   ApproxNumpy.__repr__   s6    .!5!5!7
 (**r@   c                T   SS K nSS Kn      SS jnU R                  R                  n[	        U R
                  U R                  R                  5       5      n[        U5      nUc   eXWR                  :w  a  SSU SUR                   3/$ U R                  R                  nUR                  * n	UR                  * n
/ nUR                  " S U 5       6  Hx  nU" Xl5      nU" X|5      nX:w  d  M  [        UR                  U-
  5      n[        X5      n	US:X  a  UR                  n
O[        X[        U5      -  5      n
UR                  U5        Mz     U Vs/ s H/  n[        U5      [        U" X|5      5      [        U" Xl5      5      4PM1     nn[        U R                  UUUU	U
5      $ s  snf )	Nr   c                $    U nU H  nX#   nM	     U$ )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.
rI   )nested_listnd_indexvalueis       r1   get_value_from_nested_list=ApproxNumpy._repr_compare.<locals>.get_value_from_nested_list   s     %E Lr@   z3Impossible to compare arrays with different shapes.zShapes:  and c              3  8   #    U  H  n[        U5      v   M     g 7frB   )range)rQ   r   s     r1   rT   ,ApproxNumpy._repr_compare.<locals>.<genexpr>   s     (J>aq>s           )r   z	list[Any]r   ztuple[Any, ...]rn   r	   )	itertoolsmathr.   shaper   rP   r   _as_numpy_arraysizeinfproductr8   r"   appendrq   r2   )r<   rJ   r   r   r   np_array_shapeapprox_side_as_seqother_side_as_arrayr&   r(   r)   r'   r,   approx_valueother_valueabs_diffr%   s                    r1   rK   ApproxNumpy._repr_compare   s   
	"
	.=
	
	 ,,4!5!5!7

 .j9"...666E>*%0C0I0I/JK 
 "]]//yy&&(J>(JKE56HPL45HPK*|44{BC"<:#%#'88L#&|K@P5P#QL$$U+ L$ '
 '	 E
./BJK./AIJ
 ' 	 
 MM
 	

s   6F%c                4  > SS K nUR                  U5      (       d   UR                  U5      nUR                  U5      (       d%  UR
                  U R                  R
                  :w  a  g[        TU ]!  U5      $ ! [         a  n[	        SU S35      UeS nAff = f)Nr   zcannot compare 'z' to numpy.ndarrayF)	numpyisscalarasarray	Exception	TypeErrorr   r.   superrZ   )r<   rY   npe	__class__s       r1   rZ   ApproxNumpy.__eq__   s     {{6""VF+ {{6""v||t}}7J7J'Jw~f%%  V"26(:L MNTUUVs   A8 8
BBBc              #    #    SS K nUR                  U5      (       aM  UR                  U R                  R                  5       H#  nXR                  U   R                  5       4v   M%     g UR                  U R                  R                  5       H4  nX   R                  5       U R                  U   R                  5       4v   M6     g 7f)Nr   )r   r   ndindexr.   r   item)r<   rY   r   r   s       r1   rW   ApproxNumpy._yield_comparisons   s      ;;vZZ 3 34mmA.33555 5 ZZ 3 34inn&a(8(=(=(??? 5s   CCrI   rp   )rJ   zndarray | list[Any]rn   rr   rs   )ru   rv   rw   rx   ry   rF   rK   rZ   rW   r}   __classcell__r   s   @r1   r   r      s"    R+>
@& @ @r@   r   c                  T   ^  \ rS rSrSrS	S jrS
S jrSU 4S jjrS rSS jr	Sr
U =r$ )ApproxMapping   zuPerform approximate comparisons where the expected value is a mapping
with numeric values (the keys can be anything).c           	         SU R                   R                  5        VVs0 s H  u  pXR                  U5      _M     snn< S3$ s  snnf r   )r.   itemsrP   )r<   kvs      r1   rF   ApproxMapping.__repr__   sD    ATATAVWAV111!44AVW[[\]]Ws   Ac           	     <   SS K nU R                  R                  5        VVs0 s H  u  p4X0R                  U5      _M     nnn[	        U5      nUR
                  * nUR
                  * n/ n	[        UR                  5       UR                  5       5       H  u  u  pnX:w  d  M  UR                  bs  Ubp   [        U[        UR                  U-
  5      5      nUR                  S:X  a  UR
                  nO0[        U[        UR                  U-
  UR                  -  5      5      n U	R                  U
5        M     U	 Vs/ s H'  n[        U5      [        X   5      [        X]   5      4PM)     nn[        U R                  UUU	UU5      $ s  snnf ! [         a     Nuf = fs  snf )Nr   r   )r   r.   r   rP   r#   r   zipvaluesr"   r8   ZeroDivisionErrorr   rq   r2   )r<   rJ   r   r   r   approx_side_as_mapr&   r(   r)   r'   
approx_keyr   r   keyr%   s                  r1   rK   ApproxMapping._repr_compare   s    37--2E2E2G
2G$!A""1%%2G 	 
 !!34yy7:$$&
(9(9(;8
3&Z *((49P'*(#l.C.Ck.Q*R( (00C7+/88L+. , #%1%:%:[%H&2&;&;%<!",L $$Z0+8
2 %
$ Xs:?+S1C1H-IJ$ 	 

 MM
 	
I
6 - 
s#   F1>F	0/F	9.F	
FFc                   >  [        UR                  5       5      [        U R                  R                  5       5      :w  a  g [        TU ]  U5      $ ! [         a     gf = fNF)setkeysr.   AttributeErrorr   rZ   r<   rY   r   s     r1   rZ   ApproxMapping.__eq__)  sZ    	6;;=!S););)=%>> ?
 w~f%%  		s   >A 
AAc              #  x   #    U R                   R                  5        H  nX   U R                   U   4v   M     g 7frB   )r.   r   )r<   rY   r   s      r1   rW    ApproxMapping._yield_comparisons2  s2     ##%A)T]]1--- &s   8:c           
        SnU R                   R                  5        Hd  u  p#[        U[        U R                   5      5      (       d  M+  Sn[	        UR                  X#[        R                  " U R                   5      5      5      e   g )NTz[pytest.approx() does not support nested dictionaries: key={!r} value={!r}
  full mapping={})r.   r   rd   r   r   formatpprintpformat)r<   r=   r   r   msgs        r1   r;   ApproxMapping._check_type6  s_     ----/JC%dmm!455t

3v~~dmm7T UVV 0r@   rI   rp   )rJ   zMapping[object, float]rn   rr   rs   rt   ru   rv   rw   rx   ry   rF   rK   rZ   rW   r;   r}   r   r   s   @r1   r   r      s*    7^.
`&.W Wr@   r   c                  T   ^  \ rS rSrSrS	S jrS
S jrSU 4S jjrS rSS jr	Sr
U =r$ )ApproxSequenceLikei>  zRPerform approximate comparisons where the expected value is a sequence of numbers.c                   ^  [        T R                  5      nU[        [        4;  a  [        nSU" U 4S jT R                   5       5      < S3$ )Nr   c              3  F   >#    U  H  nTR                  U5      v   M     g 7frB   rO   )rQ   rS   r<   s     r1   rT   .ApproxSequenceLike.__repr__.<locals>.<genexpr>E  s     !P-Q$"5"5a"8"8-   !r   )r   r.   r   r    )r<   r   s   ` r1   rF   ApproxSequenceLike.__repr__A  sB    &E4=(H!P$--!PPSSTUUr@   c           	        SS K n[        U R                  5      [        U5      :w  a&  SS[        U R                  5       S[        U5       3/$ [        U R                  U R                  5      n[        U5      nUR
                  * nUR
                  * n/ n[        [        X15      5       Hm  u  nu  pX:w  d  M  [        U	R                  U
-
  5      n[        X[5      nU
S:X  a  UR
                  nO[        Xk[        U
5      -  5      nUR                  U5        Mo     U Vs/ s H'  n[        U5      [        X   5      [        X8   5      4PM)     nn[        U R                  UUUUU5      $ s  snf )Nr   z1Impossible to compare lists with different sizes.z	Lengths: r   r   )r   r#   r.   r   rP   r   	enumerater   r8   r"   r   rq   r2   )r<   rJ   r   r   r&   r(   r)   r'   r   r   r   r   r%   s                r1   rK    ApproxSequenceLike._repr_compareG  sg   t}}Z0CC./uS_4EF 
 5T5H5H$--X !34yy.7"//
*A* *|44{BC"<:#%#'88L#&|K@P5P#QL$$Q'/
 #
" VS'-?-B)CD" 	 

 MM
 	

s   .E'c                   >  [        U5      [        U R                  5      :w  a  g [        TU ]  U5      $ ! [         a     gf = fr   )r#   r.   r   r   rZ   r   s     r1   rZ   ApproxSequenceLike.__eq__p  sJ    	6{c$--00 1 w~f%%  		s   "6 
AAc                ,    [        XR                  5      $ rB   )r   r.   rX   s     r1   rW   %ApproxSequenceLike._yield_comparisonsx  s    6==))r@   c           
        Sn[        U R                  5       Hd  u  p#[        U[        U R                  5      5      (       d  M+  Sn[	        UR                  X2[        R                  " U R                  5      5      5      e   g )NTz]pytest.approx() does not support nested data structures: {!r} at index {}
  full sequence: {})r   r.   rd   r   r   r   r   r   )r<   r=   r,   rS   r   s        r1   r;   ApproxSequenceLike._check_type{  s[     !$--0HE!T$--011v

1V^^DMM5R STT 1r@   rI   rp   )rJ   zSequence[float]rn   rr   rs   rt   r   r   s   @r1   r   r   >  s(    \V'
R&*U Ur@   r   c                  ^    \ rS rSr% SrSrS\S'   SrS\S'   SS jrSS	 jr	S
r
\S 5       rSrg
)rf   i  zLPerform approximate comparisons where the expected value is a single number.g-q=zfloat | DecimalDEFAULT_ABSOLUTE_TOLERANCEgư>DEFAULT_RELATIVE_TOLERANCEc                ~   [        U R                  [        5      (       dt  [        U R                  [        [        45      (       aO  [
        R                  " [        U R                  5      =(       d    [        U R                  [        5      5      (       a  [        U R                  5      $  U R                  S n[        U R                  [        5      (       aE  U R                  R                  (       a*  [
        R                  " U R                  5      (       d  US-  nU R                   SU 3$ ! [         a    Sn Nf = f)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°``.
z.1eu    ∠ ±180°z???u    ± )rd   r.   rm   r   r   r   isinfr8   rq   	toleranceimag
ValueError)r<   vetted_tolerances     r1   rF   ApproxScalar.__repr__  s     t}}d++t}}w.@AAzz#dmm,O
4==$0OPPt}}%%		%"&..!54=='22MM&&

4>>22 N2  --%5$677  	%$	%s   *A2D- -D<;D<c                  ^  [        U5      nUb  [        U 4S jUR                   5       5      $ [        T R                  [
        5      (       a  [        U[
        5      (       d  gUT R                  :X  a  g[        T R                  [
        5      (       d@  [        T R                  [        [        45      (       a  [        U[        [        45      (       d  g[        R                  " [        T R                  5      5      (       a2  T R                  =(       a    [        R                  " [        U5      5      $ [        R                  " [        T R                  5      5      (       a  g[        T R                  U-
  5      T R                  :*  nU$ )zaReturn whether the given value is equal to the expected value
within the pre-specified tolerance.c              3  F   >#    U  H  nTR                  U5      v   M     g 7frB   )rZ   )rQ   rR   r<   s     r1   rT   &ApproxScalar.__eq__.<locals>.<genexpr>  s     <|!t{{1~~|r   FT)r   rV   flatrd   r.   rm   r   r   r   isnanr8   r:   r   r   )r<   rY   r   results   `   r1   rZ   ApproxScalar.__eq__  s    "&) <w||<<< dmmT**:fd3K3Kt}}$ dmmT**t}}w&8996GW#566
 ::c$--());;:4::c&k#:: ::c$--()) 4==612dnnDr@   Nc                   S nU" U R                   U R                  5      nUS:  a  [        SU 35      e[        R                  " U5      (       a  [        S5      eU R
                  c  U R                   b  U$ U" U R
                  U R                  5      [        U R                  5      -  nUS:  a  [        SU 35      e[        R                  " U5      (       a  [        S5      e[        X25      $ )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                    U b  U $ U$ rB   rI   )rS   defaults     r1   set_default+ApproxScalar.tolerance.<locals>.set_default  s    1272r@   r   z&absolute tolerance can't be negative: z absolute tolerance can't be NaN.z&relative tolerance can't be negative: z relative tolerance can't be NaN.)	r8   r   r   r   r   r9   r   r.   r"   )r<   r  absolute_tolerancerelative_tolerances       r1   r   ApproxScalar.tolerance  s    	3
 )43R3RS!89K8LM  ::())?@@ 88xx#)) )HHd55
 !89K8LM  ::())?@@ %::r@   rI   rp   rs   )ru   rv   rw   rx   ry   r   __annotations__r   rF   rZ   r|   propertyr   r}   rI   r@   r1   rf   rf     sA    V 3872668>*Z H,; ,;r@   rf   c                  8    \ rS rSrSr\" S5      r\" S5      rSrg)re   i	  zFPerform approximate comparisons where the expected value is a Decimal.z1e-12z1e-6rI   N)	ru   rv   rw   rx   ry   r   r   r   r}   rI   r@   r1   re   re   	  s    P!(!1!(r@   re   c                   Sn[        U [        5      (       a  [        nO[        U [        5      (       a  [        nO[        U 5      (       a  [        U 5      n [        nO^[        U 5      (       a  [        nOG[        U [        5      (       a,  [        U [        [        45      (       d  SU < 3n[        U5      e[        nU" XX#5      $ )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

You can also use ``approx`` to compare nonnumeric types, or dicts and
sequences containing nonnumeric 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>`_.

.. 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 nonnumeric type.

.. versionchanged:: 6.1.0
   ``approx`` falls back to strict equality for nonnumeric types instead
   of raising ``TypeError``.
Tz:pytest.approx() only supports ordered sequences, but got: )rd   r   re   r   r   _is_numpy_arrayr   r   r   r   r   rq   bytesr   rf   )r.   r9   r8   r:   r=   clsr   s          r1   approxr    s    J (G$$ -	Hg	&	&		"	""8,	8	$	$ 	Hj	)	)*XU|2T2TJ8,Wnxc**r@   c                    [        U S5      =(       a2    [        U [        5      =(       a    [        U [        [        45      (       + $ )N__getitem__)hasattrrd   r   rq   r  )r.   s    r1   r   r     s6    -( 	3x'	38c5\22r@   c                    [        U 5      SL$ )zf
Return true if the given object is implicitly convertible to ndarray,
and numpy is already imported.
N)r   )objs    r1   r  r    s    
 3t++r@   c                   SSK nUR                  R                  S5      nUbf  UR                  U 5      (       a  g[	        XR
                  5      (       a  U $ [        U S5      (       d  [        SS5      (       a  UR                  U 5      $ g)z|
Return an ndarray if the given object is implicitly convertible to ndarray,
and numpy is already imported, otherwise None.
r   Nr   	__array__r  __array_interface__)sysmodulesgetr   rd   r   r  r   )r  r  r   s      r1   r   r     so    
 kkoog&B	~;;sZZ((JS+&&'%9N*O*O::c?"r@   E)bound.)matchc                   g rB   rI   )expected_exceptionr  s     r1   raisesr     s    
 r@   c                    g rB   rI   )r  funcargskwargss       r1   r   r     s     &)r@   c                <   SnU (       d  [        SU < S35      e[        U [        5      (       a  U 4nOU nU H  n[        U[        5      (       a  [        U[        5      (       a  M/  Sn[        U[        5      (       a  UR
                  O[        U5      R
                  n[        UR                  U5      5      e   SU  3nU(       dT  UR                  SS5      n	U(       a/  SnUS	R                  [        U5      5      -  nUS
-  n[        U5      e[        XU	5      $ US   n
[        U
5      (       d  [        U
< S[        U
5       S35      e U
" USS 0 UD6  [#        U5        g! U  a3  n[        R                  R                  R!                  U5      s SnA$ SnAff = f)a\  Assert that a code block/function call raises an exception type, or one of its subclasses.

:param expected_exception:
    The expected exception type, or a tuple if one of multiple possible
    exception types are expected. Note that subclasses of the passed exceptions
    will also match.

:kwparam str | re.Pattern[str] | None match:
    If specified, a string containing a regular expression,
    or a regular expression object, that is tested against the string
    representation of the exception and its :pep:`678` `__notes__`
    using :func:`re.search`.

    To match a literal string that may contain :ref:`special characters
    <re-syntax>`, the pattern can first be escaped with :func:`re.escape`.

    (This is only used when ``pytest.raises`` is used as a context manager,
    and passed through to the function otherwise.
    When using ``pytest.raises`` as a function, you can use:
    ``pytest.raises(Exc, func, match="passed on").match("my pattern")``.)

Use ``pytest.raises`` as a context manager, which will capture the exception of the given
type, or any of its subclasses::

    >>> import pytest
    >>> with pytest.raises(ZeroDivisionError):
    ...    1/0

If the code block does not raise the expected exception (:class:`ZeroDivisionError` in the example
above), or no exception at all, the check will fail instead.

You can also use the keyword argument ``match`` to assert that the
exception matches a text or regex::

    >>> with pytest.raises(ValueError, match='must be 0 or None'):
    ...     raise ValueError("value must be 0 or None")

    >>> with pytest.raises(ValueError, match=r'must be \d+$'):
    ...     raise ValueError("value must be 42")

The ``match`` argument searches the formatted exception string, which includes any
`PEP-678 <https://peps.python.org/pep-0678/>`__ ``__notes__``:

    >>> with pytest.raises(ValueError, match=r"had a note added"):  # doctest: +SKIP
    ...     e = ValueError("value must be 42")
    ...     e.add_note("had a note added")
    ...     raise e

The context manager produces an :class:`ExceptionInfo` object which can be used to inspect the
details of the captured exception::

    >>> with pytest.raises(ValueError) as exc_info:
    ...     raise ValueError("value must be 42")
    >>> assert exc_info.type is ValueError
    >>> assert exc_info.value.args[0] == "value must be 42"

.. warning::

   Given that ``pytest.raises`` matches subclasses, be wary of using it to match :class:`Exception` like this::

       with pytest.raises(Exception):  # Careful, this will catch ANY exception raised.
           some_function()

   Because :class:`Exception` is the base class of almost all exceptions, it is easy for this to hide
   real bugs, where the user wrote this expecting a specific exception, but some other exception is being
   raised due to a bug introduced during a refactoring.

   Avoid using ``pytest.raises`` to catch :class:`Exception` unless certain that you really want to catch
   **any** exception raised.

.. note::

   When using ``pytest.raises`` as a context manager, it's worthwhile to
   note that normal context manager rules apply and that the exception
   raised *must* be the final line in the scope of the context manager.
   Lines of code after that, within the scope of the context manager will
   not be executed. For example::

       >>> value = 15
       >>> with pytest.raises(ValueError) as exc_info:
       ...     if value > 10:
       ...         raise ValueError("value must be <= 10")
       ...     assert exc_info.type is ValueError  # This will not execute.

   Instead, the following approach must be taken (note the difference in
   scope)::

       >>> with pytest.raises(ValueError) as exc_info:
       ...     if value > 10:
       ...         raise ValueError("value must be <= 10")
       ...
       >>> assert exc_info.type is ValueError

**Using with** ``pytest.mark.parametrize``

When using :ref:`pytest.mark.parametrize ref`
it is possible to parametrize tests such that
some runs raise an exception and others do not.

See :ref:`parametrizing_conditional_raising` for an example.

.. seealso::

    :ref:`assertraises` for more examples and detailed discussion.

**Legacy form**

It is possible to specify a callable by passing a to-be-called lambda::

    >>> raises(ZeroDivisionError, lambda: 1/0)
    <ExceptionInfo ...>

or you can specify an arbitrary callable with arguments::

    >>> def f(x): return 1/x
    ...
    >>> raises(ZeroDivisionError, f, 0)
    <ExceptionInfo ...>
    >>> raises(ZeroDivisionError, f, x=0)
    <ExceptionInfo ...>

The form above is fully supported but discouraged for new code because the
context manager form is regarded as more readable and less error-prone.

.. note::
    Similar to caught exception objects in Python, explicitly clearing
    local references to returned ``ExceptionInfo`` objects can
    help the Python interpreter speed up its garbage collection.

    Clearing those references breaks a reference cycle
    (``ExceptionInfo`` --> caught exception --> frame stack raising
    the exception --> current frame stack --> local variables -->
    ``ExceptionInfo``) which makes Python keep all objects referenced
    from that cycle (including all local variables in the current
    frame) alive until the next cyclic garbage collection run.
    More detailed information can be found in the official Python
    documentation for :ref:`the try statement <python:try>`.
TzCExpected an exception type or a tuple of exception types, but got `z`. Raising exceptions is already understood as failing the test, so you don't need any special code to say 'this should never raise an exception'.z7expected exception must be a BaseException type, not {}zDID NOT RAISE r  Nz6Unexpected keyword arguments passed to pytest.raises: z, z"
Use context-manager form instead?r   z object (type: z) must be callabler   )r   rd   r   
issubclassBaseExceptionru   r   r   popjoinsortedRaisesContextcallable_pytest_codeExceptionInfofrom_exceptionr   )r  r#  r$  r=   expected_exceptionsexcr   not_amessager  r"  r   s               r1   r   r   "  s   Z QRdQg hN O
 	

 $d++4F3H0"#t$$JsM,J,JKC$.sD$9$9CLLtCy?Q?QECJJu-..	 # 123G+1::gt+DJC499VF^,,C88CC. /%@@Aw~~thod4j\ASTUU	A$qr(%f% 	M " 	A==..==a@@	As   E" "F((FFFc                  V    \ rS rSr S       SS jjrS	S jr        S
S jrSrg)r+  i  Nc                   Xl         X l        X0l        S U l        U R                  b6  S n [        R
                  " U R                  5        Ub  [        SU 35        g g g ! [        R                   a  nUn S nAN/S nAff = f)Nz+Invalid regex pattern provided to 'match': )r  r4  
match_exprexcinforecompileerrorr   )r<   r  r4  r7  re_errorr   s         r1   r>   RaisesContext.__init__  s|     #5$>B??&H

4??+ #B8*MN $ ' 88 s    A A>2A99A>c                t    [         R                  R                  R                  5       U l        U R                  $ rB   )r-  r.  r/  	for_laterr8  rE   s    r1   	__enter__RaisesContext.__enter__  s&    }}22<<>||r@   c                |   SnUc  [        U R                  5        U R                  c   e[        XR                  5      (       d  g[        [        [        [           [        [        4   XU45      nU R                  R                  U5        U R                  b%  U R                  R                  U R                  5        g)NTF)r   r4  r8  r&  r  r   r   r   r  r   fill_unfilledr7  r  )r<   exc_typeexc_valexc_tbr=   exc_infos         r1   __exit__RaisesContext.__exit__  s     !||'''($;$;<<d1gq-788f:UV""8,??&LLt/r@   )r8  r  r7  r4  rB   )r  type[E] | tuple[type[E], ...]r4  rq   r7  str | Pattern[str] | Nonern   ro   )rn   _pytest._code.ExceptionInfo[E])rD  ztype[BaseException] | NonerE  zBaseException | NonerF  zTracebackType | Nonern   rm   )ru   rv   rw   rx   r>   r@  rH  r}   rI   r@   r1   r+  r+    sg     15	O9O O .	O
 
O&, & %	
 
r@   r+  )r$   objectr%   zSequence[tuple[str, str, str]]r&   intr'   zSequence[object]r(   floatr)   rO  rn   rr   rl   )r:   rm   rn   r4   )r.   rM  rn   rm   )r  rM  rn   rm   )r  rM  rn   zndarray | None)r  rJ  r  rK  rn   zRaisesContext[E])
r  rJ  r"  zCallable[..., Any]r#  r	   r$  r	   rn   rL  )r  rJ  r#  r	   r$  r	   rn   z1RaisesContext[E] | _pytest._code.ExceptionInfo[E])5
__future__r   collections.abcr   r   decimalr   r   numbersr   r   r9  typesr   typingr	   r
   r   r   r   r   r   r   r   r   r   r   r   _pytest._coder-  _pytest.outcomesr   r   r   r2   r4   r   r   r   r   rf   re   r  r   r  r   r'  r  r   r   r.  r/  r+  rI   r@   r1   <module>rX     s   " & !     	     !            ! 0  $	
   :8K 8K@e@* e@PIWJ IWXBU BUJC;: C;L1L 1V+r,* C}% 
 (+5 % 	 
 
)5)
) ) 	)
 $) 
)q5q>AqMPq6qj >>  )N7==#>#>q#AB ) )r@   