HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/test/__pycache__/test_struct.cpython-310.opt-2.pyc
o

�i�@s�ddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
ddlmZejdkZdZdZefd	d
�Zdd�Zd
d�ZGdd�dej�ZGdd�dej�Zedkrke��dSdS)�)�abcN)�support)�
import_helper)�assert_python_ok�big)�b�B�h�H�i�I�l�L�q�Q�n�N)��@�=�<�>�!ccs6�tD]}|D]}|dvr|dvrq||fVqqdS)N�rr)rr)�
integer_codes)�
byteorders�code�	byteorder�r�-/usr/local/lib/python3.10/test/test_struct.py�iter_integer_formatss���r cCs|ddd�S)N���r)�srrr�string_reversesr#cCstr|St|�S�N)�ISBIGENDIANr#)�valuerrr�bigendian_to_nativesr'c@seZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zejd'd(��Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zejd7d8��Z d9d:�Z!d;S)<�
StructTestcCs |�t�dd�ddkt�dS)Nz=i�r)�assertEqual�struct�packr%��selfrrr�test_isbigendian%s zStructTest.test_isbigendiancCs|�tjtjd�t�d�}|�|dt�d��d}d}t�|�}t�|�}|�|d|�|�tjtjdd�|�tjtjdddd�|�ttjftjdd�|�ttjftjdd�|�tjtjd	d
�t�ddd
�}|�tjtjd|�|�tjtjd|�dS)N�Zr�Ziiizcbxxxxxxhhhhiillffd?z3c3b18x12h6i6l6f3d3?Zfoo�P�dsflap�iir)�)�assertRaisesr+�error�calcsizer*r,�	TypeError�unpack)r.Zsz�fmtZfmt3Zsz3r"rrr�test_consistence(s 


zStructTest.test_consistencec
Cs�d}d}d}d}d}d}d}d}dD]f}	d	D]a}
|	|
}
t�|
||||||||�	}t�|
|�\}}
}}}}}}|�||�|�|
|�|�||�|�||�|�||�|�td
|�td
|��|�td
|�td
|��|�||�qqdS)N�ar)�i��igo���!	@T)rrrrrr)z	xcbhilfd?z	xcBHILfd?�d)r+r,r:r*�int)r.�crr	rr
�fr3�t�prefix�formatr"ZcpZbpZhpZipZlp�fpZdp�tprrr�test_transitiveness=s.��zStructTest.test_transitivenesscCs@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"gd#d#d$f�d%�}|D]N\}}}}}d&||fd'||fd(||fd)|trl|pm|ffD],\}}t�||�}	|�|	|�|�t�|�t|	��t�||	�d*}
|
|kr�|�|�qpqOdS)+N)rAr=r=r=r)Zxcr=�arIr)Zcxr=�arJr)r"r=r=r=r)�0s�
helloworld�rMr))Z1srL�hrNr))Z9srL�	helloworlrOr))Z10srLrLrLr)Z11srL�helloworldrPr))Z20srL�helloworldrQr))r��rSr)ri������rTr)rrRrSrSr)r�rTrTr)r	�����r)r	iD�����D�D�r)r
rVrWrXr)r
iD�rYrZr)r�,�,���,r)r�����������r)rr[r\r]r)r��b�wr_r`r)r
r[r\r]r)r
r^r_r`r)rr[r\r]r)rrar_r`r)rB�@s@s@r)r3rbs@s@r)rB��s�s�r)r3rcs�s�r)�?r�rer)rdr1�rfr))rdTrfrfrrdrer))rd)r)rfrfr)rrrrr)r%r+r,r*r8�lenr:�
assertTrue)r.Ztestsr;�argrZlilZasyZxfmt�exp�resZrevrrr�test_new_featuresUs���������	�
���
������������������!�"�#�$�%�(�
���zStructTest.test_new_featuresc
CsZddddddddddd�
}td�D]\}}||}t�|�}|�|||�qd}|D]}dD]}t�||d	�}t�||d�}	|�||	�q/q+|�t�d
�d�|�dt�d��|�dt�d��|�t�d�t�d
��|�t�d
�t�d��|�dt�d��|�t�d�t�d��|�t�d�t�d
��|�t�d�t�d��dS)Nr)r5��)
rrr	r
rrr
rrr�rrrr)ZbBZhHZiIZlL�nNZqQrrrr	r
rrrr2)r r+r8r*ZassertLessEqual�assertGreaterEqual)
r.Z
expected_sizerrrE�sizeZnative_pairsZformat_pairZsigned_sizeZ
unsigned_sizerrr�
test_calcsize�s4�	
�zStructTest.test_calcsizecsNddl�G���fdd�dtj��t�D]\}}||����}|��qdS)Nrcs@eZdZ��fdd�Zejej�jfdd�Z�fdd�Z	�Z
S)z+StructTest.test_integers.<locals>.IntTestercs�t�|�jdd�||_|d|_|dd�|_|jtvr$td|j��t�|�|_	|j	d|_
|jtd�vrOd|_d|j
d	|_
d|j
d	d	|_dS|jtd
�vrfd|_d|_
d|j
d	|_dStd
|j��)N�test_one)Z
methodNamer!z"unrecognized packing byteorder: %srnZbhilqnTr5r)ZBHILQNFrzunrecognized format code: %s)�super�__init__rErrr�
ValueErrorr+r8�bytesize�bitsize�tuple�signed�	min_value�	max_value)r.rE)�	IntTester�	__class__rrrv�s*

��z4StructTest.test_integers.<locals>.IntTester.__init__c	Ss.|j}|j|kr|jkr�nnx|}|jr!|dkr!|d|j>7}|�|d�d|}t|�d@r5d|}|�d�}||�}d|jt|�|}|j	dksU|j	dvrYt
sYt|�}|�t|�|j�|||�}|�||�|||�d}|�||�|�
tjtf||d	|�dS|�
tttjf|||�dS)
Nrr)z%x�0�asciirer)rrrrf)rEr|r}r{ryrqrg�encoderxrr%r#r*r6r+r7r9�
OverflowErrorrw)	r.�xr,r:�	unhexlifyrE�expected�gotZ	retrievedrrrrt�s8
�

��z4StructTest.test_integers.<locals>.IntTester.test_onecsddlm}g}t|jd�D]	}|�d|>�qt|j�D]}d}t|j�D]
}|d>|d�B}q'|�|�q|�ddtjd	g�|D]}||fD]}d
D]}||}	|�	|	�qPqLqEGdd�d�}
Gd
d�dt
�}Gdd�dt
�}|�tt
jft
j|jd�|�tt
jft
j|j|�|�tt
jft
j|jd�|�tt
jft
j|j|
��|�tt
jft
j|j|��|d�|d�|d�|d�|d�|d�fD]}
zt
��|
�Wq�|�d�Yq�|d�|d�|d�|ddi�|gd��fD]}
|�tt
jft
j|j|
�q�dS)Nr)�	randranger1r)rn�i,i`�
rm)r!rr)c@�eZdZdd�ZdS)zAStructTest.test_integers.<locals>.IntTester.run.<locals>.NotAnIntcS�dS�N�*rr-rrr�__int__�zIStructTest.test_integers.<locals>.IntTester.run.<locals>.NotAnInt.__int__N)�__name__�
__module__�__qualname__r�rrrr�NotAnInt
�r�c@�eZdZdd�Zdd�ZdS)zBStructTest.test_integers.<locals>.IntTester.run.<locals>.IndexablecSs
||_dSr$��_value)r.r&rrrrvs
zKStructTest.test_integers.<locals>.IntTester.run.<locals>.Indexable.__init__cSs|jSr$r�r-rrr�	__index__szLStructTest.test_integers.<locals>.IntTester.run.<locals>.Indexable.__index__N)r�r�r�rvr�rrrr�	Indexable�r�c@r�)zAStructTest.test_integers.<locals>.IntTester.run.<locals>.BadIndexcS�t�r$)r9r-rrrr�r�zKStructTest.test_integers.<locals>.IntTester.run.<locals>.BadIndex.__index__cSr�r�rr-rrrr�r�zIStructTest.test_integers.<locals>.IntTester.run.<locals>.BadIndex.__int__N)r�r�r�r�r�rrrr�BadIndexr�r�za stringy@E@�
�r�r?�z:integer code pack failed on object with '__index__' methodr=r�a)r)r5r1)�randomr��rangery�appendrx�extend�sys�maxsizert�objectr6r9r+r7r,rE�fail)r.r��valuesrjr�val�j�baseZincrr�r�r�r��obj)rErr�run�sn��	���������z/StructTest.test_integers.<locals>.IntTester.run)r�r�r�rvr+r,r:r�rtr��
__classcell__r�r~�binasciirE)rrr~�s
�&r~)r��unittest�TestCaser r�)r.rrrCrr�r�
test_integers�s
�zStructTest.test_integerscsT�fdd�}dD]}dD]}||}|tj|�|tj|d�|tj|d�qqdS)NcsP��tj��}||i|��Wd�n1swY��dt|j��dS)Nzbad char in struct format)r6r+r7�assertIn�str�	exception)�func�args�kwargs�cmr-rr�assertStructErrorHs�z2StructTest.test_nN_code.<locals>.assertStructErrorrprorrM)r+r8r,r:)r.r�rrrErr-r�test_nN_codeFs��zStructTest.test_nN_codecCsHdD]\}}}}t�||�}|�||�t�||�\}|�||�qdS)N))�p�abcrerM)Z1pr�rerM)Z2pr�sar=)Z3pr�sabsab)Z4pr�sabcr�)Z5pr�sabcr�)Z6pr�sabcr�)Z1000ps�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)r+r,r*r:)r.r�inputr�Zexpectedbackr�rrr�test_p_codeSs	�zStructTest.test_p_codecCstdd�D]L}d}||d|kr|d}||d|ks||}t�d|�}t�d|�d}|�||�t�d|�}|�|t|��t�d|�d}|�||�qd}t�|d	�}t�d|�}t�d|�d}|�||�d
}t�|d�}|�t	tjd|�dS)Nr)�!g�?rbz<frz>fi����hi����g)
r�r+r,r:r*r#�math�ldexpr6r�)r.r�ZdeltaZsmaller�packedZunpackedZ	bigpackedrrrr�test_705836cs*�zStructTest.test_705836cCslt�D]\}}||}|�tjtj|d�|�tjtj|d�q|�tjtjdd�|�tjtjdd�dS)N��?g�?r2)r r6r+r7r,)r.rrrErrr�test_1530559�szStructTest.test_1530559c	Cs�d}d}t�|�}ttfD]Q}||�}|�|�|�d�|�|�|d�d�|�|�|d�d�td�D]}|�|�||�|||d�f�q4tdt|�d	�D]}|�tj	|j||�qQq
ttfD]V}||�}|�t�||�d�|�t�||d�d�|�t�||d�d�td�D]}|�t�|||�|||d�f�q�tdt|�d	�D]
}|�tj	tj|||�q�qc|�|j|dd
�d�dS)Ns	abcd01234Z4s)sabcdr5)scd01rm)s0123�r))�buffer�offset)
r+�Struct�bytes�	bytearrayr*�unpack_fromr�rgr6r7)r.�test_stringr;r"�cls�datarrrr�test_unpack_from�s4
$�&��zStructTest.test_unpack_fromcCs�d}t�dd�}d}t�|�}|�|d|�|��dt|��}|�||�|�|d|�|��dt|�d�}|�||dd�|�t�dd�}|�ttj	f|j|d|�|�ttj	f|j|d|�|}|�t
tj	ftjd	|d�dS)
N�Reykjavik rocks, eow!r�d                                                                                                    �21srr��
          r5rM)�arrayr+r��	pack_into�tobytesrgr*r6rwr7r9)r.r��writable_bufr;r"�from_buf�	small_bufZsbrrr�test_pack_into�s*
���zStructTest.test_pack_intocs�d}t�dd�}d��fdd�}||d|�|��dt|��}|�||�||d|�|��dt|�d�}|�||dd�|�t�dd	�}|�ttjf||d|�|�ttjf||d
|�dS)Nr�rr�r�cstj�g|�R�Sr$)r+r�)r��r;rr�<lambda>�sz.StructTest.test_pack_into_fn.<locals>.<lambda>rr�r�r5)r�r�rgr*r6rwr+r7)r.r�r�r�r�r�rr�r�test_pack_into_fn�s"��zStructTest.test_pack_into_fncCs@t�dd�}td�}||fD]}t�d|�\}|�|d�qdS)Nrs4Vxz>IixV4)r��
memoryviewr+r:r*)r.Zdata1Zdata2r�r&rrr�test_unpack_with_buffer�s�z"StructTest.test_unpack_with_bufferc	Cs�Gdd�dt�}td�dD]�}dggddf}dgd	d
ddd
f}|dt|�}tj|g|�R�}t�||�}|dt|�}tj|g|�R�}	t�||	�}
|�t|�t|
��|�t|�t|��|D]}|�|�qd|
D]}|�|�qnt�|dd�}|�t|�t�	|d��t|�dkr�|j|d|d�zt�|d|��Wn	t
y�Yqw|�d|d�qdD]
}
|�t�d|
�d�q�dS)Nc@r�)z+StructTest.test_bool.<locals>.ExplodingBoolcSr�r$)�OSErrorr-rrr�__bool__�r�z4StructTest.test_bool.<locals>.ExplodingBool.__bool__N)r�r�r�r�rrrr�
ExplodingBool�r�r�z<>!=)rrrrr)�test�r!lg���Ardz encoded bool is not one byte: %r)�msgz2Expected OSError: struct.pack(%r, ExplodingBool()))rf������z>?)r�rzrgr+r,r:r*ZassertFalserhr8r�r�)r.r�rDZfalse�trueZfalseFormatZpackedFalseZ
unpackedFalseZ
trueFormatZ
packedTrueZunpackedTruerCr�rArrr�	test_bool�sB����zStructTest.test_boolcCsPd�tjd�}|�tjtj|�d�tjdtjd�}|�tjtj|�dS)Nz{}br)z{}b{}Hr5)rEr�r�r6r+r7r8)r.Z	hugecountZ
hugecount2rrr�test_count_overflow
szStructTest.test_count_overflowcCst�dd�}|�tjtjd�|�tjtjdd�|�tjtjd|d�|�tjtjd|d�|�tjtjdd�|�tjtjdd�|�tjtjd|dd�|�tjtjd|d�|�tjtjd	d
�|�tjtjd	d�|�tjtjd	|dd
�|�tjtjd	|d�dS)Nrr�Z12345rMrZc12345r��xZ14s42z
spam and eggss
spam and eggs)r�r6r+r7r,r:r�r�)r.�storerrr�test_trailing_counters*����z StructTest.test_trailing_countercCst�d�}|�d�dS)Nrr4)r+r�rv�r.r"rrr�test_Struct_reinitialization-s
z'StructTest.test_Struct_reinitializationcCs8t�d�}|t�d�|d7}t�|t�|�|�dS)NZ2n3PZP3n0Pr))rZcalcobjsizer+r8�check_sizeofr�)r.Z
format_strZnumber_of_codesZ	totalsizerrrr�4s
zStructTest.check_sizeofcCs�tD]}|�|d�q|�dd�|�dd�|�dd�|�dd	�|�d
d�|�dd�|�dd�|�d
d�|�dd	�dS)Nr)Z	BHILfdspP�	A�BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB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BBBBBBBi��fdr5ZxxxxxxxxxxxxxxrZ100HZ187sZ20prKZ0c)rr�)r.rrrr�test__sizeof__;szStructTest.test__sizeof__cCs�d}|�tj|��t�dtd�dd�Wd�n1swYd}|�tj|��t�dtd�d�Wd�dS1sAwYdS)Nzkpack_into requires a buffer of at least 6 bytes for packing 1 bytes at offset 5 \(actual buffer size is 1\)rr)r�zounpack_from requires a buffer of at least 6 bytes for unpacking 1 bytes at offset 5 \(actual buffer size is 1\))�assertRaisesRegexr+r7r�r�r��r.Zregex1Zregex2rrr�test_boundary_error_messageIs���"�z&StructTest.test_boundary_error_messagecCstd�}|�tjd��t�d|dd�Wd�n1swY|�tjd��t�d|dd�Wd�n1s=wY|�tjd	��t�d|d�Wd�n1s[wY|�tjd��t�d|d�Wd�dS1szwYdS)
Nr�z%no space to pack 4 bytes at offset -2�<I����{z*offset -11 out of range for 10-byte bufferz<Bi����z.not enough data to unpack 4 bytes at offset -2)r�r�r+r7r�r�)r.Z	byte_listrrr�0test_boundary_error_message_with_negative_offsetZs2�������"�z;StructTest.test_boundary_error_message_with_negative_offsetcCs�dttjd�dttj�d}|�tj|��t�dtd�tjd�Wd�n1s/wYdttjd�d	ttj�d}|�tj|��t�dtd�tj�Wd�dS1scwYdS)
Nz(pack_into requires a buffer of at least rmz% bytes for packing 4 bytes at offset z \(actual buffer size is 10\)r�r�r)z*unpack_from requires a buffer of at least z' bytes for unpacking 4 bytes at offset )	r�r�r�r�r+r7r�r�r�r�rrr�-test_boundary_error_message_with_large_offsetps,���������"�z8StructTest.test_boundary_error_message_with_large_offsetcCsN|�t��t�dd�Wd�n1swY|�t�dd�d�dS)Nrrr=)�a)r6r9r+r:r*r-rrr�test_issue29802�s�zStructTest.test_issue29802cCs<t�d�}|�|jd�t�|j���}|�|j|j�dS)Nz=i2H)r+r�r*rEr�)r.r"�s2rrr�test_format_attr�s
zStructTest.test_format_attrcCsLd}td|�\}}}|�|d�|�|��d�|�d|�|�d|�dS)Nz�if 1:
            import struct

            class C:
                def __init__(self):
                    self.pack = struct.pack
                def __del__(self):
                    self.pack('I', -42)

            struct.x = C()
            z-crrMsException ignored in:s	C.__del__)rr*�rstripr�)r.r�rc�stdout�stderrrrr�)test_struct_cleans_up_at_runtime_shutdown�sz4StructTest.test_struct_cleans_up_at_runtime_shutdowncCs:t�d�}t�|�}|�d�~t��|�|�d�dS)N�_structrz(_struct module was not garbage collected)rZimport_fresh_module�weakref�refr8�gcZcollectZassertIsNone)r.Z_struct_moduleZ
module_refrrr�'test__struct_reference_cycle_cleaned_up�s


�z2StructTest.test__struct_reference_cycle_cleaned_upc
Cs�tj}tt�dd��}||fD]0}|j|d�� |�t��d|_Wd�n1s+wYWd�n1s:wYqdS)Nrr�)r�r))r+r��type�iter_unpackZsubTestr6r9r�)r.r�Zunpack_iteratorr�rrr�test__struct_types_immutable�s�����z'StructTest.test__struct_types_immutablec	CsFdD]}|�tjd��
t�|�Wd�n1swYqdS)N)�z2irezembedded null character)r�r+r7r8r�rrr�test_issue35714�s����zStructTest.test_issue35714N)"r�r�r�r/r<rHrlrsr�r�r�r�r�r�r�r�r�r�r�r�r�r�rZcpython_onlyr�r�rrrrrrrrrrrrr($sB5"
!+

	
r(c@sFeZdZ	dd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�UnpackIteratorTestcs"�fdd�}t�d�}|�d�}||�|�d�}||���tj��
|�d�Wd�n1s3wY��tj��
|�d�Wd�n1sNwYt�d�}��tj��
|�d�Wd�n1snwY��tj��|�d	�Wd�dS1s�wYdS)
Ncs ��|tj���|tj�dSr$)ZassertIsInstancer�Iterator�Iterable)�itr-rr�_check_iterator�sz:UnpackIteratorTest.test_construct.<locals>._check_iterator�>ibcprMs1234567s123456s12345678rs12)r+r�rr6r7)r.rr"rrr-r�test_construct�s&


��
�"�z!UnpackIteratorTest.test_constructcCs$tt�d��d��}|�t|�dS)NrrM)rr+r�rr6r9)r.Ziter_unpack_typerrr�test_uninstantiable�sz&UnpackIteratorTest.test_uninstantiablecCsrt�d�}ttdd��}|�|�}|�t|�d�|�t|�d�|�t|�d�|�tt|�|�tt|�dS)N�>IBr)��ir��i	r�)i
�)	r+r�r�r�rr*�nextr6�
StopIteration�r.r"rrrrr�test_iterate�s

zUnpackIteratorTest.test_iteratecCsft�d�}ttdd��}|�t|��}|�t|�d�|�t|�d�|�t	t|�|�t	t|�dS�Nrr)�r!r")
r+r�r�r�rr�r*r$r6r%r&rrr�test_arbitrary_buffer�s
z(UnpackIteratorTest.test_arbitrary_buffercCs�tj}t�d�}ttdd��}|�|�}|�||�d�t|�|�||�d�t|�|�||�d�t|�|�||�d�|�	t
t|�|�||�d�dS)Nrr)r r1r5r)�operator�length_hintr+r�r�r�rr*r$r6r%)r.Zlhr"rrrrr�test_length_hint�s

z#UnpackIteratorTest.test_length_hintcCsVt�dttdd���}|�t|�d�|�t|�d�|�tt|�|�tt|�dSr()r+rr�r�r*r$r6r%)r.rrrr�test_module_funcs
z#UnpackIteratorTest.test_module_funccCs ddddddddtd	�fd
td�fdg
}|D]i\}}|ddd
�}|�|t�d|�d�|�|t�d|��|�|t�d|�d�|�|t�d|��tjdkri|�|t�d|�d�|�|t�d|��q|�|t�d|�d�|�|t�d|��qgd�}|D]%\}}|�t�	t�d|�d��|�t�	t�d|ddd
��d��q�t�dtj
�}|�|dd@d�t�dtj
�}|�|dd@d�gd�}	|	D]\}}}|�|t�||��q�gd�}
|
D]
\}}|�ttj||�q�dg}|D]\}}}|�|t�||��q�dS)N)s<r�)s�rc)s�{g��@)s�?)sgp>)�g)s�g�s|z+infs�z-inf)sU5gT�?r!�<er�>e�little�e))r1s�)r1s�)r1s��)r1s|)r1s~)r1s�r)�~))r2sg`>)r2r0g`>)r2r0gP>)r2��g�?)r2r6g������?)r2�g�?)r2r7r/)r2s<g�?)r2�<g�?)r2r8g�?)r2�{�i�)r2r9i�)r2s�g`�)r2��g`�)r2r:gP�)r2s�g�)r2��g�)r2r;g�)r2s��i��))r2���@)r2��@)r2�u�<�7~)r2���)r2��)r2�u�<�7�)r1r<)r1r=)r1r>)r1r?)r1r@)r1rA)r2sg�g�����@)
�floatr*r+r:r,r�rrhr��isnan�nanr6r�)r.Z&format_bits_float__cleanRoundtrip_listZle_bitsrBZbe_bitsZformat_bits__nan_listZ
formatcode�bitsr�Z format_bits_float__rounding_listZ%format_bits_float__roundingError_listZ+format_bits_float__doubleRoundingError_listrrr�test_half_floatsR

�

	(��z"UnpackIteratorTest.test_half_floatN)
r�r�r�rrr'r*r-r.rFrrrrr�s
	r�__main__)�collectionsrr�rr�r+r�r+r�rr�rZtest.supportrZtest.support.script_helperrrr%rrr r#r'r�r(rr��mainrrrr�<module>s:
)2�