
    dafe                    \   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZmZmZmZmZ ddlmZmZmZmZmZmZ ddlmZ ddlmZ ddlmZ ddlZddlZddlZej<                  dk(  r ed	        ed
dg      Z ed
dg      Z ddl!Z" eddg      Z#e ejH                  d
<    eddg      Z%eejH                  d
<   ee#e e%iZ&e"ejH                  d
<    ejN                  ed      Z(eer. e)ejU                         jV                  jY                               nde  e)e jU                         jV                  jY                               iZ-eereej\                  ej^                  ej`                  ejb                  ejd                  ejf                  ejh                  ejj                  ejl                  g	nde e j\                  e j^                  e j`                  e jb                  e jd                  e jf                  e jh                  e jj                  e jl                  g	iZ7d Z8e jr                  Z9e jt                  Z:e jv                  Z;e jx                  Z<e jz                  Z=e j|                  Z>e j~                  Z?e j                  Z@e9e:e;e<e=e>e?e@gZAeerejU                         j                         nde e jU                         j                         iZBd ZCdZDeEdk(  rej                  d   ZGneHZGej                  j                  eG      xs ej                  ZLeLej                  z   eDz   ej                  z   ZNej                  j                  eN       aPdZQ eRed      rdndZS ejN                  eSd      ZT ej                  eSd      ZV G d d      ZW G d d      ZXe( G d deXej                               ZZ G d d eXej                        Z[ G d! d"      Z\e( G d# d$e\ej                               Z] G d% d&e\ej                        Z^ G d' d(      Z_e( G d) d*e_ej                               Z` G d+ d,e_ej                        Za G d- d.      Zbe( G d/ d0ebej                               Zc G d1 d2ebej                        Zdd3 Zed4 Zf ej                          G d5 d6             Zhe( G d7 d8ehej                               Zi G d9 d:ehej                        Zj G d; d<      Zke( G d= d>ekej                               Zl G d? d@ekej                        Zm G dA dB      Zne( G dC dDenej                               Zo G dE dFenej                        Zp G dG dH      Zqe( G dI dJeqej                               Zr G dK dLeqej                        Zs G dM dN      Zte( G dO dPetej                               Zu G dQ dRetej                        Zv G dS dT      Zwe( G dU dVewej                               Zx G dW dXewej                        Zy G dY dZ      Zze( G d[ d\ezej                               Z{ G d] d^ezej                        Z| G d_ d`      Z}e( G da dbe}ej                               Z~ G dc dde}ej                        Z G de df      Ze( G dg dheej                               Z G di djeej                        ZeVe( G dk dlej                                      Z G dm dn      Ze( G do dpeej                               Z G dq dreej                        Z G ds dtej                        Z G du dvej                        Z G dw dxej                        Ze( G dy dzej                               Zee( G d{ d|ej                                      Zd} Zd~ Zd ZdadadadaddZeEdk(  rddlZ ej*                  d      Zej/                  dddd       ej/                  dddd       ej1                         \  ZZej6                  r edd       yer eddeej8                         y edd       yy)ab  
These are the test cases for the Decimal module.

There are two groups of tests, Arithmetic and Behaviour. The former test
the Decimal arithmetic using the tests provided by Mike Cowlishaw. The latter
test the pythonic behaviour according to PEP 327.

Cowlishaw's tests can be downloaded from:

   http://speleotrove.com/decimal/dectest.zip

This test module can be called from command line with one parameter (Arithmetic
or Behaviour) to test each part, or without parameter to test both parts. If
you're working through IDLE, you can import this test module and call test()
with the corresponding argument.
    N)is_resource_enabledrequires_IEEE_754requires_docstringsrequires_legacy_unicode_capicheck_sanitizer)
TestFailedrun_with_localecpython_onlydarwin_malloc_err_warningis_emscriptenskip_on_s390x)import_fresh_module)threading_helper)warnings_helperdarwintest_decimaldecimal_decimal)fresh)blocked	fractionsztest requires C versionc                 h    t        ||      | j                  t        fdD                     y )Nc              3   <   K   | ]  }|v r|   n|      y wN ).0sdexpecteds     ,/root/Python-3.12.4/Lib/test/test_decimal.py	<genexpr>z!assert_signals.<locals>.<genexpr>V   s&     FqqH}qtad(:Fs   )getattr
assertTrueall)clscontextattrr   r   s      `@r    assert_signalsr(   T   s&    ANN3FAFFG    c                     | sy | j                  dt        t        j                  t        |    d            }| j                  |       y )N	   r   )precroundingtraps)ContextROUND_HALF_EVENdictfromkeysSignals
setcontext)mDefaultTestContexts     r    initr7   m   s@    ft}}WQZ/K #  LL#$r)   decimaltestdata__main__F
DecClampedTz.test requires build with -DEXTRA_FUNCTIONALITYztest requires regular buildc                   X    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zy)IBMTestCasesz?Class which tests the Decimal class against the IBM test cases.c                 h   | j                   j                         | _        | j                   j                         | _        dg| _        t        g d      | _        | j                   t        k(  r| j                  j                  d       | j                  j                  d       | j                  j                  d       | j                  j                  d       | j                  j                  d       | j                  j                  d       | j                  j                  d	       | j                  j                  d
       | j                  | j                  | j                  | j                  | j                  d| _        i ddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-i d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdS| _        t         t"        t$        t&        t(        t*        t,        t.        dT| _        | j                   j2                  | j                   j4                  | j                   j6                  | j                   j4                  | j                   j4                  | j                   j8                  | j                   j4                  | j                   j4                  | j                   j:                  | j                   j<                  | j                   j>                  | j                   j@                  dU| _!        dV| _"        y )WN#)scbx164scbx165expx901expx902expx903expx905lnx901lnx902lnx903lnx905logx901logx902logx903logx905powx1183powx1184powx4001powx4002powx4003powx4005powx4008powx4010powx4012powx4014pwsx803pwsx805powx4302powx4303powx4342powx4343pwmx325pwmx326)	precisionr-   maxexponentminexponentclampandlogical_andapply_applyclassnumber_class
comparesigcompare_signalcomparetotalcompare_totalcomparetotmagcompare_total_magcopycopy_decimalcopyabscopy_abs
copynegatecopy_negatecopysign	copy_sign	divideint
divide_intinvertlogical_invertiscanonicalis_canonicalisfinite	is_finite
isinfiniteis_infiniteisnanis_nanisnormal	is_normalisqnanis_qnanissigned	is_signedissnanis_snanissubnormalis_subnormaliszerois_zeromaxmagmax_magminmagmin_mag	nextminus
next_minusnextplus	next_plus
nexttowardnext_towardor
logical_orreduce	normalizeremaindernearremainder_nearsamequantumsame_quantum
squarerootsqrttoengto_eng_string
tointegralto_integral_valueto_integral_exactto_sci_stringlogical_xor)tointegralxtoscixor)ceilingdownfloor	half_down	half_evenhalf_upup05up)clampedconversion_syntaxdivision_by_zerodivision_impossibledivision_undefinedinexactinvalid_contextinvalid_operationoverflowrounded	subnormal	underflow)r|   r~   r   r   r   r   r   r   r   r   r   )#r   r/   r&   readcontextignore_listsetskipped_test_idsCaddchange_precisionchange_rounding_methodchange_max_exponentchange_min_exponentchange_clamp
ChangeDictNameAdapterROUND_CEILING
ROUND_DOWNROUND_FLOORROUND_HALF_DOWNr0   ROUND_HALF_UPROUND_UP
ROUND_05UPRoundingDictClampedInvalidOperationDivisionByZeroInexactOverflowRounded	Subnormal	Underflow
ErrorNamesLogicalFunctionsselfs    r    setUpzIBMTestCases.setUp   s   ||++-<<//15 !$ "% "!H <<1!!%%i0!!%%i0!!%%j1!!%%j1!!%%j1!!%%j1!!%%i0!!%%i0 *.)>)>(,(C(C+/+C+C+/+C+C%)%6%6	8$1E- $1#H$1#N$1 ))9$1 +?	$1
 ,,?$1 #>$1 &j$1 )$1 '{$1 ($1 %%5$1 *.$1 '{$1 )$1 $H$1  '{!$1" %Y#$1$ '{%$1& %Y'$1( *.)$1* %Y+$1, %Y-$1. %Y/$10 (1$12 '{3$14 )5$16 !7$18 %[9$1: ,,<;$1< *.=$1> )?$1@ $OA$1B ))<C$1D +>$3"/I$1N *7&0'2+:+:)6$,&02 (,||';';151N1N040K0K37<<3P3P26,,2O2O'+||';';/3||/L/L151N1N(,(=(='+||';';)-)?)?)-)?)?A
!1r)   c                 j   | j                   t        k(  r| j                   j                  dk(  rl| j                  j	                  d       | j                  j                  d       | j                  j                  d       | j                  j                  |      S | j                   j                  ||      S )a2  Work around the limitations of the 32-bit _decimal version. The
           guaranteed maximum values for prec, Emax etc. are 425000000,
           but higher values usually work, except for rare corner cases.
           In particular, all of the IBM tests pass with maximum values
           of 1070000000.@Ti?i9)	r   r   MAX_EMAXr   _unsafe_setprec_unsafe_setemax_unsafe_setemincreate_decimalDecimal)r   vr&   s      r    read_unlimitedzIBMTestCases.read_unlimited  s     <<1!6!6)!C,,Z8,,Z8,,[9##22155<<''733r)   c                    t         rt        j                  t        |d      5 }|D ]6  }|j	                  dd      j	                  dd      }	 | j                  |      }8 	 d d d        y # | j                  j                  $ r8}| j                  d|j                  j                  z   dz   |z          Y d }~d }~ww xY w# 1 sw Y   y xY w)Nutf-8)encodingz
 
zException "z" raised on line )skip_expectedunittestSkipTestopenreplace	eval_liner   DecimalExceptionfail	__class____name__)r   fileflinet	exceptions         r    	eval_filezIBMTestCases.eval_file(  s    ###$) 	eQ e||FB/77bAet,A	e	e 	e ||44 eIImI,?,?,H,HHK^^_ccdde	e 	es5   (B>A*B>*B;.B61B>6B;;B>>Cc                    |j                  d      dk\  rf|d d dk7  r^|j                  d      sM|j                  d      d   dz   |j                  d      d   j                  d      d   z   j                         }n"|j                  d      d   j                         }| j                  D ]  }|j                  |      dk\  s y  |sy d|v r| j                  |      S | j                  |      S )	Nz -> r      --z  --->   :)find
startswithsplitstripr   eval_directiveeval_equation)r   r   ignores      r    r   zIBMTestCases.eval_line7  s    66&>Q1Ra5D=f9Mq!D(q!''-a0127%'  a &&(A&& 	Fvvf~"	 AX&&q))%%a((r)   c                     d |j                  d      D        \  }}|dk(  r| j                  |   }n	 t        |      }| j                  j                  |d       } ||       y # t        $ r Y 1w xY w)Nc              3   X   K   | ]"  }|j                         j                          $ y wr   )r  lower)r   xs     r    r!   z.IBMTestCases.eval_directive.<locals>.<genexpr>J  s     @a	)@s   (*r  r-   c                       y r   r   )argss    r    <lambda>z-IBMTestCases.eval_directive.<locals>.<lambda>S  s    r)   )r
  r   int
ValueErrorr   get)r   r   functvalues       r    r  zIBMTestCases.eval_directiveI  sr    @1773<@uJ%%e,EE
 ##E,>@e	  s   A# #	A/.A/c                 v   t         st        j                         dk  ry | j                  j                          	 |j	                  d      }|d   j                         j	                         }|d   }t        rt        d|d       |d   j                         }|dd  }|d   j                         j	                         }|d   }|dd  }d	 }	|| j                  v ry | j                  j!                  ||      }
|
d
k(  ry t#        | j                  |
      }g }d}d}|D cg c]  }| j$                  |j                            ! }}t&        | j                     D ]  }d| j                  j(                  |<    |D ]  }d| j                  j(                  |<    t+        |      D ]  \  }}|j-                  d      dz  dk(  rd|z
  }|r	|dz   |z   }.||z   }d} |	|      }|
dv rt.        rr|D ]m  }d| j                  j(                  |<   	  || j                  j1                  |             | j3                  d|d|       d| j                  j(                  |<   o | j                  j1                  |      }n| j5                  || j                        }|j7                  |         |	|      }t.        r|
dvr|D ]Q  }d| j                  j(                  |<   	  ||  | j3                  d|d|       d| j                  j(                  |<   S t8        | j                     D cg c]	  }||v s| }}|D ]8  }d| j                  j(                  |<   	  ||  | j3                  d|d|       : |D ]  }d| j                  j(                  |<    t        rt        d| j                         	 t=         ||       }|
| j>                  v rt=        tA        tC        |                  }| jE                         }|jG                  tH               |jG                  tH               | jK                  |d|z   dz   |z          | jK                  ||d|z   dz   t=        |      z          y # t        t        t        f$ r | j                  j                  w xY wc c}w # |$ r Y `t&        | j                     $ r&}| j3                  d|d|d|d       Y d }~d }~ww xY w# |$ r Y t&        | j                     $ r&}| j3                  d|d|d|d       Y d }~(d }~ww xY wc c}w # |$ r Y t&        | j                     $ r.}| j3                  dt;        |      d|d|       Y d }~9d }~ww xY w# t&        | j                     $ r"}| j3                  d|d|       Y d }~d }~w t        d|        xY w)Ng?r  r   zTest  )endr  r  c                     | j                  dd      j                  dd      } | j                  dd      j                  dd      } | j                  dd      j                  dd      } | S )Nz''SingleQuotez""DoubleQuote'r   ")r   )vals    r    	FixQuotesz-IBMTestCases.eval_equation.<locals>.FixQuotesj  s^    ++dM2::4OC++c2&..sB7C++mS199-MCJr)   rescaler   r!  )r   r   zDid not raise z in zRaised z when z	 disabledz; expected r  zERROR:keyzIncorrect answer for z -- got zIncorrect flags set in )&TEST_ALLrandomr&   clear_flagsr
  r  DEBUGprintr  	TypeErrorAttributeError
IndexErrorr   r   r   r   r  r"   r   r3   r.   	enumeratecountEXTENDEDERRORTESTr   r   r   appendOrderedSignalstypestrr   r  evalgetexceptionssortreprassertEqual)r   r   SidesLidr  valstempans
exceptionsr$  fnamevalsconglomeratequoter  theirexceptionsr   ir#  r   erroreordered_errorsresultmyexceptionss                            r    r  zIBMTestCases.eval_equationV  s   FMMOd2  "	0GGDMEa &&(A1Bgrs+aDJJLEuHa &&(AA$C12J	 &&&  $$UE2Ie,?IJ!4??17795JJ . 	.I,-DLLy)	.( 	.I,-DLLy)	.) 	FAsyy~!Q&E	+c1C7"S(!#A::$!0 645**51M!$,,"="=a"@A !II%&KL45**516 LL//2''4<<8KKN7	: n.P!P( .,-""5)E4L II%CD,-""5). *8)E^AoI]a^N^' 
E,-""5)E4L II%CD
E ( .,-""5). $%	&F---Sf./ ))+d#&014zAFJ	L 	'!+j83|;LL	NW >:6 	0,,///	0$ K,  % ! &t||4 5 II'(!U'4 5 55$  t||, -II !U, - -- _
  t||, 3II#Aw52 3 33  t||$ 	6II5!455	(As   BQ! $R!RS 	T *T T%*9U3 !+RSS1SST"T7TT%U0-U0#U++U03V8	V&&V8c                     t         | j                     D cg c]  }| j                  j                  |   s|  c}S c c}w r   )r3   r   r&   flags)r   rI  s     r    r8  zIBMTestCases.getexceptions  s0    "4<<0JaDLL4F4Fq4IJJJs   <<c                     | j                   t        k(  r5| j                   j                  dk(  r| j                  j	                  |       y || j                  _        y Nr   )r   r   MAX_PRECr&   r   r,   )r   r,   s     r    r   zIBMTestCases.change_precision  s=    <<1!6!6)!CLL((. $DLLr)   c                 &    || j                   _        y r   )r&   r-   )r   r-   s     r    r   z#IBMTestCases.change_rounding_method  s     (r)   c                     | j                   t        k(  r5| j                   j                  dk(  r| j                  j	                  |       y || j                  _        y rP  )r   r   rQ  r&   r   Eminr   exps     r    r   z IBMTestCases.change_min_exponent  =    <<1!6!6)!CLL((- #DLLr)   c                     | j                   t        k(  r5| j                   j                  dk(  r| j                  j	                  |       y || j                  _        y rP  )r   r   rQ  r&   r   EmaxrU  s     r    r   z IBMTestCases.change_max_exponent  rW  r)   c                 &    || j                   _        y r   )r&   rb   )r   rb   s     r    r   zIBMTestCases.change_clamp  s    "r)   N)r   
__module____qualname____doc__r   r   r  r   r  r  r8  r   r   r   r   r   r   r)   r    r<   r<      sH    IK1Z4e)$~N@K%
)$
$
#r)   r<   c                       e Zd ZdZd Zd Zd Zd Ze e	        e
j                  e      d                      Zd Zd	 Zd
 Zd Zed        Zd Zd Zd Zy)ExplicitConstructionTestz6Unit tests for Explicit Construction cases of Decimal.c                 j    | j                   j                  }| j                   |        |d             y )N0r   r   r;  r   r   s     r    test_explicit_emptyz,ExplicitConstructionTest.test_explicit_empty  s'    ,,&&GCL1r)   c                 ^    | j                   j                  }| j                  t        |d        y r   )r   r   assertRaisesr-  rc  s     r    test_explicit_from_Nonez0ExplicitConstructionTest.test_explicit_from_None  s#    ,,&&)Wd3r)   c           	         | j                   j                  } |d      }| j                  t        |      d        |d      }| j                  t        |      d        |d      }| j                  t        |      d        |d      }| j                  t        |      d       t	        dd	      D ]Q  }d
D ]J  }t	        dd      D ]9  }|d|z  |z   z  } ||      }| j                  t        |      t        |             ; L S y )N-   45{e	500000123-45r   ra      r     r  )r   r   r;  r6  range)r   r   r   nsignr  rG  s          r    test_explicit_from_intz/ExplicitConstructionTest.test_explicit_from_int  s    ,,&& BKQ& IQ- CLQ' AJQ% q" 	5A 5r1 5A1q)A
A$$SVSV455	5r)   c           
         | j                   j                  }| j                   j                  }| j                   j                  }| j	                  t         |d            d       | j	                  t         |d            d       | j	                  t         |d            d       | j	                  t         |d            d       | j	                  t         |d            d       | j	                  t         |d            d	       | j	                  t         |d
            d       | j	                  t         |d            d       | j	                  t         |d            d       | j	                  t         |d            d       dD ]0  }dD ])  }| j	                  t         ||dz   |z               d       + 2  |       5 }d|j                  |<   | j                  ||d       | j                  t        |ddd       | j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       d d d        y # 1 sw Y   y xY w)Nr   NaNrj  45.3445e2z4.5E+3uglyz1.3E4 
z1.3E+4z  -7.89z-7.89z  3.45679  z3.45679z	1_3.3e4_0z1.33E+411_0_0_01000)r   r      u    z	9.311E+28Txyz1234r  yu   1 2 3u    1 2 r  u     z12 3z1_2_ 3)	r   r   r   localcontextr;  r6  r.   rf  r-  )r   r   r   r  leadtrailcs          r    test_explicit_from_stringz2ExplicitConstructionTest.test_explicit_from_string  s[   ,,&&<<88||00 	WR[)51 	WT]+T2 	WW-.8 	WV_-x8 	WV_-u5 	WZ018<WY/0':W]34i@ 	W[12J?WY/0&9 2 	.D6 .  WTK-?%-G%H!I!,..	.
 ^ 	Hq(,AGG$%.?i&#sC .9JK.9OP .B.H .E .G'	H 	H 	Hs   	B.J  J	categoryc                 $   dd l }| j                  j                  }| j                  j                         }|j	                  d      }| j                  t         ||            d       | j                  t        |j                  |            d       y )Nr   9.999999)	_testcapir   r   r/   unicode_legacy_stringr;  r6  r   )r   r  r   r&   r   s        r    test_from_legacy_stringsz1ExplicitConstructionTest.test_from_legacy_stringsN  sp     	,,&&,,&&(++J7WQZ*5W33A67Dr)   c                    | j                   j                  } |d      }| j                  t        |      d        |d      }| j                  t        |      d        |d      }| j                  t        |      d        |d      }| j                  t        |      d        |d	      }| j                  t        |      d
       | j	                  t
        |d       | j	                  t
        |d       | j	                  t
        |d       | j	                  t
        | |d      ddf       | j	                  t
        |d       | j	                  t
        |d       | j	                  t
        |d       | j	                  t
        |d       | j	                  t
        |d       | j	                  t
        |d       | j	                  t
        |d       | j	                  t
        |d       y )Nr   r   r   ra  r  )   rs  r   rn  r   r  rs     r  rz  r  	r  r  r  r+   r  r  rs  r  r  -4.34913534E-17)r   r   FInfinity)r  r  r  r  r+   r  )   r  r  )        r  r  r  r  r  )r  r  zwrong!)r  r  r  )r  r  1)r  r  r  )r  )r  r  r  Nr  r  )r  )r  r  r+   r  r  )r  )r  
   r  r+   r  r  )r  )r  r  r  ar  r  )r   r   r;  r6  rf  r  r   r   r   s      r    test_explicit_from_tuplesz2ExplicitConstructionTest.test_explicit_from_tuplesZ  s   ,,&& \#Q% ^%Q' *,Q) :<Q!23 \#Q, 	*g/CE 	*g/FH*g/GI*g
OQ/OP 	*g/MO*g/GI*g/HJ 	*g}>*g/IK*g/GI*g/GI*g/HJr)   c                 h   | j                   j                  } |ddgdg      }| j                  t        |      d        |dg ddg      }| j                  t        |      d        |g d      }| j                  t        |      d        |dg ddf      }| j                  t        |      d       y )Nr   ra  r  r  r  r  r  r   r   r;  r6  r  s      r    test_explicit_from_listz0ExplicitConstructionTest.test_explicit_from_list  s    ,,&&QQK Q%Q3S9:Q!239:Q!23Q3S9:Q!23r)   c                 ,   | j                   j                  }| j                  t         |d            d       | j                  t         |d            d       | j	                   |d       |d             | j	                   |d       |d             y )Nr   Fr  T)r   r   assertIsboolr;  rc  s     r    test_explicit_from_boolz0ExplicitConstructionTest.test_explicit_from_bool  so    ,,&&d71:&.d71:&-4
3r)   c                    | j                   j                  } |d      } ||      }| j                  t        |      d        |d      } ||      }| j                  t        |      d        |d      } ||      }| j                  t        |      d        |d      } ||      }| j                  t        |      d       y )	Nri  rj  rk  rl  rm  rn  r   ra  r  r   r   r   rI  s       r    test_explicit_from_Decimalz3ExplicitConstructionTest.test_explicit_from_Decimal  s    ,,&& BKAJQ& IAJQ- CLAJQ' AJAJQ%r)   c           	      J   | j                   j                  } |d      }| j                  t        |      |       | j                  t	        |      d       | j                   |t        d            j                                | j                   |t        d            j                                | j                   |t        d            j                                | j                  t	         |t        d                  t	         |d                   | j                  t	         |t        d                  t	         |d                   | j                  t	         |t        d                  t	         |d                   | j                  t	         |t        d	                  t	         |d
                   t        d      D ]S  }t        j                  d      t        j                         dz  dz
  z  }| j                  |t         ||                   U y )N皙?90.1000000000000000055511151231257827021181583404541015625naninf-infry  r  	-Infinity-0.0-0   {Gz?       @      ?)r   r   r;  r5  r6  r#   floatr   r   rt  r)  expovariate)r   r   rrG  r  s        r    test_explicit_from_floatz1ExplicitConstructionTest.test_explicit_from_float  s    ,,&&CLa'*QK	Me-5578e-99;<f.::<=WU5\23WU^,	.WU5\23WZ01	3WU6]34W[12	4WU6]34WT]+	-s 	3A""4(FMMOc,AC,GHAQgaj 12	3r)   c           	      f
   | j                   j                  }| j                   j                  }| j                   j                  }t	        j                  | j                   j                               }d|_         |       }| j                  t        |      d       |j                         }| j                  t        |      d       | j                  t        |j                  d        |j                  d      }| j                  ||       | j                  |j                  d      |j                  d              |d      }| j                  t        |      d       |j                  d      }| j                  t        |      d       | j                  t        |j                  d            d	        |d
      }| j                  t        |      d       |j                  d
      }| j                  t        |      d        |d      } ||      }| j                  t        |      d       |j                  |      }| j                  t        |      d       d|_        d|j                  |<   dD ]I  }|j                  |      }| j                  t        ||             | j                  t!        |      |       K d|_        d|j                  |<   | j                  ||j                  d       d|_        | j                  t        |j                  d            d       | j                  t        |j                  d            d       | j                  t        |j                  d            d       | j                  t        |j                  d            d       | j                  ||j                  d       | j                  t"        |j                  d       | j                  t        |j                  dd       | j                  ||j                  d       | j                  ||j                  d       d|_        | j                  ||j                  d        | j                  ||j                   |d              d!|j                  |<   | j                  t        |j                  d             d	       | j                  |j$                  |          d!|j$                  |<   | j                  t        |j                   |d                   d	       | j                  |j$                  |          y )"Nr  ra    in  z457E+2456789z4.57E+5z3.14
ry  r  r  z	-4.35E-17rk  rl  z5.00E+8   T)	l        l         l    i   r   l                          z0E-017z0E-17rj  -Infr  NaN123r  )r  r  r  r  5678z 123412_34NaN12345F)r   r   r   r   ro   
getcontextr,   r;  r6  r   rf  r-  assertIsInstancer.   r#   
isinstancer  r  rN  )r   r   r   r   ncr   prevdecr   s           r    $test_explicit_context_create_decimalz=ExplicitConstructionTest.test_explicit_context_create_decimal  s\   ,,&&<<88,,&&YYt||..01 IQ%Q% 	)R%6%6= c"a)**51**84	6 HQ*h'Q+ 	R..x895A :<Q!23DFQ- )$GQ-g&Q+ %)!"3 	(A!!!$AOOJq'23SVQ'		(  '2#4#4d; R..x897CR..t45t<R..v67ER..x898D 	*B,=,=uE*b&7&7I)R%6%6G*B,=,=wG*B,=,=wG *B,=,=zJ*B,=,=!*-	/ &+!"R..z:;UC!123%*!"R..wz/BCDeL!123r)   c           	      v   | j                   j                  }| j                   j                         }|j                  d      }| j	                  t        |      |       | j	                  t        |      d       | j                  |j                  t        d            j                                | j                  |j                  t        d            j                                | j                  |j                  t        d            j                                | j	                  t        |j                  t        d                  t        |j                  d                   | j	                  t        |j                  t        d                  t        |j                  d                   | j	                  t        |j                  t        d                  t        |j                  d                   | j	                  t        |j                  t        d	                  t        |j                  d
                   d|_        t        d      D ]\  }t        j                  d      t        j                         dz  dz
  z  }| j	                  |t        |j                  |                   ^ y )Nr  z0.1000000000000000055511151231r  r  r  ry  r  r  r  r  d   r  r  r  r  )r   r   r/   r   r;  r5  r6  r#   r  r   r   r,   rt  r)  r  )r   r   r  r  rG  r  s         r    'test_explicit_context_create_from_floatz@ExplicitConstructionTest.test_explicit_context_create_from_float$  s   ,,&&\\!!#c"a'*Q!AB))%,7??AB))%,7CCEF))%-8DDFGR..uU|<=R..u56	8R..uU|<=R..z:;	=R..uV}=>R..{;<	>R..uV}=>R..t45	7s 	=A""4(FMMOc,AC,GHAQb&7&7&: ;<	=r)   c                     | j                   j                  }dddd}|j                         D ]&  \  }}| j                  t	         ||            |       ( y )Nr  z	0.0000372z-NaN2400)u   １u   ٠.٠٣٧٢e-٣u   -nan౨౪౦౦)r   r   itemsr;  r6  )r   r   test_valuesinputr   s        r    test_unicode_digitsz,ExplicitConstructionTest.test_unicode_digits<  sZ    ,,&& 8C-7
  +002 	<OE8S0(;	<r)   N)r   r[  r\  r]  rd  rg  rw  r  r
   r   r   ignore_warningsDeprecationWarningr  r  r  r  r  r   r  r  r  r  r   r)   r    r_  r_    s    @24566Hp !#$_$$.@AE B $ E)KV44&. 3 3.W4r=0	<r)   r_  c                       e Zd ZeZy)CExplicitConstructionTestNr   r[  r\  r   r   r   r)   r    r  r  G      Gr)   r  c                       e Zd ZeZy)PyExplicitConstructionTestNr   r[  r\  Pr   r   r)   r    r  r  J      Gr)   r  c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	ImplicitConstructionTestz6Unit tests for Implicit Construction cases of Decimal.c                 x    | j                   j                  }| j                  t        t        dt                      y )NzDecimal(5) + Noner   r   rf  r-  r7  localsrc  s     r    test_implicit_from_Nonez0ImplicitConstructionTest.test_implicit_from_NoneP  s(    ,,&&)T+>Ir)   c                     | j                   j                  }| j                  t         |d      dz         d       | j                   |d      dz    |d             y )Nrs  ri  50l   2}r r  rc  s     r    test_implicit_from_intz/ImplicitConstructionTest.test_implicit_from_intT  sN    ,,&& 	WQZ"_-t4l2GL4IJr)   c                 x    | j                   j                  }| j                  t        t        dt                      y )NzDecimal(5) + "3"r  rc  s     r    test_implicit_from_stringz2ImplicitConstructionTest.test_implicit_from_string\  (    ,,&&)T+=vxHr)   c                 x    | j                   j                  }| j                  t        t        dt                      y )NzDecimal(5) + 2.2r  rc  s     r    test_implicit_from_floatz1ImplicitConstructionTest.test_implicit_from_float`  r  r)   c                 ~    | j                   j                  }| j                   |d       |d      z    |d             y )Nrs  ri  2   rb  rc  s     r    test_implicit_from_Decimalz3ImplicitConstructionTest.test_implicit_from_Decimald  s2    ,,&&gbk172;?r)   c                 "   | j                   j                  } G d d      }| j                  t         |        |d            d       | j                  t         |d       |             d       | j                  t	        d      d       | j                  t	        d      d	       | j                  t	        d
      d       | j                  t	        d      d       | j                  t	        d      d       | j                  t	        d      d       g d}|D ]t  \  }t        |fd       t        |fd       | j                  t	        d|z   dz         dz   dz          | j                  t	        d|z   dz         dz   dz          v y )Nc                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
,ImplicitConstructionTest.test_rop.<locals>.Ec                     dt        |      z   S )Nzdivmod r6  r   others     r    
__divmod__z7ImplicitConstructionTest.test_rop.<locals>.E.__divmod__m  s     3u:--r)   c                     t        |      dz   S )Nz rdivmodr  r  s     r    __rdivmod__z8ImplicitConstructionTest.test_rop.<locals>.E.__rdivmod__o  s    5zJ..r)   c                     dt        |      z   S )Nzlt r  r  s     r    __lt__z3ImplicitConstructionTest.test_rop.<locals>.E.__lt__q      s5z))r)   c                     dt        |      z   S )Nzgt r  r  s     r    __gt__z3ImplicitConstructionTest.test_rop.<locals>.E.__gt__s  r  r)   c                     dt        |      z   S )Nzle r  r  s     r    __le__z3ImplicitConstructionTest.test_rop.<locals>.E.__le__u  r  r)   c                     dt        |      z   S )Nzge r  r  s     r    __ge__z3ImplicitConstructionTest.test_rop.<locals>.E.__ge__w  r  r)   c                     dt        |      z   S )Nzeq r  r  s     r    __eq__z3ImplicitConstructionTest.test_rop.<locals>.E.__eq__y  r  r)   c                     dt        |      z   S )Nzne r  r  s     r    __ne__z3ImplicitConstructionTest.test_rop.<locals>.E.__ne__{  r  r)   N)r   r[  r\  r   r  r  r  r	  r  r  r  r   r)   r    Er  l  s*    ./******r)   r  r  z	divmod 10z
10 rdivmodzDecimal(10) < E()zgt 10zDecimal(10) > E()zlt 10zDecimal(10) <= E()zge 10zDecimal(10) >= E()zle 10zDecimal(10) == E()zeq 10zDecimal(10) != E()zne 10))+__add____radd__)-__sub____rsub__)*__mul____rmul__)/__truediv____rtruediv__)%__mod____rmod__)z//__floordiv____rfloordiv__)z**__pow____rpow__c                 &    dz   t        |      z   S Nr6  r  )r   r  lops     r    r  z3ImplicitConstructionTest.test_rop.<locals>.<lambda>  s    c%j0H r)   c                 &    t        |      z   dz   S r%  r  )r   r  rops     r    r  z3ImplicitConstructionTest.test_rop.<locals>.<lambda>  s    E
S0@50H r)   zE()zDecimal(10)r6  10)r   r   r;  divmodr7  setattr)r   r   r  oplistsymr&  r(  s        @@r    test_ropz!ImplicitConstructionTest.test_roph  si   ,,&&	* 	*$ 	WR[1;?QS1<@12G<12G<23W=23W=23W=23W=
 $ 	1MCcAsHIAsHIT%#+"=>"S[4/1T-#"5"=>!CZ%/1	1r)   N)
r   r[  r\  r]  r  r  r  r  r  r.  r   r)   r    r  r  M  s(    @JKII@01r)   r  c                       e Zd ZeZy)CImplicitConstructionTestNr  r   r)   r    r0  r0    r  r)   r0  c                       e Zd ZeZy)PyImplicitConstructionTestNr  r   r)   r    r2  r2    r  r)   r2  c                   L    e Zd ZdZd Zd Zd Zd Z edd      d        Z	d	 Z
y
)
FormatTestz#Unit tests for the format function.c                     | j                   j                  }g d}|D ](  \  }}}| j                  t         ||      |      |       * | j	                  t
         |d      j                  d       y )N))rI  0E-15z0e-15)rI  z2.3E-15z2.3e-15)rI  z2.30E+2z2.30e+2)rI  z2.30000E-15z2.30000e-15)rI  z1.23456789123456789e40z1.23456789123456789e+40)rI  1.5z1.5e+0)rI  z0.15z1.5e-1)rI  z0.015z1.5e-2)rI  z0.0000000000015z1.5e-12)rI  z15.0z1.50e+1)rI  -15z-1.5e+1)rI  ra  z0e+0)rI  0E10e+1)rI  0.0z0e-1)rI  0.000e-2).6er6  z0.000000e-9)r>  ra  z0.000000e+6)r>  r  z9.999999e+0)r>  z	9.9999999z1.000000e+1)r>  z-1.23e5z-1.230000e+5)r>  z1.23456789e-3z1.234568e-3)r   ra  ra  )r   r;  r;  )r   0E-2r<  )r   z0.00E-80.0000000000)r   r9  ra  )r   z3.2E132)r   z3.2E2320)r   z3.20E2rB  )r   z3.200E2z320.0)r   z3.2E-6z	0.0000032).6fr6  0.000000)rC  r9  rD  )rC  ra  rD  ).0fra  ra  )rE  r=  ra  )rE  
3.141592653).1frF  3.1)z.4frF  3.1416)rC  rF  3.141593)z.7frF  	3.1415926)z.8frF  rF  )z.9frF  z3.141592650)gra  ra  )rM  r;  r;  )rM  r9  r:  )Gr9  z0E+1)rM  z0E-5z0.00000)rM  z0E-6rD  )rM  z0E-7z0e-7)rM  z-0E2z-0e+2).0grF  rG  )z.0nrF  rG  )z.1grF  rG  )z.2grF  rI  )z.5grF  rJ  )z.7grF  rK  )z.8grF  rL  )z.9grF  rF  )z.10grF  rF  )r  r9  0%)r  0E0rP  )r  z0E-1rP  )r  r?  rP  )r  z0E-3z0.0%)r  z0E-4z0.00%).3%ra  0.000%)rR  0E10rS  )rR  z0E-10rS  )rR  z2.34z234.000%)rR  z1.234567z123.457%).0%1.23z123%)rI  ry  ry  )r   -NaN123rW  )z+gNaN456z+NaN456)z.3eInfr  )z.16fr  r  )rO  -sNaNrZ  )r   1.00r[  )6123   123)z<6r]  z123   )z>6r]  r^  )z^6r]  z 123  )z=+6r]  z+  123)#<10ry  z
NaN#######)r_  z-4.3z
-4.3######)z#<+100.0130z
+0.0130###)z#< 10r`  z
 0.0130###)z@>10r  z
@-Infinity)z#>5r  r  )z?^5r]  z?123?)z%^6r]  z%123%%)z ^6-45.6z-45.6 )z/=10ra  z
-/////45.6)z/=+1045.6z
+/////45.6)z/= 10rb  z
 /////45.6)z =10r  z
- Infinity)z ^16r  z   -Infinity    )z >101.2345z
    1.2345)z <10rc  z
1.2345    ),1234567z	1,234,567)rd  123456123,456)rd  1234512,345)rd  r  z1,234)rd  r]  r]  )rd  12rj  )rd  r  r  )rd  ra  ra  )rd  z-1234567z
-1,234,567)rd  -123456-123,456)z7,rf  rg  )z8,rf   123,456)08,rf  z	0,123,456)z+08,rf  z+123,456)z 08,rf  rm  )rn  rk  rl  )z+09,rf  z
+0,123,456)z07,1234.561,234.56)rn  ro  rp  )z09,ro  z	01,234.56)z010,ro  z
001,234.56)z011,ro  0,001,234.56)z012,ro  rq  )z08,.1fz1234.5z01,234.5)rd  
1.23456789rr  )z,%z
123.456789z12,345.6789%)z,erf  z
1.23456e+5)z,Erf  z
1.23456E+5)rH  r  r  )rH  z-.0r  )rH  -.01r  )z.1f0.r;  )z6.1fru  z   0.0)rv  -1.z  -1.0)rt  -0.r;  )rt  .01r;  )rt  rs  r;  )z.2fru  r<  )rz  rx  r<  )rz  z.001r<  )rz  z-.001r<  )z.1eru  0.0e+1)r{  rx  r|  )z.1Eru  0.0E+1)r}  rx  r~  )zz.2e-0.001z-1.00e-3)zz.2gr  r  )zz.2%r  z-0.10%)zfz-0.0000z0.0000)rt  -00000.000001r;  )rt  -00000.r;  )rt  -.0000000000r;  )rz  r  r<  )rz  r  r<  )rz  r  r<  )rt  z.090.1)rt  z-.09z-0.1) z.0frx  z 0)+z.0frx  z+0)-z.0frx  ra  )r  rw  -1)r  rw  r  )r  rw  r  )zz>6.1frx  zzz-0.0)zz>z6.1frx  zzzz0.0)zx>z6.1frx  zxxx0.0)u
   🖤>z6.1frx  u   🖤🖤🖤0.0)z >z6.1frx  z   0.0)zz3,.10Fz
-6.24E-323r@  )r>   ra  ru  )za=-7.0z0.12345zaaaa0.1)z	<^+15.20%r  z<<+Infinity%<<<)z>,%sNaN1234567zsNaN1234567%)z=10.10%r  z
   NaN123%r  s   -020)r   r   r;  formatrf  r-  
__format__)r   r   r  fmtr   rK  s         r    test_formattingzFormatTest.test_formatting  sj    ,,&&N^ * 	>NCFVGAJ4f=	> 	)WQZ%:%:GDr)   c                     | j                   j                         5 }t        |_        | j	                  t        | j                   j                  d      d      d       d d d        y # 1 sw Y   y xY w)Nr  rz  r<  )r   r  r   r-   r;  r  r   r   ctxs     r    +test_negative_zero_format_directed_roundingz6FormatTest.test_negative_zero_format_directed_rounding{  sY    \\&&( 	$C(CLVDLL$8$8$BFK"$	$ 	$ 	$s   AA%%A.c                 n    | j                  t        t        | j                  j	                  d      d       y )NrV  fz)rf  r  r  r   r   r   s    r    test_negative_zero_bad_formatz(FormatTest.test_negative_zero_bad_format  s%    *fdll.B.B6.JDQr)   c                    	  j                   j                  		 ddlm}  fd}d>	 fd	}d |g d      dd	}d |g      d
d	}d |g d      dd	}d |ddd|g      dd	}dj                  d       |g d      dj                  d      d	} j                   | 	d      |      d        j                   | 	d      |      d        j                   | 	d      |      d        j                   | 	d      |      d        j                   |d|      d        j                   |d|      d        j                   |d|      d        j                   |d|      d        j                   |d|d      d        j                   |d|d      d        j                   |d|d      d        j                   |d|d      d         j                   |d!|d"      d#        j                   |d!|d$      d#        j                   |d!|d%      d&        j                   |d!|d'      d(        j                   |d)|d%      d*        j                   |d)|d'      d*        j                   |d)|d+      d,        j                   |d)|d-      d.        j                   |d)|d/      d.        j                   |d)|d0      d1        j                   |d2|d'      d3        j                   |d2|d+      d3        j                   |d2|d-      d3        j                   |d2|d/      d4        j                   |d2|d0      d5        j                   |d2|d6      d5        j                   |d2|d7      d8        j                   |d2|d9      d:        j                   | 	d;      |d<      d=       y # t        $ r  j                  d       Y w xY w)?Nr   CHAR_MAXlocale.CHAR_MAX not availablec                     j                   t        k(  r(dj                  | D cg c]  }t        |       c}      S | S c c}w Nr   )r   r   joinchr)lstr  r   s     r    make_groupingz/FormatTest.test_n_format.<locals>.make_grouping  s4    59\\Q5F277C0qCF01OCO0s   ?c                     j                   t        k(  r |       j                  ||      S  |       j                  ||      S )N)_localeconv)r   r   r  )r  overrider  r   r   s      r    get_fmtz)FormatTest.test_n_format.<locals>.get_fmt  s@    ||q qz,,S(;;qz,,Sh,GGr)   .r  r  r   rd  decimal_pointgroupingthousands_sepr   r  &r  r  r  r  s   ¿r   s   ´z12.7z12,7z1-2&7i[z123,456,789	123456789z123 456 789l   c}z123456-78-9012-3z.6nz
1.23457e+8z
1,23457e+8z
1&23457e+8r  03nr  04n05n0123406n00123490  ri  07nz012,34508nz	0,012,34509n010nz
00,012,345i@ z1-2345-6z	01-2345-6z0-01-2345-6011n012nz00-01-2345-6013nz000-01-2345-6-1.5020nu   -0´000´000´000´001¿5Nru  )r   r   localer  ImportErrorskipTestdecoder;  )
r   r  r  r  en_USfr_FRru_RUcrazydotsep_wider   s
   `        @r    test_n_formatzFormatTest.test_n_format  s   ,,&&	;'	P	H "&y1! "&z2  "%i0! "%q!Q&9:! *009%i0)009 	%8&A%8&A%8&A%8'BE2MBE2K@E2MB68JKE59<HE59<HE59<HE59<H 	ue4f=ue4f=ue4g>ue4h?u5x@u5x@u5yAu5{Cu5{Cv6E6
C6
C6
C6D7G7G7H7I 	+vFH	Jc  	;MM9:	;s   O O,+O,LC_ALLps_AFc                 h   | j                   j                  }t        j                         d   }t        j                         d   }|dk7  r!| j	                  dj                  |d             |dk7  r!| j	                  dj                  |d             | j                  t         |d      d      d	       y )
Nr  r  u   ٫z5inappropriate decimal point separator ({!a} not {!a})u   ٬z1inappropriate thousands separator ({!a} not {!a})z100000000.123ru  u   100٬000٬000٫123)r   r   r  
localeconvr  r  r;  )r   r   r  r  s       r    &test_wide_char_separator_decimal_pointz1FormatTest.test_wide_char_separator_decimal_point  s     ,,&&))+O<))+O<H$MM ,,2F=(,KMH$MM ,,2F=(,KM 	 8#>9	;r)   c                 F    G d d| j                   j                        }|j                  d      }| j                  | j                   j                  |j                         |j                  d      }| j                  | j                   j                  |j                         y )Nc                       e Zd Zd Zy);FormatTest.test_decimal_from_float_argument_type.<locals>.Ac                 $    t        |      | _        y r   )r5  a_type)r   r  s     r    __init__zDFormatTest.test_decimal_from_float_argument_type.<locals>.A.__init__  s    "1gr)   Nr   r[  r\  r  r   r)   r    Ar    s    &r)   r  g     @E@*   )r   r   
from_floatr;  r  )r   r  r  s      r    %test_decimal_from_float_argument_typez0FormatTest.test_decimal_from_float_argument_type  sr    	&$$ 	& LL--qxx8LL--qxx8r)   N)r   r[  r\  r]  r  r  r  r  r	   r  r  r   r)   r    r4  r4    s@    -WEr$RWJr Xw'; (; 9r)   r4  c                       e Zd ZeZy)CFormatTestNr  r   r)   r    r  r    r  r)   r  c                       e Zd ZeZy)PyFormatTestNr  r   r)   r    r  r    r  r)   r  c                   R    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zy)ArithmeticOperatorsTestz:Unit tests for all arithmetic operators, binary and unary.c                 4   | j                   j                  } |d      } |d      }| j                  ||z    |d             | j                  ||z    |d             |dz   }| j                  | |d             | j                  t        |      t        |             d|z   }| j                  | |d             | j                  t        |      t        |             ||z  }| j                  | |d             |dz  }| j                  | |d             y )N-11.122.2z11.1rs  z-6.116.1r   r   r;  r5  r   r   d1d2r  s        r    test_additionz%ArithmeticOperatorsTest.test_addition  s   ,,&&WV_ 	B0B0 FGFO,a$r(+ FGFO,a$r(+ 	bWV_- 	aWV_-r)   c                 4   | j                   j                  } |d      } |d      }| j                  ||z
   |d             | j                  ||z
   |d             |dz
  }| j                  | |d             | j                  t        |      t        |             d|z
  }| j                  | |d             | j                  t        |      t        |             ||z  }| j                  | |d             |dz  }| j                  | |d             y )	Nr  r  z-33.3z33.3rs  z-16.1r  z-38.3r  r  s        r    test_subtractionz(ArithmeticOperatorsTest.test_subtraction  s   ,,&&WV_ 	B 01B0 FGG,-a$r(+ FGFO,a$r(+ 	bWW-. 	aWW-.r)   c                 4   | j                   j                  } |d      } |d      }| j                  ||z   |d             | j                  ||z   |d             |dz  }| j                  | |d             | j                  t        |      t        |             d|z  }| j                  | |d             | j                  t        |      t        |             ||z  }| j                  | |d             |dz  }| j                  | |d             y )N-5rG  r8  rs  z-25z-75r  r  s        r    test_multiplicationz+ArithmeticOperatorsTest.test_multiplication9  s   ,,&&T]S\ 	B/B/ FGEN+a$r(+ FGEN+a$r(+ 	bWU^, 	aWU^,r)   c                 4   | j                   j                  } |d      } |d      }| j                  ||z   |d             | j                  ||z   |d             |dz  }| j                  | |d             | j                  t        |      t        |             d|z  }| j                  | |d             | j                  t        |      t        |             ||z  }| j                  | |d             |dz  }| j                  | |d             y )	Nr  2-2.5z-0.4r  z-1.25z-0.8z-0.625r  r  s        r    test_divisionz%ArithmeticOperatorsTest.test_divisionU  s   ,,&&T]S\ 	B0B0 FGG,-a$r(+ FGFO,a$r(+ 	bWV_- 	aWX./r)   c                 4   | j                   j                  } |d      } |d      }| j                  ||z   |d             | j                  ||z   |d             |dz  }| j                  | |d             | j                  t        |      t        |             d|z  }| j                  | |d             | j                  t        |      t        |             ||z  }| j                  | |d             |dz  }| j                  | |d             y )N5r  ra  r  r     r  r  r  s        r    test_floor_divisionz+ArithmeticOperatorsTest.test_floor_divisionq  s   ,,&&S\S\ 	R.R. !GGCL)a$r(+ GGCL)a$r(+ 	r	WS\* 	qWS\*r)   c                 4   | j                   j                  } |d      } |d      }| j                  ||z   |d             | j                  ||z   |d             |dz  }| j                  | |d             | j                  t        |      t        |             d|z  }| j                  | |d             | j                  t        |      t        |             ||z  }| j                  | |d             |dz  }| j                  | |d	             y )
Nr  r  25rA  r  625r  16807390625r  r  s        r    test_poweringz%ArithmeticOperatorsTest.test_powering  s   ,,&&S\S\ 	R/R/ !GGEN+a$r(+ GGG,-a$r(+ 	r	WT]+ 	qWX./r)   c                 4   | j                   j                  } |d      } |d      }| j                  ||z   |d             | j                  ||z   |d             |dz  }| j                  | |d             | j                  t        |      t        |             d|z  }| j                  | |d             | j                  t        |      t        |             ||z  }| j                  | |d             |dz  }| j                  | |d             y Nr  r  r  r  r  r  r  s        r    test_modulez#ArithmeticOperatorsTest.test_module  s   ,,&&S\S\ 	B-B- FGCL)a$r(+ FGCL)a$r(+ 	bWS\* 	aWS\*r)   c                 z   | j                   j                  } |d      } |d      }t        ||      \  }}| j                  | |d             | j                  | |d             | j                  t	        |      t	        |             | j                  t	        |      t	        |             t        |d      \  }}| j                  | |d             | j                  | |d             | j                  t	        |      t	        |             | j                  t	        |      t	        |             t        d|      \  }}| j                  | |d             | j                  | |d             | j                  t	        |      t	        |             | j                  t	        |      t	        |             y r  )r   r   r*  r;  r5  )r   r   r  r  pqs         r    test_floor_div_modulez-ArithmeticOperatorsTest.test_floor_div_module  s^   ,,&&S\S\ BAGCL)GCL)a$r(+a$r(+ AAGCL)GCL)a$r(+a$r(+ 2AGCL)GCL)a$r(+a$r(+r)   c                    | j                   j                  }| j                   |d       |d             | j                   |d        |d             | j                  t         |d            t         |d                   y )Nri  rm  )r   r   r;  absrc  s     r    test_unary_operatorsz,ArithmeticOperatorsTest.test_unary_operators  sg    ,,&&'"+ws|4'"+ws|4WR[)3ws|+<=r)   c                    | j                   j                  }| j                   j                  }| j                   j                  } |d      } |d      } |d      } |d      }||f||f||f||f||ff}||f||f||f||f||f||f||ff}	t        j
                  t        j                  t        j                  t        j                  f}
t        j                  t        j                  f} |       5 }d|j                  |<   ||	z   D ]^  \  }}|
|z   D ]Q  } |||      }|t        j                  u rdnd}| j                  ||dj                  ||j                  |||             S ` 	 d d d         |       5 }d	|j                  |<   |D ][  \  }}|D ]Q  } |||      }|t        j                  u rdnd}| j                  ||dj                  ||j                  |||             S ] |	D ]P  \  }}|D ]F  }| j                  |t        j                  ||       | j                  |t        j                  ||       H R ||	z   D ]   \  }}|
D ]  }| j                  ||||        " 	 d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)
Nry  sNaNrY  r  r   TFz8expected {0!r} for operator.{1}({2!r}, {3!r}); got {4!r}r  )r   r   r   r  operatorltlegtgeeqner.   r  r  r   rf  )r   r   r   r  ru  r   rG  r   
qnan_pairs
snan_pairs	order_opsequality_opsr  r  r  opgotr   s                     r    test_nan_comparisonsz,ArithmeticOperatorsTest.test_nan_comparisons  s    ,,&&<<88||00ENFOENCLVaVaVaVaV;
VaVaVaVaVaVaVK
KKhkk8;;F	{{HKK/ ^ 
	?s*+CII&'"Z/ ?1#l2 ?BQ(C')X[['8teHMM(C!,,2F$bkk1a->???
	? ^ 	Bs*+CII&'" ?1& ?BQ(C')X[['8teHMM(C#..4f$bkk1a/>??? # K1& KB%%&6QJ%%&6QJKK
 #Z/ B1# BB%%&6AqABB%	B 	B
	? 
	?	B 	Bs   0A6I-6C-I:-I7:Jc                    | j                   j                  } |d      j                   |d            }| j                   |d      j                  d      |       | j	                  t
         |d      j                  d       y )Nr  r  -2)r   r   rv   r;  rf  r-  r  s      r    test_copy_signz&ArithmeticOperatorsTest.test_copy_sign!  sd    ,,&&AJ  ---b115)WQZ%9%94@r)   N)r   r[  r\  r]  r  r  r  r  r  r  r  r  r  r  r  r   r)   r    r  r    s?    D.8/8-808+808+8,6>8BtAr)   r  c                       e Zd ZeZy)CArithmeticOperatorsTestNr  r   r)   r    r  r  (  r  r)   r  c                       e Zd ZeZy)PyArithmeticOperatorsTestNr  r   r)   r    r  r  +  r  r)   r  c           
      \   | j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  }| j                   j
                  }| j                   j                  }| j                   j                  }| j                   j                  } |d      }	 |d      }
|	|
z  }| j                  j                          | j                  j                          |	|
z  } |       5 }| j                  |j                  |          | j                  ||j                   |	d       | j                  |j                  |           |       5 }| j                  |j                  |          | j                  |j                  |          | j                  ||j"                  |	 |d             | j                  |j                  |          ~d d d        | j%                  |j                  |          ~d d d        | j'                  | |d             | j'                  | |d              |       }| j                  |j                  |          ||||fD ]   }| j%                  |j                  |          " y # 1 sw Y   xY w# 1 sw Y   xY w)Nr  r  r   r  0.333333333333333333333333)r   r   r   r   r   r   r   r  r  finish1r   synchrowaitr#   rN  rf  dividecompareassertFalser;  )r%   r   r   r   r   r   r   r  r  r  d3test1test2c2c3c1sigs                    r    thfunc1r(  0  s%   kk!!G{{33[[//N{{##H%%Ikk!!G''J;;++L	B	BrEEKKOOKKrEE	 2rxx()B:rxx/0^ 	rNN288G,-NN288N34-rzz2wvONN288$456	 	!123 OOE7#?@AOOE7#?@A	BNN288G$%N4DD '&'	 		 s&   A"J"(B J('J"J	J""J+c           	         | j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  }| j                   j
                  }| j                   j                  }| j                   j                  }| j                   j                  } |d      }	 |d      }
|	|
z  } |       }d|_	        |	|
z  } |       5 }| j                  |j                  |          | j                  ||j                   |d      d       | j                  |j                  |           ||      5 }| j                  |j                  |          | j                  |j                  |          d|j                  |<   | j                  ||j                    |d      d       | j                  |j                  |          ~d d d        | j                  |j                  |          | j                  |j                  |          ~d d d        | j"                  j%                          | j&                  j%                          | j)                  | |d             | j)                  | |d	             | j                  |j                  |          | j                  |j                  |          ||||fD ]   }| j                  |j                  |          " y # 1 sw Y   xY w# 1 sw Y   xY w)
Nr  r     1e425000000  Tz1e-425000000r  z0.333333333333333333)r   r   r   r   r   r   r   r  r  r,   r#   rN  rf  multiplyr   r.   r  r  r   finish2r;  )r%   r   r   r   r   r   r   r  r  r  r!  r"  thiscontextr#  r$  r%  r'  s                    r    thfunc2r0  W  sp   kk!!G{{33[[//N{{##H%%Ikk!!G''J;;++L	B	BrEE,KKrEE	 2rxx()2;;0FLrxx)*+& 	"NN288G,-OOBHHX./"&BHHYY		7>3JCPNN288I./	 	+,+, KKOOKKOOOOE7#?@AOOE7#9:;OOK%%i01NN;$$W-.N4DD 0))#./0'	 		 s'    A)K<	BK/AK</K9	4K<<Lc                       e Zd ZdZd Zy)ThreadingTestz0Unit tests for thread local contexts in Decimal.c                    | j                   j                  }| j                   t        k(  r'| j                   j                  s| j	                  d       |j
                  }|j                  }|j                  }d|_        d|_        d|_        t        j                         | _
        t        j                         | _        t        j                         | _        t        j                  t        | f      }t        j                  t        | f      }|j!                          |j!                          | j                  j#                          | j                  j#                          t$        | j                      D ]   }| j'                  |j(                  |          " |j+                          |j+                          ||_        ||_        ||_        y )Nzcompiled without threading   r   )targetr  )r   DefaultContextr   HAVE_THREADSr  r,   rY  rT  	threadingEventr  r  r.  Threadr(  r0  startr  r3   r   rN  r  )r   r7  	save_prec	save_emax	save_eminth1th2r'  s           r    test_threadingzThreadingTest.test_threading  sR   44<<1T\\%>%>MM67 #''	"''	"''	 '( ( ( (gTG<gTG<				4<<( 	8C^11#67	8 	

'''r)   N)r   r[  r\  r]  rB  r   r)   r    r2  r2    s
    :
$(r)   r2  c                       e Zd ZeZy)CThreadingTestNr  r   r)   r    rD  rD    r  r)   rD  c                       e Zd ZeZy)PyThreadingTestNr  r   r)   r    rF  rF    r  r)   rF  c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)UsabilityTestz*Unit tests for Usability cases of Decimal.c                 H   | j                   j                  } |d      } |d      } |d      }| j                  ||       | j                  ||       | j	                  ||       | j                  ||       | j                  ||       | j                  ||       | j                  ||       | j                  ||       | j                  |d       | j	                  d|       | j                  |d       | j                  |d       | j                  |d       | j                  |t                      | j                  |t               t        t        |t        d                  }|d d  }t        j                  |       |j                          | j                  ||       y )Nz23.42rj     ri  r|  gY@@r  )r   r   assertGreaterassertGreaterEqual
assertLessassertLessEqualr;  assertNotEqualobjectlistmaprt  r)  shuffler9  )r   r   dadbdcr  bs          r    test_comparison_operatorsz'UsabilityTest.test_comparison_operators  sg   ,,&&WWT] 	2r"B'BR$R B#R$B' 	2r"BR  	B'B%B)B' WeCj)*qTq	Ar)   c                 0   | j                   j                  } |d      } |d      }| j                  |d       | j                  |d       | j	                  |d       | j                  |d       | j                  |d       | j                  |d       | j	                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d |d             y )N0.253.0      @      ?g      ?r  r  )r   r   rM  rN  rK  rL  rO  r;  r   r   rT  rU  s       r    test_decimal_float_comparisonz+UsabilityTest.test_decimal_float_comparison  s    ,,&&V_U^C R%2t$D)B$T"3#R(b!T2&D"%b!C0r)   c                    | j                   j                  } |d      } |d      }| j                  |d       | j                  d|       | j                  |d       | j                  d|       | j                  d|       | j                  |d       | j                  |d       | j                  d|       | j	                  |j                  d      t               | j	                  |j                  d      t               | j	                  |j                  d      t               | j	                  |j                  d      t               y )NrZ  r[  y      ?        y      ?        y      @        y      @      ?)	r   r   rO  r;  r  r  NotImplementedr	  r  r^  s       r    test_decimal_complex_comparisonz-UsabilityTest.test_decimal_complex_comparison  s    ,,&&V_U^B)Vb)g''B'&2&f&B)Vb)bii'8bii'8bii'8bii'8r)   c           
         | j                   j                  }t        | j                      j                  }| j                   j                  }| j                   j
                  }| j                   j                  }t        rt        j                  nd}t        rt        j                  nd}t        rt        j                  nd} |||      }	 ||	      5  ||	_        | j                   |d       |dd             | j                   |dd       |d             | j                   |dd       |d	t        |      z                | j                   |d
t        |      z          |dd             | j                   |dd       |d	t        |      z                | j                   |d
t        |      z          |dd             | j                   |d       |dd             | j                   |dd       |d             d|	_        | j                   |d      dz   |dd             | j                   |dd       |d      dz         | j!                   |dd       |dt        |      z                | j#                   |dt        |      z          |dd             | j%                   |d       |dd             | j%                   |d       |dd             | j                   |d       |dd             | j                   |d       |dd             | j'                  | |d      j(                   |dd             | j+                  t,         |dd      j/                   |d                   | j                   |d       |dd             | j                   |dd       |d             d d d        y # 1 sw Y   y xY w)Nɚ;6eilʈrY  rT  r   r  l	   ZmH;5B rq  1ez-1el   !0QYr  r  i,  r  i6l   c(	 9er  l   g] {   lg] r  r  i)r   r   r   Fractionr/   r  r   r   r   MIN_EMIN	MIN_ETINYr,   rM  r6  r;  rO  rN  rL  rK  rf  r  r  ra  r  )
r   Dr  r/   r  r   emaxeminetinyr  s
             r     test_decimal_fraction_comparisonz.UsabilityTest.test_decimal_fraction_comparison  s   LL  dll#,,,,&&||00<<88 qzzIqzzJ kD)!_ 	5AFOOAaD!A&K"LMOOAb!FG1NOOAaFAdSZ&7$89OOAec%j011Qq6:OOAa 9:AdSZ>O<PQOOAec%j011Q7P3QRQuXq2w/QqWah/AF!Q!A/!A!Q/  9j!91TCI=M;NO##AdSY&6$79j9QRqx;s);<qx<)<=OOAfIqS'9:OOAfIqc':;.%2cKMM.!Bs)*:*:1U8*DE%!Bs)4"S	1U847	5 	5 	5s   K'O  O	c                 $   | j                   j                  } |d      }t        j                  |      }| j                  t	        |      t	        |             t        j
                  |      }| j                  t	        |      t	        |             y )Nz43.24)r   r   ro   r;  r>  deepcopy)r   r   r   r  rV  s        r    test_copy_and_deepcopy_methodsz,UsabilityTest.test_copy_and_deepcopy_methods1  sf    ,,&&GIIaLA1&]]1BA'r)   c                      j                   j                  } j                   j                  } fd} | |d              | |d              | |d              | |d              | |d             dD cg c]+  }t        dd	      D ]  }d
D ]  } ||d|z  |z   z          - }}}}|j	                   |d       |d       |d       |d       |d       |d       |d       |d       |d       |d       |d       |d       |d       |d       |d       |d      g       |D ],  } j                   ||      t        t        |                   . g d}	|	D ]6  }
t        |
      } ||
      } j                   ||      t        |             8  |       5 } |d      }d|_	         ||      }d	|_	         ||      }d|_	         ||      } j                  ||        j                  ||       d |_	        d!d"z  } j                   | ||             ||             d d d        y c c}}}w # 1 sw Y   y xY w)#Nc                 b    t        |       }| j                         }j                  ||       |S r   )hash__hash__r;  )r   r  rW  r   s      r    hashitz.UsabilityTest.test_hash_method.<locals>.hashit?  s,    QA

AQ"Hr)   rJ  r  r  nan123-NaN)r                     ro  !   =   >   ?   @   A   B   r  rp  r  r  r  r<  z-0.000rT  z-0E1210.0z	-23.000001230E100z
-4.5678E50l       z	1.634E100z
90.697E100z
188.83E100z
1652.9E100	56531E100)r  r  r;  z-.0e1z34.02.5z
112390.625z	-0.515625z123456789.1   r~  '  iL  i  )
r   r   r  rt  extendr;  rw  r  r  r,   )r   r   r  ry  r5   ru  rv  r  r  test_stringsr   r   r   r  r  h1h2h3s   `                 r    test_hash_methodzUsabilityTest.test_hash_method:  s   ,,&&||00	 	wr{wz"#w{#$wx !wv!A, , %c2, #*	,  	 tQTAX/ ,/ ,/ , ,
 	! $
#% )* $%%%$) 	0 ! 	>EVE]DU,<=	>
B 	1AaA
AVAYQ0	1
 ^ 	<q &AAFBAFBAFBR$R$AFAVGAJ/;#	< 	<S,R	< 	<s   ?0H>+B
IIc                 v   | j                   j                  }| j                  t        t         |d              |d      }| j                  t	        |      t        j                  |              G d d      } G d d||      } |d      }| j                  t	        |      t        j                  |             y )Nr  ry  c                       e Zd Zd Zy)-UsabilityTest.test_hash_method_nan.<locals>.Hc                      y)Nr  r   r   s    r    rx  z6UsabilityTest.test_hash_method_nan.<locals>.H.__hash__  s    r)   N)r   r[  r\  rx  r   r)   r    Hr    s    r)   r  c                       e Zd Zy)-UsabilityTest.test_hash_method_nan.<locals>.DN)r   r[  r\  r   r)   r    rm  r    s    r)   rm  )r   r   rf  r-  rw  r;  rP  rx  )r   r   r  r  rm  s        r    test_hash_method_nanz"UsabilityTest.test_hash_method_nan  s    ,,&&)T76?;efooe&<=	 		 	%efooe&<=r)   c                    | j                   j                  } |d      } |d      }d}d}| j                  t        ||      |       | j                  t        ||      |       | j                  t	        ||      |       | j                  t	        ||      |       | j                  t        ||      |       | j                  t        ||      |       | j                  t	        ||      |       | j                  t	        ||      |       y )N15.32z28.5r}  r  )r   r   r  minmax)r   r   r  r  l1l2s         r    test_min_and_max_methodsz&UsabilityTest.test_min_and_max_methods  s    ,,&&WV_ 	c"Rj"%c"Rj"%c"Rj"%c"Rj"% 	c"Rj"%c"Rj"%c"Rj"%c"Rj"%r)   c                     | j                   j                  }| j                   |d             | j                   |d             y )Nr   z0.372)r   r   r   r#   rc  s     r    test_as_nonzerozUsabilityTest.test_as_nonzero  s6    ,,&& 	$()r)   c                     | j                   j                  } |d      }| j                  t        |      d       | j                  t	        |      d       y )Nr  zDecimal('15.32'))r   r   r;  r6  r:  r  s      r    test_tostring_methodsz#UsabilityTest.test_tostring_methods  sD    ,,&&GQ)a"45r)   c           
         | j                   j                  } |d      } |d      }| j                  t        |      d       | j                  t        |      d       | j                  t	        |      d       | j                  t	        |      d       g d}|D ]0  \  }}| j                  t        j                   ||            |       2 | j                  t        t
        j                   |d             | j                  t        t
        j                   |d             | j                  t        t
        j                   |d	             | j                  t        t
        j                   |d
             | j                  t        t
        j                   |d             g d}|D ]0  \  }}| j                  t        j                   ||            |       2 | j                  t        t
        j                   |d             | j                  t        t
        j                   |d             | j                  t        t
        j                   |d	             | j                  t        t
        j                   |d
             | j                  t        t
        j                   |d             g d}|D ]&  \  }}| j                  t         ||            |       ( | j                  t        t         |d             | j                  t        t         |d             | j                  t        t         |d	             | j                  t        t         |d
             | j                  t        t         |d             g d}|D ]1  \  }}}	| j                  t        t         ||      |            |	       3 y )N66r  r  r}  gp=
ף.@)	z123.00ri  3.2r  )3.54r  )3.899r  )-2.3r  z-11.0ir;  r   z-0E3r   )89891211712379812736.1l   {#'s{M r{  r  r  rY  r  )	r  )r  r  r  r  r  r  r  r  r  r  r  )r  l   {#'s{M )r  r  r  r  r  r  r  r  )z-3.5)r  r  )r  r  )-0.5r   )0.5r   )r7  r  )r  r  )z3.5r  ))123.456r  z0E+4)r  r  z0E+3)r  r  z1E+2)r  rq  z1.2E+2)r  r   r]  )r  r  z123.5)r  r  123.46)r  r  r  )r  r  z123.4560)z123.455r  r  )z123.445r  z123.44)rY  r  ry  )r  iry  )sNaN314r  NaN314)r   r   r;  r  r  mathr   rf  r  OverflowErrorceilroundr6  )
r   r   r  r  
test_pairsr   rG  test_triplesru  r  s
             r    test_tonum_methodsz UsabilityTest.test_tonum_methods  s   ,,&&T]W 	R"%R"% 	rB'rE*

  	8DAqTZZ
3Q7	8*djj'&/B*djj'&/B*djj'(2CD-WU^D-WV_E

  	7DAqTYYwqz2A6	7*diiA*diiA*dii1BC-GENC-GFOD
$  	3DAqU71:.2	3*eWV_=*eWV_=*eWX->?-?-@  $ 	;GAq!Swqz1!56:	;r)   c                    | j                   j                  }dD ]r  }t         ||            }| j                  t	        j
                  |             t	        j                  d|      }| j                  ||j                  d      rdnd       t y )N)r  nan1234-nanz-nan2468r  r  g      )	r   r   r  r#   r  r   ru   r;  r	  )r   r   r   r   rv  s        r    test_nan_to_floatzUsabilityTest.test_nan_to_float   ss     ,,&&7 	GAgaj!AOODJJqM*==a(DT1<<+<4#F		Gr)   c                     | j                   j                  }dD ]%  } ||      }| j                  t        t        |       ' y )N)snanz-snansnan1357z	-snan1234)r   r   rf  r  r  )r   r   r   r   s       r    test_snan_to_floatz UsabilityTest.test_snan_to_float*  s;    ,,&&; 	4A
Aj%3	4r)   c                    | j                   j                  } |d      }| j                  |t        t	        |                    |d      }| j                  |t        t	        |                    |d      }| j                  |t        t	        |                    |d      }| j                  |t        t	        |                   y )Nr  r  r  r  )r   r   r;  r7  r:  r  s      r    test_eval_round_tripz"UsabilityTest.test_eval_round_trip0  s    ,,&& \#DaM* ^%DaM* *,DaM* :<DaM*r)   c                 @   | j                   j                  } |d      }| j                  |j                         d        |d      }| j                  |j                         d        |d      }| j                  |j                         d        |d      }| j                  |j                         d        |d	      }| j                  |j                         d
        |d      }| j                  |j                         d        |d      }| j                  |j                         d        |d      }| j                  |j                         d        |d      }| j                  |j                         d        |d      }| j                  |j                         d        |d      }| j                  |j                         d        |d      }| j                  |j                         d        |d      }| j                  |j                         d       y )Nr   r  rm  r  r  r  r  )r   r  r  )r   r   r   r  r   rs  r  r  r  )r   r  r   rs  r  r  r  )r  r   r   r   %   )r  r  r  )r  r   r  )r   r  ru  )r   r  ru  )r  r  Nr  r   r  )r  r   ru  )r   r  r  )r  )r   r  r  r  r  )r  r  r  )r   r   r;  as_tupler  s      r    test_as_tuplezUsabilityTest.test_as_tupleC  s   ,,&& AJ|5 CL~7 %&'LN J~7 35'?A')}5["}5 46'@B(*|5\#|5 ^%~6+-~6+-~6r)   c           	      4   | j                   j                  }| j                  t        |j                   |d             | j                  t        |j                   |d             | j                  t
        |j                   |d             | j                  t
        |j                   |d             t        dd      D ]  }t        d      D ]  }dD ]  } |d	|||fz        }|j	                         }|\  }}| j                  |t               | j                  |t               | j                  |t               | j                  |d
       | j                  t        j                  ||      d       | j                   ||       ||      z  |          y )Nr  r  r  snan123r  r    )r  r  z%s%dE%dr   r  )r   r   rf  r  as_integer_ratior  rt  r  tupler  rK  r;  r  gcd)	r   r   rV  coeffrv  r   pqr  r  s	            r    test_as_integer_ratioz#UsabilityTest.test_as_integer_ratiop  s}   ,,&& 	-!22GEN	D-!22GFO	E*!22GFO	E*!22GI4F	H Q< 	ACt A$ AD	T5#,> >?A++-BDAq ))"e4))!S1))!S1 &&q!,$$TXXa^Q7 $$WQZ'!*%<a@!AA	Ar)   c                 <   | j                   j                  } G d d|      } |d      } |d      }||z   }| j                  t        |      |       |j	                  |      }| j                  t        |      |       t        j
                  |      }| j                  t        |      |       | j                  ||       t        j                  |      }| j                  t        |      |       | j                  ||        |d      } ||      }| j                  t        |      |       | j                  ||        ||      }| j                  t        |      |       | j                  ||       | j                  |j                  d         ||      }| j                  t        |      |       | j                  ||       d|_         ||      }| j                  t        |      |       | j                  ||       | j                  |j                  d        y )Nc                       e Zd ZdZy)1UsabilityTest.test_subclassing.<locals>.MyDecimalN)r   r[  r\  r  r   r)   r    	MyDecimalr    s    Ar)   r  r  r  1.0r+   )	r   r   r  r5  r  ro   r;  rs  r  )r   r   r  r  r  r   r  r5   s           r    test_subclassingzUsabilityTest.test_subclassing  s   ,,&&	 	 q\q\Gd1gw'FF2Jd1gw'IIbMd1gy)BMM"d1gy)B ENAJd1gw'A aLd1gy)Aacc4  AJd1gw'A aLd1gy)Aacc4 r)   c           
         | j                   j                  }| j                   j                  } |       }| j                  t	         |d      j                               t	        |j                   |d                         y Nr   )r   r   r  r;  r6  r   r   r   r  r  s       r    test_implicit_contextz#UsabilityTest.test_implicit_context  s^    ,,&&\\,,
 LWQZ__./QVVGAJ/0	2r)   c                 $'   | j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  }| j                   j
                  }| j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  }	| j                   j                  }
| j                   j                  } | |             5 }d|_        d|_        d|_         |d      } |d      } |d      }|j                          | j!                  t#        |j%                  d             d       | j'                  |j(                  |	          | j'                  |j(                  |
          |j                          | j+                  ||j$                  d        | j'                  |j(                  |          | j-                  |j/                  d       d	       | j-                  |j1                  d       d
       |j                          | j!                  t#        |j3                  d             d       | j'                  |j(                  |	          | j'                  |j(                  |
          |j                          | j+                  | |d      j2                  d        | j'                  |j(                  |          |j                          | j!                  t#        |j5                  d             d       | j'                  |j(                  |	          | j'                  |j(                  |
          |j                          | j+                  | |d      j4                  d        | j'                  |j(                  |          |j                          | j!                  t#        |j7                  d             d       | j+                  | |d      j6                  d        | j'                  |j(                  |          |j                          | j!                  t#        |j9                  d             d       | j+                  ||j8                  d        | j'                  |j(                  |          |j                          | j!                  t#        |j;                  d             d       | j+                  | |d      j:                  d        | j'                  |j(                  |          |j                          | j!                  t#        |j=                  d             d       | j+                  | |d      j<                  d        | j'                  |j(                  |          |j                          | j!                  t#        |j?                  d             d       | j+                  ||j>                  d        | j'                  |j(                  |          | j!                  t#        |jA                  d             d       |j                          | j!                  t#        |jC                  d             d       | j'                  |j(                  |          | j'                  |j(                  |	          | j'                  |j(                  |
          | j'                  |j(                  |          | j'                  |j(                  |          |j                          | j+                  ||jB                  d        | j'                  |j(                  |          d|_"        | j!                  t#        |jG                  d             d       d|_"        |j                          t#        |jI                   |d      d             }| j!                  |d       | j+                  ||jH                   |d      d        | j'                  |j(                  |          |j                          t#        |jK                  dd             }| j!                  |d       | j+                  ||jJ                   |d      d        | j'                  |j(                  |          |j                          t#        |jM                  dd             }| j!                  |d       | j+                  ||jL                  dd        | j'                  |j(                  |          |j                          t#        |jO                  dd             }| j!                  |d       | j+                  ||jN                  dd        | j'                  |j(                  |          |j                          t#        |jQ                  dd             }| j!                  |d        | j+                  ||jP                  dd        | j'                  |j(                  |          |j                          t#        |jS                  dd             }| j!                  |d       | j+                  ||jR                   |d      d        | j'                  |j(                  |          |j                          t#        |jU                  dd             }| j!                  |d       | j+                  ||jT                   |d      d        | j'                  |j(                  |          |j                          t#        |jW                  dd             }| j!                  |d       | j+                  ||jV                   |d      d        | j'                  |j(                  |          |j                          t#        |jY                  dd             }| j!                  |d       | j+                  ||jX                   |d      d        | j'                  |j(                  |          |j                          t#        |j[                  dd             }| j!                  |d        | j+                  ||jZ                  dd        | j'                  |j(                  |          |j                          t#        |j]                  d!d             }| j!                  |d"       | j+                  ||j\                  dd        | j'                  |j(                  |          |j                          t#        |j_                  dd             }| j!                  |d#       | j+                  ||j^                  d$d        | j'                  |j(                  |          |j                          t#        |ja                  d!d             }| j!                  |d"       | j+                  ||j`                  d$d        | j'                  |j(                  |          |j                          t#        |jc                  d!d%d             }| j!                  |d&       | j+                  ||jb                   |d      d%d        | j'                  |j(                  |          td        |_3        t#         |d'      ji                  d d (            }| j!                  |d       tj        |_3        t#         |d'      ji                  d d (            }| j!                  |d)       t#         |d'      ji                  tl        d (            }| j!                  |d       |j                          | j+                  | |d      jh                  d        | j'                  |j(                  |          td        |_3        t#         |d'      jo                  d d (            }| j!                  |d       tj        |_3        t#         |d'      jo                  d d (            }| j!                  |d)       t#         |d'      jo                  tl        d (            }| j!                  |d       |j                          | j+                  | |d      jn                  d        | j'                  |j(                  |          td        |_3        t#         |d'      jq                  d d (            }| j!                  |d       tj        |_3        t#         |d'      jq                  d d (            }| j!                  |d)       t#         |d'      jq                  tl        d (            }| j!                  |d       |j                          | j+                  | |d      jp                  d        | j'                  |j(                  |          tl        |_3        t#         |d*      js                   |d+      d d ,            }| j!                  |d-       tj        |_3        t#         |d*      js                   |d+      d d ,            }| j!                  |d.       t#         |d*      js                   |d+      tl        d ,            }| j!                  |d-       |j                          | j+                  ||jr                   |d/      tl        d (       | j'                  |j(                  |          d d d         | |             5 }d|_        d|_        d|_         |d 0      5 }| j!                  |j                  d       | j!                  |j                  d       | j!                  |j                  d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)1Nr  r,  i1111e9999z1e-9999r&   z1.609487E+48FTz4.709530rq  z2.045323r  r   1111000z9.999999E+999r  r  ra  
+Subnormalz0E-1005r  Nan891287828
NaN1287828i    r  ry  e   101ri  r)  r  11100z1.11E+9r  r  225r7  r-   r&   r  z1.50001z1e-3)rV  r-   r&   z1.501z1.500z1e-10)r  ):r   r   r/   r  r   r   r   r   r   r   r   r   r,   rY  rT  r*  r;  r6  rV  r#   rN  rf  r  r   r   lnlog10logbrz   r   r   r   rh   r   capitalsr   r  rj   rd   r   r   r  r   r  r   r   rotatescalebshiftfmar0   r-   to_integralr   r   r   r   quantize)r   r   r/   r  r   r   r   r   r   r   r   r   r  r  r  zr@  r&   s                     r    test_none_argszUsabilityTest.test_none_args  sy   ,,&&,,&&||00<<8844<<((LL**	LL**	,,&&,,&&,,&&')$ W	7AFAFAFA!A	"A MMOSt!45~FOOAGGG,-OOAGGG,-MMOht<OOAGGH-.MM!++d+3U;MM!...6=MMOSd!34jAOOAGGG,-OOAGGG,-MMO.MOOAGG$456MMOS!67DOOAGGG,-OOAGGG,-MMO.0A0A4POOAGG$456MMOS!56<ngajootLOOAGGN34MMOS!1!1$!1!?@)L.0@0@$OOOAGG$456MMOSd!;<oN.0J0JTXYOOAGG$456MMOST!:;ZH.0I0ISWXOOAGG$456MMOST!:;SAhTBOOAGGH-.S!=>MMMOS!56	BOOAGGG,-OOAGGG,-OOAGGG,-OOAGGI./OOAGGI./MMOh=OOAGGH-.AJS!>?KAJ MMOaii 7iFGCS,/.		76?TXYOOAGG$456MMOa&&tT&:;CS$'.0@0@'%.Z^_OOAGG$456MMOammCm67CS%(.sDQOOAGG$456MMOall3l56CS%(.c4POOAGG$456MMOammCm67CS$'.sDQOOAGG$456MMOaeeCe./CS%(.wvPTUOOAGG$456MMOaiiTi23CS%(.		76?TXYOOAGG$456MMOaeeCe./CS%(.wvPTUOOAGG$456MMOaiiTi23CS%(.		76?TXYOOAGG$456MMOa&&sD&9:CS$'.0@0@#tTOOAGG$456MMOahhq$h/0CS'*.#tLOOAGG$456MMOahhq$h/0CS),.%NOOAGG$456MMOaggag./CS'*.MOOAGG$456 MMOaeeAq$e/0CS%(hwx/@!TROOAGGH-. )AJgen00$0MNCS#&#AJgen00$0MNCS#&gen00(D0QRCS#&MMO.0K0KUYZOOAGG$456(AJgen66d6STCS#&#AJgen66d6STCS#&gen66RV6WXCS#&MMO.0Q0Q[_`OOAGG$456(AJgen66d6STCS#&#AJgen66d6STCS#&gen66RV6WXCS#&MMO.0Q0Q[_`OOAGG$456!AJgi(11gfoPT^b1cdCS'*#AJgi(11gfoPT^b1cdCS'*gi(11gfoPXbf1ghCS'*MMO.

GG<LW_imnOOAGG$456oW	7r ')$ 	/GLGLGL$' /1  +  -  ./		/ 	/sW	7 W	7z/ /		/ 	/sB    AGAM.K)ANLAAM:MANM.AM7M:AN	M?ANNANc           	      L   | j                   j                  }| j                   |d      j                  d       |d      j                   |d                   | j                   |d      j	                  d       |d      j	                   |d                   | j                   |d      j                  d       |d      j                   |d                   | j                   |d      j                  d       |d      j                   |d                   | j                   |d      j                  d       |d      j                   |d                   | j                   |d      j                  d       |d      j                   |d                   | j                   |d      j                  d       |d      j                   |d                   | j                   |d      j                  d       |d      j                   |d                   | j                   |d      j                  d       |d      j                   |d                   | j                   |d      j                  d       |d      j                   |d                   | j                   |d      j                  d       |d      j                   |d                   | j                   |d      j                  d       |d      j                   |d                   | j                   |d      j                  d       |d      j                   |d                   | j                   |d	      j!                  d       |d	      j!                   |d                   | j                   |d      j#                  d
       |d      j#                   |d
                   | j                   |d      j%                  d       |d      j%                   |d                   | j                   |d      j'                  d       |d      j'                   |d                   | j                   |d      j)                  d       |d      j)                   |d                   | j                   |d      j+                   |d      d       |d      j+                   |d       |d                   | j                   |d      j+                  dd       |d      j+                   |d       |d                   | j                   |d      j+                  d |d             |d      j+                   |d       |d                   y )Nr  r  iu'    i7  ri  r  r  i   r  r  z9.123r  rq  iri  C   )r   r   r;  r  rj   rl   rn   rd   r   r   r  r   r  r   r   r  r   r  r   r  r  r   rc  s     r    test_conversions_from_intz'UsabilityTest.test_conversions_from_int	  s    ,,&&++A. ++GAJ7	92215 2271:>	@11!4 11'!*=	?55a8 55gajA	C33D9 33GDMB	D2248 2274=A	C33D9 33GDMB	D))#. ))'#,7	9--c2 --gcl;	=))#. ))'#,7	9--c2 --gcl;	=11#6 11'#,?	A//4 //=	?44T: 44WT]C	E,,Q/ ,,WQZ8	:33D9 33GDMB	D)006 )00?	A++B/ ++GBK8	: 	))'"+r: ))'"+wr{C	E))"b1 ))'"+wr{C	E))"gbk: ))'"+wr{C	Er)   N)r   r[  r\  r]  rX  r_  rb  rq  rt  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r   r)   r    rH  rH    sw    4"H1&9((5T(L<\>&(*6e;NG4+&+7ZAB-!^2m/^/Er)   rH  c                       e Zd ZeZy)CUsabilityTestNr  r   r)   r    r  r  	  r  r)   r  c                   ,     e Zd ZeZ fdZ fdZ xZS )PyUsabilityTestc                 ~    t         |           t        j                         | _        t        j
                  d       y NiX  superr   sysget_int_max_str_digits_previous_int_limitset_int_max_str_digitsr   r   s    r    r   zPyUsabilityTest.setUp	  +    #&#=#=#? ""4(r)   c                 `    t        j                  | j                         t        |           y r   r  r  r  r  tearDownr  s    r    r  zPyUsabilityTest.tearDown	  "    ""4#;#;<r)   r   r[  r\  r  r   r   r  __classcell__r   s   @r    r  r  	      G)
 r)   r  c                   X    e Zd Zd Zd Zd Zed        Zd Zd Z	d Z
d Zd	 Zd
 Zd Zy)PythonAPItestsc                 l   | j                   j                  }| j                  t        |t        j
                               | j                  t        |t        j                               | j                   |d      t        j
                         | j                   |d      t        j                         y r  )
r   r   r#   
issubclassnumbersNumberr   Realr  assertNotIsInstancerc  s     r    test_abczPythonAPItests.test_abc	  sq    ,,&&
7GNN;<GW\\:;gaj'..9  W\\:r)   c                    t        t        j                  dz         D ]D  }| j                  j                  }t
        j                  d   }| j                  t
        j                  d<    |d      }t        j                  ||      }t        j                  |      }| j                  ||       t        rt        j	                  d      }t        j	                  d      }t        t
        j                  d<   t        j                  ||      }	t        t
        j                  d<   t        j                  |	      }
| j                  |
t        j                         | j                  |
|       t        t
        j                  d<   t        j                  ||      }t        t
        j                  d<   t        j                  |      }
| j                  |
t        j                         | j                  |
|       t        j	                  d      j                         }t        j	                  d      j                         }t        t
        j                  d<   t        j                  ||      }	t        t
        j                  d<   t        j                  |	      }
| j                  |
t        j                         | j                  |
|       t        t
        j                  d<   t        j                  ||      }t        t
        j                  d<   t        j                  |      }
| j                  |
t        j                         | j                  |
|       |t
        j                  d<   G y )Nr  r   z-3.141590000z-3.123e81723)rt  pickleHIGHEST_PROTOCOLr   r   r  modulesdumpsloadsr;  r   r  r  r  DecimalTuple)r   protor   savedecimalr   r  rI  r  r  sxr  sys               r    test_picklezPythonAPItests.test_pickle
  s]   622Q67 0	1Ell**G++i0K &*\\CKK	"'AQ&AQAQ"IIn-IIn-)*I&\\!U+)*I&LL$%%a3  A&)*I&\\!U+)*I&LL$%%a3  A&IIn-668IIn-668)*I&\\!U+)*I&LL$%%a8  A&)*I&\\!U+)*I&LL$%%a8  A&%0CKK	"a0	1r)   c           	      L   | j                   j                  }t        dd      D ]{  }d|dz  z  }| j                  t	         ||            t	        t        |                    ||      }|j                  t              }| j                   |t	        |            |       } | j                  t        t         |d             | j                  t        t         |d             | j                  t        t         |d             | j                  t        t         |d             y )	N   %0.2f      Y@r  r  r  r  )r   r   rt  r;  r  r  r  r   rf  r  r  r   r   r  r   r   r  s         r    test_intzPythonAPItests.test_int5
  s    ,,&&tS! 	1A1u9%AS_c%(m<
Aj)AWSV_a0	1 	*c76?;*c76?;-gen=-gfo>r)   c                     | j                   j                  }t        dd      D ]#  }| j                  t	         ||            |       % y )Nrr  i  )r   r   rt  r  r  r   r   r  s      r    test_small_intszPythonAPItests.test_small_intsF
  s<    ,,&&r3 	.AMM#gaj/1-	.r)   c           	      X   | j                   j                  }t        dd      D ]  }d|dz  z  }| j                  t	         ||            t	        t        |                    ||      }|j                  t              }| j                   |t        j                  |            |        y )Nr6  r7  r8  r9  )
r   r   rt  r;  r  r  r  r   r  truncr:  s         r    
test_trunczPythonAPItests.test_truncM
  s    ,,&&tS! 	8A1u9%AS_c%(m<
Aj)AWTZZ]3Q7	8r)   c           	         | j                   j                  } G d d|      }| j                  t        ||             |j	                  d      }| j                  t        |      |       | j                  t        |      d       | j                  |j                  d       d}| j                  |j	                  |       ||             | j                  |j	                  t        d            j                                | j                  |j	                  t        d            j                                | j                  |j	                  t        d	            j                                | j                  t        |j	                  t        d                  t         |d
                   | j                  t        |j	                  t        d                  t         |d                   | j                  t        |j	                  t        d	                  t         |d                   | j                  t        |j                  d       t        d      D ]\  }t        j                   d      t        j                         dz  dz
  z  }| j                  |t        |j	                  |                   ^ y )Nc                       e Zd Zd Zy)1PythonAPItests.test_from_float.<locals>.MyDecimalc                     d| _         y )Nr  )r  )r   _s     r    r  z:PythonAPItests.test_from_float.<locals>.MyDecimal.__init__^
  s	    r)   Nr  r   r)   r    r  rD  ]
  s    r)   r  r  r  r  l   s\&5$3|	 r  r  r  ry  r  r  abcr  r  r  r  )r   r   r#   r#  r  r;  r5  r6  r  r  r   r   rf  r-  rt  r)  r  )r   r   r  r  bigintrG  r  s          r    test_from_floatzPythonAPItests.test_from_floatY
  s   ,,&&	 	 	
9g67  %a),QK	Mc".--f5y7HI	,,U5\:BBDE	,,U5\:FFHI	,,U6];GGIJY11%,?@WU^,	.Y11%,?@WZ01	3Y11%-@AW[12	4)Y%9%95As 	@A""4(FMMOc,AC,GHAQi&:&:1&= >?	@r)   c                    | j                   j                  }| j                   j                  }| j                   j                  } |dt              }| j                  |j                  t        j                         |d              |dt              }| j                  |j                  t        j                         |d              |d|g      }| j                  ||j                  t        j                         | j                  t        |j                  d            d       | j                  t        |j                  d            d	       | j                  t        |j                  d
            d       y )Nrs  )r,   r-   z3.1415rJ  )r,   r.          zDecimal('-0')r  zDecimal('1')r  zDecimal('10'))r   r   r/   r   r   r;  create_decimal_from_floatr  pir   rf  r:  )r   r   r/   r   r&   s        r    test_create_decimal_from_floatz-PythonAPItests.test_create_decimal_from_floaty
  s5   ,,&&,,&&,,&&q:6--dgg6H	
 q84--dgg6H	
 q	2--GG	

 	g??EF(	*g??DE'	)g??CD(	*r)   c                 T   | j                   j                  }| j                   j                  }| j                   j                  } |dd      }| j	                   |d      j                   |d             |d             | j	                   |d      j                   |d      t               |d             | j                  | |d	      j
                   |d
      |        |       } |d      }|j                  | |d      t              }| j	                  | |d             y )Ni iayrf  z7.335ry  z7.34r-   z7.3310e999991e100000r  z0.871831e8001e797)r&   rV  r-   z	8.71E+799)r   r   r/   r   r;  r  r   rf  )r   r   r/   r   r  r   r  s          r    test_quantizezPythonAPItests.test_quantize
  s   ,,&&,,&&<<88V,G%%gen5FO	
 	G%%genz%JFO	
 	J(('**=q 	 	

 IN#JJqgg&6JLGK01r)   c                 B   | j                   j                  } |d      }| j                  |j                  |       | j                  |j                  d       | j                  |j                         |        |d      }| j                  t        |      t        t        d                   | j                  t        t        |dd       | j                  t        t        |dd       | j                  t        t        |dd       | j                  t        t        |d	d       y )
Nz9.8182731e181273r   r  r  realr  imag	conjugate__complex__)r   r   r;  rV  rW  rX  complexr  rf  r.  r+  r=  s      r    test_complexzPythonAPItests.test_complex
  s    ,,&&&'##*CLWU1X%67.'1fcB.'1fcB.'1k3G.'1mSIr)   c                    | j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  }| j                   j
                  } |       }d|_        d|_        d|_         |       5 }|j                          | j                   |d|      d       | j                   |d|      d       | j                   ||d      d       | j                   ||      d       |j                          | j                  ||d|       | j                  |j                  |          | j                  |j                  |          |j                          | j                   |d      j                  |      d	       | j                  | |d
      j                  |       | j                  |j                  |          | j                  |j                  |          |j                          | j                   |d      j!                  |       |d             | j                  | |d      j                   |       | j                  |j                  |          | j                  |j                  |          | j                   |d      j#                  |       |d             | j                   |d      j%                  |      d       | j                   |d      j'                  |       |d             | j                   |d      j)                  |       |d             | j                   |d      j+                  |      d       | j                   |d      j-                  |      d       | j                   |d      j/                  |      d       | j                   |d      j1                  |       |d             | j                   |d      j3                  |d      d       |j                          | j                  | |d      j4                   |d      |       | j                  |j                  |          | j                  |j                  |          | j                   |d      j7                   |d      |       |d             | j                   |d      j7                   |d      |       |d             | j                   |d      j9                   |d       |       |d              | j                   |d!      j;                   |d"      |       |d#             | j                   |d!      j=                   |d"      |       |d             | j                   |d      j?                   |d$      |       |d%             |j                          | j                  | |d      j@                   |d&      |       | j                  |j                  |          | j                  |j                  |          | j                   |d'      jC                   |d(      |       |d)             | j                   |d*      jE                   |d+      |d	,       |d-             | j                  tF         |d      jH                  |       | j                  tF         |d      jJ                  |       | j                  tF         |d      jL                  |       | j                  tF         |d      jN                  |       | j                  tF         |d      jP                  |       | j                  tF         |d      jR                  |       | j                  tF         |d      jT                  |       | j                  tF         |d      jV                  |       | j                   |d      jY                  |             | j                   |d      j[                  |             | j                  tF         |d      j\                  |       | j                  tF         |d      j^                  |       | j                  tF         |d      j`                  |       | j                   |d.      jc                  |      d       | j                   |d      je                  |      d       | j                   |d      jg                  |      d/       | j                   |d0      ji                  |      d0       | j                   |d1      jk                   |d2      |      d       | j                   |d1      jm                   |d2      |      d       | j                   |d3      jo                   |d2      |      d       | j                   |d4      jq                  d|      d       | j                   |d4      jq                  d|      d       |j                          | j                  | |d4      jr                  d|       | j                  |j                  |          | j                  |j                  |          | j                   |d4      ju                  d|      d       | j                  tF        |jv                  d5|       | j                  tF         |d      jx                  |       | j                   |d      j{                         d       | j                  tF         |d$      j|                  |       | j                  tF         |d$      j~                  |       | j                  tF         |d      jz                  d6       | j                  tF         |d      jz                  d67       d d d        y # 1 sw Y   y xY w)8Nr  rq  r+   r  )r&   r  r   r  r  r  r  z0.7r  r  z-0.9z9.73z1E+19999'  z-2000i0r]  ri  z0.06250.2r  )r&   r  ra  r  0.01z0.0101r;  z-0.3z0.02z-0.03r  r  r  1e109.99r7  r  9.9z0.9)thirdr&   r  z7E+1ir  z0.2111r)  0123g?r  )r  )@r   r   r/   r  r   r   r,   rY  rT  r*  r;  rf  r#   rN  r   rV  r  r  r   r   r   r  r   r   r   r  rj   r  r   r  r   r   r  r   r   r-  r|   r~   r   r   r   r   r   r   r   r   adjustedrX  radixr  rz   rh   r   rd   r   r   r  r  r  r  r  	canonicalrr   rt   )r   rm  r/   r  r   r   xcr  s           r    test_named_parametersz$PythonAPItests.test_named_parameters
  s	   LL  ,,&&||00<<88<<((Y^ b	BqMMOQq"Xq)Qq"-q1Qr3Q7Qr]A.NN.5"EOOBHH%567QWW%567NNQqTXXbX115h!"=OOBHHX./QWWX./NNQqTWWRW0!E(;.""EOOBHH%567QWW%567QqTZZZ3QvY?QrU--b-92>QrU__R_8!F)DQvY000<aiHQvY2222>EQwZ99"9EuMQuX777CSIQx[--b-91U8DQx[0010ErJNN.f33QuXr  KOOBHH%567QWW%567QvY]]1X;]CQuXNQvY]]1X;]CQuXNQuX--ai-DvY(QvY]]1W:r]BAfINQvY..qz2.FuX'QuX11!D'21F%QNN.h//6B  HOOBHH%567QWW%567QvY55ah5KvY( QuX\\%"A\NvY( i1):):BGi1Di1)9)92Fi1bAi1rBi1rBi1Di1rBQvY000<=OOAfI2222>?i1Ci1Di1R@QtW\\"\5q9QqT000<a@QvY33B3?NQvY44R4@&IQtW004"0EqIQtW//$/DaHQtW004"0EqIQtW^^Ar^:A>QtW^^Ar^:A>NNhgnna  =OOBHHX./QWWX./QtW]]2r]:A>isBGi1CQqT^^-q1i4)9)92Fi4)<)<bIi1Ei1SAEb	B b	B b	Bs   mo11o:c                 4   | j                   }|j                  }|j                  }|j                  }|j                  }|j
                  }|j                  }|j                  }|j                  }	|j                  }
|j                  }| j                  t        |t                     | j                  t        ||             | j                  t        ||             | j                  t        |t                     | j                  t        ||             | j                  t        |t                     | j                  t        ||
             | j                  t        ||	             | j                  t        ||             | j                  t        ||	             | j                  t        ||
             | j                  t        ||             | j                  t        ||             | j                  t        ||             | j                  t        |	|             | j                  t        |
|             | j                  t        ||             | j                  t        |j                   |             | j                  t        |j"                  |             | j                  t        |j$                  |             | j                  t        |j$                  t                     | j                  t        |j&                  |             y r   )r   r   r   FloatOperationr   r   r   r   r   r   r   r#   r#  ArithmeticErrorr-  ZeroDivisionErrorConversionSyntaxDivisionImpossibleDivisionUndefinedInvalidContext)r   r   r   r   rn  r   r   r   r   r   r   r   s               r    test_exception_hierarchyz'PythonAPItests.test_exception_hierarchy-  sF   ,,"33"33 // //##%%	%%	//////
#3_EF
#35EFG
>3CDE
>9=>
>3CDE
>3DEF
8W56
8W56
8-=>?
9g67
9g67
9i89
9.>?@
9.>?@
7,<=>
7,<=>
7,<=>
7#;#;=MNO
7#=#=?OPQ
7#<#<>NOP
7#<#<>OPQ
7#9#9;KLMr)   N)r   r[  r\  r(  r4  r;  r
   r>  rA  rI  rN  rT  r[  rl  ru  r   r)   r    r!  r!  	  sP    ;11f?" . .
8@@*820J nB`&Nr)   r!  c                       e Zd ZeZy)CPythonAPItestsNr  r   r)   r    rw  rw  U  r  r)   rw  c                       e Zd ZeZy)PyPythonAPItestsNr  r   r)   r    ry  ry  X  r  r)   ry  c                      e Zd Zd Ze e        ej                  e      d                      Z	d Z
d Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d  Z&d! Z'd" Z(d# Z)d$ Z*d% Z+d& Z,d' Z-d( Z.d) Z/d* Z0d+ Z1d, Z2d- Z3d. Z4d/ Z5d0 Z6d1 Z7d2 Z8d3 Z9d4 Z:d5 Z;d6 Z<d7 Z=d8 Z>d9 Z?d: Z@d; ZAd< ZBd= ZCd> ZDd? ZEd@ ZFyA)BContextAPItestsc           
         | j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  } |       } |d d d d d d d d       }||fD ]  }| j                  |j                  d       | j                  |j                  t               | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       t        | |dg        t        | |d|||g        y )	N)r,   r-   rY  rT  r  rb   rN  r.   r  ?B r  r   rN  r.   )r   r/   r   r   r   r;  r,   r-   r0   rY  rT  r  rb   r(   )r   r/   r   r   r   r&  r$  r  s           r    r  zContextAPItests.test_none_args]  s   ,,&&<<8844<<((Y$Dt"$d$Hb 		9AQVVR(QZZ9QVVV,QVVW-QZZ+QWWa(4GR04G.>.6.8 9		9r)   r  c                 r   dd l }| j                  j                         }t        D ]4  }|j	                  |      |_        | j                  |j
                  |       6 |j	                  d      }| j                  t        t        |d|       |j	                  d      }| j                  t        t        |d|       y )Nr   r   r-   z	ROUND_ UP)
r  r   r/   RoundingModesr  r-   r;  rf  r-  r+  )r   r  r  rndr   s        r    r  z(ContextAPItests.test_from_legacy_stringsq  s     	LL  "  	.C"88=AJQZZ-	. ++B/)WaQ?++N;)WaQ?r)   c                    t        t        j                  dz         D ]0  }| j                  j                  }t
        j                  d   }| j                  t
        j                  d<    |       }t        j                  t        j                  ||            }| j                  |j                  |j                         | j                  |j                  |j                         | j                  |j                  |j                         | j                  |j                  |j                         | j                  |j                  |j                         | j                  |j                  |j                         | j                  |j                   |j                          | j                  |j"                  |j"                         t$        rt$        t&        ft&        t$        fgnt&        t&        fg}|D ]C  \  }}t)        t*              D ]*  \  }	}
t)        t,        |         D ]  \  }}
t)        t,        |         D ]  \  }}
t/        j0                  dd      }t/        j0                  dd      }t/        j0                  dd      }t/        j0                  d      }t/        j0                  d      }|t
        j                  d<   |j	                  |||t*        |	   ||t,        |   d | t,        |   d |       }t        j                  ||      }|t
        j                  d<   t        j                  |      }| j3                  ||j                         | j                  |j                  |       | j                  |j                  |       | j                  |j                  |       | j                  |j                  t*        |	          | j                  |j                  |       | j                  |j                  |       t5        | |dt,        |   d |        t5        | |d	t,        |   d |          - F |t
        j                  d<   3 y )
Nr  r   r  r  r   r  )r,   rT  rY  r-   r  rb   rN  r.   rN  r.   )rt  r*  r+  r   r/   r  r,  r.  r-  r;  r,   rT  rY  r-   r  rb   rN  r.   r   r  r0  r  r4  r)  	randranger  r(   )r   r0  r/   r1  r  rI  combinationsdumperloaderrirF  fitir,   ro  rn  capsrb   r   r   s                       r    r4  zContextAPItests.test_pickle  sr   622Q67 9	1Ell**G++i0K &*\\CKK	"	AV\\!U34AQVVQVV,QVVQVV,QVVQVV,QZZ4QZZ4QWWagg.QWWagg.QWWagg. 01QFQF+1vhL". "Z&}5 !ZEB!*>&+A!B  ZA%.~f/E%F ZEB#)#3#3As#;D#)#3#3D!#<D#)#3#3As#;D#)#3#3A#6D$*$4$4Q$7E 6<CKK	2 &'+$T+8+<+/u(6v(>s(C(6v(>s(C !/ !A !'Q 6A 6<CKK	2 &QA 11!V^^D ,,QVVT: ,,QVVT: ,,QVVT: ,,QZZr9JK ,,QZZ> ,,QWWe<*4G^F=STWUW=XY*4G^F=STWUW=XY?Z Z!Z"ZH &1CKK	"s9	1r)   c                     | j                   j                  }| j                   |d      dd |d      di g       | j                   |d      dddi g       y )Nr  r  r  )r  r  )r   r   assertInassertNotInrc  s     r    test_equality_with_other_typesz.ContextAPItests.test_equality_with_other_types  sO    ,,&&gbkCgbk5"#EFsC&;<r)   c                    | j                   j                  }| j                   j                  } |       }|j                         }| j	                  t        |      t        |             | j	                  t        |j                        t        |j                               | j	                  t        |j                        t        |j                               t        |j                  j                               }t        |j                  j                               }| j                  ||       | j                  |j                  |j                         y r   )r   r   r/   ro   rO  r>  rN  r.   r   keysr;  )r   r   r/   r  r   k1k2s          r    	test_copyzContextAPItests.test_copy  s    ,,&&,,&&IFFHBqE2a5)BqwwKAGG5BqwwKAGG5  R !''*r)   c                 v    | j                   j                  } |       }| j                  t        t        |d       y )N_clamp)r   r/   rf  r.  r"   r   r/   r  s      r    test__clampzContextAPItests.test__clamp  s.     ,,&&I.'1h?r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y Nrq  r  )r   r   r/   r   r;  rf  r-  r   r   r/   r  r   s        r    test_abszContextAPItests.test_abs  g    ,,&&,,&&IEE'"+rA&)QUUD1r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y Nr  r  )r   r   r/   r   r;  rf  r-  r  s        r    test_addzContextAPItests.test_add      ,,&&,,&&IEE'!*gaj)q!a(wqz1-q1q'!*-q1)QUUC3)QUUAs3r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   r  r;  rf  r-  r  s        r    test_comparezContextAPItests.test_compare      ,,&&,,&&IIIgaj'!*-1a!,71:q1151gaj115)QYYQ7)QYY37r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   rj   r;  rf  r-  r  s        r    test_compare_signalz#ContextAPItests.test_compare_signal       ,,&&,,&&IWQZ4))!Q/3))'!*a8!<))!WQZ8!<)Q%5%5sA>)Q%5%5q#>r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   rl   r;  rf  r-  r  s        r    test_compare_totalz"ContextAPItests.test_compare_total  s    ,,&&,,&&IOOGAJ
3A.2Q7;GAJ7;)Q__c1=)Q__a=r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   rn   r;  rf  r-  r  s        r    test_compare_total_magz&ContextAPItests.test_compare_total_mag  s    ,,&&,,&&I
GAJ7,,Q2A6,,WQZ;Q?,,Q
;Q?)Q%8%8#qA)Q%8%8!SAr)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   rr   r;  rf  r-  r  s        r    test_copy_abszContextAPItests.test_copy_abs$  sg    ,,&&,,&&IJJwr{#B+)QZZ6r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   rp   r;  rf  r-  r  s        r    test_copy_decimalz!ContextAPItests.test_copy_decimal-  h    ,,&&,,&&INN72;'+Q/)Q^^T:r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   rt   r;  rf  r-  r  s        r    test_copy_negatez ContextAPItests.test_copy_negate6  h    ,,&&,,&&IMM'"+&r*A.)Q]]D9r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y )Nr  r  r  r  )r   r   r/   rv   r;  rf  r-  r  s        r    r  zContextAPItests.test_copy_sign?  s    ,,&&,,&&IKK
GBK0Q+Q/WQZ4a8Q4a8)Q[[#r:)Q[[!T:r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y Nr  r  r  r  )r   r   r/   r  r;  rf  r-  r  s        r    test_dividezContextAPItests.test_divideK      ,,&&,,&&IHHWQZ,!Q+'!*a0!4!WQZ0!4)QXXsA6)QXXq#6r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   rx   r;  rf  r-  r  s        r    test_divide_intzContextAPItests.test_divide_intW      ,,&&,,&&ILLWQZ0a+Q/gaj!4a8a4a8)Q\\3:)Q\\1c:r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   r*  r;  rf  r-  r  s        r    test_divmodzContextAPItests.test_divmodc  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y Nr  r)  )r   r   r/   rV  r;  rf  r-  r  s        r    test_expzContextAPItests.test_expo  r  r)   c           	         | j                   j                  }| j                   j                  } |       }|j                   |d       |d       |d            }| j	                  |j                  ddd      |       | j	                  |j                   |d      dd      |       | j	                  |j                  d |d      d      |       | j	                  |j                  dd |d            |       | j	                  |j                   |d       |d      d      |       | j                  t        |j                  ddd       | j                  t        |j                  ddd       | j                  t        |j                  ddd       | j                  t        |j                   |d       |d      d	       | j                  t        |j                   |d
       |d      d       | j                  t         |d      j                   |d      d	       | j                  t         |d
      j                   |d      d       y )Nr  r  r  r  rG  4r  r   znot a decimalr  r  gZd;O?)r   r   r/   r   r;  rf  r-  r  s        r    test_fmazContextAPItests.test_fmax  s   ,,&&,,&&IEE'!*gaj'!*5q!Q+wqz1a0!4q'!*a0!4q!WQZ0!4wqz71:q91=)QUUCA6)QUUAsA6)QUUAq#6 	)QUU!*-wqz?	L)QUU!!*gfou	> 	)WZ%8%<%<!!*o	7)WQZ^^!&/5	2r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r~   r;  rf  r-  r  s        r    test_is_finitezContextAPItests.test_is_finite  g    ,,&&,,&&IKK$R!,)Q[[$7r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_is_infinitez ContextAPItests.test_is_infinite  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_is_nanzContextAPItests.test_is_nan  sg    ,,&&,,&&IHHWR[!"q))QXXt4r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_is_normalzContextAPItests.test_is_normal  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_is_qnanzContextAPItests.test_is_qnan  g    ,,&&,,&&IIIgbk"2*)QYY5r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_is_signedzContextAPItests.test_is_signed  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_is_snanzContextAPItests.test_is_snan  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_is_subnormalz!ContextAPItests.test_is_subnormal  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_is_zerozContextAPItests.test_is_zero  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r  r;  rf  r-  r  s        r    test_lnzContextAPItests.test_ln  sg    ,,&&,,&&IDDb1%)QTT40r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r  r;  rf  r-  r  s        r    
test_log10zContextAPItests.test_log10  g    ,,&&,,&&IGGGBK a()QWWd3r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r  r;  rf  r-  r  s        r    	test_logbzContextAPItests.test_logb  g    ,,&&,,&&IFF72;Q')QVVT2r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   rd   r;  rf  r-  r  s        r    test_logical_andz ContextAPItests.test_logical_and      ,,&&,,&&IMM'!*gaj1q!,a0wqz15q9q'!*5q9)Q]]C;)Q]]As;r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y )Nr  r~  )r   r   r/   rz   r;  rf  r-  r  s        r    test_logical_invertz#ContextAPItests.test_logical_invert
  sn    ,,&&,,&&IWT]+))$/3)Q%5%5v>r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_logical_orzContextAPItests.test_logical_or  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_logical_xorz ContextAPItests.test_logical_xor  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   r  r;  rf  r-  r  s        r    test_maxzContextAPItests.test_max+  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_max_magzContextAPItests.test_max_mag7  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   r  r;  rf  r-  r  s        r    test_minzContextAPItests.test_minC  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_min_magzContextAPItests.test_min_magO  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   minusr;  rf  r-  r  s        r    
test_minuszContextAPItests.test_minus[  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   r-  r;  rf  r-  r  s        r    test_multiplyzContextAPItests.test_multiplyd      ,,&&,,&&IJJwqz71:.Aq)1-GAJ2A6Awqz2A6)QZZa8)QZZC8r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_next_minuszContextAPItests.test_next_minusp  sh    ,,&&,,&&ILL%b)1-)Q\\48r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_next_pluszContextAPItests.test_next_plusy  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_next_towardz ContextAPItests.test_next_toward  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_normalizezContextAPItests.test_normalize  r  r)   c                    | j                   j                  }| j                   j                  } |       }| j                  |j	                  d      |j	                   |d                   | j                  |j	                  d      |j	                   |d                   | j                  |j	                  d      |j	                   |d                   y )Nri  r   rm  )r   r   r/   r;  rh   )r   r   r/   r  s       r    test_number_classz!ContextAPItests.test_number_class  s    ,,&&,,&&I,annWS\.JK*ANN71:,FG,annWS\.JKr)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   plusr;  rf  r-  r  s        r    	test_pluszContextAPItests.test_plus  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j	                  |j                   |d       |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       | j	                  |j                  ddd      d       y )	Nr  r  r  r  rs  r  r  )modulorW  r  )r   r   r/   powerr;  rf  r-  r  s        r    
test_powerzContextAPItests.test_power  s	   ,,&&,,&&IGGGAJ
+A*Q/3GAJ/3WQZ8!<)QWWc15)QWWa5Q!4a8r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   r  r;  rf  r-  r  s        r    rT  zContextAPItests.test_quantize  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   	remainderr;  rf  r-  r  s        r    test_remainderzContextAPItests.test_remainder  s    ,,&&,,&&IKK
GAJ/Q*A.WQZ3Q7Q
3Q7)Q[[#q9)Q[[!S9r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_remainder_nearz#ContextAPItests.test_remainder_near  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   r  r;  rf  r-  r  s        r    test_rotatezContextAPItests.test_rotate  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r   r;  rf  r-  r  s        r    	test_sqrtzContextAPItests.test_sqrt  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_same_quantumz!ContextAPItests.test_same_quantum  s    ,,&&,,&&INN71:wqz21-q1
A6:71:6:)Q^^S!<)Q^^Q<r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   r  r;  rf  r-  r  s        r    test_scalebzContextAPItests.test_scaleb  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   r  r;  rf  r-  r  s        r    
test_shiftzContextAPItests.test_shift  s    ,,&&,,&&IGGGAJ
+A*Q/3GAJ/3)QWWc15)QWWa5r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d       |d            }| j	                  |j                  dd      |       | j	                  |j                   |d      d      |       | j	                  |j                  d |d            |       | j                  t        |j                  dd       | j                  t        |j                  dd       y r  )r   r   r/   subtractr;  rf  r-  r  s        r    test_subtractzContextAPItests.test_subtract  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_to_eng_stringz"ContextAPItests.test_to_eng_string   h    ,,&&,,&&IOOGBK(,a0)Q__d;r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_to_sci_stringz"ContextAPItests.test_to_sci_string)  r  r)   c                    | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       y r  )r   r   r/   r   r;  rf  r-  r  s        r    test_to_integral_exactz&ContextAPItests.test_to_integral_exact2  sn    ,,&&,,&&I,,,R0!4)Q%8%8$?r)   c                 `   | j                   j                  }| j                   j                  } |       }|j                   |d            }| j	                  |j                  d      |       | j                  t        |j                  d       | j                  t        |j                  dd       y )Nr  r)  r  )r   r   r/   r   r;  rf  r-  r  s        r    test_to_integral_valuez&ContextAPItests.test_to_integral_value;  s    ,,&&,,&&I,,,R0!4)Q%8%8$?)Q%8%8"cBr)   N)Gr   r[  r\  r  r
   r   r   r  r  r  r4  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rT  r
  r  r  r  r  r  r  r  r  r  r   r"  r   r)   r    r{  r{  [  sv   9( !#$_$$.@A@ B $ @;1z=+	@2
4
8
?
>
B7;:
;
7
;
72248:58686;6143
<?
;
<
4
8
4
84
998
<8L39
9
:
?
73
=
7
6
9<<@Cr)   r{  c                       e Zd ZeZy)CContextAPItestsNr  r   r)   r    r$  r$  E  r  r)   r$  c                       e Zd ZeZy)PyContextAPItestsNr  r   r)   r    r&  r&  H  r  r)   r&  c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
ContextWithStatementc                 0   | j                   j                  }| j                   j                  } |       } |       5 } |       }d d d         |       }| j                  ||d       | j	                  |d       | j                  |d       y # 1 sw Y   JxY w)N!did not restore context correctlydid not copy the context __enter__ returned wrong context)r   r  r  r  assertIsNot)r   r  r  orig_ctx	enter_ctxset_ctx	final_ctxs          r    test_localcontextz&ContextWithStatement.test_localcontextO  s    \\,,
||00<^ 	#y lG	#L	h	+NO7,FGgy*LM	# 	#s   BBc                    | j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  } |       } |d      } ||      5 } |       }d d d         |       }| j	                  ||d       | j                  j                  |j                  d       | j                  ||d       | j	                  |d       y # 1 sw Y   qxY w)Nr  r,   r*  zdid not set correct contextr+  r,  )r   r/   r  r  r  r;  r,   r-  )	r   r/   r  r  r.  new_ctxr/  r0  r1  s	            r    test_localcontextargz)ContextWithStatement.test_localcontextarg\  s    ,,&&\\,,
||00||00<r"'" 	#i lG	#L	h	+NOw||5RS'+EFgy*LM	# 	#s   1C))C2c                    | j                   j                  dt        dddd      5 }| j                  |j                  d       | j                  |j
                  | j                   j                         | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       d d d        | j                  t        | j                   j                  d       | j                  t        | j                   j                  d       | j                  t        | j                   j                  d	
       | j                  t        | j                   j                  d       | j                  t        | j                   j                  d       | j                  t        | j                   j                  d       | j                  t        | j                   j                  d       | j                  t        | j                   j                  d       | j                  t        | j                   j                  d       | j                  t        | j                   j                  d       | j                  t        | j                   j                  d
       y # 1 sw Y   xY w)Nr  i   r   r  )r,   r-   rT  rY  r  rb   )r_   rT  rq  rY  r  r  rb   r   rP  rN  r.   )r   r  r   r;  r,   r-   rT  rY  r  rb   rf  r-  r  r  s     r    test_localcontext_kwargsz-ContextWithStatement.test_localcontext_kwargsm  s   \\&&o2 ' 
 
	+ SXXr*S\\4<<+G+GHSXXs+SXXr*S\\1-SYY*
	+ 	)T\\%>%>"M*dll&?&?aH*dll&?&?bI*dll&?&?!L*dll&?&?qI)T\\%>%>L)T\\%>%>K)T\\%>%>bI)T\\%>%>bI)T\\%>%>RH)T\\%>%>RH3
	+ 
	+s   B=KKc                    | j                   j                         }|j                  }| j                   j                  d      5 }| j	                  |j                  d       | j	                  |j                  |       d d d        | j                   j                  d      5 }| j	                  |j                  d       | j	                  |j                  |       d d d        y # 1 sw Y   gxY w# 1 sw Y   y xY w)Nr  r4  r8  )r   r  r,   r  r;  )r   r  	orig_precctx2s       r    >test_local_context_kwargs_does_not_overwrite_existing_argumentzSContextWithStatement.test_local_context_kwargs_does_not_overwrite_existing_argument  s    ll%%'HH	\\&&B&/ 	24TYY+SXXy1	2 \\&&B&/ 	24TYY+SXXy1	2 	2	2 	2	2 	2s   9C" 9C."C+.C7c           	         | j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  }| j                   j
                  }| j                   j                  } |       }|j                           |d      } |       5 }	| j                  |	j                  |j                         | j                  |	j                  |j                         d|	j                  |<   d|	_        | j                  |j                  d       | j                  ||	j                  d       | j                  |	j                  |           ||      5 }
| j                  |
j                  |j                         | j                  |
j                  |j                         | j                  ||
j                    |d      d       | j#                  |
j                  |          | j                  |
j                  |          ~
d d d        | j#                  |	j                  |          ~	d d d        | j                  |j                  d       | j#                  |j                  |          | j#                  |j                  |          | j#                  |j                  |          | j#                  |j                  |          y # 1 sw Y   xY w# 1 sw Y   xY w)N  r:  Tz0e-999z3.4e200r  )r   r   r/   r  r  r   r   r*  r;  rN  r.   rT  rO  rf  r   r#   r  r   )r   r   r/   r  r  r   r   r.  r5  r&  r$  s              r    test_nested_with_statementsz0ContextWithStatement.test_nested_with_statements  sD   ,,&&,,&&\\,,
||00,,&&<<((<s#^ 	rRXXx~~6RXXx~~6 $BHHWBGt4gr'8'8(COOBHHW-.g& "  7==9  7==9!!(BHHgi6H!L  '!23 23 RXXh/0!	" 	HMM400112w/0x01 	 	s&   ,CK,.B.K 'K, K)	%K,,K5c           	         | j                   j                  } |       5 }~ |       5 }~ |       5 }~ |       5 }~d d d        d d d        d d d        d d d        y # 1 sw Y   "xY w# 1 sw Y   &xY w# 1 sw Y   *xY w# 1 sw Y   y xY wr   r   r  r   r  r&  r$  r%  c4s         r    test_with_statements_gc1z-ContextWithStatement.test_with_statements_gc1  s    ||00^ 	r 2!^ r% 2	 	   	 	sO   	B 	A4	A(A	A(A4B A%!A((A1-A44A=	9B  B	c           	         | j                   j                  } |       5 } ||      5 }~ ||      5 }~ ||      5 }~~d d d        d d d        d d d        d d d        y # 1 sw Y   "xY w# 1 sw Y   &xY w# 1 sw Y   *xY w# 1 sw Y   y xY wr   rI  rJ  s         r    test_with_statements_gc2z-ContextWithStatement.test_with_statements_gc2  s    ||00^ 	rb! R!"% %b) R	 	
   	 	sO   	B
A7
A+A	A+A7BA($A++A40A77B 	<BBc           	         | j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  } |       5 }~ |d      } ||        ||      5 }~| j                  |j                  d       ~ |d      } ||       ~| j                   |       j                  d        |d      }	 ||	       | j                   |       j                  d        ||	      5 }
~	| j                  |
j                  d       ~
 |d      } ||       ~| j                   |       j                  d        |       5 }| j                  |j                  d       ~d d d        d d d        d d d        d d d        y # 1 sw Y   "xY w# 1 sw Y   &xY w# 1 sw Y   *xY w# 1 sw Y   y xY w)Nr  r4  r  r  r  )r   r/   r  r  r4   r;  r,   )r   r/   r  r  r4   r&  n1r$  n2n3r%  n4rK  s                r    test_with_statements_gc3z-ContextWithStatement.test_with_statements_gc3  s   ,,&&||00\\,,
\\,,
^ 	raBrNb! R  !,!_2  !2!2A6!_2  !2!2A6!"% 
$$RWWa0 aBrN$$Z\%6%6:% 2((!4
		 	. 
 
 		 	sV    G;BF7AF+ F	>F+F7GF($F++F40F77G 	<GGN)r   r[  r\  r2  r6  r?  rC  rG  rL  rN  rT  r   r)   r    r(  r(  K  s.    NN"I82!2F

r)   r(  c                       e Zd ZeZy)CContextWithStatementNr  r   r)   r    rV  rV    r  r)   rV  c                       e Zd ZeZy)PyContextWithStatementNr  r   r)   r    rX  rX    r  r)   rX  c                   4    e Zd Zd Zd Zed        Zd Zd Zy)ContextFlagsc                 
     j                   j                  } j                   j                  } j                   j                  } j                   j                  } j                   j
                  } j                   j                  } j                   j                  } fd} |dddt        g g       }	|	j                   |d      gf|	j                   |d      gf|	j                   |d       |d	      gf|	j                   |d       |d	      gf|	j                   |d       |d	      gfg}
|g|g|g|g|g|||||gg}|
D ]2  \  }}|	j                           || }|	j                  j!                         D cg c]
  \  }}|s	| }}}|D ]  }|	j                          |D ]  } ||	|         || }t#        |      }|D ]  }||vs|j%                  |        |j'                  t(        
       |	j                  j!                         D cg c]
  \  }}|s	| }}}|j'                  t(        
        j+                  ||dd|d|dz           j+                  ||dd|d|z           5 y c c}}w c c}}w )Nc                     j                   t        k(  r!d| j                  |<   | j                  |   r|y | j	                  |       y NT)r   r   rN  r.   _raise_error)r&   flagr   s     r    raise_errorz7ContextFlags.test_flags_irrelevant.<locals>.raise_error  sC    ||q &*d#==&J ' $$T*r)   r+   r5  r   )r,   rT  rY  r-   r.   rN  z100E-425000010r  rr  z
9.87654321r&  z=operation produces different answers depending on flags set: z	expected z, got r  z9operation raises different flags depending on flags set: )r   r   r/   r   r   r   r   r   r0   rf   r   r   r-  r  r*  rN  r  rQ  r3  r9  r>  r;  )r   r   r/   r   r   r   r   r   r`  r&   
operationsflagsetsfnr  r@  kr   rN  extra_flagsr_  new_ansexpected_flags	new_flagss   `                      r    test_flags_irrelevantz"ContextFlags.test_flags_irrelevant  s    ,,&&,,&&,,&&,,&&LL**	,,&&LL**		+ qI#2"BH
 ^^g&6789\\GAJ<([[7<0',2GHI 5w|7LMN 5w|7LMN
 Iy9+y9+gy'9EG # 	WHB!d)C#*==#6#6#8>41aAQ>E>' W##%' /D./d) "&e' 4D>1&--d34 ###+ +2--*=*=*?E31Q1QE	E2&  g!`;>!H"IJ   N"];I9"U#VW+W	W ?" Fs   ;
I9I9
I?
I?
c                    | j                   j                  }| j                   j                  }| j                   j                  } |       }| j	                  |j
                  |j                         | j	                  |j                  |j
                         |j                  |_        | j                  |j
                  |j                         | j                  |j                  |j
                         d|j
                  |<   |j
                  |_        | j                  |j
                  |j                         | j                  |j                  |j
                         i }|j                  |j
                         | j                  ||j
                         | j                  |j
                  |       d||<   | j	                  ||j
                         | j	                  |j
                  |       |di}| j	                  ||j
                         | j	                  |j
                  |       dg}| j	                  ||j
                         | j	                  |j
                  |       y )NTFr  )	r   r/   r   r   rO  rN  r.   r;  update)r   r/   r   r   r  r   s         r    test_flag_comparisonsz"ContextFlags.test_flag_comparisons9  s   ,,&&,,&&,,&&I 	AGGQWW-AGGQWW-''!''*!''*''!''*!''*	AGG$!$'
Aqww'AGGQ' UOAqww'AGGQ'GAqww'AGGQ'r)   c                    | j                   j                  }| j                   j                  }| j                   j                  } |       5 }| j	                  |j
                  |          |j                          | j                   |d      d       | j                  |j                  |          |j                          | j                  |j                  d      d       | j                  |j                  |          |j                          |j                  d      }| j	                  |j                  |          | j                  |d       | j                  |j                  |          |j                          |j                  d      }| j	                  |j                  |          | j                  |d       | j                  |j                  |          d|j
                  |<   |j                          | j                  ||d       | j                  |j                  |          |j                          | j                  ||j                  d       | j                  |j                  |          |j                          |j                  d      }| j	                  |j                  |          |j                          |j                  d      }| j	                  |j                  |          d d d        y # 1 sw Y   y xY w)Ng      @T)r   r   rn  r  r   r.   r*  r;  r#   rN  r   r  rL  rf  )r   r   rn  r  r  r  s         r    test_float_operationz!ContextFlags.test_float_operation_  sV   ,,&&44||00^ .	6qQWW^45 MMOWS\3/OOAGGN34MMOQ--c2C8OOAGGN34 MMO""3'AQWW^45Q$OOAGGN34MMO++C0AQWW^45Q$OOAGGN34 '+AGGN# MMOngs;OOAGGN34MMOna.>.>DOOAGGN34 MMO""3'AQWW^45MMO++C0AQWW^45].	6 .	6 .	6s   
J+K>>Lc                    	
  j                   j                   j                   j                  } j                   j                   j                   j                  }d fd		 d       d      
dd d       d      dd	 d
       d      t        d      t        d      d	
fd	}d fd	} |       } ||      5 } j                  |j                             ||d         ||d        d|j                  <    ||        ||       d d d        y # 1 sw Y   y xY w)Nc                     |j                          t        | |      }|k(  rj                  |||       nj                   ||      d       j	                  |j
                            y r]  )r*  r"   rf  r  r#   rN  )r  rW  r'   r&   signalr   rn  r   s         r    assert_attrz7ContextFlags.test_float_comparison.<locals>.assert_attr  s\    !4 A'!!&!Q/adD)OOGMM.9:r)   rZ  r[  r]  r\  r;  r  r  rK  r  r  r  r  c                    dD ]  } || |        dD ]  } || |         d| d         d| d         d| d         d| d         d| d         	
d| d         d| d         d| d          d      dd| d         	d| d         
d| d          d      t        d      d| d        y )	N)r  r	  )r  r  r  r  r  r  ry  r  )r  )r  rq  r'   r   rr  big_dbig_finf_dinf_f	neg_inf_d	neg_inf_f
neg_zero_d
neg_zero_fsmall_dsmall_fzero_dzero_fs      r    doitz0ContextFlags.test_float_comparison.<locals>.doit  s   * =GUD!V<= + =E7D!V<= (At<
J!TB
FHa>
Ha>!T:	9h4@uh48 !T:Xq$?	5(At<y(At<eh4Hr)   c                 p   | j                          t        d d      g      }j                  t        |      d       j	                  | j
                            | j                          |r j                  |t        d d      g       nt        d d      g      }j	                  | j
                            | j                          d d      dfv }j	                  | j
                            | j                          d d      dddiv }j	                  | j
                            y )	Nr9  z100.0r  r  r  g      $@r  rW  )r*  r   r;  lenr#   rN  rf  sorted)r  rq  r   rW  r   rn  r   s       r    test_containersz;ContextFlags.test_float_comparison.<locals>.test_containers  s    MMOUGG,-.ASVQ'OOAGGN34MMO!!&&32HID'&/23OOAGGN34MMO#..AOOAGGN34MMOc#66AOOAGGN34r)   )rq  Tr   )r   r   r/   rn  r  r  r   r.   )r   r/   r  r  r  r  r  r   rn  rr  rt  ru  rv  rw  rx  ry  rz  r{  r|  r}  r~  r  s   `      @@@@@@@@@@@@@@@r    test_float_comparisonz"ContextFlags.test_float_comparison  s1   ,,&&,,&&44||00	; &/V_


#K(	e&M		I 	I 	I<	5* Y" 	6QWW^454 Ad+&*AGGN#>*An5	6 	6 	6s   (AEEc                    | j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  } |       }| j                  |j                  |          | j                  |j                  |          |j                          d|j                  |<   d|j                  |<   | j                  |j                  |          | j                  |j                  |          y r]  )
r   r   r/   r   rn  r   rN  r.   clear_trapsr#   )r   r   r/   r   rn  r&   s         r    test_float_operation_defaultz)ContextFlags.test_float_operation_default  s    ,,&&,,&&,,&&33)~67~67!%g(,n%n56g./r)   N)	r   r[  r\  ri  rl  r   rn  r  r  r   r)   r    rZ  rZ    s1    @WD$(L 36 36jY6v0r)   rZ  c                       e Zd ZeZy)CContextFlagsNr  r   r)   r    r  r     r  r)   r  c                       e Zd ZeZy)PyContextFlagsNr  r   r)   r    r  r    r  r)   r  c                       e Zd ZdZd Zd Zy)SpecialContextszTest the context templates.c           
      v   | j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  }| j                   j
                  }| j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  }	t        | |d|||||	g        |       j                         }
|j                  }|j                  }d }	 dx|_        |_        ||fD ]?  } ||        |       }| j                  ||       | j                  |j                  d       A 	 ||_        ||_         ||
       |r|y # t        $ r}|j                   }Y d }~5d }~ww xY w# ||_        ||_         ||
       |r|w xY w)Nr.   i  )r   BasicContextExtendedContextr  r4   r   r   r   r   r   r(   ro   r,   r-  r;  	Exceptionr   )r   r  r  r  r4   r   r   r   r   r   savecontextbasic_context_precextended_context_precextemplater  rI  s                    r    test_context_templatesz&SpecialContexts.test_context_templates	  s   ||00,,66\\,,
\\,,
<<8844<<((LL**	,,&&t\7~xGL	
 !l'')).. / 4 4	7::L 4(/9 .8$L  H-  -	. !3L#8O {#   	B	 !3L#8O {# s1   
AE: F :	FFF FF F8c                    | j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  }| j                   j
                  }| j                   j                  }| j                   j                  }| j                   j                  }| j                  |j                  d       | j                  |j                  d       t        | |d|||g        |       j                         }	|j                  }
d }	  |       }|j                  }d|_
         |       }| j                  |j                  |        ||        |       }| j                  ||       | j                  |j                  d       |
|_
         ||	       |r|y # t        $ r}|j                  }Y d }~.d }~ww xY w# |
|_
         ||	       |r|w xY w)Nr+   r.   i  )r   r7  r  r  r  r4   r   r   r   r;  r,   r(   ro   r-  r  r   )r   r7  r  r  r  r4   r   r   r   r  default_context_precr  r  saveprecrI  s                  r    test_default_contextz$SpecialContexts.test_default_context-  s   44||00,,66\\,,
\\,,
<<8844<<((**A.--q1t^W~x8	
 !l'')-22	AvvH"%NAQVVX.~&AQ/QVVS) #7N{#   	B	 #7N{# s+   A:F, ,	G5GG GG G#N)r   r[  r\  r]  r  r  r   r)   r    r  r    s    %"H'r)   r  c                       e Zd ZeZy)CSpecialContextsNr  r   r)   r    r  r  V  r  r)   r  c                       e Zd ZeZy)PySpecialContextsNr  r   r)   r    r  r  Y  r  r)   r  c                       e Zd Zd Zy)ContextInputValidationc           	         | j                   j                  }| j                   j                  }|j                         }dD ]e  }t	        ||d       | j                  t        ||      d       | j                  t        t        ||d       | j                  t        t        ||d       g t	        |dd       | j                  t        |d      d       | j                  t        t        |dd       | j                  t        t        |dd       | j                  t        t        |d	d       | j                  t        t        |d	d
       | j                  t        t        |d	d       | j                  t        t        |d	d       dD ][  }| j                  t        t        ||d       | j                  t        t        ||d       | j                  t        t        ||g d       ] | j                  t        t        |dd       | j                  t        t        |dg        | j                  t        t        |di        | j                  t        t        |dddi       dD ]#  }| j                  t        |j                  |       % | j                  t        t        |d
       | j                  t        t        |d
       | j                  t        |d       | j                  t        |d       | j                  t        |d       | j                  t        |d       | j                  t        |dg       | j                  t        |dg       | j                  t        |d       | j                  t        |d       y )Nr,   rY  r}  rq  r  rT  r~  r  r  r  r  r-   r+   r  r  rb   r  rn  r  rN  r.   r   r   )r,   rY  rT  r-   r  rb   rN  r.   rP  r<  r;  r  r=  Qr>  r   r  )r  r   )r   r/   r7  ro   r+  r;  r"   rf  r  r-  r.  KeyError__delattr__)r   r/   r7  r  r'   s        r    test_invalid_contextz+ContextInputValidation.test_invalid_context^  s   ,,&&44! % 	BDAtV$WQ-v6j'1dB?i!T5A		B 	67#F+W5*gq&!<)WaA)WaR@)WaQ?)WaSA)WaUC * 	DDj'1dB?j'1dA>i!T7C	D 	.'1fcB 	)Wa"=(GQ<(GQ-a0	2' 	CDnammTB	C
 	)Wa3)Wa3 	)Wv>)Wu=*gQ7*g;(GC59(GC59 	)WE:)WE:r)   N)r   r[  r\  r  r   r)   r    r  r  \  s    :;r)   r  c                       e Zd ZeZy)CContextInputValidationNr  r   r)   r    r  r    r  r)   r  c                       e Zd ZeZy)PyContextInputValidationNr  r   r)   r    r  r    r  r)   r  c                       e Zd Zd Zy)ContextSubclassingc                 	   | j                   j                  }j                  j                  }j                  }j
                  }j                  }j                  }j                  }j                  }j                  }	 G fdd      }
        } |
       }dD ](  }| j                  t        ||      t        ||             *  | j                  t        |
fi ddi  |
d      }| j                  |j                  d       | j                  |	|j                    |d      d	        | j                  t"        |
fi d
di  |
t$        d      }| j                  |j&                  t$               | j                  |j)                   |d            d        | j                  t        |
fi ddi  |
dd      }| j                  |j*                  d       |j-                   |d       |d            }| j                  | |d             |||||fD ]   }| j/                  |j0                  |          "  | j                  t        |
fi ddi  |
dd      }| j                  |j2                  d       | j                  ||j,                   |d       |d             | j                   t4        k(  r(|||fD ]   }| j/                  |j0                  |          "  | j                  t        |
fi ddi  |
d	      }| j                  |j6                  d	       |j9                  d      }| j                  |j;                  |      d        | j                  t        |
fi ddi  |
dd       }| j                  |j<                  d       |j)                   |d            }| j                  t?        |      d!        | j                  t"        |
fi d"di  |
||g#      }||fD ]   }| j/                  |j0                  |          " |jA                          tB           D ]   }| jE                  |j0                  |          "  | j                  t"        |
fi d$di  |
||g%      }||fD ]   }| j/                  |jF                  |          " |jI                          tB           D ]   }| jE                  |jF                  |          " y )&Nc                   "    e Zd Z	 	 	 d fd	Zy)>ContextSubclassing.test_context_subclassing.<locals>.MyContextNc	                 ~   
j                  |        ||| _        ||| _        ||| _        ||| _        ||| _        ||| _        |3t        |t              rt           |z   D 	ci c]  }	|	|	|v 	 }}	|| _
        |4t        |t              rt           |z   D 	ci c]  }	|	|	|v 	 }}	|| _        y y c c}	w c c}	w r   )r  r,   r-   rT  rY  r  rb   r  rQ  r4  rN  r.   )r   r,   r-   rT  rY  r  rb   rN  r.   r   r/   r   s             r    r  zGContextSubclassing.test_context_subclassing.<locals>.MyContext.__init__  s       &# $DI'$,DM# $DI# $DI'$,DM$!&DJ$!%.9G9PSX9X YAAJ Y Y!&DJ$!%.9G9PSX9X YAAJ Y Y!&DJ % !Z !Zs   )B5B:)NNNNNNNNr  )r/   r   s   r    	MyContextr    s    IM@D%)'r)   r  r,   r-   rT  rY  r  rb   rN  r.   r,   rq  r  r4  9e2r   r-   XYZ)r-   r,   rc  r+   rT  rs  )rT  r,   z1e-99z2.234e-2000r;  rY  )rY  r,   1e99z
2.234e2000r  r;  1E222z1e+222rb   r  c   )rb   rY  z!1.000000000000000000000000000E+99rN  r=  r.   r>  )%r   r   r/   r   r   r   r   r   r   r   r   r;  r"   rf  r  r,   r  r-  r   r-   r  rT  r   r#   rN  rY  r   r  r   r   rb   r6  r*  r4  r   r.   r  )r   r   r   r   r   r   r   r   r   r   r  r  r   r'   r  rq  r/   r   s                   @@r    test_context_subclassingz+ContextSubclassing.test_context_subclassing  st   ,,////// ////##//%%	%%	"33	' 	'4 IK' 	ADWQ-wq$/?@	A
 	*i?F2;?1#*AJJJ 	)YE:e2DEz2Z0/3 	*i>F1:>2A&$EE''"GM$:;GEN+	9gwG 	-FOOAGGFO,	- 	*i?F2;?11%#(AEE76?GL<QR<<1"Hg6 101 	*iCJr?Cq!Q'W%+X6 	*i?GA;?AB'!$FF76?#Q!DE 	)YB75/BWn56/ 	-FOOAGGFO,	-	$W- 	.FQWWV_-	. 	)YB75/BWn56/ 	-FOOAGGFO,	-	$W- 	.FQWWV_-	.r)   N)r   r[  r\  r  r   r)   r    r  r    s    i.r)   r  c                       e Zd ZeZy)CContextSubclassingNr  r   r)   r    r  r    r  r)   r  c                       e Zd ZeZy)PyContextSubclassingNr  r   r)   r    r  r    r  r)   r  c                       e Zd Zd Zd Zd Zy)CheckAttributesc                    | j                  t        j                  t        j                         | j                  t        j                  t        j                         | j                  t        j
                  t        j
                         | j                  t        j                  t        j                         | j                  t        j                  du xs t        j                  du        | j                  t        j                  du xs t        j                  du        | j                  t        j                  t        j                         | j                  t        t              t        t                     y )NTF)r;  r   rQ  r  r   rk  rl  r#   r8  __version__dirr   s    r    test_module_attributesz&CheckAttributes.test_module_attributes  s     	QZZ0QZZ0QZZ0akk2$.I!..E2IJ$.I!..E2IJ6QQ(r)   c                 v   t        t        j                               D cg c]  }d|v s|j                  d      r| }}t        t        j                               D cg c]  }d|v s|j                  d      r| }}| j                  t        |      t        |      z
  t                      y c c}w c c}w )N__rF  )r  r   r/   r	  r  r;  r   r   r   r  r  s       r    test_context_attributesz'CheckAttributes.test_context_attributes&  s    AIIK(O1DAIQ\\#=NQOOAIIK(O1DAIQ\\#=NQOOQ#a&#%0 POs   B1B1 B6;B6c                 z   t        t        j                  d            D cg c]  }d|v s|j                  d      r| }}t        t        j                  d            D cg c]  }d|v s|j                  d      r| }}| j	                  t        |      t        |      z
  t                      y c c}w c c}w )Nr+   r  rF  )r  r   r   r	  r;  r   r  s       r    test_decimal_attributesz'CheckAttributes.test_decimal_attributes,  s    AIIaL)P1TQYall3>OQPPAIIaL)P1TQYall3>OQPPQ#a&#%0 QPs   B3B3"B8=B8N)r   r[  r\  r  r  r  r   r)   r    r  r    s    )11r)   r  c                   Z    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zy)Coveragec                    | j                   j                  }| j                   |d      j                         d       | j                   |d      j                         d       | j                   |d      j                         d       y )N	1234e9999i'  r  r   r  )r   r   r;  rh  rc  s     r    test_adjustedzCoverage.test_adjusted4  si    ,,&&-668%@002A6002A6r)   c                    | j                   j                  }| j                   j                  } |d      j                         }| j	                  |d        |       }|j                   |d            }| j	                  |d       y )Nr+   )r   r   r  rj  r;  )r   r   r  r  r  s        r    test_canonicalzCoverage.test_canonical<  sk    ,,&&\\,,
AJ  "ALKK
#Ar)   c                 \   | j                   j                  j                         }d|_        d|_        d|_        t        |_        d|_        d|_	        t        | j                      D ]   }d|j                  |<   d|j                  |<   " |j                         }d}| j                  ||       y )Nr   r5  r   r  Fz{Context(prec=425000000, rounding=ROUND_HALF_DOWN, Emin=-425000000, Emax=425000000, capitals=0, clamp=1, flags=[], traps=[]))r   r7  ro   r,   rY  rT  r   r-   r  rb   r4  rN  r.   __repr__r;  )r   r  r'  r   r   s        r    test_context_reprzCoverage.test_context_reprG  s    LL'',,.$

!$,,/ 	!C AGGCL AGGCL	! JJL" 	Ar)   c                 
   | j                   j                  }| j                   j                  } |       5 }d|_        d|_        d|_        | j                  t         |d            d       | j                   |d      dz   d       | j                   |d      dz  d	       | j                   |d      d
z  d       | j                   |d      j                   |d      d      d       | j                   |d      j                  d
d      j                         d       | j                  t         |d      d	d
      d	       | j                   |d      j                         d       | j                   |d      j                         d       | j                   |d      j                         d       | j                   |d      j                         d       | j                   |d      j!                         d       | j                   |d      j#                         d	       | j                   |d      j%                         d       | j                   |d       d       | j                   |d      dz  d       | j                   |d      j'                         d       | j                   |d      j)                          |d             | j                   |d      j+                          |d             | j                   |d      j-                         d       | j                   |d      d       | j                   |d      d
z  d       | j                   |d      d
z
  d       | j                   |d      j/                         d       | j1                   |d      j3                                | j1                   |d      j5                                | j1                   |d      j5                                | j1                   |d      j7                                | j1                   |d      j9                                | j1                   |d      j;                                | j1                   |d      j;                                d d d         |       5 }d|_        d d!z  } ||       }|j=                         }| j                  ||       |j?                         }| j                  ||       |jA                   |d            }| j                  ||       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)"Nr  rq  z-10r  7r  r)  rs  r  r  z1.2r`  ry  Tz1.01r  F20580r  r  r+   z2E+1z-1E+1z+Normalr  z1.12345r  r  ra  r  i  i  )!r   r   r  r,   rY  rT  r;  r   r   r  r   powrV  r   r   r  r  r  rz   r   r   r   rh   r   r#   r|   r~   r   r   r   rr   rt   rv   )r   r   r  r  r  r  r  s          r    r  zCoverage.test_implicit_contextZ  sE   ,,&&||00^ <	4qAFAFAF S0"5WS\A-q1WT]Q.2WT]a/3WU^//CQGMM'%.,,Q299;TBSa3Q7WV_002A6MM'&/335u=MM'&/668$?WT]--/3WT]002A6WU^002A6WT]99;Q?gen_b1WS\A-q1WT]557;WT]446HWU^5579IJWT]7799Egdm^R0WT]Q.2WT]Q.2WY/AACQG OOGCL5578OOGCL2245OOGCL2245OOGFO3356OOGDM3356OOGCL0023OOGCL0023y<	4~ ^ 	#qAFAA

AQ"AQ"GAJ'AQ"	# 	#<	4 <	4~	# 	#s   Q)T8,BU8UUc                    | j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  } |       5 }t         |d      d      \  }}| j                  | |d             | j                  | |d             t         |d      d      \  }}| j                  |j                         xr |j                                d|j                  |<   t         |d      d      \  }}| j                  |j                         xr |j                                d|j                  |<   |j                          t         |d       |d            \  }}| j                  |j                         xr |j                                | j                  |j                  |          |j                          t         |d      d	      \  }}| j                  |j                         xr |j                                | j                  |j                  |          |j                          t         |d
      d
      \  }}| j                  |j                         xr |j                                | j                  |j                  |          d|j                  |<   |j                          t         |d      d
      \  }}| j                  |j                         xr |j                                | j                  |j                  |   xr |j                  |          d d d        y # 1 sw Y   y xY w)N10912837129r  10901935194ry  r  Fr  r  r      )r   r   r  r   r   r*  r;  r#   r   r.   r*  rN  r   )r   r   r  r   r   r  r  r  s           r    r  zCoverage.test_divmod  s   ,,&&||00<<8844^ !	5q'-0$7DAqQ
 34Q/'%.!,DAqOOAHHJ5188:6(-AGG$%'%.!,DAqOOAHHJ5188:6(-AGG$%MMO'%.'%.9DAqOOAHHJ5188:6OOAGG$456MMO'%.#.DAqOOAMMO:
;OOAGG$456MMO'!*a(DAqOOAHHJ5188:6OOAGG$456&+AGGN#MMO'"+q)DAqOOAMMO:
;OOAGG$45 4GGN35A!	5 !	5 !	5s    K&MMc                    | j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  } |       5 }d|_        |j                          | j                   |d      dz   |d             | j                  |j                  |          d|_        d|_
        d|_        |j                          d|j                  |<   | j                   |d       |d	      z   |d
             | j                  |j                  |          d d d        y # 1 sw Y   y xY w)Nr  r  r  r[  r  rq  Fr  r  r  )r   r   r  r   r   r,   r*  r;  r#   rN  rY  rT  r.   )r   r   r  r   r   r  s         r    r  zCoverage.test_power  s    ,,&&||00<<((,,&&^ 	/qAFMMOWU^s2GFODOOAGGG,-AFAFAFMMO %AGGHWU^wu~=wu~NOOAGGH-.	/ 	/ 	/s    CD99Ec                    | j                   j                  }| j                   j                  }| j                   j                  } |       5 }d|_        d|_        d|_        d|j                  |<    |d      j                   |d            }| j                  |j                                d d d        y # 1 sw Y   y xY w)Nr  rq  Fr  1e1)r   r   r  r   r,   rY  rT  r.   r  r#   r   r   r   r  r   r  r  s         r    rT  zCoverage.test_quantize  s    ,,&&||00<<88^ 	(qAFAFAF(-AGG$%$$WU^4AOOAHHJ'	( 	( 	(s   
A!B44B=c                     | j                   j                  }| j                   j                  } |       }| j                   |d      j	                         d       | j                  |j	                         d       y )Nr  r  )r   r   r  r;  ri  r  s       r    
test_radixzCoverage.test_radix  sZ    ,,&&\\,,
L++-r2B'r)   c           	          | j                   j                  }dD ].  }| j                   t         |d      |      d      t               0 y )N)r  r  r  r  r  r  r!  r#  r  r  )r   r   r  r"   ra  )r   r   r'   s      r    r.  zCoverage.test_rop  sF    ,,&&M 	NDMM5''#,5e<nM	Nr)   c                    | j                   j                  }| j                   j                  } |       5 }d|_        | j	                  t         |d      j                               d       | j	                  t         |d      j                               d       | j	                  t         |d      j                  d            d       | j	                  t         |d	      j                  d
            d       | j	                  t         |d	      j                  d            d       | j                  t         |d      j                  d       | j                  t         |d      j                  dd       d d d        y # 1 sw Y   y xY w)Nr  rb  r)  z9.99e-5ra  rr  rs  z1.23457rc  r  z1.2345000000r  z0E+10rV  r  r  )	r   r   r  r,   r;  r6  	__round__rf  r-  )r   r   r  r  s       r    
test_roundzCoverage.test_round  s5   ,,&&||00^ 
	JqAFS!:!:!<=tDS!3!=!=!?@#FS!6!@!@!CDiPS!2!<!<R!@A>RS!2!<!<S!ABGLi)B)BCHi)B)BAqI
	J 
	J 
	Js   EFFc                 |    | j                   j                         }| j                  t        |j                  dg       y )Nr  )r   r/   rf  r  r   )r   r  s     r    test_create_decimalzCoverage.test_create_decimal  s.    LL  "*a&6&6>r)   c                 :   | j                   j                  }| j                   j                  } |       5 }d|_         |ddz        ddz  z  }| j	                  t        |      d       | j	                  |j                         d       d d d        y # 1 sw Y   y xY w)Nr^  i  i  r  iS  r  r  )r   r   r  r,   r;  r  r  r   r   r  r  r  s        r    r;  zCoverage.test_int  s    ,,&&||00^ 	1qAFd
#b$h.ASVQ'Q]]_a0		1 	1 	1s   ABBc                 2   | j                   j                  } |       }d|_        ddz   }|j                  |      }| j	                  ||        |j                  |      }| j	                  ||        |j                  |d      }| j	                  ||        y )Nr  i  i  r  )r   r/   r,   rr   r;  rt   rv   )r   r/   r  r  r  s        r    r  zCoverage.test_copy#  s    ,,&&IdlOJJqMQBMM!QBKK1QBr)   N)r   r[  r\  r  r  r  r  r  r  rT  r  r.  r  r  r;  r  r   r)   r    r  r  2  sH    7	&O#b'5R/(((NJ"?1 r)   r  c                       e Zd ZeZy)	CCoverageNr  r   r)   r    r  r  3  r  r)   r  c                   ,     e Zd ZeZ fdZ fdZ xZS )
PyCoveragec                 ~    t         |           t        j                         | _        t        j
                  d       y r  r  r  s    r    r   zPyCoverage.setUp9  r  r)   c                 `    t        j                  | j                         t        |           y r   r  r  s    r    r  zPyCoverage.tearDown>  r  r)   r  r  s   @r    r  r  6  r  r)   r  c                       e Zd ZdZd Zy)PyFunctionalityz!Extra functionality in decimal.pyc                     t         j                  }t         j                  }g d}|D ](  \  }}}| j                  t	         ||      |      |       * y )N)
)z.0er  z1e+0)z#.0er  z1.e+0)rE  r  r  )z#.0fr  1.)rM  1.1r  )z#gr  r  )rO  r  r  )z#.0gr  r  )rU  r  z100%)z#.0%r  z100.%)r  r   r  r;  r  )r   r   r  r  r  r   rK  s          r    test_py_alternate_formattingz,PyFunctionality.test_py_alternate_formattingE  sM    ))~~ * 	>NCFVGAJ4f=	>r)   N)r   r[  r\  r]  r  r   r)   r    r  r  B  s
    +>r)   r  c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)
PyWhiteboxz White box testing for decimal.pyc                    t         j                  }t         j                  } |       5 }d|_         |d       |d      z  }| j	                  | |d              |d       |d      z  }| j	                  | |d              |d       |d      z  } |d       |d	      z  }| j	                  | |d
              |d       |d	      z  } |ddz         |d	      z  }d|_         |d       |d      z  }| j	                  | |d             d|_         |d       |d      z  }| j	                  | |d             d|_         |d       |d      z  }| j	                  | |d             d|_         |d       |d      z  }| j	                  | |d             d|_         |ddz         |d      z  }t         j
                  |_        t         j                  |_        t         j                  |_	        d|j                  t         j                  <    |d      }|dz  }| j	                  |d       d d d        y # 1 sw Y   y xY w)Nr  i   r  z
0.00390625z-0.6z0.0012885819256e7l   o z-0.0625r_  152587890625e7rs  ic
  r  152587890625z3e-6r  z2.6e-6r  z2.56e-6r     iB  u   l                  )r  r   r  r,   r;  rQ  r   rY  rk  rT  r.   r   )r   r   r  r  r  D2ress          r    test_py_exact_powerzPyWhitebox.test_py_exact_power]  s   ))~~^ ,	,qAF'&/1AQ 56'&/1AQ 78 GFO3A%);;AQ/()WY-??A4 GI$66AAF'76?:AQ0AF'76?:AQ 12AF'76?:AQ	 23AF'76?:AQ	 23AF376?2A ZZAFZZAFZZAF!"AGGAIIB)CS(+Y,	, ,	, ,	,s   HI  I	c                    	 t         j                  }t         j                  }t         j                  }|j	                         }t        d t        t            D              |_         ||        |d       |d       |d      	 |d      d1	 fd	} |        j                  j                  j                          j                  j                  j                          j                  j                  j                          |d        |dd        |dd        |d	d        |d
d        |dd        |dd        |dd        |dd        |d        |dd        |d        |d        |d        |dd        |dd        |d        |d        |d        |dd        |dd        |dd        |d        |dd        |dd        |dd        |d d        |d!d        |d"        |d#d        |d$d        |d%        |d&        |d'd        |d(d        |d)d        |d*        |d+d        |d,d        |d-d        |d.        |d/        |d0       y )2Nc              3   $   K   | ]  }|d f 
 yw)r   Nr   )r   r   s     r    r!   z=PyWhitebox.test_py_immutability_operations.<locals>.<genexpr>  s     9!1v9s   z-25e55z33e+33c                    |rt        d| z   dz          j                  j                  j                         j                  j                  j                         j                  j                  j                         j                  j                  j                         j                  j                  j                         j                  j                  j                         y t        d| z   dz          j                  j                  j                         j                  j                  j                         j                  j                  j                         y )Nzd1.z(d2)z())r7  r;  _sign_int_exp)	operationuseOtherb1b2r  r  r   s     r    checkSameDecz@PyWhitebox.test_py_immutability_operations.<locals>.checkSameDec  s   UY&/0  2884  "''2  "''2  2884  "''2  "''2UY&-.  2884  "''2  "''2r)   __abs__r  Tr   r  r  r	  r  r  r  	__float__r   rx  __int__	__trunc__r  r  __neg____bool____pos__r"  r  r  r  r!  r  r  r#  r  __str__r  r  rh  r  r  r  r  r   r  r   r   r   r   r  )F)r  r   r7  r4   ro   r1   r4  r.   r;  r  r  r  )
r   r   r7  r4   r  r  r  r  r  r  s
   `     @@@@r    test_py_immutability_operationsz*PyWhitebox.test_py_immutability_operations  s^   ))))\\
!9~a'8991XXXX	3 	3 	288,"''*"''*YY%\4(Xt$Xt$Xt$Xt$Xt$Xt$[!^T*Z Y[!Y%Y%YZ YY%Z&]D)Z _d+Z&Z&Z&Z&YY%]D)Z Z Y%UD!UD![!Z&%t,^T*V_%]#r)   c                     t         j                  } |d      } ||      }| j                  t        |      d       | j	                  t        |      t        |             y )Nri  rj  )r  r   r;  r6  rO  r>  r  s       r    test_py_decimal_idzPyWhitebox.test_py_decimal_id  sI    ))BKAJQ&BqE2a5)r)   c                     t         j                  }t         j                  } |       5 } |d      j                  dt              }| j                  |j                                d d d        y # 1 sw Y   y xY w)Nry  r  )r  r   r  _rescaler   r#   r   r  s        r    test_py_rescalezPyWhitebox.test_py_rescale  sX    ))~~^ 	(q''84AOOAHHJ'	( 	( 	(s   <A--A6c                 |    t         j                  }| j                  t         |d      j                  dt
               y )Nz3.1234r   )r  r   rf  r  _roundr   rc  s     r    test_py__roundzPyWhitebox.test_py__round  s*    ))*gh&7&>&>8Lr)   N)	r   r[  r\  r]  r  r  r  r   r#  r   r)   r    r  r  Z  s"    *1,fM$^*(Mr)   r  c                   @    e Zd ZdZed        Zed        Zed        Zy)CFunctionalityzExtra functionality in _decimalc                 r   t         j                  }t         j                  }t         j                  }t         j                  }d } ||      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d        || |        ||      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d        || |        ||      }| j                  |j                  d       | j                  |j                  d	       | j                  |j                  d
        || |       | j                  t        |d       | j                  t        |d       | j                  t        |d       y )Nc                 t    | j                  |j                  d       t        | |dg        t        | |dg        y )Nr  r.   rN  )r;  rb   r(   )r   r&   s     r    assert_restz7CFunctionality.test_c_ieee_context.<locals>.assert_rest  s2    W]]A.4'264'26r)   r  `   ir~  rE  rF  "   i   ir  rq  i   )r   IEEEContext	DECIMAL32	DECIMAL64
DECIMAL128r;  r,   rY  rT  rf  r  r  )r   r+  r,  r-  r.  r(  r  s          r    test_c_ieee_contextz"CFunctionality.test_c_ieee_context  sW    mmKK	KK	\\
	7
 	"#$%D!	"$%&D!
#$&'D! 	-e<*k26*k48r)   c                    t         j                  } |t         j                  t         j                        }| j	                  |j
                  t         j                         | j	                  |j                  t         j                         y )N)rN  r.   )r   r/   r:   
DecRoundedr;  _flags_trapsr  s      r    test_c_contextzCFunctionality.test_c_context  sO    ))!,,all;1<<01<<0r)   c                 `   t         j                  t         j                  t         j                  t         j                  t         j
                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  f}| j!                  t         j"                  d       | j!                  t         j$                  d       | j!                  t         j&                  d       | j!                  t         j(                  d       t+        |      D ]  \  }}| j!                  |d|z          | j!                  t         j,                  t         j                  t         j                  z  t         j
                  z  t         j                  z  t         j                  z  t         j                  z  t         j                  z         | j!                  t         j.                  t         j,                  t         j                  z         | j!                  t         j0                  t         j.                  t         j                  z  t         j                  z         y )Nro  r     i   r  )r   r:   DecConversionSyntaxDecDivisionByZeroDecDivisionImpossibleDecDivisionUndefinedDecFpuError
DecInexactDecInvalidContextDecInvalidOperationDecMallocErrorDecFloatOperationDecOverflowr1  DecSubnormalDecUnderflowr;  r,  r-  r.  IEEE_CONTEXT_MAX_BITSr0  DecIEEEInvalidOperation	DecErrorsDecTraps)r   condrG  r   s       r    test_constantszCFunctionality.test_constants%  s    LL!//1D1D##Q%;%;MM1<<)<)<!!1#3#3NNANN
 	b)b)s+00#6 dO 	&DAqQ1%	& 	22..001//0 ' ,,	-
 ../ ))*	+ 	22,,-	. 	Q]]21>>A	Cr)   N)r   r[  r\  r]  requires_extra_functionalityr/  r4  rI  r   r)   r    r%  r%    sB    )!!9 "!9F "1 "1 "#C "#Cr)   r%  c                      e Zd ZdZd Zd Zd Zd Zd Zd Z	e
d        Zd	 Ze
d
        Zd Zd Zd Zd Zd Ze
d        Ze
d        Zd Zd Zd Zd Zd Z ej6                  ej:                  j=                  d      d       ej6                  ed       ej6                   e dd      d      e!d                             Z"d Z#d Z$d  Z%y!)"	CWhiteboxzWhitebox testing for _decimalc                 h   t         j                  }t         j                  }ddz  }ddz  } |       5 }d|_        t	        d      D ]V  }t        j                  ||      }t        j                  dd      }||z  }	 ||       ||      z  }
| j                  |	|
       X 	 d d d        y # 1 sw Y   y xY w)Nr  #   $   i@B rs  r  i  )r   r   r  r,   rt  r)  r  r;  )r   r   r  r  r  r  rG  r  rW  r  r  s              r    test_bignumzCWhitebox.test_bignumO  s     ))~~VV^ 	'qAF1X '$$R,$$T40FAJ'!*,  A&'	' 	' 	's   A,B((B1c                 P    | j                  t        t        j                  dd       y )Nr+   r  )rf  r-  r   r   r   s    r    test_invalid_constructionz#CWhitebox.test_invalid_construction`  s    )QYY59r)   c                     t         j                  }t         j                  }t         j                  }t         j                  } | |             5  | j                  ||d       d d d        y # 1 sw Y   y xY w)N1e9999999999999999999)r   r   r   r/   r  rf  )r   r   r   r/   r  s        r    test_c_input_restrictionz"CWhitebox.test_c_input_restrictionc  s^    ))--))~~')$ 	7.57	7 	7 	7s   A++A4c                    t         j                  }t         j                  }|j                         }d|_        d|_        d|_        t        |_        d|_	        d|_
        t        t            D ]   }d|j                  |<   d|j                  |<   " d|j                  |<   d|j                  |<   |j                         }d}| j                  ||       y )Nr   r5  r   r  TaQ  Context(prec=425000000, rounding=ROUND_HALF_DOWN, Emin=-425000000, Emax=425000000, capitals=0, clamp=1, flags=[Clamped, InvalidOperation, DivisionByZero, Inexact, FloatOperation, Overflow, Rounded, Subnormal, Underflow], traps=[Clamped, InvalidOperation, DivisionByZero, Inexact, FloatOperation, Overflow, Rounded, Subnormal, Underflow]))r   r7  rn  ro   r,   rY  rT  r   r-   r  rb   r4  rN  r.   r  r;  )r   r7  rn  r  r'  r   r   s          r    test_c_context_reprzCWhitebox.test_c_context_reprn  s     ))))!$

!!$ 	 CAGGCLAGGCL	  #'"&JJLO 	Ar)   c           	      Z   t         j                  }t         j                  }t         j                  }t         j                  }t         j
                  }t         j                  }t         j                  }t         j                  dkD  } |       }	| j                  t        |	j                  j                  dd       | j                  t        |	j                  j                  dd       | j                  t        |	j                  j                  |       | j                  t        |	j                  j                  |       | j                  t         t"        |	ddg       | j                  t         t"        |	ddg       | j                  t        t"        |	dddi       | j                  t        t"        |	dddi       |	j                  j%                         }
|
|= d	|
d
<   | j                  t        t"        |	d|
       | j                  t        t"        |	d|
       |rdnd}|rdnd}dD ]  }| j                  t        t"        |	||       ! | j                  t        t"        |	d|        | j                  t        ||       | j                  t        ||       | j                  t        ||        | j                  t&        ||dz          | j                  t&        ||dz          | j                  t&        || dz
         | j                  t&        ||dz          | j                  t&        ||dz          dD ]  }| j                  t&        t"        |	||dz          | j                  t&        t"        |	|| dz
         t(        j*                  dk7  sX| j                  t        t"        |	||       | j                  t        t"        |	|| dz
          t         j                  dk(  rm| j                  t&        t-        |	d      |dz          | j                  t&        t-        |	d      |dz          | j                  t&        t-        |	d      | dz
         t         j                  dk(  r| j                  t        t-        |	d      d       | j                  t        t-        |	d      d       | j                  t        t-        |	d      d       | j                  t        t-        |	d      d       | j                  t        t-        |	d      d       | j                  t        t-        |	d      d       dD ]  }| j                  t        t"        |	|d       | j                  t        t"        |	|d       | j                  t         t"        |	|g d        |s_| j                  t        t"        |	|d!       | j                  t        t"        |	|d"        | j                  t         t.        d#t1                      | j                  t         t.        d$t1                       |       }| j                  t         |d%        ||       y )&Nr   i!  r   rN  r  r.   r  r  ipr  r  r  l     NZoi ʚ;r  rT  r4  r:  r9  r  r<  r;  )r,   rT  rY  r  rb   win32r   r   r   i?rq  i9r  r                 zwith localcontext("xyz"): passz-with localcontext(context=getcontext()): passr  )r   r/   r   r   rn  r  r  r4   rQ  rf  r  rN  __setitem__r.   r  __delitem__r-  r+  ro   r  r  platformr"   execr  )r   r/   r   r   rn  r  r  r4   HAVE_CONFIG_64r  r   int_maxgt_max_emaxr'   saved_contexts                  r    test_c_context_errorszCWhitebox.test_c_context_errors  s(   ))--::))~~\\
\\
**y0I 	(AGG$7$7a@(AGG$7$7a@*agg&9&98D*agg&9&9;KL)Wa3%@)Wa#?(GQ!A?(GQ!A? GGLLNn%(GQ;(GQ; ,' .fE % 	IDj'1dKH	I*gq&;,G 	*gK@*gK@*g[LA 	-wqyA-wqyA-xzB-	B-719E B 	LDmWawqyImWaxzJ||w&!!*gq$H!!*gq$
K	L ::"mWQ8I-J%ai)mWQ8I-J%ai)mWQ8I-J&hqj* ::"j'!5F*GKj'!5F*G(*j'!5F*GLj'!5F*G(*j'!5F*G)+j'!5F*GK * 	IDj'1dB?j'1dA>i!T7C!!*gq$F!!*gq$H	I 	)T+K (	$)TI (	$
 #)Z7=!r)   c                    | j                  t        j                  t        j                         | j                  t        j                  t        j                         | j                  t        j
                  t        j
                         | j                  t        j                  t        j                         | j                  t        j                  t        j                         | j                  t        j                  t        j                         | j                  t        j                  t        j                         | j                  t        j                  t        j                         y r   )r  r   r   r  r   r   r   r   r   r0   r   r   s    r    test_rounding_strings_internedz(CWhitebox.test_rounding_strings_interned  s    ajj!**-allALL1aooq7ammQ]]3aooq7a''):):;a''):):;allALL1r)   c           	         t         j                  }t         j                  }t         j                  }t         j                  }t         j
                  }t         j                  }t         j                  dkD  } |       }|rdnd}	| j                  t        t        |d|	dz          | j                  t        t        |d|	 dz
         t        j                  dk7  r>| j                  t        t        |d|	       | j                  t        t        |d|	 dz
         dD ]  }
| j                  t        t        ||
|	dz          | j                  t        t        ||
|	 dz
         t        j                  dk7  sX| j                  t        t        ||
|	       | j                  t        t        ||
|	 dz
          | j                  t        t        |dd	       | j                  t        t        |dd       | j                  t        t        |dg d
       |r:| j                  t        t        |dd       | j                  t        t        |dd       dD ]<  }
| j                  t        t        ||
d       | j                  t        t        ||
d       > y )Nr   r  r  _allcrr  r  rY  )r2  r3  rq  r  rZ  r[  r}  r  )r   r/   r   r   r  r  r4   rQ  rf  r  r+  r  r^  r  r-  )r   r/   r   r   r  r  r4   r`  r  ra  r'   s              r    test_c_context_errors_extraz%CWhitebox.test_c_context_errors_extra  s
   ))--::~~\\
\\
**y0I ,' 	-!XwqyI-!XxzJ<<7"j'1hHj'1h
K ) 	KDmWawqyImWaxzJ||w&!!)WawG!!)WaxzJ	K 	*gq(B?*gq(A>)Wa7Cj'1hFj'1hH ) 	@Di!T6Bi!T3?	@r)   c                 N   t         j                  }t         j                  }t         j                  }t         j                  }t         j
                  }t         j                  }|j                         }d|_        t        |_
        d|_        d|_        d|_        d|_        | j                  |j                  d       | j                  |j                  t               | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j!                         d       | j                  |j#                         d       t         j$                  dk(  r|j'                  d	       |j)                  d	       |j+                  d
       | j                  |j                  d	       | j                  |j                  d	       | j                  |j                  d
       y y )Nr*  i  iHr  r   i'i  r   rd  re  )r   r7  r   r   r   r   r   ro   r,   r   r-   rY  rT  r  rb   r;  EtinyEtoprQ  r   r   r   )r   r7  r   r   r   r   r   r  s           r    test_c_valid_contextzCWhitebox.test_c_valid_context&  s   ))))KK	))))KK	! "

$]3'&Q'!$E*4( ::"i(i(j)QVVY/QVVY/QVVZ0 #r)   c                     t         j                  }|j                         }| j                  |j                  d       d|_        | j                  |j                  d       y )Nr  r   )r   r7  ro   r;  rh  )r   r7  r  s      r    test_c_valid_context_extraz$CWhitebox.test_c_valid_context_extraL  sJ    ))!1%1%r)   c           	      @   t         j                  }t         j                  }t         j                  }t         j                  }t         j
                  }t         j                  dkD  rdnd} |       5 }d|j                  |<   | j                  | |d      j                  | dz
         | j                  | |d      j                  |       | j                  | |d      j                  t        |dz                | j                  t         j                   |d      j                  t        |dz
                | j                  t         |d      j                  | dz
         | j                  t         |d      j                  |dz          d d d        y # 1 sw Y   y xY w)	Nr   r  r  TrV  r  r  r  )r   r   r   r  r   rl  rQ  r.   rf  r  r  r  )r   r   r   r  r   rl  ra  r  s           r    test_c_roundzCWhitebox.test_c_roundU  sV   ))--~~::KK	ZZ)3'^ 	)q(,AGG$%.0I0I&hqj*.0I0I%'.0F0F!(1*o/a00'#,2H2H"9Q;//1mWV_-F-F&hqj*mWV_-F-F%ai)	) 	) 	)s   /DFFc                    t         j                  }t         j                  dkD  }| j                  t         |d      j
                  dg d       | j                  t         |d      j
                  dd       | j                  t         |d      j
                  g        | j                  t         |d      j
                  d       |rdnd}| j                  t         |d      j
                  d	|z         y )
Nr   r  z=10.10r+   z<>=10.10r  r  rr  z=%d.1)r   r   rQ  rf  r-  r  r  )r   r   r`  maxsizes       r    test_c_formatzCWhitebox.test_c_formatm  s    ))**y0)WQZ%:%:Hb!L)WQZ%:%:HaH)WQZ%:%:B?*gaj&;&;ZH+'*gl&;&F&F!G+	-r)   c                    t         j                  }t         j                  }t         j                  } |d      }| j	                  |j                         d       | j                  t        |j
                  d       | j                  t        |j
                  dd       | j                  t        |j
                  d       | j	                  |j                         d       | j                  t        |j                  d       | j                  t        |j                  dd       | j                  t        |j                  d       | j	                  |j                         d       | j                  t        |j                  d       | j                  t        |j                  dd       | j                  t        |j                  d        |       5 } |d      j                  t              }| j	                  | |d              |d      j                  t              }| j	                  | |d             d|j                  |<   | j                  | |d      j                  t               d d d        y # 1 sw Y   y xY w)Nr  r)  r  z99999999999999999999999999.9100000000000000000000000000Tz999.9)r   r   r   r  r;  r  rf  r-  r   r   r   r.   )r   r   r   r  r  r  s         r    test_c_integralzCWhitebox.test_c_integral{  s   ))))~~BK"-)Q]]D9)Q]]B<)Q]]B7,,.3)Q%8%8$?)Q%8%8"cB)Q%8%8"=,,.3)Q%8%8$?)Q%8%8"cB)Q%8%8"=^ 	Uq67II(SAQ(E FG67II(SAQ(E FG#AGGGgww'7'I'I8T	U 	U 	Us   BI22I;c           
         t         j                  }t         j                  }t         j                  }t         j                  }t         j
                  }| j                   |d      j                         d       | j                  t        t         |d      dd       | j                  t         |d      j                  dd       | j                  t         |d      j                  d	dd       | j                  t         |d
      j                   |d      g        | j                  t         |d
      j                   |d       |              | j                  t         |d
      j                   |d      d       | j                  t         |d
      j                   |d      t        d        |       5 }|j                          | j                  t        |j                    |d      dd       | j                  t        |j"                  d       | j                  t        |j$                  d       | j                  t        |j&                  dddd       | j                  t        |j                  dd	dd       | j                  t)        |j#                   |d                  d       | j                  |j+                         d       d|j,                  |<   | j                  | |d      j.                  d       | j                  ||j&                  dd       | j1                  |j2                  |          |j5                          d|j,                  |<   | j                  | |d      j.                  d       | j                  ||j&                  dd       | j1                  |j2                  |          d|j,                  |<   d|_        | j                  |t         |d      dd       d d d        y # 1 sw Y   y xY w)Nz9.99e10z99.9E+9r  r  rG  r+   r  r  r  rr  z	1e-100000r  r  r  r  200Tr   i  )r   r   r   r   r  r  r;  r   rf  r-  r  rh   r   r  r   r  rv   rj  r|   r*  r6  ri  r.   r   r#   rN  r*  r,   )r   r   r   r   r  r  r  s          r    test_c_funcszCWhitebox.test_c_funcs  s'   ))--))\\
~~+99;YG)S'!*a=)WQZ%<%<c3G)WQZ%<%<acJL!**GK,@"	
 	L!**GK,@*,	
 	L!**GK,@"	
 	L!**GK,@(D	

 ^ 	LqMMO igaj#sKic:i=i1acBiAsCHSWS\!:;UCQWWY+&*AGGN#ngaj.C.CQGnahh1=OOAGG$456MMO(,AGG$%.
0E0EqI.!Q?OOAGGN34(,AGG$%AF.WT]AsK5	L 	L 	Ls   4H5O22O;c                 "   t         j                  }t         j                  } |d      }dD ]?  }t        ||      }| j	                  t
        |d       | j	                  t
        |dd        A dD ]?  }t        ||      }| j	                  t
        |d       | j	                  t
        |dd        A | j	                  t
        |j                  d g        | j	                  t
        |j                  i g        | j	                  t
        |j                  g g        | j	                  t
        |j                  d g        | j	                  t
        |j                  i g        | j	                  t
        |j                  g g        | j	                  t
        |j                  d g        | j	                  t
        |j                  i g        | j	                  t
        |j                  g g        | j	                  t
        |j                  ddd       | j	                  t
        |j                  dddd        | j	                  t
        |j                  dg d        | j	                  t
        |j                  dg d 	       | j	                  t
        |j                  dg g         |       }| j	                  t
        |j                  ddd
       | j	                  t
        |j                  ddd 
       | j	                  t
        |j                  ddd 
       y )N10001111111)rV  r   r   r  r  r  rz   r   r   r   rh   r   r   r  r  )r  rj   rd   r   r  r   r  r   r   r  r  r  r  r  r  rP  )mod)r   r   r/   r"   rf  r-  r  r   r   r   r  r  )r   r   r/   r  r'   funcr  s          r    test_va_args_exceptionsz!CWhitebox.test_va_args_exceptions  s   ))))M"K 	BD 1d#Dis;isDA	BD 	BD 1d#Dis;isDA	B 	)Q]]T2N)Q]]RL)Q]]B;)Q%8%84QST)Q%8%82rR)Q%8%8"bA)Q%8%84QST)Q%8%82rR)Q%8%8"bA)QUUAq#>)QUUAq#tD)QZZBE)QZZBF)QZZB;I)QWWa<)QWWa$?)QWWc1$?r)   c                    | j                  t        j                  j                  t        j                  t        j
                  z  t        j                  z  t        j                  z  t        j                  z         | j                  t        j                  j                  t        j                  t        j
                  z  t        j                  z         y r   )
r;  r   r  r3  rE  r8  rA  rC  r:   r7  r   s    r    test_c_context_templatesz"CWhitebox.test_c_context_templates  s    NN!!%%a&9&99!--GNN<<(	

 	##%%a&9&99!--G	
r)   c                 X    t         j                  }t         j                  }t         j                  }t         j                  }t         j
                  }t         j                  }t         j                  }t         j                  }t         j                  }	t         j                  }
t         j                  }t         j                  }t         j                  }t         j                  } fd}|j                         } j!                  ||j"                  v        |j%                          |j"                  j'                         D ]  }d|j"                  |<    |j"                  j)                         D ]  } j!                  |        |j%                          |j"                  j+                         D ]  \  }} j-                  |         j-                  |j.                  j1                  |              j3                  |j.                  j1                  d      d         j5                  |j.                  j1                  dd      d        j7                  t8        |j.                  j0                  ddd        j5                  t;        |j.                        t;        |j"                               t=        j>                  |j.                        }t=        j>                  |j"                        }|j.                  jA                         }|jC                          ||_"         j!                  |j.                  |          |j%                          ||_#         j!                  |j"                  |          |jC                          |j.                  j                         }d||<   ||_         |||j.                         |j%                          |j"                  j                         }d||<   ||_         |||j"                         |t         j                  |	t         jH                  |
t         jJ                  |t         jL                  |t         jN                  |t         jP                  |t         jR                  |t         jT                  |t         j                  i	}t         jV                  t         jX                  t         jZ                  t         j\                  t         j                  t         j^                  t         j`                  g}t;        tb        t                  }te        |      D ]  }te        |      D ]  }tf        D ]  }ti        jj                  tb        t            |      }ti        jj                  tb        t            |      }ti        jl                  dd      }ti        jl                  dd	      }ti        jl                  d	d      }ti        jl                  d	d
      } ti        jl                  d	d
      }!ti        jl                  d	d
      }" ||||||!| to        |      to        |            } j5                  |jp                  |        j5                  |jr                  |        j5                  |jt                  |        j5                  |jv                  |        j5                  |jx                  |!        j5                  |jz                  |        d	}#|D ]
  }$|#||$   z  }#  j5                  |jD                  |#       d	}#|D ]
  }$|#||$   z  }#  j5                  |jF                  |#          |D ]:  }%|%|_"         j!                  |jD                  |z          |||j.                         < |D ]:  }%|%|_#         j!                  |jF                  |z          |||j"                         < y )Nc                 p    |D ]0  }|| k(  rj                  ||          j                  ||          2 y r   )r#   r   )rq  signal_dictr'  r   s      r    assertIsExclusivelySetz<CWhitebox.test_c_signal_dict.<locals>.assertIsExclusivelySet"  s=    " 7&=OOK$45$$[%56	7r)   Tr  r  r  r  r  ir   r  r  )>r   r/   r7  r   rn  r   r   r   r   r   r   r   r:   r>  rE  ro   r#   r.   r  r  valuesr  r   rN  r  r  r;  rf  r-  r  r  	getsizeofr  r*  r2  r3  r1  r<  rB  rC  rA  r8  r@  r9  r:  r;  r=  r?  r7  r4  rt  r  r)  sampler  rQ  r,   r-   rT  rY  r  rb   )&r   r/   r7  r   rn  r   r   r   r   r   r   r   r:   r>  rE  r  r  rd  r   r   r   
IntSignalsIntCondlimr  r   r  rN  r.   r,   ro  rn  rb   r  crr   r  rH  s&   `                                     r    test_c_signal_dictzCWhitebox.test_c_signal_dict  s    ))))--))))::KK	KK	))))))\\
33"#";";	7 ! 	AGG+,	 	AAGGAJ	! 	AOOA		GGMMO 	 DAqQ	  	X./aggkk#&-S#.4)QWW[[#sC@QWWs177|4MM!''"MM!''"GG 	
()	& 012 	
GGLLN .~qww7	GGLLN)y!''2 1<<
1<<
1<<
Q^^
Q^^
AMM
!--
!--
A55


 
!
!1#9#91==


q44a6F6F



 .#$s 	2A3Z 2* 2E"MM.*;Q?E"MM.*;Q?E!++Au5D!++FA6D!++Au5D",,Q2E!++Aq1D))!Q/BTE4)-U$u+&*5k3A $$QVVT2$$QZZ7$$QVVT2$$QVVT2$$QZZ6$$QWWe4A" +Z]*+$$QXXq1A" +Z]*+$$QXXq1922	2@  	>DAHOOAHH%<<="#3QWW=	>
  	>DAHOOAHH%<<="#3QWW=	>r)   c                 z   t         j                  	 ddlm} d }dfd	}d |g d      dd}d	 |g d
      dd}d |g d
      dd}dk(  r| j                  t        |d|d       | j                  t        |d|d       | j                  t        |d|d       y # t        $ r | j                  d       Y w xY w)Nr   r  r  c                 \    dj                  | D cg c]  }t        |       c}      S c c}w r  )r  r  )r  r  s     r    r  z6CWhitebox.test_invalid_override.<locals>.make_grouping  s#    77C0qCF0110s   )c                 4     |       j                  ||      S r   )r  )r  r  r  r   s      r    r  z0CWhitebox.test_invalid_override.<locals>.get_fmt  s    1:((h77r)   rd  )   r  r   r  xxxxxr  r  yyyyy   r  rM  r  )r   r   r  r  r  r  rf  r  )r   r  r  r  invalid_groupinginvalid_dotinvalid_sepr   s          @r    test_invalid_overridezCWhitebox.test_invalid_override  s    ))	;'	2	8 "&}5!
 &&y1!
 "&y1%
 s?j'5.5 	*guk3G*guk3G=  	;MM9:	;s   B B:9B:c                    t         j                  }t         j                  }t         j                  } |       5 }d|j                  |<   dt
        j                  z  }| j                  |||       dt
        j                   dz
  z  }| j                  |||       dt
        j                  z  }| j                  |||       dt
        j                   dz
  z  }| j                  |||       d d d        y # 1 sw Y   y xY w)NTz0e%dr  z1e%d)r   r   r  r   r.   r  rs  rf  r  s         r    test_exact_conversionzCWhitebox.test_exact_conversion  s    ))~~--^ 	<q(,AGG$% $A.;3;;,q.)A.; $A.; 3;;,q.)A.;#	< 	< 	<s   B0C11C:c                    t         j                  }t         j                  }t         j                  }t         j                  }t         j
                  } |       5 }d|_        d|j                  |<   d|j                  |<   d|j                  |<   ddt        j                  f}| j                  t        |j                  |            d       | j                  |||       ddt        j                  f}| j                  ||j                  |       | j                  |||       ddt        j                   dz
  f}| j                  t        |j                  |            d       | j                  |||       ddt        j                   dz
  f}| j                  ||j                  |       | j                  |||       ddt        j                  dz   f}| j                  t        |j                  |       | j                  t        ||       ddt        j                   dz
  f}| j                  t        |j                  |       | j                  t        ||       d	}| j                  t         ||            d
       d}| j                  t         ||            d
       d}| j                  t         ||            d       d d d        y # 1 sw Y   y xY w)Nr+   Tr  r   z
-0E+999999)r   r  r  z-0E-1000007r  r  rZ  )r  r  r  )r  r  r  z-sNaN1)r   r   r  r   r   r   r,   r.   r  rs  r;  r6  r   rf  r  )r   r   r  r   r   r   r  r  s           r    test_from_tuplezCWhitebox.test_from_tuple  sf   ))~~--::KK	^ (	8qAF(,AGG$% $AGGH!%AGGI B$AS!1!1!!45|D.;Is{{+Ah(8(8!<.; BQ'AS!1!1!!45}E.;I|A~.Ai)9)91=.; BA&AmQ-=-=qAmWa8BQ'AmQ-=-=qAmWa8 AS_g6AS_g6 AS_h7Q(	8 (	8 (	8s   I)K

Kc                    t         j                  }t         j                  dkD  }| j                   |d      j	                         d       |rH |ddz        j	                         } |ddz        j	                         }| j                  ||dz          y  |ddz        j	                         } |ddz        j	                         }| j                  ||d	z          y )
Nr   r   r  r  i  r        r  )r   r   rQ  rK  
__sizeof__r;  )r   r   r`  r  r  s        r    test_sizeofzCWhitebox.test_sizeof  s    ))**y071:002A6U$//1AU$//1AQ!$T
#..0AT
#..0AQ!$r)   c                 "   t         j                  } G d dt              } G d dt              } G d dt               G fddt              }|||fD ]8  }| j	                  |j                   |d	            |j                  d	             : y )
Nc                       e Zd Zd Zd Zy)<CWhitebox.test_internal_use_of_overridden_methods.<locals>.Xc                      yNr  r   r   s    r    r  zMCWhitebox.test_internal_use_of_overridden_methods.<locals>.X.as_integer_ratio  s    r)   c                     | S r   r   r   s    r    r  zDCWhitebox.test_internal_use_of_overridden_methods.<locals>.X.__abs__      r)   Nr   r[  r\  r  r  r   r)   r    Xr    s    r)   r  c                       e Zd Zd Zy)<CWhitebox.test_internal_use_of_overridden_methods.<locals>.Yc                     dgdz  S Nr  r  r   r   s    r    r  zDCWhitebox.test_internal_use_of_overridden_methods.<locals>.Y.__abs__      s3wr)   N)r   r[  r\  r  r   r)   r    Yr        r)   r  c                       e Zd Zd Zy)<CWhitebox.test_internal_use_of_overridden_methods.<locals>.Ic                     dgdz  S r  r   r   s    r    
bit_lengthzGCWhitebox.test_internal_use_of_overridden_methods.<locals>.I.bit_length  r  r)   N)r   r[  r\  r  r   r)   r    Ir    r  r)   r  c                       e Zd Z fdZd Zy)<CWhitebox.test_internal_use_of_overridden_methods.<locals>.Zc                 $     d       d      fS r  r   )r   r  s    r    r  zMCWhitebox.test_internal_use_of_overridden_methods.<locals>.Z.as_integer_ratio"  s    !ad|#r)   c                     | S r   r   r   s    r    r  zDCWhitebox.test_internal_use_of_overridden_methods.<locals>.Z.__abs__$  r  r)   Nr  )r  s   r    Zr  !  s    $r)   r  gfffffFY@)r   r   r  r  r;  r  )r   r   r  r  r  r%   r  s         @r    'test_internal_use_of_overridden_methodsz1CWhitebox.test_internal_use_of_overridden_methods  s    ))	 		 		 		 	 a7 	8CW//E
;$//68	8r)   aixzEAIX: default ulimit: test is flaky because of extreme over-allocationzTest is unstable on EmscriptenT)addressmemoryzVASAN/MSAN sanitizer defaults to crashing instead of returning NULL for malloc failure.c                 t   g d}t         j                  }t         j                  }t         j                  } |t         j                  t         j
                  t         j                        } ||      5  | j                   |d      j                         d       | j                   |d      j                         d       | j                   |d      j                         d       | j                   |d      j                         d       | j                   |ddz        j                         d       | j                   |d	      j                         d
       | j                   |d      j                         d       | j                   |d      j                          |d             | j                  t         |d      d      d       | j                   |d      dz  d       | j                   |d      dz  d       | j                   |d      dz   |d             d d d        y # 1 sw Y   y xY w)N)	rz   r   r   rd   r   r   r   r  r  )r,   rT  rY  r   r  r  r  r     l     9V    r  40E9z2.0E+5r  )r  r  i  rq  z0.0025)r   r   r/   r  rQ  rk  r   r;  rV  r  r  r  r   r*  )r   MaxContextSkipr   r/   r  
maxcontexts         r    test_maxcontext_exact_arithz%CWhitebox.test_maxcontext_exact_arith,  s   $< ))))~~ !**1::AJJO
*% 	DWQZ^^-q1WQZ]]_a0WQZ--/3WU^113Q7WRW-335s;WV_113R8WQZ__.2WV_113WX5FGVGBK3V<WR[A-q1WQZ!^Q/WS\R/1BC	D 	D 	Ds   2F3H..H7c                 N   t        t        j                         j                        } |       }d}| j	                  t
        |      5  t        |       d d d        | j	                  t
        |      5  t        |       d d d        | j	                  t
        |      5  t        |       d d d        | j	                  t
        |      5  d|t        j                  <   d d d        | j	                  t
        |      5  |t        j                      d d d        | j	                  t
        |      5  |t        j                         j                  k(   d d d        | j	                  t
        |      5  t        j                         j                  |k(   d d d        | j	                  t
        |      5  |j                          d d d        y # 1 sw Y   rxY w# 1 sw Y   UxY w# 1 sw Y   8xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nzinvalid signal dictT)r5  r   r/   rN  assertRaisesRegexr  r  iterr:  r   ro   )r   
SignalDictsderr_msgs       r    test_c_signaldict_segfaultz$CWhitebox.test_c_signaldict_segfaultX  s   !))+++,
\'##J8 	G	 ##J8 	H	 ##J8 	H	 ##J8 	*%)Bq!!"	* ##J8 	#q!!"	# ##J8 	$!))+###	$ ##J8 	$IIK#	$ ##J8 	GGI	 	+	 		 		 		* 	*	# 	#	$ 	$	$ 	$	 	s`   G1GGG*7G7)"H)"H)HGGG'*G47H HHH$c                     t         j                  d      }| j                  t        |d      d       t         j	                  d      5  | j                  t        |d      d       d d d        y # 1 sw Y   y xY w)Nz6.09e+23r>   z6.09E+23r   r;  )r   r   r;  r  r  )r   r  s     r    test_format_fallback_capitalsz'CWhitebox.test_format_fallback_capitalsv  sa     IIj!34^^Q^' 	9VAs^Z8	9 	9 	9s   A..A7c                    t         j                  d      }| j                  t        |d      d       t         j	                  t         j
                        5  | j                  t        |d      d       d d d        y # 1 sw Y   y xY w)Nz6.09z#.1fz6.1rP  z6.0)r   r   r;  r  r  r   )r   r  s     r    test_format_fallback_roundingz'CWhitebox.test_format_fallback_rounding~  se    IIf6*E2^^Q\\^2 	7VAv.6	7 	7 	7s   A<<BN)&r   r[  r\  r]  rP  rR  rU  rW  rd  rf  rJ  ri  rm  ro  rq  rt  rw  rz  r  r  r  r  r  r  r  r  r   skipIfr  r^  r	  r   r   r   r  r  r  r  r   r)   r    rL  rL  K  sG   ''":	7:c"J	2 "(@ "(@T$1L "& "&)0-U>9Lv*@X "	
 "	
 "C> "C>J#HJ<0/8b%8: X__S\\,,U3\^X__]$DEX___T$?EF
  D F F^ DF<97r)   rL  c                       e Zd ZdZd Zd Zy)SignatureTestzFunction signaturesc                 X   t        t              D ]  }|j                  d      rt        t        |      }t        t        |      }|dk(  s|dk(  st        j                  |      sVt        j                  |      }t        j                  |      }t        |j                  j                               }|j                  j                         D cg c]  }|j                  d      s| }}| j                  ||d|z         |j                  j                         D cg c]  }|j                   }	}|j                  j                         D cg c]%  }|d   j                  d      s|d   j                  ' }
}|dk7  sr| j                  |	|
d	|z          y c c}w c c}w c c}w )
NrF  r   r/   parameter name mismatch in %smsgr   r  r4   parameter kind mismatch in %s)r  r  r	  r"   r   inspect
isfunction	signaturerQ  
parametersr  r;  r  kindr  )r   r'   p_funcc_funcp_sigc_sigc_namesr  p_namesc_kindp_kinds              r    test_inspect_modulez!SignatureTest.test_inspect_module  s   F 	SDs#Q%FQ%F	!TY%6""6*))&1))&1 u//4467&+&6&6&;&;&= .<<,  . .   '%Dv%M ! O +0*:*:*A*A*CDQ!&&DD-2-=-=-C-C-E 0A$//#. A$)) 0 0 <'$$VV)H6)Q % S1	S. E0s   FF"*F'c                     t         j                  j                  t         j                  j                  t        t        j                  d      t        j                  d      t        j                  d      t        j                  d      t        j                  d      t        j                  d      t        j                  d      t        j                  d      t        j                  d      t        j                  d      ddt        j                  t        j                         dt        t        j                  d      t        j                  d      t        j                  d      t        j                  d      t        j                  d      t        j                  d      t        j                  d      ddt        j                  t        j                         difdd  fd} |d	        |d
       y )Nr  r  r  )r  rd  r  r  r  r  rW  r  rV  r  numr   r-   r&   )r  rd  r  rW  r  rV  r  r  r   r-   r&   c                     g }i }|j                   j                         D ]W  \  }}|dk(  r|j                  k(  r|j                  |    |          3|j                  k(  r|    |   ||<   Nt	        d       ||fS )Nr   zunexpected parameter kind)r  r  r  r3  r   )	moduler'  r  kwargsnameparamPOSPOS_KWDpdicts	         r    mkargsz0SignatureTest.test_inspect_types.<locals>.mkargs  s    DF"~~335 Be6>8::$KKfd 34ZZ7*#(=#6F4L$%@AAB <r)   c                 *    | dk(  ry| dk(  ry| dk(  ry| S )zwThe C Context docstrings use 'x' in order to prevent confusion
               with the article 'a' in the descriptions.r  r  r  rW  r  r  r   )r   s    r    trz,SignatureTest.test_inspect_types.<locals>.tr  s$     CxCxCxHr)   c           
         t        t        |       }t        t        |       }t        |      D ]  }|j	                  d      rt        ||      }t        ||      }t        j                  |      sDt        j                  |      }t        j                  |      }t        |j                  j                               }|j                  j                         D 	cg c]
  }	 |	       }
}	j                  |
|d|z         |j                  j                         D 	cg c]  }	|	j                   }}	|j                  j                         D 	cg c]  }	|	j                   }}	j                  |d          j                  |d          | dk(  rj                  |dd  |dd  d|z         n)j                  t        |      t        |      d|z          t        |      \  }}	  t         |d      |      |i |  t        |      \  }}	  t         |d      |      |i |  y c c}	w c c}	w c c}	w # t         $ r t#        d	|d
|d|      w xY w# t         $ r t#        d	|d
|d|      w xY w)NrF  r  r  r   r   r  r  r+   zinvalid signature for z: r  )r"   r  r   r  r	  r  r  r  rQ  r  r  r;  r  r  r  r  r  r   )typ_typec_typer'   r  r  r  r  r  r  r  r  r  r  kwdsr  r  r  r   r  s                  r    r  z.SignatureTest.test_inspect_types.<locals>.doit  sx   Q^FQ^FF *c??3' . .%%f-#--f5E#--f5E #5#3#3#8#8#:;G.3.>.>.C.C.EFr!uFGF$$Wg)H6)Q % S /4.>.>.E.E.GHaffHFH.3.>.>.E.E.GHaffHFH MM&)W5MM&)S1 Y((VABZ-Lv-U ) W ((Vc&k-Lv-U ) W "(5!1JD$c0q	40$?$? "(5!1JD$c0q	40$?$?Q*c G
 IH$ % c(fVZ\`)abbc % c(fVZ\`)abbcs*   H0H5H:+H?I ?I I>r   r/   )	r  _ParameterKindPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORDr   r   r   r  r  )r   r  r  r  r  r  r  s   ` @@@@@r    test_inspect_typesz SignatureTest.test_inspect_types  sL   $$44((>> aiiliil))A,))A,))A,))A,))A,))A,IIaL yy|!" !0 aiiliil))A,))A,))A,IIaL yy|!" !
014	 	-	c -	c^ 	YYr)   N)r   r[  r\  r]  r  r  r   r)   r    r  r    s     S8er)   r  c           	          t         | j                         }t        j                  t              D ]X  }d|vs|j                  d      r|j                  d      \  }}t         	|t         vr<|fd}t        t        d|z   |       ~~~~Z dt        fdt        ffD ]N  \  }}|s	t        |dz   t        t        j                  fd|i      }	|j                  | j                  |	             P t         d	d
lm}
m} t'        j(                         j+                         t        t        fD ]b  }|s|fd}|ffd	}|t        u r|nd	}|t,        j.                  d<   |j                   |
||||             t&        t,        j.                  d<   d |S )Nz.decTestr  c                 2    | j                  t        |z         S r   )r  	directory)r   r   s     r    r  zload_tests.<locals>.<lambda>  s    $..Q*G r)   test_r   Pyr<   r   r   )DocTestSuiteIGNORE_EXCEPTION_DETAILc                 @    |t         j                  d<   t        |       y Nr   )r  r,  r7   )slfr}  s     r    r   zload_tests.<locals>.setUp+  s    ),I&S	r)   c                     t         t        j                  d<   |j                  t        |   j                                t        j                  j                                y r  )orig_sys_decimalr  r,  r4   ORIGINAL_CONTEXTro   )r  r}  orig_contexts     r    r  zload_tests.<locals>.tearDown.  sC    )9I&/499;< ++L,=,=,?@r)   )r   r  optionflags)
TODO_TESTS
suiteClassoslistdirr   r	  r
  r+  r<   r   r  r5  r   TestCaseaddTestloadTestsFromTestCasedoctestr  r  r	  r  ro   r  r,  )r  testspatternfilenameheadtailtesterprefixr}  
test_classr  r  r   r  r  r  s                  @r    
load_testsr    s   !!# JJy) )X%)<)<S)A^^C(
d!d*&< (Ggnf5dD&) Qx$* @&>1'):):;$c*,
 	f22:>?@ A'22499;a4 	6C"  #& A 69AX11K%(CKK	"MM,s%(/:< =%5CKK	"	6 Lr)   c                  p    t        t               t        t               t        t        ay t	        d      ay r  )r7   r   r  ARITHr   r(  r   r)   r    setUpModuler   9  s$    GG)uH/B9/MHr)   c                  P   t         r.t         j                  t        t            j                                t        j                  t        t           j                                t         st        j                  dt               t        t        j                  d   urt        d      y )Nz*C tests skipped: no module named _decimal.r   zGInternal error: unbalanced number of changes to sys.modules['decimal'].)r   r4   r
  ro   r  warningswarnUserWarningr	  r  r,  r   r   r)   r    tearDownModuler%  ?  sw    !,,'*//1
2LL!!$))+,B!	#s{{955 3 4 	4 6r)   c                 \    | a |a|at        j                  t
        |rdnddt
        g       y)z Execute the tests.

    Runs all arithmetic tests if arith is True or if the "decimal" resource
    is enabled in regrtest.py
    r  r  F)	verbosityexitargvN)r  r  r+  r   mainr   arithverbose
todo_testsdebugs       r    testr0  O  s+     EJEMM(7aXJWr)   z:test_decimal.py [--debug] [{--skip | test1 [test2 [...]]}]z--debugz-d
store_truez2shows the test number and context before each test)actionhelpz--skipz-sz%skip over 90% of the arithmetic tests)r,  r-  r+  )NNNN)r]  r  r  r  r  r"  r*  ro   r   r$  r  test.supportr   r   r   r   r   r   r	   r
   r   r   r   test.support.import_helperr   r   r   r)  r  r9  r^  r   r  r   r	  
cfractionsr,  
pfractionsr   
skipUnlessrequires_cdecimalr  r  rN  r  r3   r   r   r   r   r   r   r   r   rn  r4  r(   r   r   r   r   r   r   r0   r   r  r
  r7   TESTDATADIRr   r)  r   __file__pathdirnamecurdirtestdirsepr   isdirr   r2  hasattrEXTRA_FUNCTIONALITYrJ  r  skip_if_extra_functionalityr<   r_  r  r  r  r  r0  r2  r4  r  r  r  r  r  r(  r0  requires_working_threadingr2  rD  rF  rH  r  r  r!  rw  ry  r{  r$  r&  r(  rV  rX  rZ  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r%  rL  r  r  r   r%  r  r(  r  r+  r0  optparseOptionParserr  
add_option
parse_argsoptr  skipr/  r   r)   r    <module>rL     s  "        I I) ) ; ) (    <<8n- 	*6	J<8 " ![MB
I  [MB
I z1Z(	)I 'H''+DE  1U1<<>$$&'$U1<<>$$&'  iiAIIq{{AKKjj!""A$6$6"&aiiAIIq{{AKKjj!""A$6$6	H ::\\
mm####\\
 J{/ aQ\\^TQ\\^ %  z88A;DD
''//$

,299bff{*RVV3	GGMM),,   &a6dE 2x22G I -hoo46 a# a#LU< U<n
  8(:K:K  !98;L;L K1 K1Z  8(:K:K  !98;L;L V9 V9p
 *h//  :x00 hA hAT	 68I8I   79J9J 
%'N*0Z -,,.*( *( /*(Z ]H$5$5  mX%6%6 nE nE` ]H$5$5  
mX%6%6 
[N [Nz
 nh&7&7  ~x'8'8 hC hCT (9(9  ):): b bH 0(2C2C  183D3D I0 I0V L("3"3  \8#4#4 N N` (9(9  ):): <; <;| 4h6G6G  5x7H7H k. k.Z ,h.?.?  -x/@/@  1h'' 1  1:   B (++  
8,, 
>h'' >0ZM"" ZMxSCX&& SCj v7!! v7 v7p DH%% D  DN*XN4 	
X zZ[ALLD<pLqLLD<cLd,,.KS$
xx5$'	4$ciiH4& r)   