§ |<ˆj–ãóÊ—ddlZddlZddlmZddlmZddlmZddlmZddl m Z ddl m Z ddl m Z dd l mZdd l mZdd l mZdd l mZdd l mZddl mZddl mZddl mZddl mZddl mZddl mZddl mZerddlmZddlZddlmZddlm Z ddlm!Z!ddl"m#Z#dee$de%fd„Z&de'deee$e$e$fde(d ee'd!e)d"e)dee$fd#„Z*Gd$„d%¦«Z+d&„Z,Gd'„d(e+¦«Z-Gd)„d*e+¦«Z.Gd+„d,e+¦«Z/Gd-„d.e+¦«Z0Gd/„d0e0¦«Z1dGd2e2de+fd3„Z3d4e'de2fd5„Z4d4e'ded6fd7„Z5ed8e6¬9¦«Z7e!d:d;œdfd?„¦«Z8e!dej9j:e7ffdD„Z8e#j;e8_;eGdE„dFeej9j:e7¦«¦«Zz#_compare_approx..>ssø€ð ð ð á 'ˆG�X˜xð Ð^�Y˜q”\Ð^Ð^Ð^Ð^ xÐ^°)¸A´,Ð^Ð^Ð^Ð^ÀHÐ^ÈyÐYZÌ|Ð^Ð^Ð^Ð^ð ð ð r%)ÚlistÚinsertÚmaxÚlen) r&r'r(r)r*r+Ú message_listÚindexr8r9Ú explanationr:s @r#Ú_compare_approxrC+sø€õ˜ Ñ%Ô%€LØ×Ò˜Ð<Ñ=Ô=Ð=Ø� � €IØ%1ð8ð8Ñ!ˆˆx˜Ý˜9 Qœ<­¨U©¬Ñ4Ô4ˆ �!‰ ݘ9 Qœ<­¨X©¬Ñ7Ô7ˆ �!‰ ݘ9 Qœ<­¨X©¬Ñ7Ô7ˆ �!‰ ˆ à_µ3°}Ñ3EÔ3EÐ_Ð_ÐJ\Ð_Ð_Ð_Ø2 LÐ2Ð2Ø2 LÐ2Ð2ðð ð ð ð à+7ð ñ ô ñ €Kð Ðr%cóŒ—eZdZdZdZdZddeddfd„Zdefd„Z d e de efd „Z defd „Z d „ZdZdefd „Zdd„Zd„Zdd„ZdS)Ú ApproxBasezhProvide shared utilities for making approximate comparisons between numbers or sequences of numbers.NédFÚnan_okrcój—d}||_||_||_||_| ¦«dS)NT)r9ÚabsÚrelrGÚ _check_type)Úselfr9rJrIrGÚ__tracebackhide__s r#Ú__init__zApproxBase.__init__Ps<€Ø ÐØ ˆŒ ؈ŒØˆŒØˆŒ Ø ×ÒÑÔÐÐÐr%có—t‚©N©ÚNotImplementedError©rLs r#Ú__repr__zApproxBase.__repr__Xs€Ý!Ð!r%Ú other_sidecó—dd|›�d|›�gS)Nzcomparison failedz Obtained: z Expected: r5)rLrUs r#Ú _repr_comparezApproxBase._repr_compare[s%€à Ø %˜Ð %Ð %Ø ˜Ð Ð ð ð r%có`‡—tˆfd„‰ |¦«D¦«¦«S)Nc3óP•K—|] \}}|‰ |¦«kV—Œ!dSrP©Ú_approx_scalar)r6ÚaÚxrLs €r#ú z$ApproxBase.__eq__..csKøèè€ð ð Ù,0¨A¨qˆA�×$Ò$ QÑ'Ô'Ò 'ð ð ð ð ð ð r%)ÚallÚ_yield_comparisons©rLÚactuals` r#Ú__eq__zApproxBase.__eq__bsIø€Ýð ð ð ð Ø48×4KÒ4KÈFÑ4SÔ4Sð ñ ô ñ ô ð r%có$—d}td¦«‚)NTzVapprox() is not supported in a boolean context. Did you mean: `assert a == approx(b)`?)ÚAssertionError)rLrMs r#Ú__bool__zApproxBase.__bool__gs€Ø ÐÝØ eñ ô ð r%có—||k SrPr5ras r#Ú__ne__zApproxBase.__ne__ps€Ø˜d’NÐ#Ð#r%Ú ApproxScalarcó´—t|t¦«r"t||j|j|j¬¦«St ||j|j|j¬¦«S)N)rJrIrG)Ú isinstancerÚ ApproxDecimalrJrIrGri)rLr]s r#r[zApproxBase._approx_scalarssO€Ý �a�Ñ !Ô !ð TÝ  ¨¬°d´hÀtÄ{ÐSÑSÔSÐ SݘA 4¤8°´À$Ä+ÐNÑNÔNÐNr%có—t‚)zoYield all the pairs of numbers to be compared. This is used to implement the `__eq__` method. rQras r#r`zApproxBase._yield_comparisonsxs €õ "Ð!r%có—dS)z.Œs.øèè€ÐCÐC¸2Õ/°°2Ñ6Ô6ÐCÐCÐCÐCÐCÐCr%)rkr<ÚtupleÚtype)r~r]Úseq_types` r#r|r|ˆsVø€å�!•d�E�]Ñ#Ô#ðݘ‘7”7ˆØˆxÐCÐCÐCÐCÀÐCÑCÔCÑCÔCÐCàˆq�‰tŒtˆ r%cóV‡—eZdZdZdefd„Zdddeefd„Zdefˆfd„ Z d„Z ˆxZ S) Ú ApproxNumpyzHPerform approximate comparisons where the expected value is numpy array.rcóf—t|j|j ¦«¦«}d|›d�S)Nzapprox(ú))r|r[r9Útolist)rLÚ list_scalarss r#rTzApproxNumpy.__repr__”s:€Ý.Ø Ô  ¤×!5Ò!5Ñ!7Ô!7ñ ô ˆ ð+˜Ð*Ð*Ð*Ð*r%rUrcóꇇ‡—ddl}ddl}dttdttdfdtfd„Š|jj}t|j|j  ¦«¦«Š|‰jkrdd|›d ‰j›�gS|jj }|j }|j }g}|j d „|D¦«ŽD]Š} ‰‰| ¦«} ‰‰| ¦«} | | krjt| j| z ¦«} t|| ¦«}| d kr|j }n t|| t| ¦«z ¦«}| | ¦«Œ‹ˆˆˆfd „|D¦«} t!|j| ||||¦«S) NrÚ nested_listÚnd_index.rcó$—|}|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. r5)r‰rŠr!Úis r#Úget_value_from_nested_listz=ApproxNumpy._repr_compare..get_value_from_nested_listžs(€ð%ˆEØð !ð !�ؘaœ��؈Lr%z3Impossible to compare arrays with different shapes.zShapes: ú and c3ó4K—|]}t|¦«V—ŒdSrP)Úrange)r6rŒs r#r^z,ApproxNumpy._repr_compare..¹s(èè€Ð(JÐ(J°a­¨q©¬Ð(JÐ(JÐ(JÐ(JÐ(JÐ(Jr%çc ó�•—g|]B}t|¦«t‰‰|¦«¦«t‰‰|¦«¦«f‘ŒCSr5©rx)r6rAÚapprox_side_as_seqr�rUs €€€r#r;z-ApproxNumpy._repr_compare..Åsiø€ð ð ð ð õ �E‘ ” ÝÐ.Ð.¨z¸5ÑAÔAÑBÔBÝÐ.Ð.Ð/AÀ5ÑIÔIÑJÔJð ð ð ð r%)Ú itertoolsÚmathr rrr9Úshaper|r[r†ÚsizeÚinfÚproductrIr>ÚappendrC)rLrUr•r–Únp_array_shaper(r*r+r)rAÚ approx_valueÚ other_valueÚabs_diffr'r”r�s ` @@r#rWzApproxNumpy._repr_comparešsøøøø€ØÐÐÐØˆ ˆ ˆ ð Ý�cœð Ý.3µC¸°H¬oð å ð ð ð ð ðœÔ,ˆÝ4Ø Ô  ¤×!5Ò!5Ñ!7Ô!7ñ ô Ðð ˜ZÔ-Ò -Ð -àEØB˜>ÐBÐB° Ô0@ÐBÐBðð ð "œ]Ô/ÐØœ�yˆ Øœ�yˆ ؈ Ø&�YÔ&Ð(JÐ(J¸>Ð(JÑ(JÔ(JÐKð ,ð ,ˆEØ5Ð5Ð6HÈ%ÑPÔPˆLØ4Ð4°ZÀÑGÔGˆKؘ{Ò*Ð*ݘ|Ô4°{ÑBÑCÔC�Ý" <°Ñ:Ô:� Ø #Ò%Ð%Ø#'¤8�L�Lå#& |°XÅÀKÑ@PÔ@PÑ5PÑ#QÔ#Q�LØ×$Ò$ UÑ+Ô+Ð+øð ð ð ð ð ð ð 'ð  ñ ô ˆ õØ ŒMØ Ø Ø Ø Ø ñ  ô ð r%cóJ•—ddl}| |¦«s= | |¦«}n&#t$r}t d|›d�¦«|‚d}~wwxYw| |¦«s|j|jjkrdSt¦« |¦«S)Nrzcannot compare 'z' to numpy.ndarrayF) ÚnumpyÚisscalarÚasarrayÚ Exceptionrr—r9Úsuperrc)rLrbÚnpÚeÚ __class__s €r#rczApproxNumpy.__eq__ÖsÁø€ØÐÐÐð�{Š{˜6Ñ"Ô"ð Vð VØŸš FÑ+Ô+��øÝð Vð Vð VÝÐ M°6Ð MÐ MÐ MÑNÔNÐTUÐUøøøøð Vøøøð�{Š{˜6Ñ"Ô"ð  v¤|°t´}Ô7JÒ'JÐ'JØ�5å‰wŒw�~Š~˜fÑ%Ô%Ð%sœ2² A¼AÁAc#ó„K—ddl}| |¦«rG| |jj¦«D]%}||j| ¦«fV—Œ&dS| |jj¦«D]=}|| ¦«|j| ¦«fV—Œ>dS)Nr)r¡r¢Úndindexr9r—Úitem)rLrbr¦rŒs r#r`zApproxNumpy._yield_comparisonsæsßèè€ØÐÐÐð �;Š;�vÑ Ô ð @Ø—Z’Z ¤ Ô 3Ñ4Ô4ð 6ð 6�ؘdœm¨AÔ.×3Ò3Ñ5Ô5Ð5Ð5Ð5Ð5Ð5ð 6ð 6ð—Z’Z ¤ Ô 3Ñ4Ô4ð @ð @�ؘQ”i—n’nÑ&Ô&¨¬ °aÔ(8×(=Ò(=Ñ(?Ô(?Ð?Ð?Ð?Ð?Ð?ð @ð @r%) rqrrrsrtrxrTr rWrwrcr`Ú __classcell__©r¨s@r#rƒrƒ‘s¢ø€€€€€ØRÐRð+˜#ð+ð+ð+ð+ð : ¨ ð: °d¸3´ið: ð: ð: ð: ðx& ð&ð&ð&ð&ð&ð&ð @ð @ð @ð @ð @ð @ð @r%rƒcón‡—eZdZdZdefd„Zdeeefde efd„Z de fˆfd„ Z d„Z d d „ZˆxZS) Ú ApproxMappingzyPerform approximate comparisons where the expected value is a mapping with numeric values (the keys can be anything).rcót‡—d ˆfd„‰j ¦«D¦«¦«S)Nú approx({!r})cóB•—i|]\}}|‰ |¦«“ŒSr5rZ©r6ÚkÚvrLs €r#ú z*ApproxMapping.__repr__..ûs-ø€Ð IÐ IÐ I©4¨1¨aˆQ�×#Ò# AÑ&Ô&Ð IÐ IÐ Ir%)r r9ÚitemsrSs`r#rTzApproxMapping.__repr__ùs@ø€Ø×$Ò$Ø IÐ IÐ IÐ I°4´=×3FÒ3FÑ3HÔ3HÐ IÑ IÔ Iñ ô ð r%rUcóf‡‡‡ —ddl}ˆfd„‰j ¦«D¦«Š t‰ ¦«}|j }|j }g}t ‰  ¦«‰ ¦«¦«D]ˆ\\}}} || krzt|t|j| z ¦«¦«}|jdkr|j}n-t|t|j| z |jz ¦«¦«}|  |¦«Œ‰ˆ ˆfd„|D¦«} t‰j| ||||¦«S)NrcóB•—i|]\}}|‰ |¦«“ŒSr5rZr³s €r#r¶z/ApproxMapping._repr_compare..s:ø€ð ð ð Ù*.¨!¨QˆAˆt×"Ò" 1Ñ%Ô%ð ð ð r%r‘c󀕗g|]:}t|¦«t‰|¦«t‰|¦«f‘Œ;Sr5r“)r6ÚkeyÚapprox_side_as_maprUs €€r#r;z/ApproxMapping._repr_compare..sPø€ð ð ð àõ�‰XŒX•s˜: cœ?Ñ+Ô+­SÐ1CÀCÔ1HÑ-IÔ-IÐ Jð ð ð r%) r–r9r·r?r™ÚzipÚvaluesr>rIr›rC) rLrUr–r(r*r+r)Ú approx_keyr�ržr'r¼s `` @r#rWzApproxMapping._repr_compareþs˜øøø€Øˆ ˆ ˆ ð ð ð ð Ø26´-×2EÒ2EÑ2GÔ2Gð ñ ô Ðõ!Ð!3Ñ4Ô4ÐØœ�yˆ Øœ�yˆ ؈ Ý7:Ø × $Ò $Ñ &Ô &¨ ×(9Ò(9Ñ(;Ô(;ñ8 ô8 ð 1ð 1Ñ 3Ñ &ˆZ˜¨ ð˜{Ò*Ð*Ý"Ø ¥# lÔ&;¸kÑ&IÑ"JÔ"Jñ ô � ð Ô(¨CÒ/Ð/Ø#'¤8�L�Lå#&Ø$ÝØ)Ô2°[Ñ@Ø*Ô3ñ4ñôñ$ô$�Lð×$Ò$ ZÑ0Ô0Ð0øð ð ð ð ð à$ð ñ ô ˆ õ Ø ŒMØ Ø Ø Ø Ø ñ  ô ð r%có•— t| ¦«¦«t|j ¦«¦«krdSn#t$rYdSwxYwt ¦« |¦«S©NF)ÚsetÚkeysr9ÚAttributeErrorr¥rc©rLrbr¨s €r#rczApproxMapping.__eq__*s}ø€ð Ý�6—;’;‘=”=Ñ!Ô!¥S¨¬×);Ò);Ñ)=Ô)=Ñ%>Ô%>Ò>Ð>Ø�uð?øåð ð ð Ø�5�5ð øøøõ‰wŒw�~Š~˜fÑ%Ô%Ð%sƒA AÁ AÁAc#ópK—|j ¦«D]}|||j|fV—ŒdSrP)r9rÃ)rLrbr´s r#r`z ApproxMapping._yield_comparisons3sLèè€Ø”×#Ò#Ñ%Ô%ð .ð .ˆAؘ”)˜Tœ]¨1Ô-Ð-Ð -Ð -Ð -Ð -ð .ð .r%Nc ó—d}|j ¦«D]d\}}t|t|j¦«¦«r=d}t | ||t j|j¦«¦«¦«‚ŒedS)NTz[pytest.approx() does not support nested dictionaries: key={!r} value={!r} full mapping={})r9r·rkr€rr ÚpprintÚpformat)rLrMr»r!Úmsgs r#rKzApproxMapping._check_type7s‰€Ø ÐØœ-×-Ò-Ñ/Ô/ð Wð W‰JˆC�ݘ%¥ d¤mÑ!4Ô!4Ñ5Ô5ð WØt�Ý § ¢ ¨3°µv´~ÀdÄmÑ7TÔ7TÑ UÔ UÑVÔVÐVð Wð Wð Wr%rp)rqrrrsrtrxrTr ÚobjectÚfloatr rWrwrcr`rKr¬r­s@r#r¯r¯õsÄø€€€€€ð7ð7ð ˜#ð ð ð ð ð * ¨°¸° Ô(>ð* À4ÈÄ9ð* ð* ð* ð* ðX& ð&ð&ð&ð&ð&ð&ð.ð.ð.ðWðWðWðWðWðWðWðWr%r¯cój‡—eZdZdZdefd„Zdeedeefd„Z de fˆfd„ Z d„Z d d „Z ˆxZS) ÚApproxSequenceLikezRPerform approximate comparisons where the expected value is a sequence of numbers.rc󸇗t‰j¦«}|ttfvrt}d |ˆfd„‰jD¦«¦«¦«S)Nr±c3óB•K—|]}‰ |¦«V—ŒdSrPrZ)r6r]rLs €r#r^z.ApproxSequenceLike.__repr__..Gs1øèè€ÐCÐC°�T×(Ò(¨Ñ+Ô+ÐCÐCÐCÐCÐCÐCr%)r€r9rr<r )rLr�s` r#rTzApproxSequenceLike.__repr__Bsbø€Ý˜œ Ñ&Ô&ˆØ �E¥4˜=Ð (Ð (݈HØ×$Ò$Ø ˆHÐCÐCÐCÐC°T´]ÐCÑCÔCÑ CÔ Cñ ô ð r%rUc󜇇 —ddl}t|j¦«t‰¦«kr)ddt|j¦«›dt‰¦«›�gSt|j|j¦«Š t‰ ¦«}|j }|j }g}t t‰ ‰¦«¦«D]x\}\}} || krjt|j| z ¦«} t|| ¦«}| dkr|j}n t|| t| ¦«z ¦«}|  |¦«Œyˆ ˆfd„|D¦«} t|j| ||||¦«S)Nrz1Impossible to compare lists with different sizes.z Lengths: rŽr‘c󀕗g|]:}t|¦«t‰|¦«t‰|¦«f‘Œ;Sr5r“)r6rŒr¼rUs €€r#r;z4ApproxSequenceLike._repr_compare..esPø€ð ð ð àõ�‰VŒV•S˜ AœÑ'Ô'­Ð-?ÀÔ-BÑ)CÔ)CÐ Dð ð ð r%) r–r?r9r|r[r™Ú enumerater½rIr>r›rC) rLrUr–r(r*r+r)rŒr�ržrŸr'r¼s ` @r#rWz ApproxSequenceLike._repr_compareJs‘øø€Øˆ ˆ ˆ å ˆtŒ}Ñ Ô ¥ Z¡¤Ò 0Ð 0àCØF�C ¤ Ñ.Ô.ÐFÐFµS¸±_´_ÐFÐFðð õ 5°TÔ5HÈ$Ì-ÑXÔXÐå Ð!3Ñ4Ô4ÐØœ�yˆ Øœ�yˆ ؈ Ý.7Ý Ð" JÑ /Ô /ñ/ ô/ ð (ð (Ñ *ˆAÑ*� ˜kð˜{Ò*Ð*ݘ|Ô4°{ÑBÑCÔC�Ý" <°Ñ:Ô:� Ø #Ò%Ð%Ø#'¤8�L�Lå#& |°XÅÀKÑ@PÔ@PÑ5PÑ#QÔ#Q�LØ×$Ò$ QÑ'Ô'Ð'øð ð ð ð ð à"ð ñ ô ˆ õ Ø ŒMØ Ø Ø Ø Ø ñ  ô ð r%c󺕗 t|¦«t|j¦«krdSn#t$rYdSwxYwt¦« |¦«SrÁ)r?r9rr¥rcrÅs €r#rczApproxSequenceLike.__eq__sseø€ð Ý�6‰{Œ{�c $¤-Ñ0Ô0Ò0Ð0Ø�uð1øåð ð ð Ø�5�5ð øøøå‰wŒw�~Š~˜fÑ%Ô%Ð%s ƒ%+« 9¸9có,—t||j¦«SrP)r½r9ras r#r`z%ApproxSequenceLike._yield_comparisons{s€Ý�6˜4œ=Ñ)Ô)Ð)r%Nc óü—d}t|j¦«D]d\}}t|t|j¦«¦«r=d}t | ||t j|j¦«¦«¦«‚ŒedS)NTz]pytest.approx() does not support nested data structures: {!r} at index {} full sequence: {})rÓr9rkr€rr rÈrÉ)rLrMrAr]rÊs r#rKzApproxSequenceLike._check_type~s…€Ø ÐÝ! $¤-Ñ0Ô0ð Uð U‰HˆE�1ݘ!�T $¤-Ñ0Ô0Ñ1Ô1ð UØv�Ý § ¢ ¨1¨eµV´^ÀDÄMÑ5RÔ5RÑ SÔ SÑTÔTÐTð Uð Uð Ur%rp)rqrrrsrtrxrTrrÌr rWrwrcr`rKr¬r­s@r#rÎrÎ?s»ø€€€€€Ø\Ð\ð ˜#ð ð ð ð ð' ¨°¬ð' ¸DÀ¼Ið' ð' ð' ð' ðR& ð&ð&ð&ð&ð&ð&ð*ð*ð*ðUðUðUðUðUðUðUðUr%rÎcó‚—eZdZUdZdZeeefed<dZ eeefed<de fd„Z de fd„Z d Zed „¦«Zd S) rizLPerform approximate comparisons where the expected value is a single number.gê-�™—q=ÚDEFAULT_ABSOLUTE_TOLERANCEg�íµ ÷ư>ÚDEFAULT_RELATIVE_TOLERANCErcó’—t|jttf¦«r&t jt |j¦«¦«rt|j¦«S |jd›}t|jt¦«r*|jj rt j|j¦«s|dz }n#t$rd}YnwxYw|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°``. z.1eu ∠ ±180°z???u ± ) rkr9rrr–ÚisinfrIrxÚ toleranceÚimagÚ ValueError)rLÚvetted_tolerances r#rTzApproxScalar.__repr__Žsé€õ˜4œ=­7µGÐ*<Ñ=Ô=ð &Å$Ä*Ý �” Ñ Ô ñC ôC ð &õ�t”}Ñ%Ô%Ð %ð %Ø"&¤.Ð6Ð6Ð å˜4œ=­'Ñ2Ô2ð 3à”MÔ&ð 3õœ  4¤>Ñ2Ô2ð 3ð ! NÑ2Ð øøÝð %ð %ð %Ø$Ð Ð Ð ð %øøøð”-Ð7Ð7Ð%5Ð7Ð7Ð7sÁA B+Â+ B:Â9B:có.‡—t|¦«}|� tˆfd„|jD¦«¦«S|‰jkrdSt ‰jt t f¦«rt |t t f¦«sdStjt‰j¦«¦«r(‰j o tjt|¦«¦«Stj t‰j¦«¦«rdSt‰j|z ¦«‰j k}|S)ziReturn whether the given value is equal to the expected value within the pre-specified tolerance.Nc3óB•K—|]}‰ |¦«V—ŒdSrP)rc)r6r\rLs €r#r^z&ApproxScalar.__eq__..²s-øèè€Ð<Ð<¨!�t—{’{ 1‘~”~Ð<Ð<Ð<Ð<Ð<Ð.set_defaultßs€Ø˜ �1�1¨7Ð 2r%rz&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.) rIrØrÞr–rärJrÙr9r>)rLréÚabsolute_toleranceÚrelative_tolerances r#rÜzApproxScalar.tolerance×s$€ð 3ð 3ð 3ð )˜[¨¬°4Ô3RÑSÔSÐà  Ò !Ð !ÝØMÐ9KÐMÐMñôð õ Œ:Ð(Ñ )Ô )ð AÝÐ?Ñ@Ô@Ð @ð Œ8Ð ØŒxÐ#Ø)Ð)ð)˜[Ø ŒH�dÔ5ñ ô å �” Ñ Ô ñÐð  Ò !Ð !ÝØMÐ9KÐMÐMñôð õ Œ:Ð(Ñ )Ô )ð AÝÐ?Ñ@Ô@Ð @õÐ%Ð'9Ñ:Ô:Ð:r%)rqrrrsrtrØrrÌrÚ__annotations__rÙrxrTrwrcryÚpropertyrÜr5r%r#riri†s©€€€€€€ØVÐVð9>Р e¨W nÔ 5Ð=Ð=Ñ=Ø8<Р e¨W nÔ 5Ð<Ð<Ñ<ð8˜#ð8ð8ð8ð8ð:' ð'ð'ð'ð'ðT€Hà ð,;ð,;ñ„Xð,;ð,;ð,;r%ricó>—eZdZdZed¦«Zed¦«ZdS)rlzFPerform approximate comparisons where the expected value is a Decimal.z1e-12z1e-6N)rqrrrsrtrrØrÙr5r%r#rlrls4€€€€€ØPÐPà!( ¨Ñ!1Ô!1ÐØ!( ¨¡¤ÐÐÐr%rlFrGcó —d}t|t¦«rt}n×t|t¦«rt}nºt |¦«rt |¦«}t}n”t|d¦«r2t|t¦«rt|t¦«st}nRt|t¦«r6t|t¦«s!dt|¦«›�}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 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 `_ from the `re_assert package `_. .. 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``. TÚ __getitem__z:pytest.approx() only supports ordered sequences, but got: )rkrrlr r¯Ú_is_numpy_arrayrârƒÚhasattrrrrÎrÚreprrri)r9rJrIrGrMÚclsrÊs r#Úapproxrõs€ðLÐå�(�GÑ$Ô$ðÝ -ˆˆÝ �H�gÑ &Ô &ð݈ˆÝ ˜Ñ "Ô "ðÝ" 8Ñ,Ô,ˆÝˆˆå�˜-Ñ(Ô(ðå �x¥Ñ 'Ô 'ðõ˜8¥\Ñ2Ô2ð õ !ˆˆå�8�ZÑ(Ô(ðõ˜8¥\Ñ2Ô2ðð \Í4ÐPXÉ>Ì>Ð[Ð[ˆÝ˜‰nŒnÐåˆà ˆ3ˆx˜˜c 6Ñ *Ô *Ð*r%Úobjcó$—t|¦«duS)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%rcó —ddl}|j d¦«}|�c| |¦«rdSt ||j¦«r|St |d¦«st dd¦«r| |¦«SdS)zˆ Return an ndarray if the given object is implicitly convertible to ndarray, and numpy is already imported, otherwise None. rNr¡Ú __array__röÚ__array_interface__)ÚsysÚmodulesÚgetr¢rkrròr£)rörûr¦s r#rârâùs�€ð €J€J€JàŒk�oŠo˜gÑ&Ô&€BØ €~à �;Š;�sÑ Ô ð #Ø�4Ý ˜˜RœZÑ (Ô (ð #؈JÝ �S˜+Ñ &Ô &ð #­'°%Ð9NÑ*OÔ*Oð #Ø—:’:˜c‘?”?Ð "Ø ˆ4r%ÚE)Úbound.)ÚmatchÚexpected_exceptionrzRaisesContext[E]có—dSrPr5)rrs r#Úraisesrs €ð €Cr%ÚfuncÚargsÚkwargscó—dSrPr5)rrrrs r#rrs €ð€Cr%cóf—d}|std|›d�¦«‚t|t¦«r|f}n|}|D]€}t|t¦«rt|t¦«sTd}t|t¦«r|jnt|¦«j}t | |¦«¦«‚Œ�d|›�}|sd| dd¦«} |r;d}|d   t|¦«¦«z }|d z }t |¦«‚t||| ¦«S|d } t| ¦«s"t | ›d t| ¦«›d �¦«‚ | |dd…i|¤Žn6#|$r.} tjj | ¦«cYd} ~ Sd} ~ wwxYwt#|¦«dS)a8Assert that a code block/function call raises an exception. :param typing.Type[E] | typing.Tuple[typing.Type[E], ...] expected_exception: The expected exception type, or a tuple if one of multiple possible exception types are expected. :kwparam str | typing.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 using :func:`re.search`. To match a literal string that may contain :ref:`special characters `, the pattern can first be escaped with :func:`re.escape`. (This is only used when :py:func:`pytest.raises` is used as a context manager, and passed through to the function otherwise. When using :py:func:`pytest.raises` as a function, you can use: ``pytest.raises(Exc, func, match="passed on").match("my pattern")``.) .. currentmodule:: _pytest._code Use ``pytest.raises`` as a context manager, which will capture the exception of the given type:: >>> import pytest >>> with pytest.raises(ZeroDivisionError): ... 1/0 If the code block does not raise the expected exception (``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 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" .. 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. **Legacy form** It is possible to specify a callable by passing a to-be-called lambda:: >>> raises(ZeroDivisionError, lambda: 1/0) or you can specify an arbitrary callable with arguments:: >>> def f(x): return 1/x ... >>> raises(ZeroDivisionError, f, 0) >>> raises(ZeroDivisionError, f, x=0) 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 `. 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 {}zDID NOT RAISE rNz6Unexpected keyword arguments passed to pytest.raises: z, z" Use context-manager form instead?rz object (type: z) must be callabler0)rÞrkr€Ú issubclassÚ BaseExceptionrqrr ÚpopÚjoinÚsortedÚ RaisesContextÚcallableÚ_pytestÚ_codeÚ ExceptionInfoÚfrom_exceptionr) rrrrMÚexpected_exceptionsÚexcrÊÚnot_aÚmessagerrr§s r#rr$s€ðdÐà ð Ýð OÐRdð Oð Oð Oñ ô ð õ Ð$¥dÑ+Ô+ð1Ø4FÐ3HÐÐà0ÐØ"ð/ð/ˆÝ˜#�tÑ$Ô$ð /­J°s½MÑ,JÔ,Jð /ØKˆCÝ$.¨sµDÑ$9Ô$9ÐQ�C”L�L½tÀC¹y¼yÔ?QˆEݘCŸJšJ uÑ-Ô-Ñ.Ô.Ð .ð /ð 4Ð1Ð3Ð3€Gà ðAØ4:·J²J¸wÈÑ4MÔ4MˆØ ð !ØJˆCØ �4—9’9�V F™^œ^Ñ,Ô,Ñ ,ˆCØ Ð8Ñ 8ˆCݘC‘.”.Ð ÝÐ/°¸%Ñ@Ô@Ð@à�AŒwˆÝ˜‰~Œ~ð VݘtÐTÐTµd¸4±j´jÐTÐTÐTÑUÔUÐ Uð AØ ˆD�$�q�r�r”(Ð %˜fÐ %Ð %Ð %Ð %øØ!ð Að Að AÝ”=Ô.×=Ò=¸aÑ@Ô@Ð @Ð @Ð @Ð @Ð @Ð @øøøøð Aøøøåˆ�M„M€M€M€MsÅE,Å,FÅ1#FÆFÆFc óþ—eZdZ d deeeeeedffdedeeee efddfd„Z de j j efd„Zd eeed eed eedefd „ZdS)rNr.rÚ match_exprrcó>—||_||_||_d|_dSrP)rrrÚexcinfo)rLrrrs r#rNzRaisesContext.__init__Ãs%€ð #5ˆÔ؈Œ Ø$ˆŒØAEˆŒ ˆ ˆ r%có`—tjj ¦«|_|jSrP)rrrÚ for_laterrrSs r#Ú __enter__zRaisesContext.__enter__Îs"€Ý”}Ô2×<Ò<Ñ>Ô>ˆŒ ØŒ|Ðr%Úexc_typeÚexc_valÚexc_tbcól—d}|€t|j¦«|j€J‚t||j¦«sdSt t ttttf|||f¦«}|j  |¦«|j �|j  |j ¦«dS)NTF) rrrr rr rrrþrÚ fill_unfilledrr)rLrr r!rMÚexc_infos r#Ú__exit__zRaisesContext.__exit__Òs©€ð !ÐØ Ð Ý �”Ñ Ô Ð ØŒ|Ð'Ð'Ð'ݘ( DÔ$;Ñ<Ô<ð Ø�5å��d¥1œg¥q­-Ð7Ô8¸8ÀWÈfÐ:UÑVÔVˆØ Œ ×"Ò" 8Ñ,Ô,Ð,Ø Œ?Ð &Ø ŒL× Ò ˜tœÑ /Ô /Ð /؈tr%rP)rqrrrsrrrþrrxrrrNrrrrr rrwr%r5r%r#rrÁs€€€€€ð :>ð Fð Fà! $ q¤'¨5°°a´¸#°Ô+>Ð">Ô?ð Fðð Fð˜U 3¨°¬ Ð#4Ô5Ô6ð Fð ð Fð Fð Fð Fð˜7œ=Ô6°qÔ9ðððððà˜4  Ô.Ô/ðð˜-Ô(ðð˜Ô'ð ð ð ðððððr%rro)=r–rÈÚcollections.abcrrÚdecimalrÚnumbersrÚtypesrÚtypingrr r r r r rrrrrrrrr¡rÚ _pytest._coderÚ_pytest.compatrrrÚ_pytest.outcomesrrxrr$rËÚintrÌrCrEr|rƒr¯rÎrirlrwrõrñrâr rþrrrr¤rr5r%r#úr/s ðØ € € € Ø € € € Ø&Ð&Ð&Ð&Ð&Ð&Ø!Ð!Ð!Ð!Ð!Ð!ØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØ!Ð!Ð!Ð!Ð!Ð!ØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØ Ð Ð Ð Ð Ð ØÐÐÐÐÐØÐÐÐÐÐàðØÐÐÐÐÐðÐÐÐØ Ð Ð Ð Ð Ð Ø'Ð'Ð'Ð'Ð'Ð'Ø#Ð#Ð#Ð#Ð#Ð#Ø!Ð!Ð!Ð!Ð!Ð!ð x°¤}ð¸ðððððØðà˜5  c¨3 Ô/Ô0ðððð˜FÔ#ð ð ð ð ð ð ˆ#„Yððððð:8Kð8Kð8Kð8Kð8Kñ8Kô8Kð8Kð@ððða@ða@ða@ða@ða@�*ña@ôa@ða@ðHGWðGWðGWðGWðGW�JñGWôGWðGWðTDUðDUðDUðDUðDU˜ñDUôDUðDUðN~;ð~;ð~;ð~;ð~;�:ñ~;ô~;ð~;ðB1ð1ð1ð1ð1�Lñ1ô1ð1ð`+ð`+°ð`+À*ð`+ð`+ð`+ð`+ðF,˜ð, Dð,ð,ð,ð,ð˜ð H¨YÔ$7ððððð* €GˆC�}Ð%Ñ%Ô%€ð ð14ðððؘd 1œg u¨T°!¬W°c¨\Ô':Ð:Ô;ðð �E˜#˜w sœ|Ð+Ô,Ô -ððð ððñ „ðð ðؘd 1œg u¨T°!¬W°c¨\Ô':Ð:Ô;ðà �3˜�8Ô ðð ððð ð  „]Ô  Ô#ð ððñ „ððVؘd 1œg u¨T°!¬W°c¨\Ô':Ð:Ô;ðVØDGðVØSVðVà Ð ˜wœ}Ô:¸1Ô=Ð =Ô>ðVðVðVðVðt”>€Ôðð!ð!ð!ð!ð!�N 7¤=Ô#>¸qÔ#AÔBñ!ô!ñ„ð!ð!ð!r%