o
    HXh>G                    @   s  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mZmZ ddlmZmZmZ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ried ed	d
gdZed	d
gdZddl Z!eddgdZ"eej#d	< eddgdZ$eej#d	< ee"ee$iZ%e!ej#d	< eere&e' j() ndee&e' j() iZ*eerej+ej,ej-ej.ej/ej0ej1ej2ej3g	ndeej+ej,ej-ej.ej/ej0ej1ej2ej3g	iZ4dd Z5ej6Z6ej7Z7ej8Z8ej9Z9ej:Z:ej;Z;ej<Z<ej=Z=e6e7e8e9e:e;e<e=gZ>eere'  ndee'  iZ?dd Z@dZAeBdkr.ejCd ZDneEZDejFGeDp9ejHZIeIejJ eA ejJ ZKejFLeK aMdZNeOedrUdndZPeQePdZReSePdZTG dd dejUZVG dd deVZWG dd deVZXG dd  d ejUZYG d!d" d"eYZZG d#d$ d$eYZ[G d%d& d&ejUZ\G d'd( d(e\Z]G d)d* d*e\Z^G d+d, d,ejUZ_G d-d. d.e_Z`G d/d0 d0e_ZaG d1d2 d2ejUZbG d3d4 d4ebZcG d5d6 d6ebZdd7d8 Zed9d: ZfG d;d< d<ejUZgG d=d> d>egZhG d?d@ d@egZiG dAdB dBejUZjG dCdD dDejZkG dEdF dFejZlG dGdH dHejUZmG dIdJ dJemZnG dKdL dLemZoG dMdN dNejUZpG dOdP dPepZqG dQdR dRepZrG dSdT dTejUZsG dUdV dVesZtG dWdX dXesZuG dYdZ dZejUZvG d[d\ d\evZwG d]d^ d^evZxG d_d` d`ejUZyG dadb dbeyZzG dcdd ddeyZ{G dedf dfejUZ|G dgdh dhe|Z}G didj dje|Z~G dkdl dlejUZG dmdn dneZG dodp dpeZeTG dqdr drejUZG dsdt dtejUZG dudv dveZG dwdx dxeZG dydz dzejUZG d{d| d|ejUZG d}d~ d~ejUZG dd dejUZeeQedG dd dejUZg eZe[e]e^e`eaecedeheiekeleneoeqereteuewexeze{e}e~eeeeeeeeeWeXZesseddd Znede ede dddZeBdkrddlZedZejddddd ejddddd e \ZZejreddd dS ereddeejd dS eddd dS dS )ag  
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_main()
with the corresponding argument.
    N)run_unittestrun_doctestis_resource_enabledrequires_IEEE_754requires_docstringsrequires_legacy_unicode_capicheck_sanitizer)
TestFailedrun_with_localecpython_onlydarwin_malloc_err_warning)import_fresh_module)warnings_helperdarwinZtest_decimaldecimalZ_decimal)Zfresh)Zblocked	fractionsc                    s,   t || | t fdd D  d S )Nc                 3   s*    | ]}|v r | n |  V  qd S N .0sdexpectedr   ;/opt/python-3.10.19/usr/lib/python3.10/test/test_decimal.py	<genexpr>S   s   ( z!assert_signals.<locals>.<genexpr>)getattr
assertTrueall)clscontextattrr   r   r   r   assert_signalsQ   s   
"r"   c                 C   s2   | sd S | j dttt|  dd}| | d S )N	   r   )precroundingtraps)ContextROUND_HALF_EVENdictfromkeysSignals
setcontext)mZDefaultTestContextr   r   r   initj   s
   r.   Zdecimaltestdata__main__F
DecClampedTz.test requires build with -DEXTRA_FUNCTIONALITYztest requires regular buildc                   @   sp   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )IBMTestCasesz?Class which tests the Decimal class against the IBM test cases.c                 C   s  | j  | _| j  | _dg| _tg d| _| j tkrL| jd | jd | jd | jd | jd | jd | jd	 | 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 j| j j| j j| j j| j j| j j| j j| j j| j j| j j| j j| j j dU| _!dV| _"d S )WN#)Zscbx164Zscbx165Zexpx901Zexpx902Zexpx903Zexpx905Zlnx901Zlnx902Zlnx903Zlnx905Zlogx901Zlogx902Zlogx903Zlogx905Zpowx1183Zpowx1184Zpowx4001Zpowx4002Zpowx4003Zpowx4005Zpowx4008Zpowx4010Zpowx4012Zpowx4014Zpwsx803Zpwsx805Zpowx4302Zpowx4303Zpowx4342Zpowx4343Zpwmx325Zpwmx326)Z	precisionr%   ZmaxexponentZminexponentclampandlogical_andZapply_applyclassnumber_classZ
comparesigcompare_signalZcomparetotalcompare_totalZcomparetotmagcompare_total_magcopycopy_decimalZcopyabscopy_absZ
copynegatecopy_negatecopysign	copy_signZ	divideint
divide_intinvertlogical_invertZiscanonicalis_canonicalisfinite	is_finiteZ
isinfiniteis_infiniteisnanis_nanZisnormal	is_normalZisqnanis_qnanZissigned	is_signedZissnanis_snanZissubnormalis_subnormalZiszerois_zeroZmaxmagmax_magZminmagmin_magZ	nextminus
next_minusZnextplus	next_plusZ
nexttowardnext_towardor
logical_orreduce	normalizeZremaindernearremainder_nearZsamequantumsame_quantumZ
squarerootsqrtZtoengto_eng_stringZ
tointegralto_integral_valueto_integral_exactto_sci_stringlogical_xor)ZtointegralxZtoscixor)ZceilingZdownfloorZ	half_downZ	half_evenZhalf_upZupZ05up)ZclampedZconversion_syntaxZdivision_by_zeroZdivision_impossibleZdivision_undefinedZinexactZinvalid_contextZinvalid_operationZoverflowZroundedZ	subnormalZ	underflow)rE   rG   rH   rJ   rK   rL   rM   rN   rO   rP   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_DOWNr(   ROUND_HALF_UPROUND_UP
ROUND_05UPRoundingDictClampedInvalidOperationDivisionByZeroInexactOverflowRounded	Subnormal	Underflow
ErrorNamesLogicalFunctionsselfr   r   r   setUp   s   
$	
 !"
'

zIBMTestCases.setUpc                 C   sT   | j tkr#| j jdkr#| jd | jd | jd | j|S | 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   rh   MAX_EMAXrd   _unsafe_setprec_unsafe_setemax_unsafe_setemincreate_decimalDecimal)r   vr    r   r   r   read_unlimited  s   zIBMTestCases.read_unlimitedc                 C   s   t rtjt|dd@}|D ]4}|dddd}z| |}W q | jjyB } z| d|j	j
 d |  W Y d }~qd }~ww W d    d S 1 sNw   Y  d S )Nutf-8)encodingz
 
zException "z" raised on line )skip_expectedunittestZSkipTestopenreplace	eval_liner   DecimalExceptionfail	__class____name__)r   fileflinet	exceptionr   r   r   	eval_file%  s   &"zIBMTestCases.eval_filec                 C   s   | ddkr,|d d dkr,|ds,|dd d |dd dd   }n	|dd  }| jD ]}| |dkrD d S q8|sId S d|v rR| |S | |S )	Nz -> r      --z  --->   :)find
startswithsplitstripre   eval_directiveeval_equation)r   r   ignorer   r   r   r   4  s    (


zIBMTestCases.eval_linec                 C   sj   dd | dD \}}|dkr| j| }nzt|}W n	 ty%   Y nw | j|dd }|| d S )Nc                 s   s    | ]	}|   V  qd S r   )r   lowerr   xr   r   r   r   G  s    z.IBMTestCases.eval_directive.<locals>.<genexpr>r   r%   c                  W   s   d S r   r   )argsr   r   r   <lambda>P  s    z-IBMTestCases.eval_directive.<locals>.<lambda>)r   rx   int
ValueErrorro   get)r   r   functvaluer   r   r   r   F  s   zIBMTestCases.eval_directivec                    s  t s
t dk r
d S  j  z:|d}|d   }|d }tr*td|dd |d  }|dd  }|d   }|d }|dd  }W n t	t
tfyW    jjw d	d
 }	| jv rcd S  j||}
|
dkrpd S t j|
}g }d}d} fdd|D t j D ]}d jj|< qD ]}d jj|< qt|D ]\}}|dd dkrd| }|r|d | }q|| }d}|	|}|
dv r"trD ]J}d jj|< z
| j| W n( |y   Y n) t j y
 } z d|||f  W Y d }~nd }~ww  d||f  d jj|< qЈ j|}n | j}|| q|	|}tr|
dvrD ]H}d jj|< z||  W n) |yU   Y n) t j yt } z d|||f  W Y d }~nd }~ww  d||f  d jj|< q=fddt j D }|D ]F}d jj|< z||  W n- |y   Y q t j y } z dt|||f  W Y d }~qd }~ww  d||f  q|D ]	}d jj|< qtrtd j zt|| }|
 jv rttt |}W n' t j y% } z d||f  W Y d }~nd }~w   td|   ! }|j"t#d j"t#d  $||d| d |   $|d| d t|  d S )Ng?r   r   zTest  )endr   r   c                 S   s@   |  dd dd} |  dd dd} |  dd dd} | S )Nz''ZSingleQuotez""ZDoubleQuote'r   ")r   )valr   r   r   	FixQuotesg  s   z-IBMTestCases.eval_equation.<locals>.FixQuotesZrescaler   c                    s   g | ]	} j |  qS r   )r   r   r   r   r   r   
<listcomp>w  s    z.IBMTestCases.eval_equation.<locals>.<listcomp>r   )r`   r]   z Raised %s in %s when %s disabledzDid not raise %s in %sc                    s   g | ]}| v r|qS r   r   r   e)theirexceptionsr   r   r         zRaised %s in %s; expected %sr   zRaised %s in %szERROR:keyzIncorrect answer for z -- got zIncorrect flags set in )%TEST_ALLrandomr    clear_flagsr   r   DEBUGprintr   	TypeErrorAttributeError
IndexErrorr   rz   rg   rp   r   r   r+   r&   	enumeratecountEXTENDEDERRORTESTr   r   r   appendOrderedSignalstypestrr   r   evalgetexceptionssortreprassertEqual)r   r   ZSidesLidr   Zvalstempans
exceptionsr   ZfnameZvalsZconglomeratequoter   ir   r   errorr   Zordered_errorsresultZmyexceptionsr   )r   r   r   r   S  s   




zIBMTestCases.eval_equationc                    s    fddt  j D S )Nc                    s   g | ]
} j j| r|qS r   )r    flagsr   r   r   r   r     s    z.IBMTestCases.getexceptions.<locals>.<listcomp>)r+   r   r   r   r   r   r     s   zIBMTestCases.getexceptionsc                 C   2   | j tkr| j jdkr| j| d S || j_d S Nr   )r   rh   MAX_PRECr    r   r$   )r   r$   r   r   r   rj        zIBMTestCases.change_precisionc                 C      || j _d S r   )r    r%   )r   r%   r   r   r   rk        z#IBMTestCases.change_rounding_methodc                 C   r   r   )r   rh   r   r    r   Eminr   expr   r   r   rm     r   z IBMTestCases.change_min_exponentc                 C   r   r   )r   rh   r   r    r   Emaxr   r   r   r   rl     r   z IBMTestCases.change_max_exponentc                 C   r   r   )r    r3   )r   r3   r   r   r   rn     r   zIBMTestCases.change_clampN)r   
__module____qualname____doc__r   r   r   r   r   r   r   rj   rk   rm   rl   rn   r   r   r   r   r1      s       r1   c                   @      e Zd ZeZdS )CIBMTestCasesNr   r   r   rh   r   r   r   r   r   r         r   c                   @   r   )PyIBMTestCasesNr   r   r   Pr   r   r   r   r   r     r   r   c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zee	e
jed
dd Zdd Zdd Zdd Zdd Zedd Zdd Zdd Zdd ZdS )ExplicitConstructionTestz6Unit tests for Explicit Construction cases of Decimal.c                 C   s   | j j}| | |d d S )N0r   r   r   r   r   r   r   r   test_explicit_empty     z,ExplicitConstructionTest.test_explicit_emptyc                 C   s   | j j}| t|d  d S r   )r   r   assertRaisesr   r   r   r   r   test_explicit_from_None  s   z0ExplicitConstructionTest.test_explicit_from_Nonec                 C   s   | j j}|d}| t|d |d}| t|d |d}| t|d |d}| t|d tdd	D ]%}d
D ] }tddD ]}|d| |  }||}| t|t| qDq=q9d S )N-   45{e	500000123-45r   r       r      r   )r   r   r   r   range)r   r   r   nsignr   r   r   r   r   test_explicit_from_int  s$   z/ExplicitConstructionTest.test_explicit_from_intc                 C   s  | j j}| j j}| j j}| t|dd | t|dd | t|dd | t|dd | t|dd | t|dd	 | t|d
d | t|dd | t|dd | t|dd dD ]}dD ]}| t||d | d qvqr| H}d|j|< | ||d | t|ddd | ||d | ||d | ||d | ||d | ||d | ||d W d    d S 1 sw   Y  d S )Nr   NaNr   45.34Z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+41Z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   rz   localcontextr   r   r&   r   r   )r   r   rz   r  Zleadtrailcr   r   r   test_explicit_from_string  s<   
"z2ExplicitConstructionTest.test_explicit_from_stringcategoryc                 C   sR   dd l }| jj}| j }|d}| t||d | t||d d S )Nr   9.999999)	_testcapir   r   r'   unicode_legacy_stringr   r   r   )r   r  r   r    r   r   r   r   test_from_legacy_stringsO  s   

z1ExplicitConstructionTest.test_from_legacy_stringsc                 C   s6  | j j}|d}| t|d |d}| t|d |d}| t|d |d}| t|d |d	}| t|d
 | t|d | t|d | t|d | t||dddf | t|d | t|d | t|d | t|d | t|d | t|d | t|d | t|d d S )Nr   r   r   r   r   )   r  r   r  r   r"  r     r"  r  r   	r"  r%  r"  r#   r   r%  r  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   r   r   r   r   r   r   r   r   r   test_explicit_from_tuples[  s.   z2ExplicitConstructionTest.test_explicit_from_tuplesc                 C   s   | j j}|ddgdg}| t|d |dg ddg}| t|d |g d}| t|d |dg ddf}| t|d d S )Nr   r   r   r(  r)  r*  r'  r   r   r   r   r4  r   r   r   test_explicit_from_list  s   z0ExplicitConstructionTest.test_explicit_from_listc                 C   s\   | j j}| t|dd | t|dd | |d|d | |d|d d S )Nr   Fr   T)r   r   assertIsboolr   r   r   r   r   test_explicit_from_bool  s
   z0ExplicitConstructionTest.test_explicit_from_boolc                 C   s   | j j}|d}||}| t|d |d}||}| t|d |d}||}| t|d |d}||}| t|d d S )	Nr   r   r   r  r  r  r   r   r6  r   r   r   r   r   r   r   test_explicit_from_Decimal  s   z3ExplicitConstructionTest.test_explicit_from_Decimalc                 C   s2  | j j}|d}| t|| | t|d | |td  | |td  | |td  | t|tdt|d | t|tdt|d | t|tdt|d | t|td	t|d
 t	dD ]}t
dt

 d d  }| |t|| q}d S )N皙?90.1000000000000000055511151231257827021181583404541015625naninf-infr  r,  	-Infinity-0.0-0   {Gz?       @      ?)r   r   r   r   r   r   floatrL   rH   r	  r   expovariate)r   r   rr   r   r   r   r   test_explicit_from_float  s2   




z1ExplicitConstructionTest.test_explicit_from_floatc                 C   s  | j j}| j j}| j j}t| j  }d|_| }| t|d |	 }| t|d | 
t|j	d  |	d}| || | |	d|	d |d}| t|d |	d}| t|d | t|	dd	 |d
}| t|d |	d
}| t|d |d}||}| t|d |	|}| t|d d|_d|j|< dD ]}|	|}| t|| | t|| qd|_d|j|< | 
||j	d d|_| t|	dd | t|	dd | t|	dd | t|	dd | 
||j	d | 
t|j	d | 
t|j	dd | 
||j	d | 
||j	d d|_| 
||j	d  | 
||j	|d  d!|j|< | t|	d d	 | |j|  d!|j|< | t|	|d d	 | |j|  d S )"Nr%  r     in  z457E+2Z456789z4.57E+5z3.14
r  r'  r*  z	-4.35E-17r   r  z5.00E+8   T)	l        l         l    i   r   l                          z0E-017z0E-17r   -InfrB  NaN123r  )r   r  r)  r  Z5678z 1234Z12_34ZNaN12345F)r   r   rz   r~   r<   
getcontextr$   r   r   r   r   r   assertIsInstancer&   r   
isinstancer   r   r   )r   r   rz   r~   ncr   Zprevdecr   r   r   r   $test_explicit_context_create_decimal  sv   









z=ExplicitConstructionTest.test_explicit_context_create_decimalc                 C   s\  | j j}| j  }|d}| t|| | t|d | |td	  | |td
  | |td
  | t|tdt|d | t|tdt|d | t|tdt|d | t|td	t|d
 d|_tdD ]}tdt d d  }| |t|| qd S )Nr=  z0.1000000000000000055511151231r?  r@  rA  r  r,  rB  rC  rD  d   rE  rF  rG  rH  )r   r   r'   r   r   r   r   r   rI  rL   rH   r$   r	  r   rJ  )r   r   rX  rK  r   r   r   r   r   'test_explicit_context_create_from_float%  s2   

z@ExplicitConstructionTest.test_explicit_context_create_from_floatc                 C   s>   | j j}dddd}| D ]\}}| t||| qd S )Nr0  z	0.0000372z-NaN2400)u   １u   ٠.٠٣٧٢e-٣u   -nan౨౪౦౦)r   r   itemsr   r   )r   r   test_valuesinputr   r   r   r   test_unicode_digits=  s   z,ExplicitConstructionTest.test_unicode_digitsN)r   r   r   r   r   r   r  r  r   r   r   ignore_warningsDeprecationWarningr  r5  r7  r:  r<  r   rL  rY  r[  r_  r   r   r   r   r     s&    8
	+
Yr   c                   @   r   )CExplicitConstructionTestNr   r   r   r   r   rb  H  r   rb  c                   @   r   )PyExplicitConstructionTestNr   r   r   r   r   rc  J  r   rc  c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )ImplicitConstructionTestz6Unit tests for Implicit Construction cases of Decimal.c                 C      | j j}| ttdt  d S )NzDecimal(5) + Noner   r   r   r   r   localsr   r   r   r   test_implicit_from_NoneP  r   z0ImplicitConstructionTest.test_implicit_from_Nonec                 C   s<   | j j}| t|dd d | |dd |d d S )Nr  r   Z50l   2}r r6  r   r   r   r   test_implicit_from_intT  s   z/ImplicitConstructionTest.test_implicit_from_intc                 C   re  )NzDecimal(5) + "3"rf  r   r   r   r   test_implicit_from_string\  r   z2ImplicitConstructionTest.test_implicit_from_stringc                 C   re  )NzDecimal(5) + 2.2rf  r   r   r   r   test_implicit_from_float`  r   z1ImplicitConstructionTest.test_implicit_from_floatc                 C   s(   | j j}| |d|d |d d S )Nr  r   2   r   r   r   r   r   test_implicit_from_Decimald  s    z3ImplicitConstructionTest.test_implicit_from_Decimalc                    s*  | j j}G dd d}| t| |dd | t|d| d | tdd | tdd	 | td
d | tdd | tdd | tdd g d}|D ]9\} t|  fdd t|fdd | td| d d  d  | td| d d d  qYd S )Nc                   @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )z,ImplicitConstructionTest.test_rop.<locals>.Ec                 S      dt | S )Nzdivmod r   r   otherr   r   r   
__divmod__m  r   z7ImplicitConstructionTest.test_rop.<locals>.E.__divmod__c                 S   s   t |d S )Nz rdivmodro  rp  r   r   r   __rdivmod__o  r   z8ImplicitConstructionTest.test_rop.<locals>.E.__rdivmod__c                 S   rn  )Nzlt ro  rp  r   r   r   __lt__q  r   z3ImplicitConstructionTest.test_rop.<locals>.E.__lt__c                 S   rn  )Nzgt ro  rp  r   r   r   __gt__s  r   z3ImplicitConstructionTest.test_rop.<locals>.E.__gt__c                 S   rn  )Nzle ro  rp  r   r   r   __le__u  r   z3ImplicitConstructionTest.test_rop.<locals>.E.__le__c                 S   rn  )Nzge ro  rp  r   r   r   __ge__w  r   z3ImplicitConstructionTest.test_rop.<locals>.E.__ge__c                 S   rn  )Nzeq ro  rp  r   r   r   __eq__y  r   z3ImplicitConstructionTest.test_rop.<locals>.E.__eq__c                 S   rn  )Nzne ro  rp  r   r   r   __ne__{  r   z3ImplicitConstructionTest.test_rop.<locals>.E.__ne__N)r   r   r   rr  rs  rt  ru  rv  rw  rx  ry  r   r   r   r   El  s    rz  r2  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                    s   d  t | S Nr   ro  rp  )lopr   r   r         z3ImplicitConstructionTest.test_rop.<locals>.<lambda>c                    s   t |  d S r  ro  rp  )ropr   r   r     r  zE()zDecimal(10)r   10)r   r   r   divmodr   setattr)r   r   rz  ZoplistZsymr   )r  r  r   test_roph  s*   


z!ImplicitConstructionTest.test_ropN)
r   r   r   r   rh  ri  rj  rk  rm  r  r   r   r   r   rd  M  s    rd  c                   @   r   )CImplicitConstructionTestNr   r   r   r   r   r    r   r  c                   @   r   )PyImplicitConstructionTestNr   r   r   r   r   r    r   r  c                   @   s:   e Zd ZdZdd Zdd Zedddd	 Zd
d ZdS )
FormatTestz#Unit tests for the format function.c                 C   sN   | j j}g d}|D ]\}}}| t|||| q
| t|djd d S )N))r   0E-15z0e-15)r   z2.3E-15z2.3e-15)r   z2.30E+2z2.30e+2)r   z2.30000E-15z2.30000e-15)r   z1.23456789123456789e40z1.23456789123456789e+40)r   1.5z1.5e+0)r   z0.15z1.5e-1)r   z0.015z1.5e-2)r   z0.0000000000015z1.5e-12)r   z15.0z1.50e+1)r   -15z-1.5e+1)r   r   z0e+0)r   0E10e+1)r   0.0z0e-1)r   0.000e-2).6er  z0.000000e-9)r  r   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   r   r   )r   r  r  )r   0E-2r  )r   z0.00E-8z0.0000000000)r   r  r   )r   z3.2E132)r   z3.2E2320)r   z3.20E2r  )r   z3.200E2z320.0)r   z3.2E-6z	0.0000032).6fr  0.000000)r  r  r  )r  r   r  ).0fr   r   )r  r  r   )r  
3.141592653)z.1fr  3.1)z.4fr  3.1416)r  r  3.141593)z.7fr  	3.1415926)z.8fr  r  )z.9fr  z3.141592650)gr   r   )r  r  r  )r  r  r  )Gr  z0E+1)r  z0E-5z0.00000)r  z0E-6r  )r  z0E-7z0e-7)r  z-0E2z-0e+2).0gr  r  )z.0nr  r  )z.1gr  r  )z.2gr  r  )z.5gr  r  )z.7gr  r  )z.8gr  r  )z.9gr  r  )z.10gr  r  )r  r  0%)r  Z0E0r  )r  z0E-1r  )r  r  r  )r  z0E-3z0.0%)r  z0E-4z0.00%).3%r   0.000%)r  0E10r  )r  z0E-10r  )r  z2.34z234.000%)r  z1.234567z123.457%).0%1.23z123%)r   r  r  )r   -NaN123r  )z+gZNaN456z+NaN456)z.3eInfr,  )z.16frS  rB  )r  -sNaNr  )r   1.00r  )6123   123)z<6r  z123   )z>6r  r  )z^6r  z 123  )z=+6r  z+  123)#<10r  z
NaN#######)r  z-4.3z
-4.3######)z#<+100.0130z
+0.0130###)z#< 10r  z
 0.0130###)z@>10rS  z
@-Infinity)z#>5rS  rB  )z?^5r  z?123?)z%^6r  z%123%%)z ^6-45.6z-45.6 )z/=10r  z
-/////45.6)z/=+1045.6z
+/////45.6)z/= 10r  z
 /////45.6)z =10rA  z
- Infinity)z ^16rA  z   -Infinity    )z >101.2345z
    1.2345)z <10r  z
1.2345    ),Z1234567z	1,234,567)r  123456123,456)r  Z1234512,345)r  r  z1,234)r  r  r  )r  12r  )r  r0  r0  )r  r   r   )r  z-1234567z
-1,234,567)r  -123456-123,456)z7,r  r  )z8,r   123,456)08,r  z	0,123,456)z+08,r  z+123,456)z 08,r  r  )r  r  r  )z+09,r  z
+0,123,456)z07,1234.561,234.56)r  r  r  )z09,r  z	01,234.56)z010,r  z
001,234.56)z011,r  0,001,234.56)z012,r  r  )z08,.1fz1234.5z01,234.5)r  
1.23456789r  )z,%z
123.456789z12,345.6789%)z,er  z
1.23456e+5)z,Er  z
1.23456E+5)za=-7.0z0.12345zaaaa0.1)z	<^+15.20%r@  z<<+Infinity%<<<)z>,%ZsNaN1234567zsNaN1234567%)z=10.10%rT  z
   NaN123%r   s   -020)r   r   r   formatr   r   
__format__)r   r   r]  fmtr   r   r   r   r   test_formatting  s    zFormatTest.test_formattingc           	         s8  j j zddlm} W n ty   d Y nw fdd}dA fdd	}d	|g d
dd}d||gdd}d|g d
dd}d|ddd|gdd}dd|g 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d1 |d,|d2d1 |d,|d3d4 |d5|d*d6 |d5|d.d6 |d5|d0d6 |d5|d2d7 |d5|d3d8 |d5|d9d8 |d5|d:d; |d5|d<d= | d>|d?d@ d S )BNr   CHAR_MAXlocale.CHAR_MAX not availablec                    s"    j tkrddd | D S | S )Nr   c                 S      g | ]}t |qS r   chrr   r   r   r   r   I      zCFormatTest.test_n_format.<locals>.make_grouping.<locals>.<listcomp>)r   rh   joinZlstr   r   r   make_groupingH  s   "z/FormatTest.test_n_format.<locals>.make_groupingr
  c                    s,   j tkr | ||S  | j||dS )N)_localeconv)r   rh   r  r   overrider  r   r   r   r   get_fmtK  s   
z)FormatTest.test_n_format.<locals>.get_fmt.r%  r%  r   r  decimal_pointgroupingthousands_sepr   r   &r   r"  r   r~  s   ¿r   s   ´z12.7z12,7z1-2&7i[z123,456,789Z	123456789z123 456 789l   c}z123456-78-9012-3z.6nz
1.23457e+8z
1,23457e+8z
1&23457e+8rR  Z03nr  Z04nZ05nZ01234Z06nZ00123490  r  Z07nz012,345Z08nz	0,012,345Z09nZ010nz
00,012,345i@ z1-2345-6z	01-2345-6z0-01-2345-6Z011nZ012nz00-01-2345-6Z013nz000-01-2345-6-1.5Z020nu   -0´000´000´000´001¿5Nr
  )r   r   localer  ImportErrorskipTestdecoder   )	r   r  r  r  en_USfr_FRru_RUZcrazyZdotsep_wider   r  r   test_n_format@  sz   


zFormatTest.test_n_formatLC_ALLps_AFc                 C   sn   | j j}t d }t d }|dkr| d|d |dkr*| d|d | t|ddd	 d S )
Nr  r  u   ٫z5inappropriate decimal point separator ({!a} not {!a})u   ٬z1inappropriate thousands separator ({!a} not {!a})z100000000.123r
  u   100٬000٬000٫123)r   r   r  
localeconvr  r  r   )r   r   r  r  r   r   r   &test_wide_char_separator_decimal_point  s   z1FormatTest.test_wide_char_separator_decimal_pointc                 C   sP   G dd d| j j}|d}| | j j|j |d}| | j j|j d S )Nc                   @      e Zd Zdd ZdS )z;FormatTest.test_decimal_from_float_argument_type.<locals>.Ac                 S   s   t || _d S r   )r   a_type)r   r3  r   r   r   __init__  s   zDFormatTest.test_decimal_from_float_argument_type.<locals>.A.__init__Nr   r   r   r  r   r   r   r   A      r  g     @E@*   )r   r   
from_floatr   r  )r   r  r3  r   r   r   %test_decimal_from_float_argument_type  s
   

z0FormatTest.test_decimal_from_float_argument_typeN)	r   r   r   r   r  r  r
   r  r  r   r   r   r   r    s      Y
r  c                   @   r   )CFormatTestNr   r   r   r   r   r    r   r  c                   @   r   )PyFormatTestNr   r   r   r   r   r    r   r  c                   @   sh   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )ArithmeticOperatorsTestz:Unit tests for all arithmetic operators, binary and unary.c                 C   s   | j j}|d}|d}| || |d | || |d |d }| ||d | t|t| d| }| ||d | t|t| ||7 }| ||d |d7 }| ||d d S )N-11.122.2z11.1r  z-6.116.1r   r   r   r   r   r   d1d2r  r   r   r   test_addition     z%ArithmeticOperatorsTest.test_additionc                 C   s   | j j}|d}|d}| || |d | || |d |d }| ||d | t|t| d| }| ||d | t|t| ||8 }| ||d |d8 }| ||d d S )	Nr  r  z-33.3z33.3r  z-16.1r  z-38.3r  r	  r   r   r   test_subtraction  r  z(ArithmeticOperatorsTest.test_subtractionc                 C   s   | j j}|d}|d}| || |d | || |d |d }| ||d | t|t| d| }| ||d | t|t| ||9 }| ||d |d9 }| ||d d S )N-5r  r  r  z-25z-75r  r	  r   r   r   test_multiplication  r  z+ArithmeticOperatorsTest.test_multiplicationc                 C   s   | j j}|d}|d}| || |d | || |d |d }| ||d | t|t| d| }| ||d | t|t| || }| ||d |d }| ||d d S )	Nr  2-2.5z-0.4r"  z-1.25z-0.8z-0.625r  r	  r   r   r   test_division  r  z%ArithmeticOperatorsTest.test_divisionc                 C   s   | j j}|d}|d}| || |d | || |d |d }| ||d | t|t| d| }| ||d | t|t| || }| ||d |d }| ||d d S )N5r  r   r"  r0     r   r  r	  r   r   r   test_floor_division,  r  z+ArithmeticOperatorsTest.test_floor_divisionc                 C   s   | j j}|d}|d}| || |d | || |d |d }| ||d | t|t| d| }| ||d | t|t| ||C }| ||d |dC }| ||d	 d S )
Nr  r  Z25r  r"  Z625r  Z16807Z390625r  r	  r   r   r   test_poweringH  r  z%ArithmeticOperatorsTest.test_poweringc                 C   s   | j j}|d}|d}| || |d | || |d |d }| ||d | t|t| d| }| ||d | t|t| ||; }| ||d |d; }| ||d d S Nr  r  r0  r"  r  r  r	  r   r   r   test_moduled  r  z#ArithmeticOperatorsTest.test_modulec                 C   s  | j j}|d}|d}t||\}}| ||d | ||d | t|t| | t|t| t|d\}}| ||d | ||d | t|t| | t|t| td|\}}| ||d | ||d | t|t| | t|t| d S r  )r   r   r  r   r   )r   r   r
  r  pqr   r   r   test_floor_div_module  s$   z-ArithmeticOperatorsTest.test_floor_div_modulec                 C   sT   | j j}| |d
 |d | |d |d | t|dt|d d S )Nr   r  )r   r   r   absr   r   r   r   test_unary_operators  s    z,ArithmeticOperatorsTest.test_unary_operatorsc                 C   s  | 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}||	 D ](\}}|
| D ]}|||}|tj
u rndnd}| ||d||j||| q`qX| k}d|j|< |D ]&\}}|D ]}|||}|tj
u rdnd}| ||d||j||| qq|	D ]\}}|D ]}| |tj	|| | |tj
|| qq||	 D ]\}}|
D ]
}| |||| qqW d    d S 1 sw   Y  d S )	Nr  sNaNr  r  TFz8expected {0!r} for operator.{1}({2!r}, {3!r}); got {4!r}r   )r   r   rz   r  operatorltlegtgeeqner8  r  r   r&   r   )r   r   rz   r  r
  r   r   r   Z
qnan_pairsZ
snan_pairsZ	order_opsZequality_opsr   r  opZgotr   ctxr   r   r   test_nan_comparisons  s\   ".
	

	"z,ArithmeticOperatorsTest.test_nan_comparisonsc                 C   sH   | j j}|d|d}| |dd| | t|djd d S )Nr   r&  -2)r   r   rA   r   r   r   r4  r   r   r   test_copy_sign  s   z&ArithmeticOperatorsTest.test_copy_signN)r   r   r   r   r  r  r  r  r  r  r  r  r  r)  r+  r   r   r   r   r    s    7r  c                   @   r   )CArithmeticOperatorsTestNr   r   r   r   r   r,    r   r,  c                   @   r   )PyArithmeticOperatorsTestNr   r   r   r   r   r-    r   r-  c              	   C   s  | j j}| j j}| j j}| j j}| j j}| j j}| j j}| j j}|d}	|d}
|	|
 }| j	
  | j  |	|
 }| a}| |j|  | ||j|	d | |j|  | ,}| |j|  | |j|  | ||j|	|d | |j|  ~W d    n1 sw   Y  | |j|  ~W d    n1 sw   Y  | ||d | ||d | }| |j|  ||||fD ]
}| |j|  qd S )Nr   r%  r   r  0.333333333333333333333333)r   r   rz   r{   r}   r   r|   rU  r  finish1rf   synchrowaitr   r   r   dividecompareassertFalser   )r   r   rz   r{   r}   r   r|   rU  r  r
  d3test1test2c2c3c1sigr   r   r   thfunc1  sF   

r<  c              	   C   s  | j j}| j j}| j j}| j j}| j j}| j j}| j j}| j j}|d}	|d}
|	|
 }| }d|_	|	|
 }| q}| 
|j|  | ||j|dd | 
|j|  ||1}| 
|j|  | |j|  d|j|< | ||j|dd | 
|j|  ~W d    n1 sw   Y  | |j|  | |j|  ~W d    n1 sw   Y  | j  | j  | ||d | ||d	 | |j|  | 
|j|  ||||fD ]
}| |j|  qd S )
Nr   r%     Z1e425000000  Tz1e-425000000r.  z0.333333333333333333)r   r   rz   r{   r}   r   r|   rU  r  r$   r   r   r   multiplyr4  r&   r2  r0  rf   finish2r   )r   r   rz   r{   r}   r   r|   rU  r  r
  r5  r6  Zthiscontextr7  r8  r9  r;  r   r   r   thfunc2  sN   



rA  c                   @      e Zd ZdZdd ZdS )ThreadingTestz0Unit tests for thread local contexts in Decimal.c                 C   s   | j j}| j tkr| j js| d |j}|j}|j}d|_d|_d|_t	 | _
t	 | _t	 | _tjt| fd}tjt| fd}|  |  | j  | j  t| j  D ]
}| |j|  qZ|  |  ||_||_||_d S )Nzcompiled without threading   r   )targetr   )r   DefaultContextrh   HAVE_THREADSr  r$   r   r   	threadingEventr0  r/  r@  Threadr<  rA  startr1  r+   r4  r   r  )r   rG  Z	save_precZ	save_emaxZ	save_eminZth1Zth2r;  r   r   r   test_threading@  s2   






zThreadingTest.test_threadingN)r   r   r   r   rM  r   r   r   r   rC  :  s    rC  c                   @   r   )CThreadingTestNr   r   r   r   r   rN  g  r   rN  c                   @   r   )PyThreadingTestNr   r   r   r   r   rO  j  r   rO  c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*S )+UsabilityTestz*Unit tests for Usability cases of Decimal.c                 C   s  | j j}|d}|d}|d}| || | || | || | || | || | || | || | || | |d | d| | |d | |d | |d | |t  | |t t	t
|td}|d d  }t| |  | || d S )Nz23.42r      r   r  gY@@rZ  )r   r   assertGreaterassertGreaterEqual
assertLessassertLessEqualr   assertNotEqualobjectlistmapr	  r   shuffler   )r   r   dadbdcr3  br   r   r   test_comparison_operatorsp  s0   
z'UsabilityTest.test_comparison_operatorsc                 C   s   | j j}|d}|d}| |d | |d | |d | |d | |d | |d | d| | d| | d| | d| | d| | d| | d|d d S )N0.253.0      @      ?g      ?r=  0.1)r   r   rT  rU  rR  rS  rV  r   r   r   r[  r\  r   r   r   test_decimal_float_comparison  s    z+UsabilityTest.test_decimal_float_comparisonc                 C   s   | j j}|d}|d}| |d | d| | |d | d| | d| | |d | |d | d| | |dt | |dt | |dt | |dt d S )Nr`  ra  y      ?        y      ?        y      @        y      @      ?)	r   r   rV  r   r8  rt  NotImplementedrv  ru  re  r   r   r   test_decimal_complex_comparison  s   z-UsabilityTest.test_decimal_complex_comparisonc           
      C   s  | 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}|||d}	||	 ||	_| |d|dd | |dd|d | |dd|d	t|  | |d
t| |dd | |dd|d	t|  | |d
t| |dd | |d|dd | |dd|d d|	_| |dd |dd | |dd|dd  | |dd|dt|  | |dt| |dd | |d|dd | |d|dd | |d|dd | |d|dd | ||dj|dd | t|dd|d | |d|dd | |dd|d W d    d S 1 sFw   Y  d S )Nɚ;6eilʈr   r   r   r   l	   ZmH;5B r  Z1ez-1el   !0QYrd  r2  i,  r%  i6l   c(	 Z9er@  l   g] {   lg] rA  r?  i)r   r   r   ZFractionr'   r  rz   rh   r   MIN_EMIN	MIN_ETINYr$   rT  r   r   rV  rU  rS  rR  r   ru  r8  rg  rt  )
r   Dr+  r'   r  rz   emaxeminZetinyr  r   r   r    test_decimal_fraction_comparison  sB   $z.UsabilityTest.test_decimal_fraction_comparisonc                 C   sP   | j j}|d}t|}| t|t| t|}| t|t| d S )Nz43.24)r   r   r<   r   r   deepcopy)r   r   r   r  r]  r   r   r   test_copy_and_deepcopy_methods  s   

z,UsabilityTest.test_copy_and_deepcopy_methodsc                    s  j j j j}fdd}| d | d | d | d | d  fdd	d
D }| d d d d d d d d d d d d d d d dg |D ]}||tt| qlg d}|D ]}t|} |}||t| q| A}	 d}
d|	_||
}d|	_||
}d|	_||
}|| || d |	_d!d" }
| |
||
 W d    d S 1 sw   Y  d S )#Nc                    s    t | }|  } || |S r   )hash__hash__r   )r   r3  r^  r   r   r   hashit  s   z.UsabilityTest.test_hash_method.<locals>.hashitrQ  r,  rB  Znan123-NaNc                    s:   g | ]}t d dD ]}dD ]} |d| |  qq	qS )r2  r  r   )r	  )r   r-   r
  r  r   r   r   r      s    z2UsabilityTest.test_hash_method.<locals>.<listcomp>)r                     r  !   =   >   ?   @   A   B   -1rD  r  z-0.000r  z-0E1210.0z	-23.00000Z1230E100z
-4.5678E50l       z	1.634E100z
90.697E100z
188.83E100z
1652.9E100Z	56531E100)r@  rS  r  z-.0e1z34.02.5z
112390.625z	-0.515625z123456789.1   r2  r}  '  iL  i  )	r   r   r  extendr   ru  r   rI  r$   )r   r  rw  r]  r   Ztest_stringsr   r   r   r  r   Zh1Zh2Zh3r   r  r   test_hash_method  sd   
"zUsabilityTest.test_hash_methodc                 C   sz   | j j}| tt|d |d}| t|t| G dd d}G dd d||}|d}| t|t| d S )Nr  r  c                   @   r  )z-UsabilityTest.test_hash_method_nan.<locals>.Hc                 S      dS )Nr  r   r   r   r   r   rv  B     z6UsabilityTest.test_hash_method_nan.<locals>.H.__hash__N)r   r   r   rv  r   r   r   r   HA  r  r  c                   @   s   e Zd ZdS )z-UsabilityTest.test_hash_method_nan.<locals>.DN)r   r   r   r   r   r   r   ro  D  s    ro  )r   r   r   r   ru  r   rW  rv  )r   r   r   r  ro  r   r   r   test_hash_method_nan<  s   z"UsabilityTest.test_hash_method_nanc                 C   s   | j j}|d}|d}d}d}| t||| | t||| | t||| | t||| | t||| | t||| | t||| | t||| d S )N15.32z28.5r|  rN  )r   r   r8  minmax)r   r   r
  r  l1l2r   r   r   test_min_and_max_methodsI  s   z&UsabilityTest.test_min_and_max_methodsc                 C   s(   | j j}| |d | |d d S )Nr   z0.372)r   r   r4  r   r   r   r   r   test_as_nonzero]  s   zUsabilityTest.test_as_nonzeroc                 C   s4   | j j}|d}| t|d | t|d d S )Nr  zDecimal('15.32'))r   r   r   r   r   r4  r   r   r   test_tostring_methodse  s   z#UsabilityTest.test_tostring_methodsc           
      C   s4  | j j}|d}|d}| t|d | t|d | t|d | t|d g d}|D ]\}}| t||| q2| ttj|d | ttj|d | ttj|d	 | t	tj|d
 | t	tj|d g d}|D ]\}}| t
||| qz| ttj
|d | ttj
|d | ttj
|d	 | t	tj
|d
 | t	tj
|d g d}|D ]\}}| t||| q| tt|d | tt|d | tt|d	 | t	t|d
 | t	t|d g d}|D ]\}}}	| tt||||	 qd S )NZ66r  r  r|  gp=
ף.@)	z123.00rl  3.2r%  )3.54r%  )3.899r%  )-2.3r1  z-11.0ir  r   z-0E3r   )89891211712379812736.1l   {#'s{M rx  r  rT  r  rS  )	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   )r  r   )r  r   )z3.5r"  ))123.456r  z0E+4)r  r1  z0E+3)r  r&  z1E+2)r  r  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)r  r"  r  )rS  ir  )ZsNaN314r%  ZNaN314)r   r   r   r   rI  mathrc   r   r   OverflowErrorceilroundr   )
r   r   r
  r  Z
test_pairsr   r   Ztest_triplesr
  rK  r   r   r   test_tonum_methodsm  sF   z UsabilityTest.test_tonum_methodsc                 C   sX   | j j}dD ]#}t||}| t| td|}| ||dr&dnd qd S )N)r?  Znan1234-nanz-nan2468rH  r~  g      )	r   r   rI  r   r  rI   r@   r   r   )r   r   r   r   r  r   r   r   test_nan_to_float  s   zUsabilityTest.test_nan_to_floatc                 C   s,   | j j}dD ]}||}| tt| qd S )N)snanz-snanZsnan1357z	-snan1234)r   r   r   r   rI  )r   r   r   r   r   r   r   test_snan_to_float  s
   z UsabilityTest.test_snan_to_floatc                 C   s|   | j j}|d}| |tt| |d}| |tt| |d}| |tt| |d}| |tt| d S )Nr  r!  r#  r'  )r   r   r   r   r   r4  r   r   r   test_eval_round_trip  s   z"UsabilityTest.test_eval_round_tripc                 C   sD  | 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 S )Nr   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  Nr   r   r  )r   r   r
  )r   r$  r+  )r   )r   r   r  r   r+  )r   r   r+  )r   r   r   as_tupler4  r   r   r   test_as_tuple  s6   zUsabilityTest.test_as_tuplec           	   	   C   s  | j j}| t|j|d | t|j|d | t|j|d | t|j|d tddD ]M}tdD ]F}dD ]A}|d	|||f }| }|\}}| |t | |t	 | |t	 | 
|d
 | t||d | |||| | q;q7q1d S )Nr@  rA  r  Zsnan123r  r     )r{  r~  z%s%dE%dr   r   )r   r   r   r  as_integer_ratior   r	  rV  tupler   rR  r   r  gcd)	r   r   r   Zcoeffr  r   Zpqr  r  r   r   r   test_as_integer_ratio$  s8   



z#UsabilityTest.test_as_integer_ratioc                 C   sd  | j j}G dd d|}|d}|d}|| }| t|| ||}| t|| t|}| t|| | || t|}| t|| | || |d}||}| t|| | || ||}| t|| | || | |jd  ||}| t|| | || d|_||}| t|| | || | |jd  d S )Nc                   @   s   e Zd ZdZdS )z1UsabilityTest.test_subclassing.<locals>.MyDecimalN)r   r   r   r  r   r   r   r   	MyDecimalI  r   r  r   r   1.0r#   )	r   r   r8  r   r  r<   r   rs  r  )r   r   r  r
  r  r   r   r-   r   r   r   test_subclassingE  s<   


zUsabilityTest.test_subclassingc                 C   s@   | j j}| j j}| }| t|d t||d d S Nr   )r   r   rU  r   r   r\   r   r   rU  r  r   r   r   test_implicit_contextt  s   z#UsabilityTest.test_implicit_contextc              	   C   s  | j j}| j j}| j j}| j j}| j j}| j j}| j j}| j j}| j j	}	| j j
}
| j j}|| M}d|_d|_d|_|d}|d}|d}|  | t|jd dd | |j|	  | |j|
  |  | j||jd d | |j|  | |jd dd	 | |jd dd
 |  | t|jd dd | |j|	  | |j|
  |  | j||djd d | |j|  |  | t|jd dd | |j|	  | |j|
  |  | j||djd d | |j|  |  | t|jd dd | j||djd d | |j|  |  | t|jd dd | j||jd d | |j|  |  | t|jd dd | j||djd d | |j|  |  | t|jd dd | j||djd d | |j|  |  | t|jd dd | j||jd d | |j|  | t|j d dd |  | t|j!d dd | |j|  | |j|	  | |j|
  | |j|  | |j|  |  | j||j!d d | |j|  d|_"| t|j#d dd d|_"|  t|j$|dd d}| |d | j||j$|dd d | |j|  |  t|j%dd d}| |d | j||j%|dd d | |j|  |  t|j&dd d}| |d | j||j&dd d | |j|  |  t|j'dd d}| |d | j||j'dd d | |j|  |  t|j(dd d}| |d  | j||j(dd d | |j|  |  t|j)dd d}| |d | j||j)|dd d | |j|  |  t|j*dd d}| |d | j||j*|dd d | |j|  |  t|j+dd d}| |d | j||j+|dd d | |j|  |  t|j,dd d}| |d | j||j,|dd d | |j|  |  t|j-dd d}| |d  | j||j-dd d | |j|  |  t|j.d!d d}| |d" | j||j.dd d | |j|  |  t|j/dd d}| |d# | j||j/d$d d | |j|  |  t|j0d!d d}| |d" | j||j0d$d d | |j|  |  t|j1d!d%d d}| |d& | j||j1|dd%d d | |j|  t2|_3t|d'j4d d d(}| |d t5|_3t|d'j4d d d(}| |d) t|d'j4t6d d(}| |d |  | j||dj4d d | |j|  t2|_3t|d'j7d d d(}| |d t5|_3t|d'j7d d d(}| |d) t|d'j7t6d d(}| |d |  | j||dj7d d | |j|  t2|_3t|d'j8d d d(}| |d t5|_3t|d'j8d d d(}| |d) t|d'j8t6d d(}| |d |  | j||dj8d d | |j|  t6|_3t|d*j9|d+d d d,}| |d- t5|_3t|d*j9|d+d d d,}| |d. t|d*j9|d+t6d d,}| |d- |  | j||j9|d/t6d d( | |j|  W d    n	1 sw   Y  || E}d|_d|_d|_|d d0}| |jd | |jd | |jd W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )1Nr  r>  iZ111Z1e9999z1e-9999r    z1.609487E+48FTz4.709530r  z2.045323r  r   Z1111000z9.999999E+999r  r,  r   
+Subnormalz0E-1005r   ZNan891287828Z
NaN1287828i    r  r  e   Z101rl  r  r   Z11100z1.11E+9r  r%  Z225r  r%   r    r0  z1.50001z1e-3)r   r%   r    z1.501z1.500z1e-10)r(  ):r   r   r'   r  rz   r{   r}   r   r   r|   r~   ry   r$   r   r   r   r   r   r   r   r   r   r8  rK   rO   lnlog10logbrD   rS   rT   rY   r8   r\   capitalsr]   r3  r9   r5   rW   ra   r  rQ   r  rR   rZ   rotatescalebshiftfmar(   r%   to_integralrr   rv   r^   r_   quantize)r   r   r'   r  rz   r{   r}   r   r   r|   r~   ry   r  r   r  zr   r    r   r   r   test_none_args}  s    Z $zUsabilityTest.test_none_argsc                 C   s   | 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d|d|d | |d|dd|d|d|d | |ddd|d|d|d | |dd|d|d|d|d d S )Nr"  r%  iu'    i7  rl  rR  rZ  i   r   r  z9.123rM  r  ir   C   )r   r   r   r3  r9   r:   r;   r5   rW   ra   r  rQ   r  rR   rU   r  rZ   r  r[   r  r  r  r   r   r   r   test_conversions_from_intl	  s   z'UsabilityTest.test_conversions_from_intN)r   r   r   r   r_  rf  rh  rr  rt  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   rP  m  s.    $*	Ng
-!/	 prP  c                   @   r   )CUsabilityTestNr   r   r   r   r   r  	  r   r  c                       ,   e Zd ZeZ fddZ fddZ  ZS )PyUsabilityTestc                    "   t    t | _td d S NiX  superr   sysget_int_max_str_digits_previous_int_limitset_int_max_str_digitsr   r   r   r   r   	     

zPyUsabilityTest.setUpc                       t | j t   d S r   r  r  r  r  tearDownr   r  r   r   r  	     zPyUsabilityTest.tearDownr   r   r   r   r   r   r  __classcell__r   r   r  r   r  	      r  c                   @   s\   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )PythonAPItestsc                 C   sT   | j j}| t|tj | t|tj | |dtj | 	|dtj d S r  )
r   r   r   
issubclassnumbersNumberr4  ZRealrV  ZassertNotIsInstancer   r   r   r   test_abc	  s
   zPythonAPItests.test_abcc                 C   s  t tjd D ]}| jj}tjd }| jtjd< |d}t||}t|}| 	|| t
rt
d}td}t
tjd< t||}	ttjd< t|	}
| |
tj | 	|
| ttjd< t||}t
tjd< t|}
| |
t
j | 	|
| t
d }td }t
tjd< t||}	ttjd< t|	}
| |
tj | 	|
| ttjd< t||}t
tjd< t|}
| |
t
j | 	|
| |tjd< qd S )Nr   r   z-3.141590000z-3.123e81723)r	  pickleHIGHEST_PROTOCOLr   r   r  modulesdumpsloadsr   rh   r   rV  r  ZDecimalTuple)r   protor   savedecimalr   r  r   r   r  ZsxrK  Zsyr   r   r   test_pickle	  sN   















zPythonAPItests.test_picklec                 C   s   | j j}tddD ])}d|d  }| t||tt| ||}|t}| |t|| q	| t	t|d | t	t|d | t
t|d | t
t|d d S )	N   %0.2f      Y@r  r  r@  rA  )r   r   r	  r   r   rI  r  rr   r   r   r  r   r   r   r   r   rK  r   r   r   test_int	  s   
zPythonAPItests.test_intc                 C   sl   | j j}tddD ]*}d|d  }| t||tt| ||}|t}| |t	|| q	d S )Nr  r   r  r  )
r   r   r	  r   r   rI  r  rr   r  truncr  r   r   r   
test_trunc	  s   
zPythonAPItests.test_truncc                 C   sz  | j j}G dd d|}| t|| |d}| t|| | t|d | |jd d}| |||| | |t	d
  | |t	d  | |t	d	  | t|t	dt|d
 | t|t	dt|d | t|t	d	t|d | t|jd tdD ]}tdt d d  }| |t	|| qd S )Nc                   @   r  )z1PythonAPItests.test_from_float.<locals>.MyDecimalc                 S   s
   d| _ d S )Nr  )r   )r   _r   r   r   r  

     
z:PythonAPItests.test_from_float.<locals>.MyDecimal.__init__Nr  r   r   r   r   r  	
  r  r  r=  r>  r  l   s\&5$3|	 r?  r@  rA  r  r,  rB  abcrE  rF  rG  rH  )r   r   r   r  r   r   r   r   r   rI  rL   rH   r   r   r	  r   rJ  )r   r   r  rK  Zbigintr   r   r   r   r   test_from_float
  s8   




zPythonAPItests.test_from_floatc                 C   s   | j j}| j j}| j j}|dtd}| |tj|d |dt	d}| |tj|d |d|gd}| 
||jtj | t|dd | t|dd	 | t|d
d d S )Nr  )r$   r%   z3.1415r  )r$   r&          zDecimal('-0')rH  zDecimal('1')r2  zDecimal('10'))r   r   r'   r|   rr   r   create_decimal_from_floatr  pirv   r   r   )r   r   r'   r|   r    r   r   r   test_create_decimal_from_float%
  s8   

z-PythonAPItests.test_create_decimal_from_floatc                 C   s   | j j}| j j}| j j}|ddd}| |d|d|d | |dj|dtd|d | j||d	j|d
|d | }|d}|j||dtd}| ||d d S )Ni iayrk  z7.335z.01z7.34r%   z7.33Z10e99999Z1e100000r  z0.871831e800Z1e797)r    r   r%   z	8.71E+799)r   r   r'   rz   r   r  rr   r   )r   r   r'   rz   r  r   r   r   r   r   test_quantizeA
  s(   zPythonAPItests.test_quantizec                 C   s   | j j}|d}| |j| | |jd | | | |d}| t|ttd | t	t
|dd | t	t
|dd | t	t
|dd | t	t
|d	d d S )
Nz9.8182731e181273r   r0  r   realrZ  imag	conjugate__complex__)r   r   r   r  r  r  complexrI  r   r   r  )r   r   r   r   r   r   test_complexY
  s   zPythonAPItests.test_complexc                 C   s.  | j j}| j j}| j j}| j j}| j j}| }d|_d|_d|_| h}|	  | 
|d|d | 
|d|dd | 
||ddd | 
||dd |	  | j||d|d | |j|  | |j|  |	  | 
|dj|dd	 | j||d
j|d | |j|  | |j|  |	  | 
|dj|d|d | j||dj|d | |j|  | |j|  | 
|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j|d|d | |j|  | |j|  | 
|dj|d|d|d | 
|dj|d|d|d | 
|dj|d |d|d  | 
|d!j|d"|d|d# | 
|d!j|d"|d|d | 
|dj|d$|d|d% |	  | j||dj |d&|d | |j|  | |j|  | 
|d'j!|d(|d|d) | 
|d*j"|d+|d	d,|d- | jt#|dj$|d | jt#|dj%|d | jt#|dj&|d | jt#|dj'|d | jt#|dj(|d | jt#|dj)|d | jt#|dj*|d | jt#|dj+|d | |dj,|d | |dj-|d | jt#|dj.|d | jt#|dj/|d | jt#|dj0|d | 
|d.j1|dd | 
|dj2|dd | 
|dj3|dd/ | 
|d0j4|dd0 | 
|d1j5|d2|dd | 
|d1j6|d2|dd | 
|d3j7|d2|dd | 
|d4j8d|dd | 
|d4j8d|dd |	  | j||d4j9d|d | |j|  | |j|  | 
|d4j:d|dd | jt#|j;d5|d | jt#|dj<|d | 
|d= d | jt#|d$j>|d | jt#|d$j?|d | jt#|dj=d6d | jt#|dj=d6d7 W d    d S 1 sw   Y  d S )8Nr   r  r#   r  )r    r   r   r  r   r  r.  z0.7rA  r&  z-0.9z9.73z1E+1Z9999'  z-2000i0r  rl  z0.06250.2r%  )r    rq  r   r?  0.01z0.0101r  z-0.3z0.02z-0.03rC  r  rd  Z1e109.99r  r  9.9z0.9)thirdr    rq  z7E+1ir  z0.21Z11r  Z01Z23g?r   )r  )@r   r   r'   r  rz   r}   r$   r   r   r   r   r   r   r   r4  r   r  r  rS   rT   rY   r  r_   r^   r\   r3  r9   r  rQ   r  rR   rU   r  rZ   r  r   rE   rG   rH   rJ   rL   rN   rM   rP   rK   rO   adjustedr  radixr  rD   r8   r]   r5   rW   ra   r  r  r  r   r  	canonicalr>   r?   )r   ro  r'   r  rz   r}   Zxcr  r   r   r   test_named_parametersi
  s   
""""$z$PythonAPItests.test_named_parametersc                 C   s  | j }|j}|j}|j}|j}|j}|j}|j}|j}	|j	}
|j
}| t|t | t|| | t|| | t|t | t|| | t|t | t||
 | t||	 | t|| | t||	 | t||
 | t|| | t|| | t|| | t|	| | t|
| | t|| | t|j| | t|j| | t|j| | t|jt | t|j| d S r   )r   r   rz   FloatOperationr{   r}   r   r   r|   r~   ry   r   r  ArithmeticErrorr   ZeroDivisionErrorZConversionSyntaxZDivisionImpossibleZDivisionUndefinedZInvalidContext)r   r   r   rz   r!  r{   r}   r   r   r|   r~   ry   r   r   r   test_exception_hierarchy
  sB   z'PythonAPItests.test_exception_hierarchyN)r   r   r   r  r  r  r  r
  r  r  r  r   r$  r   r   r   r   r  	  s    3 pr  c                   @   r   )CPythonAPItestsNr   r   r   r   r   r%    r   r%  c                   @   r   )PyPythonAPItestsNr   r   r   r   r   r&    r   r&  c                   @   s  e Zd Zdd Zeeejeddd Z	dd Z
dd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Z d4d5 Z!d6d7 Z"d8d9 Z#d:d; Z$d<d= Z%d>d? Z&d@dA Z'dBdC Z(dDdE Z)dFdG Z*dHdI Z+dJdK Z,dLdM Z-dNdO Z.dPdQ Z/dRdS Z0dTdU Z1dVdW Z2dXdY Z3dZd[ Z4d\d] Z5d^d_ Z6d`da Z7dbdc Z8ddde Z9dfdg Z:dhdi Z;djdk Z<dldm Z=dndo Z>dpdq Z?drds Z@dtdu ZAdvdw ZBdxdy ZCdzd{ ZDd|d} ZEd~d ZFdS )ContextAPItestsc              
   C   s   | j j}| j j}| j j}| j j}| }|d d d d d d d d d}||fD ]=}| |jd | |jt | |j	d | |j
d | |jd | |jd t| |dg  t| |d|||g q#d S )	N)r$   r%   r   r   r  r3   r   r&   rN  ?B r   r   r   r&   )r   r'   rz   r{   r}   r   r$   r%   r(   r   r   r  r3   r"   )r   r'   rz   r{   r}   r:  r8  r  r   r   r   r    s(   
zContextAPItests.test_none_argsr  c                 C   sr   dd l }| j }tD ]}|||_| |j| q|d}| tt	|d| |d}| tt	|d| d S )Nr   r   r%   z	ROUND_ UP)
r  r   r'   RoundingModesr  r%   r   r   r   r  )r   r  r  Zrndr   r   r   r   r    s   


z(ContextAPItests.test_from_legacy_stringsc                 C   sv  t tjd D ]0}| jj}tjd }| jtjd< | }tt||}| 	|j
|j
 | 	|j|j | 	|j|j | 	|j|j | 	|j|j | 	|j|j | 	|j|j | 	|j|j trottfttfgnttfg}|D ]\}}ttD ]\}	}
tt| D ]\}}
tt| D ]\}}
tdd}tdd}tdd}td}td}|tjd< |j|||t|	 ||t| d | t| d | d}t||}|tjd< t|}| ||j | 	|j
| | 	|j| | 	|j| | 	|jt|	  | 	|j| | 	|j| t| |dt| d |  t| |d	t| d |  qqq~qv|tjd< qd S )
Nr   r   rZ  r  r   r   )r$   r   r   r%   r  r3   r   r&   r   r&   )r	  r  r  r   r'   r  r  r  r  r   r$   r   r   r%   r  r3   r   r&   rh   r   r   r*  r   r   	randrangerV  r"   )r   r  r'   r  r  r   combinationsZdumperloaderZrir  fiZtir$   rq  rp  capsr3   r   r   r   r   r   r  -  sb   





#zContextAPItests.test_picklec                 C   sB   | j j}| |ddd|ddi g | |ddddi g d S )Nr2  r3  rH  )r   r   )r   r   ZassertInZassertNotInr   r   r   r   test_equality_with_other_typesj  s   z.ContextAPItests.test_equality_with_other_typesc                 C   s   | j j}| j j}| }| }| t|t| | t|jt|j | t|jt|j t|j	 }t|j	 }| 
|| | 
|j|j d S r   )r   r   r'   r<   rV  r   r   r&   rf   keysr   )r   r   r'   r  r   Zk1Zk2r   r   r   	test_copyp  s   zContextAPItests.test_copyc                 C   s"   | j j}| }| tt|d d S )NZ_clamp)r   r'   r   r   r   r   r'   r  r   r   r   test__clamp  s   zContextAPItests.test__clampc                 C   J   | j j}| j j}| }||d}| |d| | t|jd d S Nr  r  )r   r   r'   r  r   r   r   r   r   r'   r  r   r   r   r   test_abs     zContextAPItests.test_absc                 C      | j j}| j j}| }||d|d}| |dd| | ||dd| | |d|d| | t|jdd | t|jdd d S Nr   r0  )r   r   r'   ri   r   r   r   r7  r   r   r   test_add     zContextAPItests.test_addc                 C   r:  r;  )r   r   r'   r3  r   r   r   r7  r   r   r   test_compare  r=  zContextAPItests.test_comparec                 C   r:  r;  )r   r   r'   r9   r   r   r   r7  r   r   r   test_compare_signal  r=  z#ContextAPItests.test_compare_signalc                 C   r:  r;  )r   r   r'   r:   r   r   r   r7  r   r   r   test_compare_total  r=  z"ContextAPItests.test_compare_totalc                 C   r:  r;  )r   r   r'   r;   r   r   r   r7  r   r   r   test_compare_total_mag  r=  z&ContextAPItests.test_compare_total_magc                 C   r5  r6  )r   r   r'   r>   r   r   r   r7  r   r   r   test_copy_abs  r9  zContextAPItests.test_copy_absc                 C   r5  r6  )r   r   r'   r=   r   r   r   r7  r   r   r   test_copy_decimal  r9  z!ContextAPItests.test_copy_decimalc                 C   r5  r6  )r   r   r'   r?   r   r   r   r7  r   r   r   test_copy_negate  r9  z ContextAPItests.test_copy_negatec                 C      | j j}| j j}| }||d|d}| |dd| | ||dd| | |d|d| | t|jdd | t|jdd d S )Nr   r&  r0  r*  )r   r   r'   rA   r   r   r   r7  r   r   r   r+    r=  zContextAPItests.test_copy_signc                 C   rE  Nr   r   r0  r  )r   r   r'   r2  r   r   r   r7  r   r   r   test_divide  r=  zContextAPItests.test_dividec                 C   rE  rF  )r   r   r'   rB   r   r   r   r7  r   r   r   test_divide_int  r=  zContextAPItests.test_divide_intc                 C   rE  rF  )r   r   r'   r  r   r   r   r7  r   r   r   test_divmod  r=  zContextAPItests.test_divmodc                 C   r5  Nr2  r  )r   r   r'   r   r   r   r   r7  r   r   r   test_exp  r9  zContextAPItests.test_expc                 C   s^  | j j}| j j}| }||d|d|d}| |ddd| | ||ddd| | |d|dd| | |dd|d| | ||d|dd| | t|jddd | t|jddd | t|jddd | t|j|d|dd	 | t|j|d
|dd | t|dj|dd	 | t|d
j|dd d S )Nr   r%  r"  r  r  4r,  r   znot a decimalr   r  gZd;O?)r   r   r'   r  r   r   r   r7  r   r   r   test_fma#  s0   

zContextAPItests.test_fmac                 C   r5  rJ  )r   r   r'   rG   r   r   r   r7  r   r   r   test_is_finite=  r9  zContextAPItests.test_is_finitec                 C   r5  rJ  )r   r   r'   rH   r   r   r   r7  r   r   r   test_is_infiniteF  r9  z ContextAPItests.test_is_infinitec                 C   r5  rJ  )r   r   r'   rJ   r   r   r   r7  r   r   r   test_is_nanO  r9  zContextAPItests.test_is_nanc                 C   r5  rJ  )r   r   r'   rK   r   r   r   r7  r   r   r   test_is_normalX  r9  zContextAPItests.test_is_normalc                 C   r5  rJ  )r   r   r'   rL   r   r   r   r7  r   r   r   test_is_qnana  r9  zContextAPItests.test_is_qnanc                 C   r5  rJ  )r   r   r'   rM   r   r   r   r7  r   r   r   test_is_signedj  r9  zContextAPItests.test_is_signedc                 C   r5  rJ  )r   r   r'   rN   r   r   r   r7  r   r   r   test_is_snans  r9  zContextAPItests.test_is_snanc                 C   r5  rJ  )r   r   r'   rO   r   r   r   r7  r   r   r   test_is_subnormal|  r9  z!ContextAPItests.test_is_subnormalc                 C   r5  rJ  )r   r   r'   rP   r   r   r   r7  r   r   r   test_is_zero  r9  zContextAPItests.test_is_zeroc                 C   r5  rJ  )r   r   r'   r  r   r   r   r7  r   r   r   test_ln  r9  zContextAPItests.test_lnc                 C   r5  rJ  )r   r   r'   r  r   r   r   r7  r   r   r   
test_log10  r9  zContextAPItests.test_log10c                 C   r5  rJ  )r   r   r'   r  r   r   r   r7  r   r   r   	test_logb  r9  zContextAPItests.test_logbc                 C   r:  r;  )r   r   r'   r5   r   r   r   r7  r   r   r   test_logical_and  r=  z ContextAPItests.test_logical_andc                 C   r5  )Nr  r  )r   r   r'   rD   r   r   r   r7  r   r   r   test_logical_invert  r9  z#ContextAPItests.test_logical_invertc                 C   r:  r;  )r   r   r'   rW   r   r   r   r7  r   r   r   test_logical_or  r=  zContextAPItests.test_logical_orc                 C   r:  r;  )r   r   r'   ra   r   r   r   r7  r   r   r   test_logical_xor  r=  z ContextAPItests.test_logical_xorc                 C   rE  rF  )r   r   r'   r  r   r   r   r7  r   r   r   test_max  r=  zContextAPItests.test_maxc                 C   rE  rF  )r   r   r'   rQ   r   r   r   r7  r   r   r   test_max_mag  r=  zContextAPItests.test_max_magc                 C   rE  rF  )r   r   r'   r  r   r   r   r7  r   r   r   test_min  r=  zContextAPItests.test_minc                 C   rE  rF  )r   r   r'   rR   r   r   r   r7  r   r   r   test_min_mag  r=  zContextAPItests.test_min_magc                 C   r5  rJ  )r   r   r'   Zminusr   r   r   r7  r   r   r   
test_minus  r9  zContextAPItests.test_minusc                 C   rE  rF  )r   r   r'   r?  r   r   r   r7  r   r   r   test_multiply  r=  zContextAPItests.test_multiplyc                 C   r5  rJ  )r   r   r'   rS   r   r   r   r7  r   r   r   test_next_minus  r9  zContextAPItests.test_next_minusc                 C   r5  rJ  )r   r   r'   rT   r   r   r   r7  r   r   r   test_next_plus$  r9  zContextAPItests.test_next_plusc                 C   rE  rF  )r   r   r'   rU   r   r   r   r7  r   r   r   test_next_toward-  r=  z ContextAPItests.test_next_towardc                 C   r5  rJ  )r   r   r'   rY   r   r   r   r7  r   r   r   test_normalize9  r9  zContextAPItests.test_normalizec                 C   sn   | j j}| j j}| }| |d||d | |d||d | |d||d d S )Nrl  r   r  )r   r   r'   r   r8   )r   r   r'   r  r   r   r   test_number_classB  s    z!ContextAPItests.test_number_classc                 C   r5  rJ  )r   r   r'   plusr   r   r   r7  r   r   r   	test_plusK  r9  zContextAPItests.test_plusc                 C   s   | j j}| j j}| }||d|d}| |dd| | ||dd| | |d|d| | ||d|d| | t|jdd | t|jdd | |jddddd d S )	Nr   r"  r0  rL  r  r.  r   )modulor^  r3  )r   r   r'   powerr   r   r   r7  r   r   r   
test_powerT  s   zContextAPItests.test_powerc                 C   rE  rF  )r   r   r'   r  r   r   r   r7  r   r   r   r  b  r=  zContextAPItests.test_quantizec                 C   rE  rF  )r   r   r'   	remainderr   r   r   r7  r   r   r   test_remaindern  r=  zContextAPItests.test_remainderc                 C   rE  rF  )r   r   r'   rZ   r   r   r   r7  r   r   r   test_remainder_nearz  r=  z#ContextAPItests.test_remainder_nearc                 C   rE  rF  )r   r   r'   r  r   r   r   r7  r   r   r   test_rotate  r=  zContextAPItests.test_rotatec                 C   r5  rJ  )r   r   r'   r\   r   r   r   r7  r   r   r   	test_sqrt  r9  zContextAPItests.test_sqrtc                 C   rE  rF  )r   r   r'   r[   r   r   r   r7  r   r   r   test_same_quantum  r=  z!ContextAPItests.test_same_quantumc                 C   rE  rF  )r   r   r'   r  r   r   r   r7  r   r   r   test_scaleb  r=  zContextAPItests.test_scalebc                 C   rE  rF  )r   r   r'   r  r   r   r   r7  r   r   r   
test_shift  r=  zContextAPItests.test_shiftc                 C   rE  rF  )r   r   r'   subtractr   r   r   r7  r   r   r   test_subtract  r=  zContextAPItests.test_subtractc                 C   r5  rJ  )r   r   r'   r]   r   r   r   r7  r   r   r   test_to_eng_string  r9  z"ContextAPItests.test_to_eng_stringc                 C   r5  rJ  )r   r   r'   r`   r   r   r   r7  r   r   r   test_to_sci_string  r9  z"ContextAPItests.test_to_sci_stringc                 C   r5  rJ  )r   r   r'   r_   r   r   r   r7  r   r   r   test_to_integral_exact  r9  z&ContextAPItests.test_to_integral_exactc                 C   s\   | j j}| j j}| }||d}| |d| | t|jd | t|jdd d S )Nr2  r  r   )r   r   r'   r^   r   r   r   r7  r   r   r   test_to_integral_value  s   z&ContextAPItests.test_to_integral_valueN)Gr   r   r   r  r   r   r   r`  ra  r  r  r0  r2  r4  r8  r<  r>  r?  r@  rA  rB  rC  rD  r+  rG  rH  rI  rK  rM  rN  rO  rP  rQ  rR  rS  rT  rU  rV  rW  rX  rY  rZ  r[  r\  r]  r^  r_  r`  ra  rb  rc  rd  re  rf  rg  rh  rj  rm  r  ro  rp  rq  rr  rs  rt  ru  rw  rx  ry  rz  r{  r   r   r   r   r'    s    
=																												r'  c                   @   r   )CContextAPItestsNr   r   r   r   r   r|    r   r|  c                   @   r   )PyContextAPItestsNr   r   r   r   r   r}    r   r}  c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )ContextWithStatementc                 C   sv   | j j}| j j}| }| }| }W d    n1 sw   Y  | }| ||d | ||d | ||d d S )N!did not restore context correctlydid not copy the context __enter__ returned wrong context)r   rU  r  r8  assertIsNot)r   rU  r  orig_ctx	enter_ctxset_ctx	final_ctxr   r   r   test_localcontext  s   z&ContextWithStatement.test_localcontextc           	      C   s   | j j}| j j}| j j}| j j}| }|dd}||}| }W d    n1 s*w   Y  | }| ||d | |j|jd | ||d | ||d d S )Nr  r$   r  zdid not set correct contextr  r  )r   r'   rU  r  r8  r   r$   r  )	r   r'   rU  r  r  new_ctxr  r  r  r   r   r   test_localcontextarg  s   

z)ContextWithStatement.test_localcontextargc              	   C   s  | j j}| j j}| j j}| j j}| j j}| j j}| }|  |dd}| }	| |	j	|j	 | |	j
|j
 d|	j
|< d|	_| |jd | ||	jd | |	j	|  ||4}
| |
j	|j	 | |
j
|j
 | ||
j|dd | |
j	|  | |
j	|  ~
W d    n1 sw   Y  | |	j	|  ~	W d    n1 sw   Y  | |jd | |j	|  | |j	|  | |j	|  | |j	|  d S )N  r   Tz0e-999z3.4e200r   )r   r   r'   rU  r  ry   r}   r   r   r   r&   r   rV  r   r   r   rl  r4  )r   r   r'   rU  r  ry   r}   r  r  r:  r8  r   r   r   test_nested_with_statements  sB   


z0ContextWithStatement.test_nested_with_statementsc                 C   s   | j j}| N}~| 1}~| }~| 	}~W d    n1 s"w   Y  W d    n1 s1w   Y  W d    n1 s@w   Y  W d    d S W d    d S 1 sXw   Y  d S r   r   r  r   r  r:  r8  r9  c4r   r   r   test_with_statements_gc1:  s"   "z-ContextWithStatement.test_with_statements_gc1c                 C   s   | j j}| Q}||4}~||}~||
}~~W d    n1 s%w   Y  W d    n1 s4w   Y  W d    n1 sCw   Y  W d    d S W d    d S 1 s[w   Y  d S r   r  r  r   r   r   test_with_statements_gc2F  s"   


"z-ContextWithStatement.test_with_statements_gc2c                 C   s  | j j}| j j}| j j}| j j}| }~|dd}|| ||~}~| |jd ~|dd}|| ~| | jd |dd}	||	 | | jd ||	>}
~	| |
jd ~
|dd}|| ~| | jd | }| |jd ~W d    n1 sw   Y  W d    n1 sw   Y  W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nr   r  r   r%  r"  )r   r'   r  rU  r,   r   r$   )r   r'   r  rU  r,   r:  Zn1r8  Zn2Zn3r9  Zn4r  r   r   r   test_with_statements_gc3R  sL   





"z-ContextWithStatement.test_with_statements_gc3N)	r   r   r   r  r  r  r  r  r  r   r   r   r   r~    s    #r~  c                   @   r   )CContextWithStatementNr   r   r   r   r   r  s  r   r  c                   @   r   )PyContextWithStatementNr   r   r   r   r   r  u  r   r  c                   @   s8   e Zd Zdd Zdd Zedd Zdd Zd	d
 ZdS )ContextFlagsc              
      s   j j} j j} j j} j j} j j} j j} j j} fdd}|dddtg g d}	|	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 ]o\}}|	  || }dd |	j D }|D ]V}|	  |D ]}||	| q|| }t|}|D ]}||vr|| q|jtd dd |	j D }|jtd  ||dd||f    ||dd||f   qqnd S )Nc                    s4    j tkrd| j|< | j| r|d S | | d S NT)r   rh   r   r&   Z_raise_error)r    flagr   r   r   raise_error  s   


z7ContextFlags.test_flags_irrelevant.<locals>.raise_errorr#   rE  r   )r$   r   r   r%   r&   r   z100E-425000010r   r  z
9.87654321c                 S      g | ]\}}|r|qS r   r   r   kr   r   r   r   r     r   z6ContextFlags.test_flags_irrelevant.<locals>.<listcomp>r   c                 S   r  r   r   r  r   r   r   r     r   z=operation produces different answers depending on flags set: zexpected %s, got %s.z9operation raises different flags depending on flags set: zexpected %s, got %s)r   r   r'   r|   r~   r   ry   r   r(   r6   r\   ri   r?  rv  r   r   r\  rX  r   r   r   r   )r   r   r'   r|   r~   r   ry   r   r  r    Z
operationsZflagsetsfnr   r   r   extra_flagsr  Znew_ansZexpected_flagsZ	new_flagsr   r   r   test_flags_irrelevantz  sb   	


z"ContextFlags.test_flags_irrelevantc                 C   s2  | j j}| j j}| j j}| }| |j|j | |j|j |j|_| |j|j | |j|j d|j|< |j|_| |j|j | |j|j i }||j | ||j | |j| d||< | ||j | |j| |di}| ||j | |j| dg}| ||j | |j| d S )NTFr  )	r   r'   r|   r~   rV  r   r&   r   update)r   r'   r|   r~   r  r   r   r   r   test_flag_comparisons  s4   
z"ContextFlags.test_flag_comparisonsc                 C   s  | j j}| j j}| j j}| }| |j|  |  | |dd | |j	|  |  | |
dd | |j	|  |  |d}| |j	|  | |d | |j	|  |  |d}| |j	|  | |d | |j	|  d|j|< |  | ||d | |j	|  |  | ||j
d | |j	|  |  |d}| |j	|  |  |d}| |j	|  W d    d S 1 sw   Y  d S )Ng      @T)r   r   r!  r  r4  r&   r   r   r   r   r   r   r  r   )r   r   r!  r  r  r   r   r   r   test_float_operation  sF   




"z!ContextFlags.test_float_operationc                    s8  j j j j}j jj j}dfdd	 d ddd d d	d	d

 d dtdtdd 	
fdd	}d fdd	}| }||.}|j  ||d d ||d d d|j< ||d ||d W d    d S 1 sw   Y  d S )Nc                    sN   |   t| |}| kr||| n||d |j   d S r  )r   r   r   r8  r   r   )r3  r^  r!   r    signalr   )r!  r   r   r   assert_attr  s   
z7ContextFlags.test_float_comparison.<locals>.assert_attrr`  ra  rc  rb  r  rC  r/  r  r,  rB  r@  rA  c                    s  dD ]
}
|| | qdD ]
}|| | q
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  d S )	N)rt  rv  )ru  rw  rx  ry  rd  r=  r  r?  )rI  )r  r  r!   )r   r  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_fr   r   doit6  s    z0ContextFlags.test_float_comparison.<locals>.doitc                    s   |    td dg}t|d | j  |    |r.|td dg ntd dg}| j  |    d ddfv }| j  |    d ddddiv }| j  d S )	Nr  z100.0r   rH  r  g      $@r3  r^  )r   rf   r   lenr   r   r   sorted)r  r  r   r^  )r   r!  r   r   r   test_containersT  s   z;ContextFlags.test_float_comparison.<locals>.test_containers)r  Tr   )r   r   r'   r!  r  rI  r4  r&   )r   r'   r  r  r  rX  r  r   )r   r!  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r   test_float_comparison  s8   	(

"z"ContextFlags.test_float_comparisonc                 C   s   | j j}| j j}| j j}| j j}| }| |j|  | |j|  |  d|j|< d|j|< | 	|j|  | 	|j|  d S r  )
r   r   r'   r|   r!  r4  r   r&   clear_trapsr   )r   r   r'   r|   r!  r    r   r   r   test_float_operation_defaults  s   

z)ContextFlags.test_float_operation_defaultN)	r   r   r   r  r  r   r  r  r  r   r   r   r   r  x  s    B&
5[r  c                   @   r   )CContextFlagsNr   r   r   r   r   r    r   r  c                   @   r   )PyContextFlagsNr   r   r   r   r   r    r   r  c                   @       e Zd ZdZdd Zdd ZdS )SpecialContextszTest the context templates.c              
   C   s.  | j j}| j j}| j j}| j j}| j j}| j j}| j j}| j j}| j j	}	t
| |d|||||	g |  }
|j}|j}d }zJz#d |_|_||fD ]}|| | }| || | |jd qIW n tyv } z	|j}W Y d }~nd }~ww W ||_||_||
 |r|d S ||_||_||
 |r|w )Nr&   i  )r   BasicContextExtendedContextrU  r,   rz   r{   r}   r   ry   r"   r<   r$   r  r   	Exceptionr   )r   r  r  rU  r,   rz   r{   r}   r   ry   savecontextZbasic_context_precZextended_context_precextemplater  r   r   r   r   test_context_templates  sP   
z&SpecialContexts.test_context_templatesc              
   C   s8  | j j}| j j}| j j}| j j}| j j}| j j}| j j}| j j}| 	|j
d | 	|j
d t| |d|||g |  }	|j
}
d }zMz)| }|j
}d|_
| }| 	|j
| || | }| || | 	|j
d W n ty } z	|j}W Y d }~nd }~ww W |
|_
||	 |r|d S |
|_
||	 |r|w )Nr#   r&   i  )r   rG  r  r  rU  r,   rz   r{   r}   r   r$   r"   r<   r  r  r   )r   rG  r  r  rU  r,   rz   r{   r}   r  Zdefault_context_precr  r  Zsaveprecr   r   r   r   test_default_context  sP   
z$SpecialContexts.test_default_contextN)r   r   r   r   r  r  r   r   r   r   r    s    $r  c                   @   r   )CSpecialContextsNr   r   r   r   r   r    r   r  c                   @   r   )PySpecialContextsNr   r   r   r   r   r    r   r  c                   @   r  )ContextInputValidationc              	   C   s@  | j j}| j j}| }dD ]#}t||d | t||d | tt||d | t	t||d qt|dd | t|dd | tt|dd | t	t|dd | t	t|d	d | t	t|d	d
 | t	t|d	d | t	t|d	d dD ]}| tt||d | tt||d | t	t||g d qy| t
t|dd | t	t|dg  | tt|di  | tt|dddi dD ]
}| t
|j| q| t	t|d
 | t	t|d
 | jt	|dd | jt	|dd | jt|dd | jt|dd | jt|dgd | jt|dgd | jt	|dd | jt	|dd d S )Nr$   r   r(  r  r  r   r)  r   r   r   r%  r%   r#   rH  r  r3   r   rp  rZ  r   r&   rz   r   )r$   r   r   r%   r  r3   r   r&   r  r3   r  r   r   Qr&   r   r   )r   r   )r   r'   rG  r<   r  r   r   r   r   r   r   KeyError__delattr__)r   r'   rG  r  r!   r   r   r   test_invalid_context  sL   z+ContextInputValidation.test_invalid_contextN)r   r   r   r  r   r   r   r   r        r  c                   @   r   )CContextInputValidationNr   r   r   r   r   r    r   r  c                   @   r   )PyContextInputValidationNr   r   r   r   r   r    r   r  c                   @   r  )ContextSubclassingc                    s  | j j}j j}j}j}j}j}j}j	}j
}	G  fddd }
  }|
 }dD ]}| t||t|| q4| jt|
fi ddi |
dd}| |jd | |	|j|dd	 | jt|
fi d
di |
tdd}| |jt | ||dd | jt|
fi ddi |
ddd}| |jd ||d|d}| ||d |||||fD ]
}| |j|  q| jt|
fi ddi |
ddd}| |jd | ||j|d|d | j tkr|||fD ]
}| |j|  q| jt|
fi ddi |
d	d}| |jd	 |d}| ||d | jt|
fi ddi |
ddd }| |jd ||d}| t|d! | jt|
fi d"di |
||gd#}||fD ]}| |j|  qh|   t! D ]}| "|j|  q|| jt|
fi d$di |
||gd%}||fD ]}| |j#|  q|$  t! D ]}| "|j#|  qd S )&Nc                       s"   e Zd Z			d fdd	ZdS )z>ContextSubclassing.test_context_subclassing.<locals>.MyContextNc	           	         s    |  |d ur|| _|d ur|| _|d ur|| _|d ur!|| _|d ur(|| _|d ur/|| _ d urHt trE fddt	   D   | _
d urcttr^fddt	  D | _d S d S )Nc                       i | ]}|| v qS r   r   r   r   r  r   r   
<dictcomp>B      z[ContextSubclassing.test_context_subclassing.<locals>.MyContext.__init__.<locals>.<dictcomp>c                    r  r   r   r  r  r   r   r  F  r  )r  r$   r%   r   r   r  r3   rW  rX  r   r   r&   )	r   r$   r%   r   r   r  r3   r   r&   r'   r   r   r&   r   r  0  s,   



zGContextSubclassing.test_context_subclassing.<locals>.MyContext.__init__)NNNNNNNNr  r   r  r   r   	MyContext/  s
    r  r$   r%   r   r   r  r3   r   r&   r$   r  r   r  Z9e2r   r%   XYZ)r%   r$   r  r#   r   r  )r   r$   z1e-99z2.234e-2000r  r   )r   r$   Z1e99z
2.234e2000r  r  Z1E222z1e+222r3   r   c   )r3   r   z!1.000000000000000000000000000E+99r   r  r&   r  )%r   r   r'   ry   r{   r|   r}   r~   r   r   rz   r   r   r   r   r$   r  r   rr   r%   ri  r   ri   r   r   r   rh   r  r   r`   r3   r   r   r   r4  r&   r  )r   r   ry   r{   r|   r}   r~   r   r   rz   r  r  r   r!   r   r  r   r  r   test_context_subclassing"  s~   


z+ContextSubclassing.test_context_subclassingN)r   r   r   r  r   r   r   r   r     r  r  c                   @   r   )CContextSubclassingNr   r   r   r   r   r    r   r  c                   @   r   )PyContextSubclassingNr   r   r   r   r   r    r   r  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )CheckAttributesc                 C   s   |  tjtj |  tjtj |  tjtj |  tjtj | tjdu p+tjdu  | tjdu p8tjdu  |  tj	tj	 |  t
tt
t d S )NTF)r   rh   r   r   r   rm  rn  r   rH  __version__dirr   r   r   r   test_module_attributes  s   z&CheckAttributes.test_module_attributesc                 C   sJ   dd t t D }dd t t D }| t|t| t  d S )Nc                 S   "   g | ]}d |v s| ds|qS __r  r   r   r   r   r   r        " z;CheckAttributes.test_context_attributes.<locals>.<listcomp>c                 S   r  r  r  r   r   r   r   r     r  )r  rh   r'   r   r   rf   r   r   r  r   r   r   test_context_attributes  s   z'CheckAttributes.test_context_attributesc                 C   sN   dd t tdD }dd t tdD }| t|t| t  d S )Nc                 S   r  r  r  r   r   r   r   r     r  z;CheckAttributes.test_decimal_attributes.<locals>.<listcomp>r#   c                 S   r  r  r  r   r   r   r   r     r  )r  rh   r   r   rf   r  r   r   r   test_decimal_attributes  s   z'CheckAttributes.test_decimal_attributesN)r   r   r   r  r  r  r   r   r   r   r    s    r  c                   @   st   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )Coveragec                 C   sH   | j j}| |d d | |d d | |d d d S )NZ	1234e9999i'  r?  r   r@  )r   r   r   r  r   r   r   r   test_adjusted  s   zCoverage.test_adjustedc                 C   sL   | j j}| j j}|d }| |d | }||d}| |d d S )Nr#   )r   r   rU  r  r   )r   r   rU  r   r  r   r   r   test_canonical  s   zCoverage.test_canonicalc                 C   sp   | j j }d|_d|_d|_t|_d|_d|_	t
| j  D ]}d|j|< d|j|< q| }d}| || d S )Nr   rE  r   r   Fz{Context(prec=425000000, rounding=ROUND_HALF_DOWN, Emin=-425000000, Emax=425000000, capitals=0, clamp=1, flags=[], traps=[]))r   rG  r<   r$   r   r   rt   r%   r  r3   r   r   r&   __repr__r   )r   r  r;  r   r   r   r   r   test_context_repr  s   
zCoverage.test_context_reprc                 C   sJ  | j j}| j j}| L}d|_d|_d|_| t|dd | |dd d | |dd d	 | |dd
 d | |d|ddd | 	|dd
d
 d | t|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  W d    n	1 s\w   Y  | 6}d|_d d! }|| }| }| || | }| || | |d}| || W d    d S 1 sw   Y  d S )"Nr   r  z-10r2  7r.  r  r  r   r  z1.2r  r  Tz1.01r%  FZ20Z580r  r"  r#   z2E+1z-1E+1z+Normalr  z1.12345r0  r  r   r  i  i  )!r   r   r  r$   r   r   r   r  r  r8  rJ   powr   rK   rO   r  r  r  rD   rS   rT   rY   r8   r_   r   rE   rG   rN   rM   rP   r>   r?   rA   )r   r   r  r  r   r  r  r   r   r   r    sb   
?
$zCoverage.test_implicit_contextc                 C   s  | j j}| j j}| j j}| j j}| }t|dd\}}| ||d | ||d t|dd\}}| | o?|  d|j	|< t|dd\}}| | oX|  d|j	|< |
  t|d|d\}}| | ow|  | |j|  |
  t|dd	\}}| | o|  | |j|  |
  t|d
d
\}}| | o|  | |j|  d|j	|< |
  t|dd
\}}| | o|  | |j| o|j|  W d    d S 1 sw   Y  d S )NZ10912837129r  Z10901935Z194r  r  Fr@  r  r      )r   r   r  rz   r{   r  r   r   rJ   r&   r   r   rH   )r   r   r  rz   r{   r  r  rK  r   r   r   rI  )  sD   


"zCoverage.test_divmodc                 C   s   | j j}| j j}| j j}| j j}| L}d|_|  | |dd |d | |j	|  d|_d|_
d|_|  d|j|< | |d|d	 |d
 | |j	|  W d    d S 1 sbw   Y  d S )Nr%  r  rZ  r  r   r  Fr  r  r@  )r   r   r  r}   r~   r$   r   r   r   r   r   r   r&   )r   r   r  r}   r~   r  r   r   r   rm  R  s"   
"zCoverage.test_powerc                 C   s   | j j}| j j}| j j}| '}d|_d|_d|_d|j|< |d|d}| 	|
  W d    d S 1 s9w   Y  d S )Nr   r  Fr  Z1e1)r   r   r  rz   r$   r   r   r&   r  r   rJ   r   r   r  rz   r  r   r   r   r   r  f  s   
"zCoverage.test_quantizec                 C   s>   | j j}| j j}| }| |d d | | d d S )Nr0  r2  )r   r   rU  r   r  r  r   r   r   
test_radixs  s
   zCoverage.test_radixc                 C   s0   | j j}dD ]}| t|d|dt qd S )N)r}  r  r  r  rs  r  r  r  r0  r  )r   r   r8  r   rg  )r   r   r!   r   r   r   r  {  s   zCoverage.test_ropc                 C   s   | j j}| j j}| `}d|_| t|d d | t|d d | t|ddd | t|d	d
d | t|d	dd | t|djd | t|djdd W d    d S 1 snw   Y  d S )NrN  r  r  z9.99e-5r   r  r  z1.23457r  r2  z1.2345000000ry  z0E+10r  r  r.  )	r   r   r  r$   r   r   	__round__r   r   )r   r   r  r  r   r   r   
test_round  s   "zCoverage.test_roundc                 C   s    | j  }| t|jdg d S )Nr  )r   r'   r   r   r   )r   r  r   r   r   test_create_decimal  s   
zCoverage.test_create_decimalc                 C   sv   | j j}| j j}| &}d|_|dd dd  }| t|d | | d W d    d S 1 s4w   Y  d S )Nr  i  i  r2  iS  r   r   )r   r   r  r$   r   r   r  r   r   r  r  r   r   r   r   r    s   "zCoverage.test_intc                 C   sl   | j j}| }d|_dd  }||}| ||  ||}| ||  ||d}| ||  d S )Nr  i  i  r   )r   r'   r$   r>   r   r?   rA   )r   r'   r  r   r  r   r   r   r2    s   


zCoverage.test_copyN)r   r   r   r  r  r  r  rI  rm  r  r  r  r  r  r  r2  r   r   r   r   r    s    Q)
r  c                   @   r   )	CCoverageNr   r   r   r   r   r    r   r  c                       r  )
PyCoveragec                    r  r  r  r   r  r   r   r     r  zPyCoverage.setUpc                    r  r   r  r   r  r   r   r    r  zPyCoverage.tearDownr  r   r   r  r   r     r  r   c                   @   rB  )PyFunctionalityz!Extra functionality in decimal.pyc                 C   s>   t j}t j}g d}|D ]\}}}| t|||| qd S )N)
)z.0er  z1e+0)z#.0er  z1.e+0)r  r  r0  )z#.0fr  1.)r  1.1r  )z#gr  r  )r  r0  r0  )z#.0gr0  r  )r  r  z100%)z#.0%r  z100.%)r   r   r  r   r  )r   r   r  r]  r  r   r   r   r   r   test_py_alternate_formatting  s   z,PyFunctionality.test_py_alternate_formattingN)r   r   r   r   r  r   r   r   r   r    s    r  c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )
PyWhiteboxz White box testing for decimal.pyc                 C   s  t j}t j}| n}d|_|d|d }| ||d |d|d }| ||d |d|d }|d|d	 }| ||d
 |d|d	 }|dd |d	 }d|_|d|d }d|_|dd |d }W d    d S 1 szw   Y  d S )Nr.  i   r  z
0.00390625z-0.6z0.0012885819Z256e7l   o z-0.0625r  Z152587890625e7r  ic
  r   Z152587890625   r   iB  )r   r   r  r$   r   r  r   r   r   test_py_exact_power  s$   "zPyWhitebox.test_py_exact_powerc                    s:  t j}t j}t j}| }tdd tt  D |_|| |d|d |d|dd4 fdd	}| 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
 |d0d
 |d1 |d2 |d3 d S )5Nc                 s   s    | ]}|d fV  qdS )r   Nr   r   r   r   r   r     s    z=PyWhitebox.test_py_immutability_operations.<locals>.<genexpr>z-25e55z33e+33Fc                    s   |r<t d|  d  j j j j j j jj jj jj d S t d|  d  j j j j j j d S )Nzd1.z(d2)z())r   r   _sign_int_exp)Z	operationZuseOtherb1b2r
  r  r   r   r   checkSameDec  s   z@PyWhitebox.test_py_immutability_operations.<locals>.checkSameDec__abs__r|  Trr  rx  ry  rv  rt  rw  ru  	__float__r  rv  __int__	__trunc__r  r  __neg____bool____pos__r  r}  rs  r  r  r  r  r  r  __str__r  r  r  r  r3  r  r  rY   r  rZ   r[   r\   r]   r  )F)r   r   rG  r,   r<   r)   r   r&   r   r  r	  r
  )r   r   rG  r,   r  r  r   r  r   test_py_immutability_operations  st   


























z*PyWhitebox.test_py_immutability_operationsc                 C   s>   t j}|d}||}| t|d | t|t| d S )Nr   r   )r   r   r   r   rV  r   r;  r   r   r   test_py_decimal_idD  s
   zPyWhitebox.test_py_decimal_idc                 C   sV   t j}t j}| }|ddt}| |  W d    d S 1 s$w   Y  d S )Nr  r%  )r   r   r  Z_rescalerv   r   rJ   r  r   r   r   test_py_rescaleL  s   "zPyWhitebox.test_py_rescalec                 C   s    t j}| t|djdt d S )Nz3.1234r   )r   r   r   r   Z_roundrv   r   r   r   r   test_py__roundU  s   zPyWhitebox.test_py__roundN)	r   r   r   r   r  r  r  r  r  r   r   r   r   r    s    O	r  c                   @   s4   e Zd ZdZedd Zedd Zedd ZdS )	CFunctionalityzExtra functionality in _decimalc                 C   s  t j}t j}t j}t j}dd }||}| |jd | |jd | |jd || | ||}| |jd | |jd | |jd || | ||}| |jd	 | |jd
 | |jd || | | 	t
|d | 	t|d | 	t|d d S )Nc                 S   s.   |  |jd t| |dg  t| |dg  d S )Nr   r&   r   )r   r3   r"   )r   r    r   r   r   assert_restf  s   z7CFunctionality.test_c_ieee_context.<locals>.assert_restr  `   ir}  r  r  "   i   irQ  r  i   )rh   IEEEContext	DECIMAL32	DECIMAL64
DECIMAL128r   r$   r   r   r   r  r   )r   r  r   r!  r"  r  r  r   r   r   test_c_ieee_context^  s.   


z"CFunctionality.test_c_ieee_contextc                 C   s:   t j}|t jt jd}| |jt j | |jt j d S )Nr  )rh   r'   r0   
DecRoundedr   _flags_trapsr3  r   r   r   test_c_context  s   zCFunctionality.test_c_contextc                 C   s  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}| t jd | t jd | t jd | t jd t|D ]\}}| |d|>  q@| t jt jt jB t jB t jB t jB t j	B t j
B  | t jt jt jB  | t jt jt jB t jB  d S )Nr  r     i   r   )rh   r0   DecConversionSyntaxDecDivisionByZeroDecDivisionImpossibleDecDivisionUndefinedDecFpuError
DecInexactDecInvalidContextDecInvalidOperationDecMallocErrorDecFloatOperationDecOverflowr$  DecSubnormalDecUnderflowr   r   r!  r"  ZIEEE_CONTEXT_MAX_BITSr   DecIEEEInvalidOperationZ	DecErrorsZDecTraps)r   condr   r   r   r   r   test_constants  sH   
	zCFunctionality.test_constantsN)r   r   r   r   requires_extra_functionalityr#  r'  r8  r   r   r   r   r  [  s    
#
r  c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	e
dd Zdd Ze
dd Zdd Zdd Zdd Zdd Zdd Ze
dd Ze
d d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zeejd,d-eed.d.d/d0d1d2 Z d3S )4	CWhiteboxzWhitebox testing for _decimalc                 C   s   t j}t j}dd }dd }| 1}d|_tdD ] }t||}tdd}|| }	|||| }
| |	|
 qW d    d S 1 sEw   Y  d S )Nr2  #   $   i@B r  r  i  )rh   r   r  r$   r	  r   r+  r   )r   r   r  r  r  r  r   r3  r^  r   r  r   r   r   test_bignum  s   "zCWhitebox.test_bignumc                 C   s   |  ttjdd d S )Nr#   r  )r   r   rh   r   r   r   r   r   test_invalid_construction  s   z#CWhitebox.test_invalid_constructionc                 C   sV   t j}t j}t j}t j}||  | ||d W d    d S 1 s$w   Y  d S )NZ1e9999999999999999999)rh   r   rz   r'   r  r   )r   r   rz   r'   r  r   r   r   test_c_input_restriction  s   "z"CWhitebox.test_c_input_restrictionc                 C   s   t j}t j}| }d|_d|_d|_t|_d|_	d|_
tt  D ]}d|j|< d|j|< q d|j|< d|j|< | }d}| || d S )Nr   rE  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]))rh   rG  r!  r<   r$   r   r   rt   r%   r  r3   r   r   r&   r  r   )r   rG  r!  r  r;  r   r   r   r   r   test_c_context_repr  s"   


zCWhitebox.test_c_context_reprc              	   C   s  t j}t j}t j}t j}t j}t j}t j}t jdk}| }	| 	t
|	jjdd | 	t
|	jjdd | 	t|	jj| | 	t|	jj| | 	tt|	ddg | 	tt|	ddg | 	t
t|	dddi | 	t
t|	dddi |	j }
|
|= d	|
d
< | 	t
t|	d|
 | 	t
t|	d|
 |rdnd}|rdnd}dD ]}| 	tt|	|| q| 	tt|	d|  | j	t||d | j	t||d | j	t|| d | j	t||d d | j	t||d d | j	t|| d d | j	t||d d | j	t||d d dD ]4}| 	tt|	||d  | 	tt|	|| d  tjdkr1| 	tt|	|| | 	tt|	|| d  qt jdkr]| 	tt|	d|d  | 	tt|	d|d  | 	tt|	d| d  t jdkr| 	tt|	dd | 	tt|	dd | 	tt|	dd | 	tt|	dd | 	tt|	dd | 	tt|	dd dD ]5}| 	tt|	|d | 	tt|	|d | 	tt|	|g d  |r| 	tt|	|d! | 	tt|	|d" q| 	ttd#t  | 	ttd$t  | }| 	t|d% || d S )&Nr   i!  r   r   r   r&   r  r   ipr  rP  rO  l     NZoi ʚ;r  r   r  r  )r   r   r  r  )r$   r   r   r  r3   win32r   r   r   i?r  i9r  r                 zwith localcontext("xyz"): passz-with localcontext(context=getcontext()): passr  )rh   r'   rz   r}   r!  r  rU  r,   r   r   r  r   __setitem__r&   r   __delitem__r   r  r<   r  r  platformr   execrg  )r   r'   rz   r}   r!  r  rU  r,   HAVE_CONFIG_64r  r   int_maxZgt_max_emaxr!   Zsaved_contextr   r   r   test_c_context_errors  s   


zCWhitebox.test_c_context_errorsc                 C   s   |  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
tj
 d S r   )r8  rh   rv   r   rr   rq   rs   ru   rt   r(   rw   r   r   r   r   test_rounding_strings_internedT  s   z(CWhitebox.test_rounding_strings_internedc              	   C   s  t j}t j}t j}t j}t j}t j}t jdk}| }|rdnd}	| t	t
|d|	d  | t	t
|d|	 d  tjdkrQ| tt
|d|	 | tt
|d|	 d  dD ]3}
| t	t
||
|	d  | t	t
||
|	 d  tjdkr| tt
||
|	 | tt
||
|	 d  qS| tt
|dd	 | tt
|dd | tt
|dg d
 |r| tt
|dd | tt
|dd dD ]}
| tt
||
d | tt
||
d qd S )Nr   rP  rO  _allcrr   r   rA  )r%  r&  r  r  rB  rC  r(  r   )rh   r'   rz   r}   r  rU  r,   r   r   r  r  r  rF  r   r   )r   r'   rz   r}   r  rU  r,   rH  r  rI  r!   r   r   r   test_c_context_errors_extra_  s>   


z%CWhitebox.test_c_context_errors_extrac                 C   s  t j}t j}t j}t j}t j}t j}| }d|_t	|_
d|_d|_d|_d|_| |jd | |j
t	 | |jd | |jd | |jd | |jd | | d | | d t jdkr|d	 |d	 |d
 | |jd	 | |jd	 | |jd
 d S d S )Nr  i  iHr   r   i'i  r   ri  rj  )rh   rG  ry   r   r|   r~   r   r<   r$   ru   r%   r   r   r  r3   r   ZEtinyZEtopr   r   r   r   )r   rG  ry   r   r|   r~   r   r  r   r   r   test_c_valid_context  s:   



zCWhitebox.test_c_valid_contextc                 C   s4   t j}| }| |jd d|_| |jd d S )Nr   r   )rh   rG  r<   r   rL  )r   rG  r  r   r   r   test_c_valid_context_extra  s
   z$CWhitebox.test_c_valid_context_extrac                 C   s  t j}t j}t j}t j}t j}t jdkrdnd}| \}d|j|< | ||dj	| d  | ||dj	| | ||dj	t
|d  | t j|dj	t
|d   | t|dj	| d  | t|dj	|d  W d    d S 1 szw   Y  d S )	Nr   rP  rO  Tr  r   r0  r   )rh   r   rz   r  r   rn  r   r&   r   r  r   r  )r   r   rz   r  r   rn  rI  r  r   r   r   test_c_round  s6   

"zCWhitebox.test_c_roundc                 C   s   t j}t jdk}| t|djdg d | t|djdd | t|djg  | t|djd |r7dnd}| t|djd	|  d S )
Nr   r   z=10.10r#   z<>=10.10rP  rO  r  z=%d.1)rh   r   r   r   r   r  r   )r   r   rH  maxsizer   r   r   test_c_format  s   
zCWhitebox.test_c_formatc                 C   sf  t j}t j}t j}|d}| | d | t|jd | t|jdd | t|jd | | d | t|jd | t|jdd | t|jd | |	 d | t|j	d | t|j	dd | t|j	d | 6}|dt
}| ||d |d	t
}| ||d d|j|< | ||dj	t
 W d    d S 1 sw   Y  d S )Nr2  r  r   z99999999999999999999999999.9Z100000000000000000000000000Tz999.9)rh   r   r|   r  r   r  r   r   r^   r_   rv   r&   )r   r   r|   r  r   r  r   r   r   test_c_integral  s0   
"zCWhitebox.test_c_integralc              	   C   sT  t j}t j}t j}t j}t j}| |d d | t	t
|ddd | t	|djdd | t	|djd	dd | t	|d
j|dg  | t	|d
j|d|  | t	|d
j|dd | t	|d
j|dtd | }|  | t	|j|ddd | t	|jd | t	|jd | t	|jdddd | t	|jdd	dd | t||dd | | d d|j|< | ||djd | ||jdd | |j|  |  d|j|< | ||djd | ||jdd | |j|  d|j|< d|_| |t
|ddd W d    d S 1 s#w   Y  d S )Nz9.99e10z99.9E+9r   r   r  r#   r   r  r%  r  z	1e-100000r2  r  rE  r.  Z200Tr   i  )rh   r   rz   r{   rU  r  r   r]   r   r   r  r8   r[   r  rv   r  rA   r  rE   r  r   r  r&   rr  r   r   r   r$   )r   r   rz   r{   rU  r  r  r   r   r   test_c_funcs  s^   


$zCWhitebox.test_c_funcsc                 C   s  t j}t j}|d}dD ]}t||}| jt|dd | jt|dd d qdD ]}t||}| jt|dd | jt|dd d q'| jt|jd g d | jt|ji g d | t|jg g  | jt|jd g d | jt|ji g d | t|jg g  | jt|jd g d | jt|ji g d | t|jg g  | jt|j	dddd | jt|j	dddd d | jt|j
dg d d | jt|j
dg d d	 | t|j
dg g  | }| jt|jdddd
 | jt|jddd d
 | jt|jddd d
 d S )NZ10001111111)r   rK   rO   r  r  r  rD   rS   rT   rY   r8   r\   r]   r   r  )r3  r9   r5   rW   r  rQ   r  rR   rZ   r  r  r  r  r   r   r  )mod)rh   r   r'   r   r   r   r  r^   r_   r  r  rl  )r   r   r'   r   r!   funcr  r   r   r   test_va_args_exceptions9  s:   

z!CWhitebox.test_va_args_exceptionsc                 C   sL   |  tjjtjtjB tjB tjB tjB  |  tj	jtjtjB tjB  d S r   )
r   rh   r  r&  r6  r*  r3  r5  r0   rG  r   r   r   r   test_c_context_templatese  s   z"CWhitebox.test_c_context_templatesc           &         s  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d}| } ||jv  |  |j D ]}d|j|< qE|j D ]} | qR|  |j D ]	\}} | qc |j|  |jdd   |jddd  t|jjddd  t|jt|j t|j}t|j}|j  }|!  ||_" |j|  |  ||_# |j|  |!  |j }d||< ||_|||j |  |j }d||< ||_|||j |t j|	t j$|
t j%|t j&|t j'|t j(|t j)|t j*|t ji	}t j+t j,t j-t j.t jt j/t j0g}tt1t  }t2|D ]}t2|D ]}t3D ]}t45t1t  |}t45t1t  |}t46dd}t46d	d
}t46d
d}t46d
d} t46d
d}!t46d
d}"||||||!| t7|t7|d} |j8|  |j9|  |j:|  |j;|  |j<|!  |j=|  d
}#|D ]	}$|#||$ O }#q |j"|# d
}#|D ]	}$|#||$ O }#qǈ |j#|# q>q:q4|D ]}%|%|_" |j"|@  |||j q|D ]}%|%|_# |j#|@  |||j qd S )Nc                    s4   |D ]}|| kr  ||  q ||  qd S r   )r   r4  )r  Zsignal_dictr;  r   r   r   assertIsExclusivelySet  s
   z<CWhitebox.test_c_signal_dict.<locals>.assertIsExclusivelySetTr   r  r  r   r  ir   r   r  )>rh   r'   rG  rz   r!  r{   r}   r   r   r~   r|   ry   r0   r0  r6  r<   r   r&   r  r1  valuesr\  r4  r   r   r8  r   r   r   r  r  	getsizeofr  r   r%  r&  r$  r.  r4  r5  r3  r*  r2  r+  r,  r-  r/  r1  r)  r   r	  r*  r   sampler+  rX  r$   r%   r   r   r  r3   )&r   r'   rG  rz   r!  r{   r}   r   r   r~   r|   ry   r0   r0  r6  rY  r  r  r   r   r   Z
IntSignalsZIntCondZlimrK  r   r  r   r&   r$   rq  rp  r3   r/  Zcrr   r   r7  r   r   r   test_c_signal_dictq  s   




zCWhitebox.test_c_signal_dictc                    s   t j zddlm} W n ty   | d Y nw dd }d fdd	}d	|g d
d	d}d|g dd	d}d|g ddd}|dkrP| t|d|d | t|d|d | t|d|d d S )Nr   r  r  c                 S   s   d dd | D S )Nr   c                 S   r  r   r  r   r   r   r   r      r  zJCWhitebox.test_invalid_override.<locals>.make_grouping.<locals>.<listcomp>)r  r  r   r   r   r    s   z6CWhitebox.test_invalid_override.<locals>.make_groupingr
  c                    s    |  ||S r   )r  r  rz  r   r   r       z0CWhitebox.test_invalid_override.<locals>.get_fmtr  )   r_  r   r  Zxxxxxr  r  Zyyyyy   r  r  r  )rh   r   r  r  r  r  r   r   )r   r  r  r  Zinvalid_groupingZinvalid_dotZinvalid_sepr   rz  r   test_invalid_override  s4   



zCWhitebox.test_invalid_overridec                 C   s   t j}t j}t j}| D}d|j|< dtj }| ||| dtj d  }| ||| dtj }| ||| dtj d  }| ||| W d    d S 1 sSw   Y  d S )NTz0e%dr   z1e%d)rh   r   r  rz   r&   r  rQ  r   r  r   r   r   test_exact_conversion  s   


"zCWhitebox.test_exact_conversionc                 C   s  t j}t j}t j}t j}t j}| }d|j|< d|j|< d|j|< ddtjf}| 	t
||d | ||| ddtjf}| ||j| | ||| ddtj d f}| 	t
||d | ||| ddtj d f}| ||j| | ||| ddtjd f}| t|j| | t|| ddtj d f}| t|j| | t|| d}| 	t
||d	 d
}| 	t
||d	 d}| 	t
||d W d    d S 1 sw   Y  d S )NTr   r   z
-0E+999999)r   r   r   z-0E-1000007r   r  r  )r   r   r  )r   r  r  z-sNaN1)rh   r   r  rz   r}   r   r&   r  rQ  r   r   r   r   r  )r   r   r  rz   r}   r   r  r   r   r   r   test_from_tuple4  sD   


"zCWhitebox.test_from_tuplec                 C   s   t j}t jdk}| |d d |r.|dd  }|dd  }| ||d  d S |dd  }|dd  }| ||d	  d S )
Nr   r   r2  rM  i  r.        r"  )rh   r   r   rR  
__sizeof__r   )r   r   rH  r   r  r   r   r   test_sizeofd  s   
zCWhitebox.test_sizeofc                    sz   t j}G dd dt}G dd dt}G dd dt G  fdddt}|||fD ]}| ||d	|d	 q*d S )
Nc                   @   s   e Zd Zdd Zdd ZdS )z<CWhitebox.test_internal_use_of_overridden_methods.<locals>.Xc                 S   r  Nr   r   r   r   r   r   r  w  r  zMCWhitebox.test_internal_use_of_overridden_methods.<locals>.X.as_integer_ratioc                 S      | S r   r   r   r   r   r   r  y  r  zDCWhitebox.test_internal_use_of_overridden_methods.<locals>.X.__abs__Nr   r   r   r  r  r   r   r   r   Xv  s    rk  c                   @   r  )z<CWhitebox.test_internal_use_of_overridden_methods.<locals>.Yc                 S   
   dgd S Nr   rE  r   r   r   r   r   r  }  r  zDCWhitebox.test_internal_use_of_overridden_methods.<locals>.Y.__abs__N)r   r   r   r  r   r   r   r   Y|  r  rn  c                   @   r  )z<CWhitebox.test_internal_use_of_overridden_methods.<locals>.Ic                 S   rl  rm  r   r   r   r   r   
bit_length  r  zGCWhitebox.test_internal_use_of_overridden_methods.<locals>.I.bit_lengthN)r   r   r   ro  r   r   r   r   I  r  rp  c                       s    e Zd Z fddZdd ZdS )z<CWhitebox.test_internal_use_of_overridden_methods.<locals>.Zc                    s    d dfS rh  r   r   rp  r   r   r    r^  zMCWhitebox.test_internal_use_of_overridden_methods.<locals>.Z.as_integer_ratioc                 S   ri  r   r   r   r   r   r   r    r  zDCWhitebox.test_internal_use_of_overridden_methods.<locals>.Z.__abs__Nrj  r   rq  r   r   Z  s    rr  gfffffFY@)rh   r   rI  r   r   r   )r   r   rk  rn  rr  r   r   rq  r   'test_internal_use_of_overridden_methodsr  s   z1CWhitebox.test_internal_use_of_overridden_methodsZaixzEAIX: default ulimit: test is flaky because of extreme over-allocationT)addressZmemoryzVASAN/MSAN sanitizer defaults to crashing instead of returning NULL for malloc failure.c                 C   sZ  g d}t j}t j}t j}|t jt jt jd}|| | |d d | |d	 d | |d
 d | |d
 d | |dd 
 d | |d	 d
 | |d d | |d |d | t|ddd | |dd d | |dd d | |dd |d W d    d S 1 sw   Y  d S )N)	rD   rS   rT   r5   rW   ra   rU   r  r  )r$   r   r   r   r   rZ  r   r2     l     9V    r"  Z40E9z2.0E+5r%  )r%  r   i  r  z0.0025)rh   r   r'   r  r   rm  r   r   r   r  r  r  r\   r  )r   ZMaxContextSkipr   r'   r  Z
maxcontextr   r   r   test_maxcontext_exact_arith  s&   
"z%CWhitebox.test_maxcontext_exact_arithN)!r   r   r   r   r=  r>  r?  r@  rJ  rK  r9  rM  rN  rO  rP  rR  rS  rT  rW  rX  r]  ra  rb  rc  rg  rs  r   skipIfr  rF  r   r   rw  r   r   r   r   r:    sF    e
*&
;,

 %0r:  ztest requires C versionc                   @   r  )SignatureTestzFunction signaturesc           
      C   s   t tD ]f}|drqtt|}tt|}|dks#|dks#t|rjt|}t|}t|j	
 }dd |j	
 D }| j||d| d dd |j	 D }d	d |j	 D }	|d
krj| j||	d| d qd S )Nr  r   r'   c                 S   s   g | ]	}| d s|qS )r  r  r   r   r   r   r     s    
z5SignatureTest.test_inspect_module.<locals>.<listcomp>parameter name mismatch in %smsgc                 S      g | ]}|j qS r   kindr   r   r   r   r         c                 S   s$   g | ]}|d   ds|d jqS )r   r  r   )r   r  r   r   r   r   r     s    r,   parameter kind mismatch in %s)r  r   r   r   rh   inspect
isfunction	signaturerX  
parametersr1  r   rZ  r\  )
r   r!   p_funcc_funcp_sigc_sigc_namesp_namesc_kindp_kindr   r   r   test_inspect_module  s.   




z!SignatureTest.test_inspect_modulec                    s  t jj t jjttdtdtdtdtdtdtdtdtdtdddtjt dttdtdtdtdtdtdtdddtjt di fdddd	  fd
d}|d |d d S )Nr   r0  rH  )rq  r  r   r  r  r3  r^  r  r   rk  numr   r%   r    )rq  r  r3  r^  r  r   rk  r  r   r%   r    c                    sn   g }i }|j  D ])\}}|dkrq	|j kr!||  |  q	|jkr/|  | ||< q	td||fS )Nr   zunexpected parameter kind)r  r\  r  r   r	   )moduler;  r   kwargsnameZparam)POSPOS_KWDpdictr   r   mkargs  s   


z0SignatureTest.test_inspect_types.<locals>.mkargsc                 S   s(   | dkrdS | dkrdS | dkrdS | S )zwThe C Context docstrings use 'x' in order to prevent confusion
               with the article 'a' in the descriptions.r   r3  r  r^  r  r  r   )r   r   r   r   tr  s   z,SignatureTest.test_inspect_types.<locals>.trc              	      s  t t| }t t| }t|D ]}|drqt ||}t ||}t|rt|}t|}t|j	
 }fdd|j	
 D }	j|	|d| d dd |j	 D }
dd |j	 D }|
d  |d   | d	krj|d
d  |
d
d  d| d njt|t|
d| d t|\}}zt |d||i | W n ty   td|||f w t|\}}zt |d||i | W q ty   td|||f w qd S )Nr  c                    s   g | ]} |qS r   r   r   )r  r   r   r     r  zBSignatureTest.test_inspect_types.<locals>.doit.<locals>.<listcomp>rz  r{  c                 S   r}  r   r~  r   r   r   r   r      r  c                 S   r}  r   r~  r   r   r   r   r   !  r  r   r   r   r  r#   zinvalid signature for %s: %s %s)r   r   rh   r  r   r  r  r  rX  r  r1  r   rZ  r8  r  r  r	   )tyZp_typeZc_typer!   r  r  r  r  r  r  r  r  r   kwds)r  r  r  r   r  r   r   r    sP   







z.SignatureTest.test_inspect_types.<locals>.doitr   r'   )	r  Z_ParameterKindZPOSITIONAL_ONLYZPOSITIONAL_OR_KEYWORDrh   r   ru   rU  r   )r   r  r   )r  r  r  r  r   r  r   test_inspect_types  sF   

/z SignatureTest.test_inspect_typesN)r   r   r   r   r  r  r   r   r   r   ry    s    ry  r   r   c              
   C   s  t t t t | dur| ntda|a|du rt}nttg}t	
tD ]6}d|vs/|dr0q$|d\}}|dur@||vr@q$|fdd}ttd| | ttd| | ~~~~q$zVt|  |du rdd	lm}	 tjd }
tr}ttjd< tt||	d
 ttjd< tt| |
tjd< W trttt  ttt  tstdt ttjd urtddS trttt  ttt  tstdt ttjd urtdw )z Execute the tests.

    Runs all arithmetic tests if arith is True or if the "decimal" resource
    is enabled in regrtest.py
    Nr   z.decTestr  c                 S   s   |  t| S r   )r   	directory)r   r   r   r   r   r   w  s    ztest_main.<locals>.<lambda>Ztest_r   )IGNORE_EXCEPTION_DETAIL)Zoptionflagsz*C tests skipped: no module named _decimal.zGInternal error: unbalanced number of changes to sys.modules['decimal'].)r.   rh   r   r   r   r   	all_testsr   r   oslistdirr  r   r   r  r   doctestr  r  r  r   r,   ORIGINAL_CONTEXTwarningswarnUserWarningorig_sys_decimalr	   )arithverbose
todo_testsdebugZtest_classesfilenameheadtailZtesterr  r  r   r   r   	test_main\  s\   






r  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  r  r  r  )NNNN)r   r  r  r  r   r  r  r<   r   r  r  Ztest.supportr   r   r   r   r   r   r   r	   r
   r   r   Ztest.support.import_helperr   r   r   r  rI  rF  rh   r   r   r  Z
cfractionsr  Z
pfractionsr   r  rU  r   r1  r+   ry   r~   r|   r   r   r}   r{   rz   r!  r   r"   rv   rr   rq   rs   ru   rt   r(   rw   r*  r  r.   ZTESTDATADIRr   argvr   __file__pathdirnamecurdirZtestdirsepr  isdirr   r   hasattrZEXTRA_FUNCTIONALITYZ
skipUnlessr9  rx  Zskip_if_extra_functionalityZTestCaser1   r   r   r   rb  rc  rd  r  r  r  r  r  r  r,  r-  r<  rA  rC  rN  rO  rP  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:  ry  r  insertr  ZoptparseZOptionParserr  Z
add_option
parse_argsoptr   skipr  r   r   r   r   <module>   s  	$



	
  e  YM    )',-      6  X     o~  P>m   U      
 		



7
