Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_decimal.cpython-39.pyc

a

��gDE�"@s4dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZm
Z
mZmZmZmZmZmZmZmZmZddlZddlZddlZejdkr�ed�eddgd�Zeddgd	�ZddlZed
d
gd�Zeej d<ed
d
gd�Z!eej d<eeee!iZ"eej d<ee�r6e#e�$�j%�&��ndee#e�$�j%�&��iZ'ee�r~ej(ej)ej*ej+ej,ej-ej.ej/ej0g	ndeej(ej)ej*ej+ej,ej-ej.ej/ej0g	iZ1dd�Z2ej3Z3ej4Z4ej5Z5ej6Z6ej7Z7ej8Z8ej9Z9ej:Z:e3e4e5e6e7e8e9e:gZ;ee�re�$���ndee�$���iZ<d
d�Z=dZ>e?dk�r@ej@dZAneBZAejC�DeA��pVejEZFeFejGe>ejGZHejC�IeH�aJdZKeLed��r�dndZMe�NeMd�ZOe�PeMd�ZQGdd�dejR�ZSGdd�deS�ZTGdd�deS�ZUGdd�dejR�ZVGdd�deV�ZWGd d!�d!eV�ZXGd"d#�d#ejR�ZYGd$d%�d%eY�ZZGd&d'�d'eY�Z[Gd(d)�d)ejR�Z\Gd*d+�d+e\�Z]Gd,d-�d-e\�Z^Gd.d/�d/ejR�Z_Gd0d1�d1e_�Z`Gd2d3�d3e_�Zad4d5�Zbd6d7�ZcGd8d9�d9ejR�ZdGd:d;�d;ed�ZeGd<d=�d=ed�ZfGd>d?�d?ejR�ZgGd@dA�dAeg�ZhGdBdC�dCeg�ZiGdDdE�dEejR�ZjGdFdG�dGej�ZkGdHdI�dIej�ZlGdJdK�dKejR�ZmGdLdM�dMem�ZnGdNdO�dOem�ZoGdPdQ�dQejR�ZpGdRdS�dSep�ZqGdTdU�dUep�ZrGdVdW�dWejR�ZsGdXdY�dYes�ZtGdZd[�d[es�ZuGd\d]�d]ejR�ZvGd^d_�d_ev�ZwGd`da�daev�ZxGdbdc�dcejR�ZyGddde�deey�ZzGdfdg�dgey�Z{Gdhdi�diejR�Z|Gdjdk�dke|�Z}Gdldm�dme|�Z~eQGdndo�doejR��ZGdpdq�dqejR�Z�Gdrds�dse��Z�Gdtdu�due��Z�Gdvdw�dwejR�Z�Gdxdy�dyejR�Z�Gdzd{�d{ejR�Z�Gd|d}�d}ejR�Z�ee�Ned~�Gdd��d�ejR���Z�eWeXeZe[e]e^e`eaeeefeheiekeleneoeqereteuewexeze{e}e~e�e�e�e�e�e�eTeUg"Z�e�s�e�d�dd��Z�ne���de�e���d�e��d�d�d��Z�e?dk�r0ddl�Z�e���d��Z�e�j�d�d�d�d�d��e�j�d�d�d�d�d��e����\Z�Z�e�j��r
e�ddd��n&e��r$e�dde�e�j�d��ne�ddd��dS)�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�import_fresh_module�
TestFailed�run_with_locale�cpython_only�darwin_malloc_err_warning�check_sanitizer�darwinZtest_decimal�decimalZ_decimal)Zfresh)Zblocked�	fractionscs,t||��|�t��fdd��D���dS)Nc3s(|] }|�vr�|n�|VqdS�N���.0�s��d�expectedr�-/usr/local/lib/python3.9/test/test_decimal.py�	<genexpr>Q�z!assert_signals.<locals>.<genexpr>)�getattr�
assertTrue�all)�cls�context�attrrrrr�assert_signalsOs
r!cCs2|sdS|jdtt�t|d�d�}|�|�dS)N�	r)�prec�rounding�traps)�Context�ROUND_HALF_EVEN�dict�fromkeys�Signals�
setcontext)�mZDefaultTestContextrrr�iniths
�r-Zdecimaltestdata�__main__F�
DecClampedTz.test requires build with -DEXTRA_FUNCTIONALITYztest requires regular buildc@speZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�IBMTestCasesz?Class which tests the Decimal class against the IBM test cases.c&Csx|j��|_|j��|_dg|_tgd��|_|jtkr�|j�d�|j�d�|j�d�|j�d�|j�d�|j�d�|j�d	�|j�d
�|j	|j
|j|j|j
d�|_dd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1�%|_ttttttttd2�|_|jj|jj|jj|jj|jj|jj|jj|jj|jj|jj|jj|jj d3�|_!d4|_"dS)5N�#)Zscbx164Zscbx165Zexpx901Zexpx902Zexpx903Zexpx905Zlnx901Zlnx902Zlnx903Zlnx905Zlogx901Zlogx902Zlogx903Zlogx905Zpowx1183Zpowx1184Zpowx4001Zpowx4002Zpowx4003Zpowx4005Zpowx4008Zpowx4010Zpowx4012Zpowx4014Zpwsx803Zpwsx805Zpowx4302Zpowx4303Zpowx4342Zpowx4343Zpwmx325Zpwmx326)Z	precisionr$ZmaxexponentZminexponent�clamp�logical_and�_apply�number_class�compare_signal�
compare_total�compare_total_mag�copy_decimal�copy_abs�copy_negate�	copy_sign�
divide_int�logical_invert�is_canonical�	is_finite�is_infinite�is_nan�	is_normal�is_qnan�	is_signed�is_snan�is_subnormal�is_zero�max_mag�min_mag�
next_minus�	next_plus�next_toward�
logical_or�	normalize�remainder_near�same_quantum�sqrt�
to_eng_string�to_integral_value�to_integral_exact�
to_sci_string�logical_xor)%�andZapply�classZ
comparesigZcomparetotalZ
comparetotmag�copyZcopyabsZ
copynegate�copysignZ	divideint�invertZiscanonical�isfiniteZ
isinfinite�isnanZisnormalZisqnanZissignedZissnanZissubnormalZiszeroZmaxmagZminmagZ	nextminusZnextplusZ
nexttoward�or�reduceZ
remaindernearZsamequantumZ
squarerootZtoengZ
tointegralZtointegralxZtosci�xor)ZceilingZdown�floorZ	half_downZ	half_evenZhalf_upZupZ05up)ZclampedZconversion_syntaxZdivision_by_zeroZdivision_impossibleZdivision_undefinedZinexactZinvalid_contextZinvalid_operationZoverflowZroundedZ	subnormalZ	underflow)r?r@rArBrCrDrErFrGrHrQ)#rr&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��selfrrr�setUp�s�$
��'�
�zIBMTestCases.setUpcCsX|jtkrF|jjdkrF|j�d�|j�d�|j�d�|j�|�S|j�||�SdS)a2Work 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.�@�Ti���?i�9�N)	rrg�MAX_EMAXrc�_unsafe_setprec�_unsafe_setemax�_unsafe_setemin�create_decimal�Decimal)r��vrrrr�read_unlimitedszIBMTestCases.read_unlimitedcCs�tr
tj�t|���}|D]j}|�dd��dd�}z|�|�}Wq|jjy�}z&|�d|j	j
d|�WYd}~qd}~00qWd�n1s�0YdS)Nz
��
zException "z" raised on line )�
skip_expected�unittestZSkipTest�open�replace�	eval_liner�DecimalException�fail�	__class__�__name__)r��file�f�line�t�	exceptionrrr�	eval_file#s
zIBMTestCases.eval_filecCs�|�d�dkrX|dd�dkrX|�d�sX|�d�dd|�d�d�d�d��}n|�d�d��}|jD]}|�|�dkrpdSqp|s�dSd|vr�|�|�S|�|�SdS)	Nz -> r��--z  --�->��:)�find�
startswith�split�striprd�eval_directive�
eval_equation)r�r�ignorerrrr�2s(�


zIBMTestCases.eval_linecCsjdd�|�d�D�\}}|dkr,|j|}n zt|�}WntyJYn0|j�|dd��}||�dS)Ncss|]}|����VqdSr)r��lower�r�xrrrrErz.IBMTestCases.eval_directive.<locals>.<genexpr>r�r$cWsdSrr)�argsrrr�<lambda>Nrz-IBMTestCases.eval_directive.<locals>.<lambda>)r�rw�int�
ValueErrorrn�get)r�r�funct�valuerrrr�DszIBMTestCases.eval_directivecs�tst��dkrdS�j��zt|�d�}|d����}|d}trTtd|dd�|d��}|dd�}|d����}|d}|dd�}Wn t	t
tfy��jj
�Yn0d	d
�}	|�jvr�dS�j�||�}
|
dkr�dSt�j|
�}g}d}d}
�fd
d�|D��t�jD]}d�jj|<�q�D]}d�jj|<�q0t|�D�]&\}}|�d�ddk�rrd|
}
|
�r�|d|}�qLn||}d}|	|�}|
dv�rZt�rL�D]�}d�jj|<z|�j�|��WnR|�y�YnRt�j�y(}z ��d|||f�WYd}~nd}~00��d||f�d�jj|<�q��j�|�}n��|�j�}|�|��qL|	|�}t�r�|
dv�r�D]�}d�jj|<z||�WnR|�y�YnRt�j�y}z ��d|||f�WYd}~nd}~00��d||f�d�jj|<�q��fdd�t�jD�}|D]�}d�jj|<z||�WnV|�ypYnVt�j�y�}z$��dt|�||f�WYd}~nd}~00��d||f��q@|D]}d�jj|<�q�t�r�td�j�z,t||��}|
�jv�rttt |���}WnTt�j�y^}z��d||f�WYd}~n d}~0td|��Yn0��!�}|j"t#d��j"t#d���$||d|d|���$|�d|dt|��dS)Ng�������?r�rzTest � )�endr�r�cSs@|�dd��dd�}|�dd��dd�}|�dd��dd�}|S)Nz''ZSingleQuotez""ZDoubleQuote�'r��")r�)�valrrr�	FixQuotesesz-IBMTestCases.eval_equation.<locals>.FixQuotesZrescaler�csg|]}�j|���qSr)r�r�r�r�rr�
<listcomp>urz.IBMTestCases.eval_equation.<locals>.<listcomp>r�)rVrSz Raised %s in %s when %s disabledzDid not raise %s in %scsg|]}|�vr|�qSrr�r�e)�theirexceptionsrrr��rzRaised %s in %s; expected %sr�zRaised %s in %szERROR:��keyzIncorrect answer for z -- got zIncorrect flags set in )%�TEST_ALL�randomr�clear_flagsr�r��DEBUG�printr��	TypeError�AttributeError�
IndexErrorrryrfror�rr*r%�	enumerate�count�EXTENDEDERRORTESTr�r�r��append�OrderedSignals�type�strr�r��eval�
getexceptions�sort�repr�assertEqual)r�rZSides�L�idr�Zvalstemp�ans�
exceptionsr�ZfnameZvalsZconglomerate�quoter��ir�r��errorr�Zordered_errors�resultZmyexceptionsr)r�r�rr�Qs�



���&
��zIBMTestCases.eval_equationcs�fdd�t�jD�S)Ncsg|]}�jj|r|�qSr)r�flagsr�r�rrr��rz.IBMTestCases.getexceptions.<locals>.<listcomp>)r*rr�rr�rr��szIBMTestCases.getexceptionscCs0|jtkr$|jjdkr$|j�|�n||j_dS�Nr�)rrg�MAX_PRECrr�r#)r�r#rrrri�szIBMTestCases.change_precisioncCs||j_dSr)rr$)r�r$rrrrj�sz#IBMTestCases.change_rounding_methodcCs0|jtkr$|jjdkr$|j�|�n||j_dSr�)rrgr�rr��Emin�r��exprrrrl�sz IBMTestCases.change_min_exponentcCs0|jtkr$|jjdkr$|j�|�n||j_dSr�)rrgr�rr��Emaxr�rrrrk�sz IBMTestCases.change_max_exponentcCs||j_dSr)rr2)r�r2rrrrm�szIBMTestCases.change_clampN)r��
__module__�__qualname__�__doc__r�r�r�r�r�r�r�rirjrlrkrmrrrrr0�s
r0c@seZdZeZdS)�
CIBMTestCasesN�r�r�r�rgrrrrrr��sr�c@seZdZeZdS)�PyIBMTestCasesN�r�r�r��Prrrrrr��sr�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zed
d��Z	dd
�Z
dd�Zdd�Zdd�Z
edd��Zdd�Zdd�Zdd�ZdS)�ExplicitConstructionTestz6Unit tests for Explicit Construction cases of Decimal.cCs|jj}|�|�|d��dS)N�0�rr�r��r�r�rrr�test_explicit_empty�sz,ExplicitConstructionTest.test_explicit_emptycCs|jj}|�t|d�dSr)rr��assertRaisesr�r�rrr�test_explicit_from_None�sz0ExplicitConstructionTest.test_explicit_from_NonecCs�|jj}|d�}|�t|�d�|d�}|�t|�d�|d�}|�t|�d�|d�}|�t|�d�tdd	�D]J}d
D]@}tdd�D]0}|d
||}||�}|�t|�t|��q�qzqrdS)N�-�45�{e��	500000123�����-45rr�� ����r�����r�)rr�r�r��range)r�r�r�n�signr�r�rrr�test_explicit_from_int�sz/ExplicitConstructionTest.test_explicit_from_intcCs�|jj}|jj}|jj}|�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�dD]*}dD] }|�t||d|��d�q�q�|���}d|j|<|�||d�|�t|ddd�|�||d�|�||d�|�||d�|�||d�|�||d�|�||d�Wd�n1�s�0YdS)Nr��NaNr��45.34Z45e2z4.5E+3�uglyz1.3E4 
z1.3E+4z  -7.89z-7.89z  3.45679  z3.45679z	1_3.3e4_0z1.33E+41Z1_0_0_0�1000)r�r�� u z	9.311E+28T�xyz�1234r��yu1 2 3u 1 2 ru  z123z1_2_3)	rr�ry�localcontextr�r�r%r�r�)r�r�ryr
Zlead�trail�crrr�test_explicit_from_strings8�
z2ExplicitConstructionTest.test_explicit_from_stringcCsRddl}|jj}|j��}|�d�}|�t||��d�|�t|�|��d�dS)Nr�9.999999)�	_testcapirr�r&�unicode_legacy_stringr�r�r�)r�rr�rrrrr�test_from_legacy_stringsMs

z1ExplicitConstructionTest.test_from_legacy_stringscCs6|jj}|d�}|�t|�d�|d�}|�t|�d�|d�}|�t|�d�|d�}|�t|�d�|d	�}|�t|�d
�|�t|d�|�t|d�|�t|d
�|�t||d�ddf�|�t|d�|�t|d�|�t|d�|�t|d�|�t|d�|�t|d�|�t|d�|�t|d�dS)N�r�rrr��r�)�r�rr��r�rr��r���r�r��	rrrr"r�rr�rr����-4.34913534E-17)rr�F�Infinity)r��rrrr"r�)�r r�)�r r�r�r r�)r�r zwrong!)r�r r")r�r �1)r�rr�)r�)rrrNr�r�)r�)r���rr"r�r�)r�)r�
rr"r�r�)r�)rrr�ar�r�)rr�r�r�r�r��r�r�rrrr�test_explicit_from_tuplesWs.z2ExplicitConstructionTest.test_explicit_from_tuplescCs�|jj}|ddgdg�}|�t|�d�|dgd�dg�}|�t|�d�|gd��}|�t|�d�|dgd�df�}|�t|�d�dS)Nrr�r�rrrr�rr�r�r�r'rrr�test_explicit_from_list�sz0ExplicitConstructionTest.test_explicit_from_listcCs\|jj}|�t|d��d�|�t|d��d�|�|d�|d��|�|d�|d��dS)NrFr�T)rr��assertIs�boolr�r�rrr�test_explicit_from_bool�s
z0ExplicitConstructionTest.test_explicit_from_boolcCs�|jj}|d�}||�}|�t|�d�|d�}||�}|�t|�d�|d�}||�}|�t|�d�|d�}||�}|�t|�d�dS)	Nr�r�r�r�r�r�rr�r)�r�r�rr�rrr�test_explicit_from_Decimal�sz3ExplicitConstructionTest.test_explicit_from_DecimalcCs2|jj}|d�}|�t|�|�|�t|�d�|�|td�����|�|td�����|�|td�����|�t|td���t|d���|�t|td���t|d���|�t|td���t|d���|�t|td	���t|d
���t	d�D]2}t
�d�t
�
�d
d}|�|t||���q�dS)N皙�����?�90.1000000000000000055511151231257827021181583404541015625�nan�inf�-infrr�	-Infinity�-0.0�-0���{�G�z�?�@��?)rr�r�r�r�r�floatrDrAr�r��expovariate)r�r��rr�r�rrr�test_explicit_from_float�s0
�
�
�
�
�z1ExplicitConstructionTest.test_explicit_from_floatcCs�|jj}|jj}|jj}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
|<dD]0}|�	|�}|�t||��|�t|�|��qbd|_d|j
|<|�
||j	d�d|_|�t|�	d��d�|�t|�	d��d�|�t|�	d��d�|�t|�	d��d�|�
||j	d�|�
t|j	d�|�
t|j	dd�|�
||j	d�|�
||j	d�d|_|�
||j	d �|�
||j	|d ��d!|j
|<|�t|�	d ��d	�|�|j|�d!|j|<|�t|�	|d ���d	�|�|j|�dS)"Nrr���in�z457E+2Z456789z4.57E+5z3.14
rrrz	-4.35E-17r�r�z5.00E+8�T)	l����l����l����i�r��l��������z0E-017z0E-17r��-Infr5�NaN123r)r�rrrZ5678z 1234Z12_34ZNaN12345F)rr�ryr}rZ�
getcontextr#r�r�r�r�r��assertIsInstancer%r�
isinstancer�r�r�)r�r�ryr}�ncrZprevdecr�rrr�$test_explicit_context_create_decimal�sv
�






�

z=ExplicitConstructionTest.test_explicit_context_create_decimalcCs^|jj}|j��}|�d�}|�t|�|�|�t|�d�|�|�td���	��|�|�td���
��|�|�td���
��|�t|�td���t|�d���|�t|�td���t|�d���|�t|�td���t|�d���|�t|�td	���t|�d
���d|_td�D]6}t
�d
�t
�
�dd}|�|t|�|����q"dS)Nr0z0.1000000000000000055511151231r2r3r4rrr5r6r7�dr8r9r:r;)rr�r&r�r�r�r�rr<rDrAr#r�r�r=)r�r�rKr>r�r�rrr�'test_explicit_context_create_from_float!s0

����z@ExplicitConstructionTest.test_explicit_context_create_from_floatcCs>|jj}dddd�}|��D]\}}|�t||��|�qdS)Nr#z	0.0000372z-NaN2400)u1u٠.٠٣٧٢e-٣u-nan౨౪౦౦)rr��itemsr�r�)r�r��test_values�inputrrrr�test_unicode_digits9s�z,ExplicitConstructionTest.test_unicode_digitsN)r�r�r�r�r�r�rr
r
rr(r*r-r/rr?rLrNrRrrrrr��s 8
	+
Yr�c@seZdZeZdS)�CExplicitConstructionTestNr�rrrrrSDsrSc@seZdZeZdS)�PyExplicitConstructionTestNr�rrrrrTFsrTc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�ImplicitConstructionTestz6Unit tests for Implicit Construction cases of Decimal.cCs|jj}|�ttdt��dS)NzDecimal(5) + None�rr�r�r�r��localsr�rrr�test_implicit_from_NoneLsz0ImplicitConstructionTest.test_implicit_from_NonecCs<|jj}|�t|d�d�d�|�|d�d|d��dS)Nr�r�Z50l2}rr)r�rrr�test_implicit_from_intPsz/ImplicitConstructionTest.test_implicit_from_intcCs|jj}|�ttdt��dS)NzDecimal(5) + "3"rVr�rrr�test_implicit_from_stringXsz2ImplicitConstructionTest.test_implicit_from_stringcCs|jj}|�ttdt��dS)NzDecimal(5) + 2.2rVr�rrr�test_implicit_from_float\sz1ImplicitConstructionTest.test_implicit_from_floatcCs(|jj}|�|d�|d�|d��dS)Nr�r��2r�r�rrr�test_implicit_from_Decimal`sz3ImplicitConstructionTest.test_implicit_from_Decimalcs*|jj}Gdd�d�}|�t|�|d��d�|�t|d�|��d�|�td�d�|�td�d	�|�td
�d�|�td�d
�|�td�d�|�td�d�gd�}|D]r\}��t|��fdd��t|��fdd��|�td|d�d�d�|�td|d�d�d�q�dS)Nc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)z,ImplicitConstructionTest.test_rop.<locals>.EcSsdt|�S)Nzdivmod �r��r��otherrrr�
__divmod__isz7ImplicitConstructionTest.test_rop.<locals>.E.__divmod__cSst|�dS)Nz rdivmodr^r_rrr�__rdivmod__ksz8ImplicitConstructionTest.test_rop.<locals>.E.__rdivmod__cSsdt|�S)Nzlt r^r_rrr�__lt__msz3ImplicitConstructionTest.test_rop.<locals>.E.__lt__cSsdt|�S)Nzgt r^r_rrr�__gt__osz3ImplicitConstructionTest.test_rop.<locals>.E.__gt__cSsdt|�S)Nzle r^r_rrr�__le__qsz3ImplicitConstructionTest.test_rop.<locals>.E.__le__cSsdt|�S)Nzge r^r_rrr�__ge__ssz3ImplicitConstructionTest.test_rop.<locals>.E.__ge__cSsdt|�S)Nzeq r^r_rrr�__eq__usz3ImplicitConstructionTest.test_rop.<locals>.E.__eq__cSsdt|�S)Nzne r^r_rrr�__ne__wsz3ImplicitConstructionTest.test_rop.<locals>.E.__ne__N)r�r�r�rarbrcrdrerfrgrhrrrr�Ehsrir%z	divmod 10z
10 rdivmodzDecimal(10) < E()zgt 10zDecimal(10) > E()zlt 10zDecimal(10) <= E()zge 10zDecimal(10) >= E()zle 10zDecimal(10) == E()zeq 10zDecimal(10) != E()zne 10))�+�__add__�__radd__)�-�__sub__�__rsub__)�*�__mul__�__rmul__)�/�__truediv__�__rtruediv__)�%�__mod__�__rmod__)z//�__floordiv__�
__rfloordiv__)z**�__pow__�__rpow__csd�t|�S�Nr�r^r_)�loprrr��rz3ImplicitConstructionTest.test_rop.<locals>.<lambda>cst|��dSr}r^r_)�roprrr��rzE()zDecimal(10)r��10)rr�r��divmodr��setattr)r�r�riZoplistZsymr)r~rr�test_ropds(

�
�z!ImplicitConstructionTest.test_ropN)
r�r�r�r�rXrYrZr[r]r�rrrrrUIsrUc@seZdZeZdS)�CImplicitConstructionTestNr�rrrrr��sr�c@seZdZeZdS)�PyImplicitConstructionTestNr�rrrrr��sr�c@s:eZdZdZdd�Zdd�Zedd�dd	��Zd
d�ZdS)
�
FormatTestz#Unit tests for the format function.cCsN|jj}gd�}|D] \}}}|�t||�|�|�q|�t|d�jd�dS)N)�)r��0E-15z0e-15)r�z2.3E-15z2.3e-15)r�z2.30E+2z2.30e+2)r�z2.30000E-15z2.30000e-15)r�z1.23456789123456789e40z1.23456789123456789e+40)r��1.5z1.5e+0)r�z0.15z1.5e-1)r�z0.015z1.5e-2)r�z0.0000000000015z1.5e-12)r�z15.0z1.50e+1)r��-15z-1.5e+1)r�r�z0e+0)r��0E1�0e+1)r��0.0z0e-1)r��0.00�0e-2)�.6er�z0.000000e-9)r�r�z0.000000e+6)r�rz9.999999e+0)r�z	9.9999999z1.000000e+1)r�z-1.23e5z-1.230000e+5)r�z
1.23456789e-3z1.234568e-3)r�r�r�)r�r�r�)r��0E-2r�)r�z0.00E-8z0.0000000000)r�r�r�)r�z3.2E1�32)r�z3.2E2�320)r�z3.20E2r�)r�z3.200E2z320.0)r�z3.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�z3.141592650)�gr�r�)r�r�r�)r�r�r�)�Gr�z0E+1)r�z0E-5z0.00000)r�z0E-6r�)r�z0E-7z0e-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�)rvr��0%)rvZ0E0r�)rvz0E-1r�)rvr�r�)rvz0E-3z0.0%)rvz0E-4z0.00%)�.3%r��0.000%)r��0E10r�)r�z0E-10r�)r�z2.34z234.000%)r�z1.234567z123.457%)�.0%�1.23z123%)r�rr)r��-NaN123r�)z+gZNaN456z+NaN456)z.3e�Infr)z.16frFr5)r��-sNaNr�)r��1.00r�)�6�123�   123)z<6r�z123   )z>6r�r�)z^6r�z 123  )z=+6r�z+  123)�#<10rz
NaN#######)r�z-4.3z
-4.3######)z#<+10�0.0130z
+0.0130###)z#< 10r�z
 0.0130###)z@>10rFz
@-Infinity)z#>5rFr5)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=10r4z
-Infinity)z^16r4z-Infinity)z>10�1.2345z
1.2345)z<10r�z
1.2345)�,Z1234567z	1,234,567)r��123456�123,456)r�Z12345�12,345)r�rz1,234)r�r�r�)r��12r�)r�r#r#)r�r�r�)r�z-1234567z
-1,234,567)r��-123456�-123,456)z7,r�r�)z8,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)z07,�1234.56�1,234.56)r�r�r�)z09,r�z	01,234.56)z010,r�z
001,234.56)z011,r��0,001,234.56)z012,r�r�)z08,.1fz1234.5z01,234.5)r��
1.23456789r�)z,%z
123.456789z12,345.6789%)z,er�z
1.23456e+5)z,Er�z
1.23456E+5)za=-7.0z0.12345zaaaa0.1)z	<^+15.20%r3z<<+Infinity%<<<)z>,%ZsNaN1234567zsNaN1234567%)z=10.10%rGz
   NaN123%r�s-020)rr�r��formatr�r��
__format__)r�r�rP�fmtrr�rrr�test_formatting�szFormatTest.test_formattingc	s8�jj�zddlm}Wnty4��d�Yn0�fdd�}dA��fdd�	}d	|gd
��dd�}d||g�d
d�}d|gd
��dd�}d|ddd|g�dd�}d�d�|gd
��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@�dS)BNr��CHAR_MAX�locale.CHAR_MAX not availablecs"�jtkrd�dd�|D��S|S)Nr�cSsg|]}t|��qSr��chrr�rrrr�ErzCFormatTest.test_n_format.<locals>.make_grouping.<locals>.<listcomp>)rrg�join�Zlstr�rr�
make_groupingDsz/FormatTest.test_n_format.<locals>.make_groupingr�cs0�jtkr�|��||�S�|�j||d�SdS)N)�_localeconv)rrgr��r��overrider��r�r�rr�get_fmtGs
z)FormatTest.test_n_format.<locals>.get_fmt�.�rrrr���
decimal_point�grouping�
thousands_sepr�r��&r�rr�rms¿zutf-8s´z12.7z12,7z1-2&7i�[z123,456,789Z	123456789z123 456 789l��c}z123456-78-9012-3z.6nz
1.23457e+8z
1,23457e+8z
1&23457e+8rEZ03nrZ04nZ05nZ01234Z06nZ001234�90r�Z07nz012,345Z08nz	0,012,345Z09nZ010nz
00,012,345i@�z1-2345-6z	01-2345-6z0-01-2345-6Z011nZ012nz00-01-2345-6Z013nz
000-01-2345-6�-1.5Z020nu-0´000´000´000´001¿5)Nr�)rr��localer��ImportError�skipTest�decoder�)	r�r�r�r��en_US�fr_FR�ru_RUZcrazyZdotsep_widerr�r�
test_n_format<sx
��
��
��zFormatTest.test_n_format�LC_ALL�ps_AFcCsn|jj}t��d}t��d}|dkr:|�d�|d��|dkrT|�d�|d��|�t|d�d�d	�dS)
Nr�r�u٫z5inappropriate decimal point separator ({!a} not {!a})u٬z1inappropriate thousands separator ({!a} not {!a})z
100000000.123r�u100٬000٬000٫123)rr�r��
localeconvr�r�r�)r�r�r�r�rrr�&test_wide_char_separator_decimal_point�s���z1FormatTest.test_wide_char_separator_decimal_pointcCsPGdd�d|jj�}|�d�}|�|jj|j�|�d�}|�|jj|j�dS)Nc@seZdZdd�ZdS)z;FormatTest.test_decimal_from_float_argument_type.<locals>.AcSst|�|_dSr)r��a_type)r�r&rrr�__init__�szDFormatTest.test_decimal_from_float_argument_type.<locals>.A.__init__N�r�r�r�r�rrrr�A�sr�g@E@�*)rr��
from_floatr�r�)r�r�r&rrr�%test_decimal_from_float_argument_type�s


z0FormatTest.test_decimal_from_float_argument_typeN)	r�r�r�r�r�r�r	r�r�rrrrr��s Y
r�c@seZdZeZdS)�CFormatTestNr�rrrrr��sr�c@seZdZeZdS)�PyFormatTestNr�rrrrr��sr�c@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�ArithmeticOperatorsTestz:Unit tests for all arithmetic operators, binary and unary.cCs�|jj}|d�}|d�}|�|||d��|�|||d��|d}|�||d��|�t|�t|��d|}|�||d��|�t|�t|��||7}|�||d��|d7}|�||d��dS)N�-11.1�22.2z11.1r�z-6.1�16.1�rr�r�r��r�r��d1�d2rrrr�
test_addition�sz%ArithmeticOperatorsTest.test_additioncCs�|jj}|d�}|d�}|�|||d��|�|||d��|d}|�||d��|�t|�t|��d|}|�||d��|�t|�t|��||8}|�||d��|d8}|�||d��dS)	Nr�r�z-33.3z33.3r�z-16.1r�z-38.3r�r�rrr�test_subtraction�sz(ArithmeticOperatorsTest.test_subtractioncCs�|jj}|d�}|d�}|�|||d��|�|||d��|d}|�||d��|�t|�t|��d|}|�||d��|�t|�t|��||9}|�||d��|d9}|�||d��dS)N�-5r�r�r�z-25z-75r�r�rrr�test_multiplication�sz+ArithmeticOperatorsTest.test_multiplicationcCs�|jj}|d�}|d�}|�|||d��|�|||d��|d}|�||d��|�t|�t|��d|}|�||d��|�t|�t|��||}|�||d��|d}|�||d��dS)	Nr��2�-2.5z-0.4rz-1.25z-0.8z-0.625r�r�rrr�
test_divisionsz%ArithmeticOperatorsTest.test_divisioncCs�|jj}|d�}|d�}|�|||d��|�|||d��|d}|�||d��|�t|�t|��d|}|�||d��|�t|�t|��||}|�||d��|d}|�||d��dS)N�5r�r�rr#�r�r�r�rrr�test_floor_division(sz+ArithmeticOperatorsTest.test_floor_divisioncCs�|jj}|d�}|d�}|�|||d��|�|||d��|d}|�||d��|�t|�t|��d|}|�||d��|�t|�t|��||C}|�||d��|dC}|�||d	��dS)
Nr�r�Z25r�rZ625r�Z16807Z390625r�r�rrr�
test_poweringDsz%ArithmeticOperatorsTest.test_poweringcCs�|jj}|d�}|d�}|�|||d��|�|||d��|d}|�||d��|�t|�t|��d|}|�||d��|�t|�t|��||;}|�||d��|d;}|�||d��dS�Nr�r�r#rr�r�r�rrr�test_module`sz#ArithmeticOperatorsTest.test_modulecCs|jj}|d�}|d�}t||�\}}|�||d��|�||d��|�t|�t|��|�t|�t|��t|d�\}}|�||d��|�||d��|�t|�t|��|�t|�t|��td|�\}}|�||d��|�||d��|�t|�t|��|�t|�t|��dSr)rr�r�r�r�)r�r�r�r��p�qrrr�test_floor_div_module|s$z-ArithmeticOperatorsTest.test_floor_div_modulecCsT|jj}|�|d�
|d��|�|d�|d��|�t|d��t|d���dS)Nr�r�)rr�r��absr�rrr�test_unary_operators�sz,ArithmeticOperatorsTest.test_unary_operatorscCs|jj}|jj}|jj}|d�}|d�}|d�}|d�}||f||f||f||f||ff}||f||f||f||f||f||f||ff}	tjtjtjtjf}
tj	tj
f}||	D]P\}}
|
|D]>}|||
�}|tj
ur�dnd}|�||d�||j
||
|��q�q�|���}d|j|<|D]R\}}
|D]B}|||
�}|tj
u�rBdnd}|�||d�||j
||
|���q$�q|	D]:\}}
|D]*}|�|tj	||
�|�|tj
||
��q|�qp||	D]&\}}
|
D]}|�||||
��q��q�Wd�n1�s�0YdS)	Nr�sNaNr�r�TFz8expected {0!r} for operator.{1}({2!r}, {3!r}); got {4!r}r�)rr�ryr
�operator�lt�le�gt�ge�eq�ner+r�r�r%r�)r�r�ryr
r�rr�r�Z
qnan_pairsZ
snan_pairsZ	order_opsZequality_opsr�r	�opZgotr�ctxrrr�test_nan_comparisons�sL".
��

��z,ArithmeticOperatorsTest.test_nan_comparisonscCsH|jj}|d��|d��}|�|d��d�|�|�t|d�jd�dS)Nr�r�-2)rr�r<r�r�r�r'rrr�test_copy_sign�sz&ArithmeticOperatorsTest.test_copy_signN)r�r�r�r�r�r�r�r�r�r�rrrrrrrrrr��s7r�c@seZdZeZdS)�CArithmeticOperatorsTestNr�rrrrr�src@seZdZeZdS)�PyArithmeticOperatorsTestNr�rrrrr�src	Cs�|jj}|jj}|jj}|jj}|jj}|jj}|jj}|jj}|d�}	|d�}
|	|
}|j	�
�|j��|	|
}|���}
|�
|
j|�|�||
j|	d�|�
|
j|�|��X}|�
|j|�|�
|j|�|�||j|	|d��|�
|j|�~Wd�n1�s0Y|�|
j|�~
Wd�n1�sF0Y|�||d��|�||d��|�}|�
|j|�||||fD]}|�|j|��q�dS)Nr�rrr�0.333333333333333333333333)rr�ryrzr|rr{rHr
�finish1re�synchro�waitrr�r��divide�compare�assertFalser�)rr�ryrzr|rr{rHr
r��d3�test1�test2�c2�c3�c1�sigrrr�thfunc1�s@

""r$c	Cs�|jj}|jj}|jj}|jj}|jj}|jj}|jj}|jj}|d�}	|d�}
|	|
}|�}d|_	|	|
}
|���}|�
|j|�|�||j
|d�d�|�
|j|�||��b}|�
|j|�|�|j|�d|j|<|�||j|d�d�|�
|j|�~Wd�n1�s0Y|�|j|�|�|j|�~Wd�n1�s^0Y|j��|j��|�||d��|�|
|d	��|�|j|�|�
|j|�||||fD]}|�|j|��q�dS)
Nr�r�Z1e425000000��Tz1e-425000000rz0.333333333333333333)rr�ryrzr|rr{rHr
r#rr�r��multiplyrr%rrre�finish2r�)rr�ryrzr|rr{rHr
r�rrZthiscontextrr r!r#rrr�thfunc2
sH

""

r)c@seZdZdZdd�ZdS)�
ThreadingTestz0Unit tests for thread local contexts in Decimal.cCs�|jj}|jtkr$|jjs$|�d�|j}|j}|j}d|_d|_d|_t�	�|_
t�	�|_t�	�|_tj
t|fd�}tj
t|fd�}|��|��|j��|j��t|jD]}|�|j|�q�|��|��||_||_||_dS)Nzcompiled without threading�r����)�targetr�)r�DefaultContextrg�HAVE_THREADSr�r#r�r��	threading�Eventrrr(�Threadr$r)�startrr*rr�r�)r�r.Z	save_precZ	save_emaxZ	save_eminZth1Zth2r#rrr�test_threading<s2





zThreadingTest.test_threadingN)r�r�r�r�r4rrrrr*6sr*c@seZdZeZdS)�CThreadingTestNr�rrrrr5csr5c@seZdZeZdS)�PyThreadingTestNr�rrrrr6fsr6c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(S))�
UsabilityTestz*Unit tests for Usability cases of Decimal.cCs|jj}|d�}|d�}|d�}|�||�|�||�|�||�|�||�|�||�|�||�|�||�|�||�|�|d�|�d|�|�|d�|�|d�|�|d�|�|t��|�|t�t	t
|td���}|dd�}t�
|�|��|�||�dS)Nz23.42r��r�rg�����Y@@rM)rr��
assertGreater�assertGreaterEqual�
assertLess�assertLessEqualr��assertNotEqual�object�list�mapr�r��shuffler�)r�r��da�db�dcr&�brrr�test_comparison_operatorsls0
z'UsabilityTest.test_comparison_operatorscCs�|jj}|d�}|d�}|�|d�|�|d�|�|d�|�|d�|�|d�|�|d�|�d|�|�d|�|�d|�|�d|�|�d|�|�d|�|�d|d��dS)N�0.25�3.0�@��?g�?r0�0.1)rr�r;r<r9r:r=r��r�r�rBrCrrr�test_decimal_float_comparison�s z+UsabilityTest.test_decimal_float_comparisoncCs�|jj}|d�}|d�}|�|d�|�d|�|�|d�|�d|�|�d|�|�|d�|�|d�|�d|�|�|�d�t�|�|�d�t�|�|�d�t�|�|�d�t�dS)NrGrHy�?y�?y@y@�?)	rr�r=r�r+rc�NotImplementedrerdrLrrr�test_decimal_complex_comparison�sz-UsabilityTest.test_decimal_complex_comparisonc
Cs�|jj}t|jj}|jj}|jj}|jj}tr6tjnd}trDtj	nd}trRtj
nd}|||d�}	||	���||	_|�|d�|dd��|�|dd�|d��|�|dd�|d	t
|���|�|d
t
|��|dd��|�|dd�|d	t
|���|�|d
t
|��|dd��|�|d�|dd
��|�|dd
�|d��d|	_|�|d�d|dd��|�|dd�|d�d�|�|dd�|dt
|���|�|dt
|��|dd��|�|d�|dd��|�|d�|dd��|�|d�|dd��|�|d�|dd��|�||d�j|dd��|�t|dd��|d���|�|d�|dd��|�|dd�|d��Wd�n1�s�0YdS)N�ɚ;�6e�ilʈ�r�r�rr�l	��Z��mH;5�Br�Z1ez-1el��!�0QYrKr%i,ri�6l�c(	Z9er3l�g�]�{l�����g�]r4r2i����)rr�rZFractionr&r
ryrgr��MIN_EMIN�	MIN_ETINYr#r;r�r�r=r<r:r9r�rdr+rNrc)
r��Drr&r
ry�emax�eminZetinyrrrr� test_decimal_fraction_comparison�s@z.UsabilityTest.test_decimal_fraction_comparisoncCsP|jj}|d�}t�|�}|�t|�t|��t�|�}|�t|�t|��dS)Nz43.24)rr�rZr�r��deepcopy)r�r�rrrDrrr�test_copy_and_deepcopy_methods�s

z,UsabilityTest.test_copy_and_deepcopy_methodscs�jj��jj}�fdd�}|�d��|�d��|�d��|�d��|�d���fdd	�d
D�}|��d��d��d
��d��d��d��d��d��d��d��d��d��d��d��d��d�g�|D]}��||�|t|���q؈�|�d��|d����tt�d����	|�d�����	|�d���gd�}|D]*}t
|�}�|�}��||�||���qP|���}	�d�}
d |	_||
�}d!|	_||
�}d"|	_||
�}
��||���||
�d#|	_d$d%}
��|�|
��||
��Wd�n1�s
0YdS)&Ncs t|�}|��}��||�|Sr)�hash�__hash__r�)rr&rEr�rr�hashit�sz.UsabilityTest.test_hash_method.<locals>.hashitr8rr5Znan123�-NaNcs:g|]2}tdd�D]"}dD]}�|d||��qqqS)���r%r�r�)r�)rr,r�r�r�rrr��s�z2UsabilityTest.test_hash_method.<locals>.<listcomp>)r������r��!�=�>�?�@�A�B�-1r7r�z-0.000r�z-0E12�10.0z	-23.00000Z1230E100z
-4.5678E50l��z	1.634E100z
90.697E100z
188.83E100z
1652.9E100Z	56531E100rr�rF)r3rFr�z-.0e1z34.0�2.5z
112390.625z	-0.515625z123456789.1�r%rd�'iLi�)rr�r
�extendr�r�r�r�r\rr<r#)r�r
r^rPr�Ztest_stringsrr�rrr�Zh1Zh2Zh3rr�r�test_hash_method�sj
��zUsabilityTest.test_hash_methodcCs�|jj}|d�}|d�}d}d}|�t||�|�|�t||�|�|�t||�|�|�t||�|�|�t||�|�|�t||�|�|�t||�|�|�t||�|�dS)N�15.32z28.5rcrA)rr�r+�min�max)r�r�r�r��l1�l2rrr�test_min_and_max_methods>sz&UsabilityTest.test_min_and_max_methodscCs(|jj}|�|d��|�|d��dS)Nrz0.372)rr�rrr�rrr�test_as_nonzeroRszUsabilityTest.test_as_nonzerocCs4|jj}|d�}|�t|�d�|�t|�d�dS)NrvzDecimal('15.32'))rr�r�r�r�r'rrr�test_tostring_methodsZsz#UsabilityTest.test_tostring_methodsc
Cs6|jj}|d�}|d�}|�t|�d�|�t|�d�|�t|�d�|�t|�d�gd�}|D]\}}|�t�||��|�qd|�ttj|d��|�ttj|d��|�ttj|d	��|�t	tj|d
��|�t	tj|d��gd�}|D]\}}|�t�
||��|�q�|�ttj
|d��|�ttj
|d��|�ttj
|d	��|�t	tj
|d
��|�t	tj
|d��gd
�}|D]\}}|�t||��|��q�|�tt|d��|�tt|d��|�tt|d	��|�t	t|d
��|�t	t|d��gd�}|D]&\}}}	|�tt||�|��|	��q
dS)NZ66rvrnrcg�p=
ף.@)	�z123.00rS��3.2r)�3.54r)�3.899r)�-2.3r$�z-11.0i�����r�r�z-0E3r)�89891211712379812736.1l�{�#'s�{Mr_rrGr�rF)	r~)r�r�r�r�r�r�r�rr�r�r�)r�l�{�#'s�{M)r~rr�r�r�r�r�r�)z-3.5���)r�r)r�r)�-0.5r)�0.5r)r�r�)rqr�)z3.5r))�123.456r�z0E+4)r�r$z0E+3)r�rz1E+2)r�r�z1.2E+2)r�rr�)r�r�z123.5)r�r��123.46)r�rr�)r�rz123.4560)z123.455r�r�)z123.445r�z123.44)r�rr)rFi��r)ZsNaN314rZNaN314)
rr�r�r�r<�mathrbr�r��
OverflowError�ceil�roundr�)
r�r�r�r�Z
test_pairsrr�Ztest_triplesr�r>rrr�test_tonum_methodsbsDz UsabilityTest.test_tonum_methodscCsX|jj}dD]F}t||��}|�t�|��t�d|�}|�||�d�rLdnd�qdS)N)r2Znan1234�-nanz-nan2468r;rmg�)	rr�r<rr�r^r[r�r�)r�r�rr�rrrr�test_nan_to_float�szUsabilityTest.test_nan_to_floatcCs,|jj}dD]}||�}|�tt|�qdS)N)�snanz-snanZsnan1357z	-snan1234)rr�r�r�r<)r�r�rrrrr�test_snan_to_float�sz UsabilityTest.test_snan_to_floatcCs||jj}|d�}|�|tt|���|d�}|�|tt|���|d�}|�|tt|���|d�}|�|tt|���dS)Nrrrr)rr�r�r�r�r'rrr�test_eval_round_trip�sz"UsabilityTest.test_eval_round_tripcCsD|jj}|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�dS)Nrrr�rrrr)rrr)r�rrrrr�rrr)r�rrr�rrr)r��rrr�%)r�rr�)r�rr�)rr�r�)rr�r�)r�r��N�r�rr�)r�rr�)rrr)r�)rr�r�r�r)r�rr)rr�r��as_tupler'rrr�
test_as_tuple�s6zUsabilityTest.test_as_tuplec		Cs|jj}|�t|j|d��|�t|j|d��|�t|j|d��|�t|j|d��tdd�D]�}td�D]�}dD]�}|d	|||f�}|��}|\}}|�|t�|�|t	�|�|t	�|�
|d
�|�t�
||�d�|�||�||�|�qvqnqbdS)Nr3r4r�Zsnan123r�r���)rjrmz%s%dE%drr�)rr�r�r��as_integer_ratior�r�rI�tupler�r9r�r��gcd)	r�r�r�ZcoeffrrZpqrrrrr�test_as_integer_ratios2
�
�
�
�z#UsabilityTest.test_as_integer_ratiocCsd|jj}Gdd�d|�}|d�}|d�}||}|�t|�|�|�|�}|�t|�|�t�|�}|�t|�|�|�||�t�|�}|�t|�|�|�||�|d�}||�}|�t|�|�|�||�||�}|�t|�|�|�||�|�|jd�||�}|�t|�|�|�||�d|_||�}|�t|�|�|�||�|�|jd�dS)Nc@seZdZdZdS)z1UsabilityTest.test_subclassing.<locals>.MyDecimalN)r�r�r�r	rrrr�	MyDecimal>sr�r�r��1.0r")	rr�r+r�rxrZr�rZr	)r�r�r�r�r�rr�r,rrr�test_subclassing:s<


zUsabilityTest.test_subclassingcCs@|jj}|jj}|�}|�t|d����t|�|d����dS�Nr)rr�rHr�r�rR�r�r�rHrrrr�test_implicit_contextis�z#UsabilityTest.test_implicit_contextc	Cs�|jj}|jj}|jj}|jj}|jj}|jj}|jj}|jj}|jj	}	|jj
}
|jj}||���
��}d|_d|_
d|_|d�}
|d�}|d�}|��|�t|
jdd��d�|�|j|	�|�|j|
�|��|j||jdd�|�|j|�|�|jdd�d	�|�|jdd�d
�|��|�t|
jdd��d�|�|j|	�|�|j|
�|��|j||d�jdd�|�|j|�|��|�t|
jdd��d
�|�|j|	�|�|j|
�|��|j||d�jdd�|�|j|�|��|�t|
jdd��d�|j||d�jdd�|�|j|�|��|�t|
jdd��d�|j||jdd�|�|j|�|��|�t|jdd��d�|j||d�jdd�|�|j|�|��|�t|jdd��d�|j||d�jdd�|�|j|�|��|�t|jdd��d�|j||jdd�|�|j|�|�t|j dd��d�|��|�t|j!dd��d�|�|j|�|�|j|	�|�|j|
�|�|j|�|�|j|�|��|j||j!dd�|�|j|�d|_"|�t|j#dd��d�d|_"|��t|
j$|d�dd��}|�|d�|j||
j$|d�dd�|�|j|�|��t|
j%ddd��}|�|d�|j||
j%|d�dd�|�|j|�|��t|
j&ddd��}|�|d�|j||
j&ddd�|�|j|�|��t|
j'ddd��}|�|d�|j||
j'ddd�|�|j|�|��t|
j(ddd��}|�|d �|j||
j(ddd�|�|j|�|��t|
j)ddd��}|�|d�|j||
j)|d�dd�|�|j|�|��t|
j*ddd��}|�|d�|j||
j*|d�dd�|�|j|�|��t|
j+ddd��}|�|d�|j||
j+|d�dd�|�|j|�|��t|
j,ddd��}|�|d�|j||
j,|d�dd�|�|j|�|��t|
j-ddd��}|�|d �|j||j-ddd�|�|j|�|��t|
j.d!dd��}|�|d"�|j||
j.ddd�|�|j|�|��t|
j/ddd��}|�|d#�|j||
j/d$dd�|�|j|�|��t|
j0d!dd��}|�|d"�|j||
j0d$dd�|�|j|�|��t|
j1d!d%dd��}|�|d&�|j||
j1|d�d%dd�|�|j|�t2|_3t|d'�j4ddd(��}|�|d�t5|_3t|d'�j4ddd(��}|�|d)�t|d'�j4t6dd(��}|�|d�|��|j||d�j4dd�|�|j|�t2|_3t|d'�j7ddd(��}|�|d�t5|_3t|d'�j7ddd(��}|�|d)�t|d'�j7t6dd(��}|�|d�|��|j||d�j7dd�|�|j|�t2|_3t|d'�j8ddd(��}|�|d�t5|_3t|d'�j8ddd(��}|�|d)�t|d'�j8t6dd(��}|�|d�|��|j||d�j8dd�|�|j|�t6|_3t|d*�j9|d+�ddd,��}|�|d-�t5|_3t|d*�j9|d+�ddd,��}|�|d.�t|d*�j9|d+�t6dd,��}|�|d-�|��|j||j9|d/�t6dd(�|�|j|�Wd�n1�s0Y||���x}d|_d|_
d|_|dd0��:}|�|jd�|�|j
d�|�|jd�Wd�n1�sz0YWd�n1�s�0YdS)1Nr�r&i���Z111Z1e9999z1e-9999�rz1.609487E+48FTz4.709530r�z2.045323r�rZ1111000z
9.999999E+999rrr��
+Subnormalz0E-1005r�ZNan891287828Z
NaN1287828i  ror�eZ101rSr�r�Z11100z1.11E+9rsrZ225r��r$rr#z1.50001z1e-3)r�r$rz1.501z1.500z1e-10)r):rr�r&r
ryrzr|rr~r{r}rxr#r�r�r�r�r�r�rr�r�r+rCrG�ln�log10�logbr>rKrLrOr5rR�capitalsrSrr6r3rNrWrxrIrwrJrP�rotate�scaleb�shift�fmar'r$�to_integralrqrurTrU�quantize)r�r�r&r
ryrzr|rr~r{r}rxrr�r	�zr�rrrr�test_none_argsrs�0zUsabilityTest.test_none_argscCs |jj}|�|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��dd�|d��|d�|d���|�|d��d|d��|d��|d�|d���dS)Nrriu'��i7rSrErMir�r�z9.123���r@r�i�r��C)rr�r�rr6r7r8r3rNrWrxrIrwrJrMr�rPr�rQr�r�r�r�rrr�test_conversions_from_inta	s����������������������z'UsabilityTest.test_conversions_from_intN)r�r�r�r�rFrMrOrYr[rur{r|r}r�r�r�r�r�r�r�r�r�r�rrrrr7is*$*	Tg
-!/	pr7c@seZdZeZdS)�CUsabilityTestNr�rrrrr��	sr�cs,eZdZeZ�fdd�Z�fdd�Z�ZS)�PyUsabilityTestcs"t���t��|_t�d�dS�NiX��superr��sys�get_int_max_str_digits�_previous_int_limit�set_int_max_str_digitsr��r�rrr��	s

zPyUsabilityTest.setUpcst�|j�t���dSr�r�r�r�r��tearDownr�r�rrr��	szPyUsabilityTest.tearDown�r�r�r�r�rr�r��
__classcell__rrr�rr��	sr�c@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�PythonAPItestscCsT|jj}|�t|tj��|�t|tj��|�|d�tj�|�	|d�tj�dSr�)
rr�r�
issubclass�numbers�NumberrZRealrIZassertNotIsInstancer�rrr�test_abc�	s
zPythonAPItests.test_abccCs�ttjd�D�]�}|jj}tjd}|jtjd<|d�}t�||�}t�|�}|�	||�t
�r�t
�d�}t�d�}t
tjd<t�||�}	ttjd<t�|	�}
|�|
tj�|�	|
|�ttjd<t�||�}t
tjd<t�|�}
|�|
t
j�|�	|
|�t
�d��
�}t�d��
�}t
tjd<t�||�}	ttjd<t�|	�}
|�|
tj�|�	|
|�ttjd<t�||�}t
tjd<t�|�}
|�|
t
j�|�	|
|�|tjd<qdS)Nr�rz-3.141590000z-3.123e81723)r��pickle�HIGHEST_PROTOCOLrr�r��modules�dumps�loadsr�rgr�rIr�ZDecimalTuple)r��protor��savedecimalrrr�r�r	Zsxr>Zsyrrr�test_pickle�	sL















zPythonAPItests.test_picklecCs�|jj}tdd�D]R}d|d}|�t||��tt|���||�}|�t�}|�|t|��|�q|�t	t|d��|�t	t|d��|�t
t|d��|�t
t|d��dS)	N������%0.2f�Y@r�r�r3r4)rr�r�r�r�r<r�rqr�r�r��r�r�r�rrr>rrr�test_int�	s
zPythonAPItests.test_intcCsl|jj}tdd�D]T}d|d}|�t||��tt|���||�}|�t�}|�|t�	|��|�qdS)Nr�r�r�r�)
rr�r�r�r�r<r�rqr��truncr�rrr�
test_trunc�	s
zPythonAPItests.test_trunccCs||jj}Gdd�d|�}|�t||��|�d�}|�t|�|�|�t|�d�|�|jd�d}|�|�|�||��|�|�t	d���
��|�|�t	d�����|�|�t	d	�����|�t|�t	d���t|d
���|�t|�t	d���t|d���|�t|�t	d	���t|d���|�t
|jd
�td�D]6}t�d�t��dd}|�|t	|�|����q@dS)Nc@seZdZdd�ZdS)z1PythonAPItests.test_from_float.<locals>.MyDecimalcSs
d|_dS)Nr	)r�)r��_rrrr��	sz:PythonAPItests.test_from_float.<locals>.MyDecimal.__init__Nr�rrrrr��	sr�r0r1r	ls\�&�5$3�|	r2r3r4rrr5�abcr8r9r:r;)rr�rr�r�r�r�r�r�r<rDrAr�r�r�r�r=)r�r�r�r>Zbigintr�r�rrr�test_from_float�	s6

�
�
�
�zPythonAPItests.test_from_floatcCs�|jj}|jj}|jj}|dtd�}|�|�tj�|d��|dt	d�}|�|�tj�|d��|d|gd�}|�
||jtj�|�t|�d��d�|�t|�d��d	�|�t|�d
��d�dS)Nr�)r#r$z3.1415r�)r#r%��z
Decimal('-0')r;zDecimal('1')r%z
Decimal('10'))rr�r&r{rqr��create_decimal_from_floatr��pirur�r�)r�r�r&r{rrrr�test_create_decimal_from_float
s8
�
�����z-PythonAPItests.test_create_decimal_from_floatcCs�|jj}|jj}|jj}|ddd�}|�|d��|d��|d��|�|d�j|d�td�|d��|j||d	�j|d
�|d�|�}|d�}|j||d
�td�}|�||d��dS)Ni��iay��rRz7.335z.01z7.34�r$z7.33Z10e99999Z1e100000r�z0.871831e800Z1e797)rr�r$z	8.71E+799)rr�r&ryr�r�rqr�)r�r�r&ryrrr�rrr�
test_quantize6
s(���zPythonAPItests.test_quantizecCs�|jj}|d�}|�|j|�|�|jd�|�|��|�|d�}|�t|�ttd���|�t	t
|dd�|�t	t
|dd�|�t	t
|dd�|�t	t
|d	d�dS)
Nz9.8182731e181273rr#r��realrM�imag�	conjugate�__complex__)rr�r�r�r�r��complexr<r�r�r�)r�r�r�rrr�test_complexN
szPythonAPItests.test_complexcCs,|jj}|jj}|jj}|jj}|jj}|�}d|_d|_d|_|����}|�	�|�
|d|�d�|�
|d|d�d�|�
||dd�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|dd�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-��|jt#|d�j$|d�|jt#|d�j%|d�|jt#|d�j&|d�|jt#|d�j'|d�|jt#|d�j(|d�|jt#|d�j)|d�|jt#|d�j*|d�|jt#|d�j+|d�|�|d�j,|d��|�|d�j-|d��|jt#|d�j.|d�|jt#|d�j/|d�|jt#|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�|jt#|j;d5|d�|jt#|d�j<|d�|�
|d��=�d�|jt#|d$�j>|d�|jt#|d$�j?|d�|jt#|d�j=d6d�|jt#|d�j=d6d7�Wd�n1�s0YdS)8Nr�r�r"r�)rr�rrr�r�r!z0.7r4rz-0.9z9.73z1E+1Z9999�'z-2000i0���r�rSz0.0625�0.2r)rr`r�r2�0.01z0.0101r�z-0.3z0.02z-0.03r6rorKZ1e10�9.99r�r��9.9z0.9)�thirdrr`z7E+1i����r�z0.21Z11r�Z01Z23g�������?r�)r)@rr�r&r
ryr|r#r�r�r�r�r�rr�rr�r�r�rKrLrOr�rUrTrRrr6rxrIrwrJrMr�rPr�r�r?r@rArBrDrFrErHrCrG�adjustedr��radixr�r>r5rSr3rNrWr�r�r�r�r��	canonicalr:r;)r�rVr&r
ryr|Zxcrrrr�test_named_parameters^
s�
�""�"�"����z$PythonAPItests.test_named_parameterscCs�|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|jt��|�t|j|��dSr)rr�ry�FloatOperationrzr|rr~r{r}rxrr��ArithmeticErrorr��ZeroDivisionErrorZConversionSyntaxZDivisionImpossibleZDivisionUndefinedZInvalidContext)r�rr�ryr�rzr|rr~r{r}rxrrr�test_exception_hierarchy�
sBz'PythonAPItests.test_exception_hierarchyN)
r�r�r�r�r�r�r�r�r�r�r�r�rrrrrr��	s3 pr�c@seZdZeZdS)�CPythonAPItestsNr�rrrrr�
src@seZdZeZdS)�PyPythonAPItestsNr�rrrrr�
src@seZdZdd�Zedd��Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Z d;d<�Z!d=d>�Z"d?d@�Z#dAdB�Z$dCdD�Z%dEdF�Z&dGdH�Z'dIdJ�Z(dKdL�Z)dMdN�Z*dOdP�Z+dQdR�Z,dSdT�Z-dUdV�Z.dWdX�Z/dYdZ�Z0d[d\�Z1d]d^�Z2d_d`�Z3dadb�Z4dcdd�Z5dedf�Z6dgdh�Z7didj�Z8dkdl�Z9dmdn�Z:dodp�Z;dqdr�Z<dsdt�Z=dudv�Z>dwdx�Z?dydz�Z@d{d|�ZAd}d~�ZBdS)��ContextAPItestsc
Cs�|jj}|jj}|jj}|jj}|�}|ddddddddd�}||fD]z}|�|jd�|�|jt�|�|j	d�|�|j
d�|�|jd�|�|jd�t
||dg�t
||d|||g�qFdS)	N)r#r$r�r�r�r2r�r%rA�?B��r�rr�r%)rr&ryrzr|r�r#r$r'r�r�r�r2r!)r�r&ryrzr|r"r rrrrr��
s&
��zContextAPItests.test_none_argscCsrddl}|j��}tD]}|�|�|_|�|j|�q|�d�}|�tt	|d|�|�d�}|�tt	|d|�dS)Nrr�r$z	ROUND_UP)
rrr&�
RoundingModesrr$r�r�r�r�)r�rrZrndrrrrrs


z(ContextAPItests.test_from_legacy_stringscCs�ttjd�D�]l}|jj}tjd}|jtjd<|�}t�t�||��}|�	|j
|j
�|�	|j|j�|�	|j|j�|�	|j
|j
�|�	|j|j�|�	|j|j�|�	|j|j�|�	|j|j�tr�ttfttfgnttfg}|D�]�\}}tt�D�]n\}	}
tt|�D�]V\}}
tt|�D�]<\}}
t�dd�}
t�dd�}t�dd�}t�d�}t�d�}|tjd<|j|
||t|	||t|d|�t|d|�d�}t�||�}|tjd<t�|�}|�||j�|�	|j
|
�|�	|j|�|�	|j|�|�	|j
t|	�|�	|j|�|�	|j|�t||dt|d|��t||d	t|d|���q*�qq�q�|tjd<qdS)
Nr�rrMr�rr�)r#r�r�r$r�r2r�r%r�r%)r�r�r�rr&r�r�r�r�r�r#r�r�r$r�r2r�r%rgr�r�rr�r��	randrangerIr!)r�r�r&r�rr��combinationsZdumper�loaderZrir��fiZtir#rXrW�capsr2rrrrrr� sZ



�

&zContextAPItests.test_picklecCsB|jj}|�|d�dd|d�dig�|�|d�dddig�dS)Nr%r&r;)r�r�)rr�ZassertInZassertNotInr�rrr�test_equality_with_other_types]sz.ContextAPItests.test_equality_with_other_typescCs�|jj}|jj}|�}|��}|�t|�t|��|�t|j�t|j��|�t|j�t|j��t|j�	��}t|j�	��}|�
||�|�
|j|j�dSr)rr�r&rZr=r�r�r%re�keysr�)r�r�r&rrZk1Zk2rrr�	test_copycszContextAPItests.test_copycCs"|jj}|�}|�tt|d�dS)NZ_clamp)rr&r�r�r�r�r&rrrr�test__clamprszContextAPItests.test__clampcCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dS�Nr�ro)rr�r&rr�r�r��r�r�r&rrrrr�test_abs}szContextAPItests.test_abscCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dS�Nr�r#)rr�r&rhr�r�r�rrrr�test_add�szContextAPItests.test_addcCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&rr�r�r�rrrr�test_compare�szContextAPItests.test_comparecCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&r6r�r�r�rrrr�test_compare_signal�sz#ContextAPItests.test_compare_signalcCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&r7r�r�r�rrrr�test_compare_total�sz"ContextAPItests.test_compare_totalcCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&r8r�r�r�rrrr�test_compare_total_mag�sz&ContextAPItests.test_compare_total_magcCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr)rr�r&r:r�r�r�rrrr�
test_copy_abs�szContextAPItests.test_copy_abscCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr)rr�r&r9r�r�r�rrrr�test_copy_decimal�sz!ContextAPItests.test_copy_decimalcCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr)rr�r&r;r�r�r�rrrr�test_copy_negate�sz ContextAPItests.test_copy_negatecCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dS)Nr�rr#r)rr�r&r<r�r�r�rrrrr�szContextAPItests.test_copy_signcCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dS�Nr�r�r#r�)rr�r&rr�r�r�rrrr�test_divide�szContextAPItests.test_dividecCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&r=r�r�r�rrrr�test_divide_int�szContextAPItests.test_divide_intcCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&r�r�r�r�rrrr�test_divmodszContextAPItests.test_divmodcCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dS�Nr%r�)rr�r&r�r�r�r�rrrr�test_exp
szContextAPItests.test_expcCs^|jj}|jj}|�}|�|d�|d�|d��}|�|�ddd�|�|�|�|d�dd�|�|�|�d|d�d�|�|�|�dd|d��|�|�|�|d�|d�d�|�|�t|jddd�|�t|jddd�|�t|jddd�|�t|j|d�|d�d	�|�t|j|d
�|d�d�|�t|d�j|d�d	�|�t|d
�j|d�d�dS)
Nr�rrr�r��4rrz
not a decimalr�r�gZd;�O��?)rr�r&r�r�r�r�rrrr�test_fmas0
�
���zContextAPItests.test_fmacCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&r@r�r�r�rrrr�test_is_finite0szContextAPItests.test_is_finitecCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&rAr�r�r�rrrr�test_is_infinite9sz ContextAPItests.test_is_infinitecCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&rBr�r�r�rrrr�test_is_nanBszContextAPItests.test_is_nancCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&rCr�r�r�rrrr�test_is_normalKszContextAPItests.test_is_normalcCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&rDr�r�r�rrrr�test_is_qnanTszContextAPItests.test_is_qnancCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&rEr�r�r�rrrr�test_is_signed]szContextAPItests.test_is_signedcCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&rFr�r�r�rrrr�test_is_snanfszContextAPItests.test_is_snancCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&rGr�r�r�rrrr�test_is_subnormalosz!ContextAPItests.test_is_subnormalcCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&rHr�r�r�rrrr�test_is_zeroxszContextAPItests.test_is_zerocCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&r�r�r�r�rrrr�test_ln�szContextAPItests.test_lncCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&r�r�r�r�rrrr�
test_log10�szContextAPItests.test_log10cCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&r�r�r�r�rrrr�	test_logb�szContextAPItests.test_logbcCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&r3r�r�r�rrrr�test_logical_and�sz ContextAPItests.test_logical_andcCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dS)Nr�r)rr�r&r>r�r�r�rrrr�test_logical_invert�sz#ContextAPItests.test_logical_invertcCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&rNr�r�r�rrrr�test_logical_or�szContextAPItests.test_logical_orcCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&rWr�r�r�rrrr�test_logical_xor�sz ContextAPItests.test_logical_xorcCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&rxr�r�r�rrrr�test_max�szContextAPItests.test_maxcCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&rIr�r�r�rrrr�test_max_mag�szContextAPItests.test_max_magcCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&rwr�r�r�rrrr�test_min�szContextAPItests.test_mincCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&rJr�r�r�rrrr�test_min_mag�szContextAPItests.test_min_magcCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&Zminusr�r�r�rrrr�
test_minus�szContextAPItests.test_minuscCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&r'r�r�r�rrrr�
test_multiply
szContextAPItests.test_multiplycCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&rKr�r�r�rrrr�test_next_minus
szContextAPItests.test_next_minuscCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&rLr�r�r�rrrr�test_next_plus
szContextAPItests.test_next_pluscCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&rMr�r�r�rrrr�test_next_toward 
sz ContextAPItests.test_next_towardcCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&rOr�r�r�rrrr�test_normalize,
szContextAPItests.test_normalizecCsn|jj}|jj}|�}|�|�d�|�|d���|�|�d�|�|d���|�|�d�|�|d���dS)NrSrr�)rr�r&r�r5)r�r�r&rrrr�test_number_class5
sz!ContextAPItests.test_number_classcCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&�plusr�r�r�rrrr�	test_plus>
szContextAPItests.test_pluscCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�|�|d�|d��|�|�t|jdd�|�t|jdd�|�|jdddd�d�dS)	Nr�rr#r#r�r!r�)�modulorEr&)rr�r&�powerr�r�r�rrrr�
test_powerG
szContextAPItests.test_powercCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&r�r�r�r�rrrrr�U
szContextAPItests.test_quantizecCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&�	remainderr�r�r�rrrr�test_remaindera
szContextAPItests.test_remaindercCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&rPr�r�r�rrrr�test_remainder_nearm
sz#ContextAPItests.test_remainder_nearcCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&r�r�r�r�rrrr�test_rotatey
szContextAPItests.test_rotatecCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&rRr�r�r�rrrr�	test_sqrt�
szContextAPItests.test_sqrtcCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&rQr�r�r�rrrr�test_same_quantum�
sz!ContextAPItests.test_same_quantumcCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&r�r�r�r�rrrr�test_scaleb�
szContextAPItests.test_scalebcCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&r�r�r�r�rrrr�
test_shift�
szContextAPItests.test_shiftcCs�|jj}|jj}|�}|�|d�|d��}|�|�dd�|�|�|�|d�d�|�|�|�d|d��|�|�t|jdd�|�t|jdd�dSr)rr�r&�subtractr�r�r�rrrr�
test_subtract�
szContextAPItests.test_subtractcCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&rSr�r�r�rrrr�test_to_eng_string�
sz"ContextAPItests.test_to_eng_stringcCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&rVr�r�r�rrrr�test_to_sci_string�
sz"ContextAPItests.test_to_sci_stringcCsJ|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�dSr!)rr�r&rUr�r�r�rrrr�test_to_integral_exact�
sz&ContextAPItests.test_to_integral_exactcCs\|jj}|jj}|�}|�|d��}|�|�d�|�|�t|jd�|�t|jdd�dS)Nr%r�r�)rr�r&rTr�r�r�rrrr�test_to_integral_value�
sz&ContextAPItests.test_to_integral_valueN)Cr�r�r�r�r
rr�rrrrrrrrrrrrrrrr r"r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?rArDr�rFrGrHrIrJrKrLrNrOrPrQrRrrrrr�
s�
=																												rc@seZdZeZdS)�CContextAPItestsNr�rrrrrS�
srSc@seZdZeZdS)�PyContextAPItestsNr�rrrrrT�
srTc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�ContextWithStatementcCsv|jj}|jj}|�}|��}|�}Wd�n1s80Y|�}|�||d�|�||d�|�||d�dS)N�!did not restore context correctly�did not copy the context� __enter__ returned wrong context)rrHr
r+�assertIsNot)r�rHr
�orig_ctx�	enter_ctx�set_ctx�	final_ctxrrr�test_localcontext�
s$z&ContextWithStatement.test_localcontextc	Cs�|jj}|jj}|jj}|jj}|�}|dd�}||��}|�}Wd�n1sT0Y|�}|�||d�|�|j|jd�|�||d�|�||d�dS)Nr��r#rVzdid not set correct contextrWrX)rr&rHr
r+r�r#rY)	r�r&rHr
rZ�new_ctxr[r\r]rrr�test_localcontextarg�
s

$z)ContextWithStatement.test_localcontextargc	Cs�|jj}|jj}|jj}|jj}|jj}|jj}|�}|��|dd�}|���}	|�|	j	|j	�|�|	j
|j
�d|	j
|<d|	_|�|jd�|�
||	jd�|�|	j	|�||��h}
|�|
j	|j	�|�|
j
|j
�|�
||
j|d�d�|�|
j	|�|�|
j	|�~
Wd�n1�s(0Y|�|	j	|�~	Wd�n1�sZ0Y|�|jd�|�|j	|�|�|j	|�|�|j	|�|�|j	|�dS)N��r�T���z0e-999z3.4e200r�)rr�r&rHr
rxr|r�r�r�r%r�r=r�r�rrCr)r�r�r&rHr
rxr|rZr`r"r rrr�test_nested_with_statements
s>



""z0ContextWithStatement.test_nested_with_statementscCs�|jj}|���}~|��b}~|��:}~|��}~Wd�n1sD0YWd�n1sb0YWd�n1s�0YWd�n1s�0YdSr�rr
�r�r
r"r r!�c4rrr�test_with_statements_gc1-sz-ContextWithStatement.test_with_statements_gc1cCs�|jj}|���}||��h}~||��>}~||��}~~Wd�n1sJ0YWd�n1sh0YWd�n1s�0YWd�n1s�0YdSrrfrgrrr�test_with_statements_gc29s


z-ContextWithStatement.test_with_statements_gc2c
Cs~|jj}|jj}|jj}|jj}|���@}~|dd�}||�||���}~|�|jd�~|dd�}||�~|�|�jd�|dd�}	||	�|�|�jd�||	��~}
~	|�|
jd�~
|dd�}||�~|�|�jd�|�� }|�|jd�~Wd�n1�s0YWd�n1�s00YWd�n1�sP0YWd�n1�sp0YdS)Nr�r_r�rr)rr&r
rHr+r�r#)
r�r&r
rHr+r"Zn1r Zn2Zn3r!Zn4rhrrr�test_with_statements_gc3Es<





z-ContextWithStatement.test_with_statements_gc3N)	r�r�r�r^rarerirjrkrrrrrU�
s
#rUc@seZdZeZdS)�CContextWithStatementNr�rrrrrlfsrlc@seZdZeZdS)�PyContextWithStatementNr�rrrrrmhsrmc@s8eZdZdd�Zdd�Zedd��Zdd�Zd	d
�ZdS)�ContextFlagsc
s��jj}�jj}�jj}�jj}�jj}�jj}�jj}�fdd�}|dddtggd�}	|	j	|d�gf|	j
|d�gf|	j|d	�|d
�gf|	j|d	�|d
�gf|	j
|d	�|d
�gfg}
|g|g|g|g|g|||||gg}|
D]�\}}
|	��||
�}dd�|	j��D�}|D]�}|	��|D]}||	|��q||
�}t|�}|D]}||v�rB|�|��qB|jtd
�dd�|	j��D�}|jtd
���||dd||f���||dd||f��qq�dS)Ncs2�jtkr$d|j|<|j|r.|�n
|�|�dS�NT)rrgr�r%Z_raise_error)r�flagr�rr�raise_errorxs



z7ContextFlags.test_flags_irrelevant.<locals>.raise_errorr"r,r�)r#r�r�r$r%r�z100E-425000010r�r�z
9.87654321cSsg|]\}}|r|�qSrr�r�kr�rrrr��rz6ContextFlags.test_flags_irrelevant.<locals>.<listcomp>r�cSsg|]\}}|r|�qSrrrrrrrr��rz=operation produces different answers depending on flags set: zexpected %s, got %s.z9operation raises different flags depending on flags set: zexpected %s, got %s)rr�r&r{r}rrxr~r'r4rRrhr'rMr�r�rOr?r�r�r�r�)r�r�r&r{r}rrxr~rqrZ
operationsZflagsets�fnr�r�r��extra_flagsrpZnew_ansZexpected_flagsZ	new_flagsrr�r�test_flags_irrelevantms\��	�

��
��z"ContextFlags.test_flags_irrelevantcCs2|jj}|jj}|jj}|�}|�|j|j�|�|j|j�|j|_|�|j|j�|�|j|j�d|j|<|j|_|�|j|j�|�|j|j�i}|�|j�|�||j�|�|j|�d||<|�||j�|�|j|�|di}|�||j�|�|j|�dg}|�||j�|�|j|�dS)NTFr)	rr&r{r}r=r�r%r��update)r�r&r{r}rrrrr�test_flag_comparisons�s4
z"ContextFlags.test_flag_comparisonscCs�|jj}|jj}|jj}|����}|�|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	|�Wd�n1�s�0YdS)Ng@T)rr�r�r
rr%r�r�rr�r�r�r�r�)r�r�r�r
rr�rrr�test_float_operation�sD





z!ContextFlags.test_float_operationcs8�jj��jj}�jj��jj}d��fdd�	��d���d��d�
d��d���d��	d	�d
�
�d���d��td
��td��d���������	�
��
��fdd�	}d���fdd�	}|�}||��Z}��|j��||dd�||dd�d|j�<||�d�||�d�Wd�n1�s*0YdS)NcsN|��t||�}|�kr*��|||�n��||�d���|j��dSro)r�rr�r+rr�)r&rEr r�signalr�)r�r�rr�assert_attrs
z7ContextFlags.test_float_comparison.<locals>.assert_attrrGrHrJrIr�r6r"r�rr5r3r4csdD]}��
�|||�qdD]}���|||�q��
�d|d����	d|d����
d|d����	d|d����
d|d����d|d����d|d���
�d|d���d�dd|d����d|d����d|d���d�td�d|d�dS)	N)rcre)rdrfrgrhrKr0rr2)r<)rrzr )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_frr�doit)s z0ContextFlags.test_float_comparison.<locals>.doitcs�|��td�d�g�}��t|�d���|j��|��|r\��|td�d�g�ntd�d�g�}��|j��|��d�d�dfv}��|j��|��d�d�dddiv}��|j��dS)	Nr�z100.0r�r;rpg$@r&rE)r�rer��lenrr�r��sorted)rrzrrE)r�r�r�rr�test_containersGsz;ContextFlags.test_float_comparison.<locals>.test_containers)rzT)N)N)N)rr�r&r�r
r<rr%)r�r&r
r�r�rKrr)r�r�r{r|r}r~rr�r�r�r�r�r�r�r�r�r�test_float_comparisons6	(

z"ContextFlags.test_float_comparisoncCs�|jj}|jj}|jj}|jj}|�}|�|j|�|�|j|�|��d|j|<d|j|<|�	|j|�|�	|j|�dSro)
rr�r&r{r�rr�r%�clear_trapsr)r�r�r&r{r�rrrr�test_float_operation_defaultfs

z)ContextFlags.test_float_operation_defaultN)	r�r�r�rvrxrryr�r�rrrrrnksB&
5[rnc@seZdZeZdS)�
CContextFlagsNr�rrrrr�vsr�c@seZdZeZdS)�PyContextFlagsNr�rrrrr�xsr�c@s eZdZdZdd�Zdd�ZdS)�SpecialContextszTest the context templates.c
Cs4|jj}|jj}|jj}|jj}|jj}|jj}|jj}|jj}|jj	}	t
||d|||||	g�|���}
|j}|j}d}
z�zFd|_|_||fD],}||�|�}|�
||�|�|jd�q�Wn*ty�}z|j}
WYd}~n
d}~00W||_||_||
�|
�r0|
�n ||_||_||
�|
�r.|
�0dS)Nr%i�)r�BasicContext�ExtendedContextrHr+ryrzr|rrxr!rZr#rYr��	Exceptionr�)r�r�r�rHr+ryrzr|rrx�savecontextZbasic_context_precZextended_context_prec�ex�templaterr�rrr�test_context_templates~sF�
�z&SpecialContexts.test_context_templatesc
Cs@|jj}|jj}|jj}|jj}|jj}|jj}|jj}|jj}|�	|j
d�|�	|j
d�t||d|||g�|���}	|j
}
d}z�zR|�}|j
}
d|_
|�}|�	|j
|
�||�|�}|�
||�|�	|j
d�Wn,t�y}z|j}WYd}~n
d}~00W|
|_
||	�|�r<|�n|
|_
||	�|�r:|�0dS)Nr"r%i�)rr.r�r�rHr+ryrzr|r�r#r!rZrYr�r�)r�r.r�r�rHr+ryrzr|r�Zdefault_context_precr�rZsaveprecr�rrr�test_default_context�sH�
�z$SpecialContexts.test_default_contextN)r�r�r�r�r�r�rrrrr�{s$r�c@seZdZeZdS)�CSpecialContextsNr�rrrrr��sr�c@seZdZeZdS)�PySpecialContextsNr�rrrrr��sr�c@seZdZdd�ZdS)�ContextInputValidationc	CsB|jj}|jj}|��}dD]F}t||d�|�t||�d�|�tt||d�|�t	t||d�qt|dd�|�t|d�d�|�tt|dd�|�t	t|dd�|�t	t|d	d�|�t	t|d	d
�|�t	t|d	d�|�t	t|d	d�dD]>}|�tt||d�|�tt||d
�|�t	t||gd��q�|�t
t|dd�|�t	t|dg�|�tt|di�|�tt|dddi�dD]}|�t
|j|��q�|�t	t|d
�|�t	t|d
�|jt	|dd�|jt	|dd�|jt|d
d�|jt|dd�|jt|dgd�|jt|dgd�|jt	|dd�|jt	|dd�dS)N�r#r�rr�rr�rr��r�r�rr$r"r;�r�r2r�rWrMr�r%ryr)r#r�r�r$r�r2r�r%r��r2�r�r��r��Q�r%�rr�)r�r)
rr&r.rZr�r�rr�r�r�r��KeyError�__delattr__)r�r&r.rr rrr�test_invalid_context�sL�z+ContextInputValidation.test_invalid_contextN)r�r�r�r�rrrrr��sr�c@seZdZeZdS)�CContextInputValidationNr�rrrrr�sr�c@seZdZeZdS)�PyContextInputValidationNr�rrrrr�sr�c@seZdZdd�ZdS)�ContextSubclassingcs�|j��j}�j��j}�j}�j}�j}�j}�j}�j	}�j
}	G��fdd�d��}
��}|
�}dD]}
|�t||
�t||
��qh|j
t|
fiddi��|
dd�}|�|jd�|�
|	|j|d�d	�|j
t|
fid
di��|
tdd�}|�|jt�|�|�|d
��d�|j
t|
fiddi��|
ddd�}|�|jd�|�|d�|d��}|�||d��|||||fD]}|�|j|��qx|j
t|
fiddi��|
ddd�}|�|jd�|�
||j|d�|d��|jtk�r
|||fD]}|�|j|��q�|j
t|
fiddi��|
d	d�}|�|jd	�|�d�}|�|�|�d�|j
t|
fiddi��|
ddd �}|�|jd�|�|d��}|�t|�d!�|j
t|
fid"di��|
||gd#�}||fD]}|�|j|��q�|� �t!�D]}|�"|j|��q�|j
t|
fid$di��|
||gd%�}||fD]}|�|j#|��qB|�$�t!�D]}|�"|j#|��qjdS)&NcseZdZd��fdd�	ZdS)z>ContextSubclassing.test_context_subclassing.<locals>.MyContextNc		s���|�|dur||_|dur&||_|dur4||_|durB||_|durP||_|dur^||_�dur�t�t�r��fdd�t	��D���|_
�dur�t�t�r��fdd�t	��D���|_dS)Ncsi|]}||�v�qSrr�rr�r�rr�
<dictcomp>5rz[ContextSubclassing.test_context_subclassing.<locals>.MyContext.__init__.<locals>.<dictcomp>csi|]}||�v�qSrrr�r�rrr�9r)r�r#r$r�r�r�r2rJr?r�r�r%)	r�r#r$r�r�r�r2r�r%�r&r�r�r%rr�#s*


zGContextSubclassing.test_context_subclassing.<locals>.MyContext.__init__)NNNNNNNNr�rr�rr�	MyContext"s�r��r#r$r�r�r�r2r�r%r#r�r�r_Z9e2rr$�XYZ)r$r#r�r"r�r�)r�r#z1e-99z2.234e-2000r�r�)r�r#Z1e99z
2.234e2000r�r�Z1E222z1e+222r2r��c)r2r�z!1.000000000000000000000000000E+99r�r�r%r�)%rr�r&rxrzr{r|r}r~rryr�rr�r�r#r�r�rqr$r@r�rhrr�r�rgr�r�rVr2r�r�r�rr%r�)r�r�rxrzr{r|r}r~rryr�rrr r�rzrr�r�test_context_subclassings|


z+ContextSubclassing.test_context_subclassingN)r�r�r�r�rrrrr�sr�c@seZdZeZdS)�CContextSubclassingNr�rrrrr��sr�c@seZdZeZdS)�PyContextSubclassingNr�rrrrr��sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�CheckAttributescCs�|�tjtj�|�tjtj�|�tjtj�|�tjtj�|�tjdupVtjdu�|�tjdupptjdu�|�tj	tj	�|�t
t�t
t��dS)NTF)r�rgr�r�r�rTrUrr/�__version__�dirr�rrr�test_module_attributes�sz&CheckAttributes.test_module_attributescCsJdd�tt���D�}dd�tt���D�}|�t|�t|�t��dS)NcSs"g|]}d|vs|�d�s|�qS��__r��r�rrrrr��rz;CheckAttributes.test_context_attributes.<locals>.<listcomp>cSs"g|]}d|vs|�d�s|�qSr�r�rrrrr��r)r�rgr&r�r�re�r�r�r	rrr�test_context_attributes�sz'CheckAttributes.test_context_attributescCsNdd�tt�d��D�}dd�tt�d��D�}|�t|�t|�t��dS)NcSs"g|]}d|vs|�d�s|�qSr�r�rrrrr��rz;CheckAttributes.test_decimal_attributes.<locals>.<listcomp>r"cSs"g|]}d|vs|�d�s|�qSr�r�rrrrr��r)r�rgr�r�rer�rrr�test_decimal_attributes�sz'CheckAttributes.test_decimal_attributesN)r�r�r�r�r�r�rrrrr��sr�c@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�CoveragecCsH|jj}|�|d���d�|�|d���d�|�|d���d�dS)NZ	1234e9999i'r2rr3)rr�r�r�r�rrr�
test_adjusted�szCoverage.test_adjustedcCsL|jj}|jj}|d���}|�|d�|�}|�|d��}|�|d�dS)Nr")rr�rHr�r�)r�r�rHr�rrrr�test_canonical�szCoverage.test_canonicalcCsp|jj��}d|_d|_d|_t|_d|_d|_	t
|jD]}d|j|<d|j|<q:|�
�}d}|�||�dS)Nr�r,rr�Fz{Context(prec=425000000, rounding=ROUND_HALF_DOWN, Emin=-425000000, Emax=425000000, capitals=0, clamp=1, flags=[], traps=[]))rr.rZr#r�r�rsr$r�r2r�r�r%�__repr__r�)r�rr#rr�rrr�test_context_repr�s
zCoverage.test_context_reprcCsH|jj}|jj}|����}d|_d|_d|_|�t|d��d�|�|d�dd�|�|d�dd	�|�|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�dd�|�|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����Wd�n1�s�0Y|��j}d|_d d!}||�}|��}|�||�|��}|�||�|� |d��}|�||�Wd�n1�s:0YdS)"Nr�r�z-10r%�7r!r�r�r�r�z1.2r�rTz1.01rFZ20Z580r�rr"z2E+1z-1E+1z+Normalroz1.12345r#r�r�rsi�i�)!rr�r
r#r�r�r�rr�r+rB�powr�rCrGr�r�r�r>rKrLrOr5rUrr?r@rFrErHr:r;r<)r�r�r
rr�r	r�rrrr��s^
2
zCoverage.test_implicit_contextcCs|jj}|jj}|jj}|jj}|����}t|d�d�\}}|�||d��|�||d��t|d�d�\}}|�|��o�|���d|j	|<t|d�d�\}}|�|��o�|���d|j	|<|�
�t|d�|d��\}}|�|��o�|���|�|j|�|�
�t|d�d	�\}}|�|���o2|���|�|j|�|�
�t|d
�d
�\}}|�|���ot|���|�|j|�d|j	|<|�
�t|d�d
�\}}|�|���o�|���|�|j|�o�|j|�Wd�n1�s�0YdS)NZ10912837129r�Z10901935Z194rr�Fr3r�r�)
rr�r
ryrzr�r�rrBr%r�r�rA)r�r�r
ryrzrrr>rrrr sB



�zCoverage.test_divmodcCs�|jj}|jj}|jj}|jj}|���}d|_|��|�|d�d|d��|�|j	|�d|_d|_
d|_|��d|j|<|�|d�|d	�|d
��|�|j	|�Wd�n1s�0YdS)Nrr�rMr�r�r�Frsr�r3)
rr�r
r|r}r#r�r�rr�r�r�r%)r�r�r
r|r}rrrrrDEs 
zCoverage.test_powercCs~|jj}|jj}|jj}|��L}d|_d|_d|_d|j|<|d��|d��}|�	|�
��Wd�n1sp0YdS)Nr�r�Fr�Z1e1)rr�r
ryr#r�r�r%r�rrB�r�r�r
ryrr�rrrr�Ys
zCoverage.test_quantizecCs>|jj}|jj}|�}|�|d���d�|�|��d�dS)Nr#r%)rr�rHr�r�r�rrr�
test_radixfs
zCoverage.test_radixcCs0|jj}dD]}|�t|d�|�d�t�qdS)N)rlrorrrurbrxrzr|r#r)rr�r+rrN)r�r�r rrrr�nszCoverage.test_ropcCs�|jj}|jj}|���}d|_|�t|d����d�|�t|d����d�|�t|d��d��d�|�t|d	��d
��d�|�t|d	��d��d
�|�t|d�jd�|�t|d�jdd�Wd�n1s�0YdS)NrAr�r�z9.99e-5r�r�r�z1.23457r�r%z1.2345000000r`z0E+10r�r�r!)	rr�r
r#r�r��	__round__r�r�)r�r�r
rrrr�
test_rounduszCoverage.test_roundcCs |j��}|�t|jdg�dS)Nrv)rr&r�r�r�)r�rrrr�test_create_decimal�s
zCoverage.test_create_decimalcCst|jj}|jj}|��J}d|_|dd�dd}|�t|�d�|�|��d�Wd�n1sf0YdS)Nr�i�i�r%iSr�r�)rr�r
r#r�r�r��r�r�r
rr�rrrr��szCoverage.test_intcCsl|jj}|�}d|_dd}|�|�}|�||�|�|�}|�||�|�|d�}|�||�dS)Nrsi�i�r�)rr&r#r:r�r;r<)r�r&rr�r	rrrr�s


zCoverage.test_copyN)r�r�r�r�r�r�r�r rDr�r�r�r�r�r�rrrrrr��sQ)

r�c@seZdZeZdS)�	CCoverageNr�rrrrr��sr�cs,eZdZeZ�fdd�Z�fdd�Z�ZS)�
PyCoveragecs"t���t��|_t�d�dSr�r�r�r�rrr��s

zPyCoverage.setUpcst�|j�t���dSrr�r�r�rrr��szPyCoverage.tearDownr�rrr�rr��sr�c@seZdZdZdd�ZdS)�PyFunctionalityz!Extra functionality in decimal.pycCs>tj}tj}gd�}|D] \}}}|�t||�|�|�qdS)N)
)z.0er�z1e+0)z#.0er�z1.e+0)r�r�r#)z#.0fr��1.)r��1.1r�)z#gr�r�)r�r#r#)z#.0gr#r�)r�r�z100%)z#.0%r�z100.%)r�r�r
r�r�)r�r�r
rPr�rr�rrr�test_py_alternate_formatting�s

z,PyFunctionality.test_py_alternate_formattingN)r�r�r�r�r�rrrrr��sr�c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�
PyWhiteboxz White box testing for decimal.pycCstj}tj}|���}d|_|d�|d�}|�||d��|d�|d�}|�||d��|d�|d�}|d�|d	�}|�||d
��|d�|d	�}|dd
�|d	�}d|_|d�|d�}d|_|dd�|d�}Wd�n1s�0YdS)Nr!ir�z
0.00390625z-0.6z0.0012885819Z256e7l�o�
�z-0.0625r�Z152587890625e7r�ic
r�Z152587890625��r�iB)r�r�r
r#r�r�rrr�test_py_exact_power�s"zPyWhitebox.test_py_exact_powercs:tj}tj}tj}|��}tdd�ttD��|_||�|d��|d��|d��|d��d4�����fdd�	}|�����j	�j	����j
�j
����j�j�|d�|d	d
�|dd
�|dd
�|d
d
�|dd
�|dd
�|dd
�|dd
�|d�|dd
�|d�|d�|d�|dd
�|dd
�|d�|d�|d�|dd
�|dd
�|dd
�|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�dS)5Ncss|]}|dfVqdS)rNrrrrrr�rz=PyWhitebox.test_py_immutability_operations.<locals>.<genexpr>z-25e55z33e+33Fcs�|rvtd|d����j�j����j�j����j�j����j�j����j�j����j�j�n@td|d����j�j����j�j����j�j�dS)Nzd1.z(d2)z())r�r��_sign�_int�_exp)Z	operationZuseOther��b1�b2r�r�r�rr�checkSameDec�sz@PyWhitebox.test_py_immutability_operations.<locals>.checkSameDec�__abs__rkTrargrhrercrfrd�	__float__ryr]�__int__�	__trunc__rwrq�__neg__�__bool__�__pos__r{rlrbr�rzrxrrr|ro�__str__rnrtr�r�rrxrwrOr�rPrQrRrSr�)F)r�r�r.r+rZr(r�r%r�r�r�r�)r�r�r.r+rr�rr�r�test_py_immutability_operations�st


























z*PyWhitebox.test_py_immutability_operationscCs>tj}|d�}||�}|�t|�d�|�t|�t|��dS)Nr�r�)r�r�r�r�r=r�r.rrr�test_py_decimal_id7s
zPyWhitebox.test_py_decimal_idcCsTtj}tj}|��.}|d��dt�}|�|���Wd�n1sF0YdS)Nrr)r�r�r
Z_rescalerurrBr�rrr�test_py_rescale?s
zPyWhitebox.test_py_rescalecCs tj}|�t|d�jdt�dS)Nz3.1234r)r�r�r�r�Z_roundrur�rrr�test_py__roundHszPyWhitebox.test_py__roundN)	r�r�r�r�r�r�r�r�r�rrrrr��sO	r�c@s4eZdZdZedd��Zedd��Zedd��ZdS)	�CFunctionalityzExtra functionality in _decimalcCstj}tj}tj}tj}dd�}||�}|�|jd�|�|jd�|�|jd�|||�||�}|�|jd�|�|jd�|�|jd�|||�||�}|�|jd	�|�|jd
�|�|jd�|||�|�	t
|d�|�	t|d
�|�	t|d�dS)NcSs.|�|jd�t||dg�t||dg�dS)Nr�r%r�)r�r2r!)r�rrrr�assert_restYsz7CFunctionality.test_c_ieee_context.<locals>.assert_restr��`i����rdrbrd�"ii�rDr�i)rg�IEEEContext�	DECIMAL32�	DECIMAL64�
DECIMAL128r�r#r�r�r�r�r�)r�r�r�r�r�r�rrrr�test_c_ieee_contextQs.


z"CFunctionality.test_c_ieee_contextcCs:tj}|tjtjd�}|�|jtj�|�|jtj�dS)Nr�)rgr&r/�
DecRoundedr��_flags�_trapsrrrr�test_c_contextuszCFunctionality.test_c_contextcCstjtjtjtjtjtjtjtjtj	tj
tjtjtj
tjtjf}|�tjd�|�tjd�|�tjd�|�tjd�t|�D]\}}|�|d|>�q�|�tjtjtjBtjBtjBtjBtj	Btj
B�|�tjtjtjB�|�tjtjtjBtjB�dS)Nr�rl�ir�)rgr/�DecConversionSyntax�DecDivisionByZero�DecDivisionImpossible�DecDivisionUndefined�DecFpuError�
DecInexact�DecInvalidContext�DecInvalidOperation�DecMallocError�DecFloatOperation�DecOverflowr��DecSubnormal�DecUnderflowr�r�r�r�ZIEEE_CONTEXT_MAX_BITSr��DecIEEEInvalidOperationZ	DecErrorsZDecTraps)r��condr�r�rrr�test_constants}sH�
�������	���zCFunctionality.test_constantsN)r�r�r�r��requires_extra_functionalityr�r�rrrrrr�Ns
#
r�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	e
dd��Zdd�Ze
dd��Z
dd�Zdd�Zdd�Zdd�Zdd�Ze
dd��Ze
d d!��Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Ze�ej�d,�d-�e�ed.d.d/�d0�d1d2���Z d3S)4�	CWhiteboxzWhitebox testing for _decimalcCs�tj}tj}dd}dd}|��`}d|_td�D]@}t�||�}t�dd�}||}	||�||�}
|�|	|
�q2Wd�n1s�0YdS)Nr%�#�$i@Br�r�i�)rgr�r
r#r�r�rr�)r�r�r
r�r�rr�r&rEr�r	rrr�test_bignum�szCWhitebox.test_bignumcCs|�ttjdd�dS)Nr"r)r�r�rgr�r�rrr�test_invalid_construction�sz#CWhitebox.test_invalid_constructioncCsTtj}tj}tj}tj}||���|�||d�Wd�n1sF0YdS)NZ1e9999999999999999999)rgr�ryr&r
r�)r�r�ryr&r
rrr�test_c_input_restriction�s�z"CWhitebox.test_c_input_restrictioncCs�tj}tj}|��}d|_d|_d|_t|_d|_	d|_
ttD]}d|j|<d|j
|<q@d|j|<d|j
|<|��}d}|�||�dS)Nr�r,rr�TaQContext(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]))rgr.r�rZr#r�r�rsr$r�r2r�r�r%r�r�)r�r.r�rr#rr�rrr�test_c_context_repr�s"


zCWhitebox.test_c_context_reprc	Cs�tj}tj}tj}tj}tj}tj}tj}tjdk}|�}	|�	t
|	jjdd�|�	t
|	j
jdd�|�	t|	jj|�|�	t|	j
j|�|�	tt|	ddg�|�	tt|	ddg�|�	t
t|	dddi�|�	t
t|	dddi�|	j��}
|
|=d	|
d
<|�	t
t|	d|
�|�	t
t|	d|
�|�r dnd}|�r.d
nd}dD]}
|�	tt|	|
|��q6|�	tt|	d|�|j	t||d�|j	t||d�|j	t||d�|j	t||dd�|j	t||dd�|j	t||dd�|j	t||dd�|j	t||dd�dD]j}
|�	tt|	|
|d�|�	tt|	|
|d�tjdk�r|�	tt|	|
|�|�	tt|	|
|d��qtjdk�r�|�	tt|	d�|d�|�	tt|	d�|d�|�	tt|	d�|d�tjdk�rF|�	tt|	d�d�|�	tt|	d�d�|�	tt|	d�d�|�	tt|	d�d�|�	tt|	d�d�|�	tt|	d�d�dD]j}
|�	tt|	|
d�|�	tt|	|
d�|�	tt|	|
gd ��|�rJ|�	tt|	|
d!�|�	tt|	|
d"��qJ|�	ttd#t��|�	ttd$t��|�}|�	t|d%�||�dS)&Nr�i!rr�r�r%r	r�i�pr�rCrBl�N�Zoiʚ;r�r�r_rc)r�r�r�r�)r#r�r�r�r2�win32r�r�r�i���?r�i9�r�r���zwith localcontext("xyz"): passz-with localcontext(context=getcontext()): passr)rgr&ryr|r�r
rHr+r�r�r�r��__setitem__r%r��__delitem__r�r�rZr�r��platformr�execrW)r�r&ryr|r�r
rHr+�HAVE_CONFIG_64rr�int_maxZgt_max_emaxr Z
saved_contextrrr�test_c_context_errors�s�

������
��zCWhitebox.test_c_context_errorscCs�|�tjtj�|�tjtj�|�tjtj�|�tjtj�|�tjtj�|�tjtj�|�tj	tj	�|�tj
tj
�dSr)r+rgrur�rqrprrrtrsr'rvr�rrr�test_rounding_strings_internedGsz(CWhitebox.test_rounding_strings_internedc	Cs�tj}tj}tj}tj}tj}tj}tjdk}|�}|r<dnd}	|�t	t
|d|	d�|�t	t
|d|	d�tjdkr�|�t
t
|d|	�|�t
t
|d|	d�dD]f}
|�t	t
||
|	d�|�t	t
||
|	d�tjdkr�|�tt
||
|	�|�tt
||
|	d�q�|�t
t
|dd	�|�t
t
|dd�|�tt
|dgd
��|�rr|�t
t
|dd�|�t
t
|dd�dD]*}
|�tt
||
d
�|�tt
||
d��qvdS)Nr�rCrB�_allcrr�r�r)r�r�r�r�rrrr�)rgr&ryr|r
rHr+r�r�r�r�r�rr�r�)r�r&ryr|r
rHr+rrrr rrr�test_c_context_errors_extraRs:


z%CWhitebox.test_c_context_errors_extracCstj}tj}tj}tj}tj}tj}|��}d|_t	|_
d|_d|_d|_
d|_|�|jd�|�|j
t	�|�|jd�|�|jd�|�|j
d�|�|jd�|�|��d�|�|��d�tjdk�r|�d	�|�d	�|�d
�|�|jd	�|�|jd	�|�|jd
�dS)Nr�i�iH�r�ri'�i�r�rPrQ)rgr.rxrr{r}r~rZr#rtr$r�r�r�r2r�ZEtinyZEtopr�r�r�r�)r�r.rxrr{r}r~rrrr�test_c_valid_context}s8


zCWhitebox.test_c_valid_contextcCs4tj}|��}|�|jd�d|_|�|jd�dS)Nr�r)rgr.rZr�r)r�r.rrrr�test_c_valid_context_extra�s
z$CWhitebox.test_c_valid_context_extracCstj}tj}tj}tj}tj}tjdkr,dnd}|���}d|j|<|�||d�j	|d�|�||d�j	|�|�||d�j	t
|d��|�tj|d�j	t
|d��|�t|d�j	|d�|�t|d�j	|d�Wd�n1s�0YdS)	Nr�rCrBTr�r�r#r�)rgr�ryr
r�rUr�r%r�r�r�r�)r�r�ryr
r�rUrrrrr�test_c_round�s4
��
����zCWhitebox.test_c_roundcCs�tj}tjdk}|�t|d�jdgd�|�t|d�jdd�|�t|d�jg�|�t|d�jd�|rndnd}|�t|d�jd	|�dS)
Nr�r�z=10.10r"z<>=10.10rCrBr�z=%d.1)rgr�r�r�r�r�r�)r�r�r�maxsizerrr�
test_c_format�s
�zCWhitebox.test_c_formatcCsftj}tj}tj}|d�}|�|��d�|�t|jd�|�t|jdd�|�t|jd�|�|��d�|�t|jd�|�t|jdd�|�t|jd�|�|�	�d�|�t|j	d�|�t|j	dd�|�t|j	d�|��j}|d��t
�}|�||d��|d��	t
�}|�||d��d|j|<|�||d�j	t
�Wd�n1�sX0YdS)Nr%r�r�z99999999999999999999999999.9Z100000000000000000000000000Tz999.9)rgr�r{r
r�r�r�r�rTrUrur%)r�r�r{r
r�rrrr�test_c_integral�s.
zCWhitebox.test_c_integralc	CsTtj}tj}tj}tj}tj}|�|d���d�|�t	t
|d�dd�|�t	|d�jdd�|�t	|d�jd	dd�|�t	|d
�j
|d�g�|�t	|d
�j
|d�|��|�t	|d
�j
|d�d�|�t	|d
�j
|d�td
�|���T}|��|�t	|j|d�dd�|�t	|jd�|�t	|jd�|�t	|jdddd�|�t	|jdd	dd�|�t|�|d���d�|�|��d�d|j|<|�||d�jd�|�||jdd�|�|j|�|��d|j|<|�||d�jd�|�||jdd�|�|j|�d|j|<d|_|�|t
|d
�dd�Wd�n1�sF0YdS)Nz9.99e10z99.9E+9r�r�r�r"r�r	rr�z	1e-100000r%r�r8r!Z200Tri�)rgr�ryrzrHr
r�rSr�r�r�r5rQr�rur�r<r�r?r�r�r�r%rarr�r�r#)r�r�ryrzrHr
rrrr�test_c_funcs�s\����



zCWhitebox.test_c_funcscCs�tj}tj}|d�}dD]0}t||�}|jt|dd�|jt|ddd�qdD]0}t||�}|jt|dd�|jt|ddd�qN|jt|jdgd�|jt|jigd�|�t|jgg�|jt|jdgd�|jt|jigd�|�t|jgg�|jt|jdgd�|jt|jigd�|�t|jgg�|jt|j	dddd�|jt|j	ddddd�|jt|j
dgdd�|jt|j
dgdd	�|�t|j
dgg�|�}|jt|jdddd
�|jt|jdddd
�|jt|jdddd
�dS)NZ10001111111)
r�rCrGr�r�r�r>rKrLrOr5rRrSr�r�)rr6r3rNrxrIrwrJrPr�r�r�r�r�r�r�)�mod)rgr�r&rr�r�r�rTrUr�r�rC)r�r�r&r�r �funcrrrr�test_va_args_exceptions,s:

z!CWhitebox.test_va_args_exceptionscCsL|�tjjtjtjBtjBtjBtjB�|�tj	jtjtjBtjB�dSr)
r�rgr�r�rr�rrr/r.r�rrr�test_c_context_templatesXs����z"CWhitebox.test_c_context_templatesc&s"tj}tj}tj}tj}tj}tj}tj}tj}tj	}	tj
}
tj}tj}tj
}
tj}�fdd�}|��}��||jv�|��|j��D]}d|j|<q�|j��D]}��|�q�|��|j��D]\}}��|�qƈ�|j�|����|j�d�d���|j�dd�d���t|jjddd���t|j�t|j��t�|j�}t�|j�}|j� �}|�!�||_"��|j|�|��|
|_#��|j|�|�!�|j��}d||<||_|||j�|��|j��}d||<||_|||j�|tj|	tj$|
tj%|tj&|tj'|tj(|tj)|tj*|tji	}tj+tj,tj-tj.tj
tj/tj0g}tt1t�}t2|�D�]V}t2|�D�]D}t3D�]6}t4�5t1t|�}t4�5t1t|�}t4�6dd�}t4�6d	d
�}t4�6d
d�}t4�6d
d�} t4�6d
d�}!t4�6d
d�}"||||||!| t7|�t7|�d�}��|j8|���|j9|���|j:|���|j;|���|j<|!���|j=| �d
}#|D]}$|#||$O}#�qj��|j"|#�d
}#|D]}$|#||$O}#�q���|j#|#��q��qv�qh|D](}%|%|_"��|j"|@�|||j��q�|D](}%|%|_#��|j#|@�|||j��q�dS)
Ncs4|D]*}||kr ��||�q��||�qdSr)rr)rzZsignal_dictr#r�rr�assertIsExclusivelySetysz<CWhitebox.test_c_signal_dict.<locals>.assertIsExclusivelySetTr�r	r�r�rsi���rr�r�)>rgr&r.ryr�rzr|r~rr}r{rxr/rrrZrr%r�r
�valuesrOrr�r�r+r�r�r�r�r��	getsizeofr�r�r�r�r�r�rrrr�rr�r�r�r�rr�r�r�rr��samplerr?r#r$r�r�r�r2)&r�r&r.ryr�rzr|r~rr}r{rxr/rrr)rrsr�rrZ
IntSignalsZIntCondZlimr>r�r�r�r%r#rXrWr2rZcrr�r�rrr�r�test_c_signal_dictds�


��


�zCWhitebox.test_c_signal_dictcs�tj�zddlm}Wnty2|�d�Yn0dd�}d�fdd�	}d	|gd
��d	d�}d|gd
��d	d�}d|gd
��dd�}|dkr�|�t|d|d�|�t|d|d�|�t|d|d�dS)Nrr�r�cSsd�dd�|D��S)Nr�cSsg|]}t|��qSrr�r�rrrr��rzJCWhitebox.test_invalid_override.<locals>.make_grouping.<locals>.<listcomp>)r�r�rrrr��sz6CWhitebox.test_invalid_override.<locals>.make_groupingr�cs�|��||�Sr)r�r�rarrr��sz0CWhitebox.test_invalid_override.<locals>.get_fmtr�)�r.rr�Zxxxxxr�r�Zyyyyy�r�r�)Nr�)rgr�r�r�r�r�r�r�)r�r�r�r�Zinvalid_groupingZinvalid_dotZinvalid_seprrar�test_invalid_override�s2
�
�
�
�zCWhitebox.test_invalid_overridecCs�tj}tj}tj}|���}d|j|<dtj}|�|||�dtjd}|�|||�dtj}|�|||�dtjd}|�|||�Wd�n1s�0YdS)NTz0e%dr�z1e%d)rgr�r
ryr%r�r!r�r�rrr�test_exact_conversions


zCWhitebox.test_exact_conversioncCs�tj}tj}tj}tj}tj}|����}d|j|<d|j|<d|j|<ddtjf}|�	t
|�|��d�|�|||�ddtjf}|�||j|�|�|||�ddtjdf}|�	t
|�|��d�|�|||�ddtjdf}|�||j|�|�|||�ddtjdf}|�t
|j|�|�t
||�ddtjdf}|�t
|j|�|�t
||�d}|�	t
||��d	�d
}|�	t
||��d	�d}|�	t
||��d�Wd�n1�s�0YdS)
NTr�rz
-0E+999999)rr�r�z-0E-1000007r�r�r�)r�rr�)r�r�r�z-sNaN1)rgr�r
ryr|rr%r�r!r�r�r�r�r�)r�r�r
ryr|rrr�rrr�test_from_tuple'sB



zCWhitebox.test_from_tuplecCs�tj}tjdk}|�|d���d�|rZ|dd���}|dd���}|�||d�n0|dd���}|dd���}|�||d	�dS)
Nr�rr%r@i�r!����r)rgr�r�r9�
__sizeof__r�)r�r�rr�r	rrr�test_sizeofWs
zCWhitebox.test_sizeofcsztj}Gdd�dt�}Gdd�dt�}Gdd�dt��G�fdd�dt�}|||fD] }|�|�|d	��|�d	��qTdS)
Nc@seZdZdd�Zdd�ZdS)z<CWhitebox.test_internal_use_of_overridden_methods.<locals>.XcSsdS�Nr�rr�rrrr�jszMCWhitebox.test_internal_use_of_overridden_methods.<locals>.X.as_integer_ratiocSs|Srrr�rrrr�lszDCWhitebox.test_internal_use_of_overridden_methods.<locals>.X.__abs__N�r�r�r�r�r�rrrr�Xisr9c@seZdZdd�ZdS)z<CWhitebox.test_internal_use_of_overridden_methods.<locals>.YcSs
dgdS�Nr�r8rr�rrrr�pszDCWhitebox.test_internal_use_of_overridden_methods.<locals>.Y.__abs__N)r�r�r�r�rrrr�Yosr;c@seZdZdd�ZdS)z<CWhitebox.test_internal_use_of_overridden_methods.<locals>.IcSs
dgdSr:rr�rrr�
bit_lengthtszGCWhitebox.test_internal_use_of_overridden_methods.<locals>.I.bit_lengthN)r�r�r�r<rrrr�Issr=cs eZdZ�fdd�Zdd�ZdS)z<CWhitebox.test_internal_use_of_overridden_methods.<locals>.Zcs�d��d�fSr7rr��r=rrr�xszMCWhitebox.test_internal_use_of_overridden_methods.<locals>.Z.as_integer_ratiocSs|Srrr�rrrr�zszDCWhitebox.test_internal_use_of_overridden_methods.<locals>.Z.__abs__Nr8rr>rr�Zwsr?gfffffFY@)rgr�r<r�r�r�)r�r�r9r;r?rrr>r�'test_internal_use_of_overridden_methodses�z1CWhitebox.test_internal_use_of_overridden_methodsZaixzEAIX: default ulimit: test is flaky because of extreme over-allocationT)�addressZmemoryzVASAN/MSAN sanitizer defaults to crashing instead of returning NULL for malloc failure.cCs\gd�}tj}tj}tj}|tjtjtjd�}||���|�|d���d�|�|d��	�d�|�|d��
�d�|�|d��
�d�|�|dd��
�d�|�|d	���d
�|�|d���d�|�|d���|d
��|�t
|d�d�d�|�|d�dd�|�|d�dd�|�|d�d|d��Wd�n1�sN0YdS)N)	r>rKrLr3rNrWrMr�r�)r#r�r�rr�rMr�r%��l�9V�rZ40E9z2.0E+5r)rr�i�r�z0.0025)rgr�r&r
r�rTr�r�r�r�r�r�rRr�)r�ZMaxContextSkipr�r&r
Z
maxcontextrrr�test_maxcontext_exact_arith�s$z%CWhitebox.test_maxcontext_exact_arithN)!r�r�r�r�r
rrrrrr	rrrr r"r#r$r'r(r-r0r1r2r6r@r��skipIfr�rr�rrDrrrrr
�sDe
*&
;,

%0��r
ztest requires C versionc@s eZdZdZdd�Zdd�ZdS)�
SignatureTestzFunction signaturesc
Cs�tt�D]�}|�d�rqtt|�}tt|�}|dksF|dksFt�|�rt�|�}t�|�}t|j	�
��}dd�|j	�
�D�}|j||d|d�dd�|j	��D�}d	d�|j	�
�D�}	|d
kr|j||	d|d�qdS)Nr�r�r&cSsg|]}|�d�s|�qS)r�r�r�rrrr��s
�z5SignatureTest.test_inspect_module.<locals>.<listcomp>�parameter name mismatch in %s��msgcSsg|]
}|j�qSr��kindr�rrrr��rcSs$g|]}|d�d�s|dj�qS)rr�r�)r�rKr�rrrr��s�r+�parameter kind mismatch in %s)r�r�r�rrg�inspect�
isfunction�	signaturer?�
parametersr
r�r*rO)
r�r �p_func�c_func�p_sig�c_sig�c_names�p_names�c_kind�p_kindrrr�test_inspect_module�s*


�

��z!SignatureTest.test_inspect_modulecstjj�tjj�tt�d�t�d�t�d�t�d�t�d�t�d�t�d�t�d�t�d�t�d�ddtjt��d�tt�d�t�d�t�d�t�d�t�d�t�d�t�d�ddtjt��d�i����fdd��dd	�������fd
d�}|d�|d
�dS)Nr�r#r;)r`r�r�r	r�r&rErr�rB�numr�r$r)r`r�r&rErr�rBrZr�r$rcspg}i}|j��D]T\}}|dkr$q|j�krB|��||�q|j�kr^�||||<qtd��q||fS)Nr�zunexpected parameter kind)rPrOrKr�r)�moduler#r��kwargs�nameZparam)�POS�POS_KWD�pdictrr�mkargs�s



z0SignatureTest.test_inspect_types.<locals>.mkargscSs(|dkrdS|dkrdS|dkr$dS|S)zwThe C Context docstrings use 'x' in order to prevent confusion
               with the article 'a' in the descriptions.r�r&r	rEr�rr)rrrr�tr�sz,SignatureTest.test_inspect_types.<locals>.trc	s�tt|�}tt|�}t|�D�]�}|�d�r.qt||�}t||�}t�|�rt�|�}t�|�}t|j	�
��}�fdd�|j	�
�D�}	�j|	|d|d�dd�|j	��D�}
dd�|j	��D�}��
|
d����
|d��|d	k�r�j|d
d�|
d
d�d|d�n�jt|�t|
�d|d��t|�\}}
zt|d�|�|i|
��Wn&t�y~td
|||
f��Yn0�t|�\}}
zt|d�|�|i|
��Wqt�y�td
|||
f��Yq0qdS)Nr�csg|]}�|��qSrrr�)rbrrr�rzBSignatureTest.test_inspect_types.<locals>.doit.<locals>.<listcomp>rGrHcSsg|]
}|j�qSrrJr�rrrr�rcSsg|]
}|j�qSrrJr�rrrr�rrr�r�rLr"zinvalid signature for %s: %s %s)rr�rgr�r�rMrNrOr?rPr
r�r*r+r�r�r)�tyZp_typeZc_typer rQrRrSrTrVrUrXrWr��kwds)r^r_rar�rbrrr�sH







�
��z.SignatureTest.test_inspect_types.<locals>.doitr�r&)	rMZ_ParameterKindZPOSITIONAL_ONLYZPOSITIONAL_OR_KEYWORDrgr�rtrHr�)r�r�r)r^r_rar`r�rbr�test_inspect_types�sF
�
��
/z SignatureTest.test_inspect_typesN)r�r�r�r�rYrerrrrrF�srFr�r�c
Cs�tt�tt�|dur|ntd�a|a|dur6t}nttg}t	�
t�D]l}d|vsH|�d�r`qH|�
d�\}}|dur�||vr�qH|fdd�}ttd||�ttd||�~~~~qHz�t|�|du�rdd	lm}	tjd}
tr�ttjd<tt||	d
�ttjd<tt|�|
tjd<Wt�r0t�tt�t�tt�t�sPt�dt�ttjdu�r�td��nNt�r~t�tt�t�tt�t�s�t�dt�ttjdu�r�td��0dS)
z� Execute the tests.

    Runs all arithmetic tests if arith is True or if the "decimal" resource
    is enabled in regrtest.py
    Nrz.decTestr�cSs|�t|�Sr)r��	directory)r�r�rrrr�jrztest_main.<locals>.<lambda>Ztest_r)�IGNORE_EXCEPTION_DETAIL)Zoptionflagsz*C tests skipped: no module named _decimal.zGInternal error: unbalanced number of changes to sys.modules['decimal'].)r-rgr�rr�r��	all_testsr�r��os�listdirrfr�r�r�r�doctestrgr�r�rr+�ORIGINAL_CONTEXT�warnings�warn�UserWarning�orig_sys_decimalr)�arith�verbose�
todo_tests�debugZtest_classes�filename�head�tailZtesterrgr�rrr�	test_mainOsX





�
��rxz: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)rqrr)rqrrrsrt)NNNN)�r�r�rir�rrmr�rZr�r�r�Ztest.supportrrrrrrrr	r
rrr�rMr0rrgr�rrpZ
cfractionsr�Z
pfractionsrr�rHr�r
r*rxr}r{r~rr|rzryr�r�r!rurqrprrrtrsr'rvrrlr-ZTESTDATADIRr��argvr��__file__�path�dirname�curdirZtestdir�seprf�isdirr�r��hasattrZEXTRA_FUNCTIONALITYZ
skipUnlessr	rEZskip_if_extra_functionalityZTestCaser0r�r�r�rSrTrUr�r�r�r�r�r�rrr$r)r*r5r6r7r�r�r�rrrrSrTrUrlrmrnr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r
rFrh�insertrxZoptparseZOptionParserrZ
add_option�
parse_args�optr��skiprtrrrr�<module>
s�4



������	�
��eWM)',-/Xm~
P>mU

	�
7



Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists