o (]^¶ ã@sÖddlmZddlmZddlmZmZmZddlm Z ddl m Z ddl m Z dZdZd ZeeefZd ed efd d „ZGdd„de eƒZed eded e efdd„ƒZed eded e efdd„ƒZdd„ZdS)é)ÚDecimal)Úfabs)ÚAnyÚUnionÚoverload)Ú BaseMatcher)Ú Description)ÚMatcherzJon ReidzCopyright 2011 hamcrest.orgzBSD, see License.txtÚvalueÚreturncCsNt|tttfƒr dSz t|ƒddd}WdSty!YdSYdS)zKConfirm that 'value' can be treated numerically; duck-test accordingly TréF)Ú isinstanceÚfloatÚcomplexÚintrÚArithmeticError)r Ú_©rúC/usr/lib/python3/dist-packages/hamcrest/library/number/iscloseto.pyÚ isnumerics rcsveZdZdededdfdd„Zdedefdd „Zdedefd d „Zded e ddf‡fd d„ Z de ddfdd„Z ‡Z S)Ú IsCloseTor Údeltar NcCs0t|ƒstdƒ‚t|ƒstdƒ‚||_||_dS)NzIsCloseTo value must be numericzIsCloseTo delta must be numeric)rÚ TypeErrorr r)Úselfr rrrrÚ__init__ s  zIsCloseTo.__init__ÚitemcCst|ƒsdS| |¡|jkS)NF)rÚ_diffr©rrrrrÚ_matches)szIsCloseTo._matchescCst||jƒS©N)rr rrrrr.szIsCloseTo._diffÚmismatch_descriptioncsBt|ƒstt|ƒ ||¡dS| |¡}| |¡ d¡ |¡dS)Nz differed by )rÚsuperrÚdescribe_mismatchrÚappend_description_ofÚ append_text)rrr Ú actual_delta©Ú __class__rrr"2s  ÿ zIsCloseTo.describe_mismatchÚ descriptioncCs$| d¡ |j¡ d¡ |j¡dS)Nza numeric value within z of )r$r#rr )rr(rrrÚ describe_to;s ÿzIsCloseTo.describe_to) Ú__name__Ú __module__Ú __qualname__ÚNumberrÚboolrrrrr"r)Ú __classcell__rrr&rrs   rrcCódSrr©r rrrrÚclose_toAór2cCr0rrr1rrrr2Fr3cCs t||ƒS)a²Matches if object is a number close to a given value, within a given delta. :param value: The value to compare against as the expected value. :param delta: The maximum delta between the values for which the numbers are considered close. This matcher compares the evaluated object against ``value`` to see if the difference is within a positive ``delta``. Example:: close_to(3.0, 0.25) )rr1rrrr2Ks N)ÚdecimalrÚmathrÚtypingrrrÚhamcrest.core.base_matcherrÚhamcrest.core.descriptionrÚhamcrest.core.matcherr Ú __author__Ú __copyright__Ú __license__rr-r.rrr2rrrrÚs"     "