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.7/test/__pycache__/test_struct.cpython-37.opt-2.pyc
B

��g���@s�ddlmZddlZddlZddlZddlZddlZddlZddlm	Z	ej
dkZdZdZ
e
fdd�Zd	d
�Zdd�ZGd
d�dej�ZGdd�dej�Zedkr�e��dS)�)�abcN)�support�big)�b�B�h�H�i�I�l�L�q�Q�n�N)��@�=�<�>�!ccs<x6tD].}x(|D] }|dkr&|dkr&q||fVqWqWdS)N)rr)rr)�
integer_codes)�
byteorders�code�	byteorder�r�,/usr/local/lib/python3.7/test/test_struct.py�iter_integer_formatss


rcCs|ddd�S)N���r)�srrr�string_reversesr cCstr|St|�SdS)N)�ISBIGENDIANr )�valuerrr�bigendian_to_nativesr#c@s�eZdZdd�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�Zd5S)6�
StructTestcCs |�t�dd�ddkt�dS)Nz=i�r)�assertEqual�struct�packr!)�selfrrr�test_isbigendian!szStructTest.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�fmtZfmt3Zsz3rrrr�test_consistence$s 


zStructTest.test_consistencec
Cs�d}d}d}d}d}d}d}d}x�dD]�}	x�d	D]�}
|	|
}
t�|
||||||||�	}t�|
|�\}}
}}}}}}|�||�|�|
|�|�||�|�||�|�||�|�td
|�td
|��|�td
|�td
|��|�||�q0Wq&WdS)N�ar%�i��igo���!	@T)rrrrrr)z	xcbhilfd?z	xcBHILfd?�d)r'r(r5r&�int)r)�crrr	r�fr.�t�prefix�formatrZcpZbpZhpZipZlp�fpZdp�tprrr�test_transitiveness9s*

zStructTest.test_transitivenessc&Csddddddddd	d
ddd
ddddddddddddddddddd d!d"gd#d#d$fd%g#}x�|D]�\}}}}}x�d&||fd'||fd(||fd)|tr�|p�|fgD]X\}}t�||�}	|�|	|�|�t�|�t|	��t�||	�d*}
|
|kr�|�|�q�WqZWdS)+N)r<r8r8r8r)Zxcr8sasar)Zcxr8sasar)rr8r8r8r)�0ss
helloworld�rEr%)Z1ss
helloworld�hrFr%)Z9ss
helloworlds	helloworls	helloworlr%)Z10ss
helloworlds
helloworlds
helloworldr)Z11ss
helloworldshelloworldshelloworldr%)Z20ss
helloworldshelloworldshelloworldr%)r��rHr)ri������rIr)rrGrHrHr)r�rIrIr)ri�s�s�r)riD���s�DsD�r)ri�s�s�r)riD�s�DsD�r)r	i�,s,�s�,r)r	i���s���s���r)r
i�,s,�s�,r)r
l�b�ws���s���r)ri�,s,�s�,r)ri���s���s���r)ri�,s,�s�,r)rl�b�ws���s���r)r=g@s@s@r)r.g@s@s@r)r=g�s�s�r)r.g�s�s�r)�?r�rLr)rKr,�rMr%)rKTrMrMrrKrLr%)rK)r%rMrMr%rrrrr)r!r'r(r&r3�lenr5�
assertTrue)r)Ztestsr6�argrZlilZasyZxfmt�expZresZrevrrr�test_new_featuresQsX zStructTest.test_new_featuresc
Csfddddddddddd�
}x6td�D]*\}}||}t�|�}|�|||�q$Wd}xJ|D]B}x<dD]4}t�||d	�}t�||d�}	|�||	�qfWq\W|�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%r0��)
rrrrr	r
rrr
r)rrrr)ZbBZhHZiIZlL�nNZqQ)rrrrrrr	r
rr-)rr'r3r&ZassertLessEqual�assertGreaterEqual)
r)Z
expected_sizerrr@�sizeZnative_pairsZformat_pairZsigned_sizeZ
unsigned_sizerrr�
test_calcsize�s0



zStructTest.test_calcsizecsRddl�G���fdd�dtj��x*t�D] \}}||����}|��q*WdS)Nrcs@eZdZ��fdd�Zejej�jfdd�Z�fdd�Z	�Z
S)z+StructTest.test_integers.<locals>.IntTestercs�t�|�jdd�||_|d|_|dd�|_|jtkrHtd|j��t�|�|_	|j	d|_
|jtd�kr�d|_d|j
d	|_
d|j
d	d	|_n:|jtd
�kr�d|_d|_
d|j
d	|_ntd
|j��dS)N�test_one)Z
methodNamerz"unrecognized packing byteorder: %srTZbhilqnTr0r%ZBHILQNFrzunrecognized format code: %s)�super�__init__r@rrr�
ValueErrorr'r3�bytesize�bitsize�tuple�signed�	min_value�	max_value)r)r@)�	IntTester�	__class__rrr[�s&


z4StructTest.test_integers.<locals>.IntTester.__init__c	Ss.|j}|j|kr |jk�rnn�|}|jrD|dkrD|d|j>7}|�|d�d|}t|�d@rld|}|�d�}||�}d|jt|�|}|j	dks�|j	dkr�t
s�t|�}|�t|�|j�|||�}|�||�|||�d}|�||�|�
tjtf||d	|�n|�
tttjf|||�dS)
Nrr%z%x�0�asciirLr)rrrrM)r@rarbr`r^rVrN�encoder]rr!r r&r1r'r2r4�
OverflowErrorr\)	r)�xr(r5�	unhexlifyr@�expected�gotZ	retrievedrrrrY�s2


z4StructTest.test_integers.<locals>.IntTester.test_onecs:ddlm}g}x$t|jd�D]}|�d|>�q WxDt|j�D]6}d}x"t|j�D]}|d>|d�B}qVW|�|�qBW|�ddtjd	g�x@|D]8}x2||fD]$}xd
D]}||}	|�	|	�q�Wq�Wq�WGdd�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|��xZ|d�|d�|d�|d�|d�|d�fD].}
yt
��|
�Wn|�d�YnX�q�WxP|d�|d�|d�|ddi�|dddg�fD] }
|�tt
jft
j|j|
��qWdS)Nr)�	randranger,r%rT�i,i`�
rS)rrr%c@seZdZdd�ZdS)zAStructTest.test_integers.<locals>.IntTester.run.<locals>.NotAnIntcSsdS)N�*r)r)rrr�__int__szIStructTest.test_integers.<locals>.IntTester.run.<locals>.NotAnInt.__int__N)�__name__�
__module__�__qualname__rprrrr�NotAnIntsrtc@seZdZdd�Zdd�ZdS)zBStructTest.test_integers.<locals>.IntTester.run.<locals>.IndexablecSs
||_dS)N)�_value)r)r"rrrr[szKStructTest.test_integers.<locals>.IntTester.run.<locals>.Indexable.__init__cSs|jS)N)ru)r)rrr�	__index__szLStructTest.test_integers.<locals>.IntTester.run.<locals>.Indexable.__index__N)rqrrrsr[rvrrrr�	Indexable
srwc@seZdZdd�Zdd�ZdS)zAStructTest.test_integers.<locals>.IntTester.run.<locals>.BadIndexcSst�dS)N)r4)r)rrrrvszKStructTest.test_integers.<locals>.IntTester.run.<locals>.BadIndex.__index__cSsdS)Nror)r)rrrrpszIStructTest.test_integers.<locals>.IntTester.run.<locals>.BadIndex.__int__N)rqrrrsrvrprrrr�BadIndexsrxza stringy@E@�
�ror:�z:integer code pack failed on object with '__index__' methodr8r�ar0)Zrandomrm�ranger^�appendr]�extend�sys�maxsizerY�objectr1r4r'r2r(r@�fail)r)rm�valuesrQr	�val�j�baseZincrrirtrwrx�obj)r@rr�run�sX

	z/StructTest.test_integers.<locals>.IntTester.run)rqrrrsr[r'r(r5rjrYr��
__classcell__r)rc�binasciir@)rdrrc�s
$rc)r��unittest�TestCaserr�)r)rrr>r)rcr�r@r�
test_integers�szStructTest.test_integerscs\�fdd�}xJdD]B}x<dD]4}||}|tj|�|tj|d�|tj|d�qWqWdS)Nc	s8��tj��}|||�WdQRX��dt|j��dS)Nzbad char in struct format)r1r'r2ZassertIn�strZ	exception)�func�args�kwargs�cm)r)rr�assertStructErrorDsz2StructTest.test_nN_code.<locals>.assertStructErrorrU)rrrrrrE)r'r3r(r5)r)r�rrr@r)r)r�test_nN_codeBs

zStructTest.test_nN_codecCsLxFdD]>\}}}}t�||�}|�||�t�||�\}|�||�qWdS)N))�psabcrLrE)Z1psabcrLrE)Z2psabcsar8)Z3psabcsabsab)Z4psabcsabcsabc)Z5psabcsabcsabc)Z6psabcsabcsabc)Z1000ps�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)r'r(r&r5)r)r�inputrkZexpectedbackrlrrr�test_p_codeOs
	zStructTest.test_p_codecCs�x�tdd�D]�}d}x||d|kr0|d}qW||}t�d|�}t�d|�d}|�||�t�d|�}|�|t|��t�d|�d}|�||�qWd}t�|d	�}t�d|�}t�d|�d}|�||�d
}t�|d�}|�t	tjd|�dS)Nr%�!g�?g@z<frz>fi����hi����g)
r}r'r(r5r&r �mathZldexpr1rh)r)r�ZdeltaZsmaller�packedZunpackedZ	bigpackedrrrr�test_705836_s(zStructTest.test_705836cCspxBt�D]8\}}||}|�tjtj|d�|�tjtj|d�qW|�tjtjdd�|�tjtjdd�dS)Ng�?g�?r-)rr1r'r2r()r)rrr@rrr�test_1530559�szStructTest.test_1530559c	Cs�d}d}t�|�}x�ttfD]�}||�}|�|�|�d�|�|�|d�d�|�|�|d�d�x2td�D]&}|�|�||�|||d�f�qlWx.tdt|�d	�D]}|�tj	|j||�q�WqWx�ttfD]�}||�}|�t�||�d�|�t�||d�d�|�t�||d�d�x6td�D]*}|�t�|||�|||d�f��q*Wx2tdt|�d	�D]}|�tj	tj|||��qlWq�W|�|j|dd
�d�dS)Ns	abcd01234Z4s)sabcdr0)scd01rS)s0123�r%)�buffer�offset)
r'�Struct�bytes�	bytearrayr&�unpack_fromr}rNr1r2)r)�test_stringr6r�cls�datar	rrr�test_unpack_from�s.
&* 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)
NsReykjavik rocks, eow!rsd                                                                                                    �21srrys
          r0rE)�arrayr'r��	pack_into�tobytesrNr&r1r\r2r4)r)r��writable_bufr6r�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)NsReykjavik rocks, eow!rsd                                                                                                    r�cstj�f|��S)N)r'r�)r�)r6rr�<lambda>�rEz.StructTest.test_pack_into_fn.<locals>.<lambda>rrys
          r0)r�r�rNr&r1r\r'r2)r)r�r�r�r�r�r)r6r�test_pack_into_fn�szStructTest.test_pack_into_fncCsDt�dd�}td�}x*||gD]}t�d|�\}|�|d�qWdS)Nrs4Vxz>IixV4)r��
memoryviewr'r5r&)r)Zdata1Zdata2r�r"rrr�test_unpack_with_buffer�s
z"StructTest.test_unpack_with_bufferc	Cs�Gdd�dt�}�xptd�dD�]^}dggddf}dgd	d
ddd
f}|dt|�}tj|f|��}t�||�}|dt|�}tj|f|��}	t�||	�}
|�t|�t|
��|�t|�t|��x|D]}|�|�q�Wx|
D]}|�|�q�Wt�|dd�}|�t|�t�	|d��t|�dk�r@|j|d|d�yt�|d|��Wnt
k
�rlYq X|�d|d�q Wx$dD]}
|�t�d|
�d��q�WdS)Nc@seZdZdd�ZdS)z+StructTest.test_bool.<locals>.ExplodingBoolcSst�dS)N)�OSError)r)rrr�__bool__�sz4StructTest.test_bool.<locals>.ExplodingBool.__bool__N)rqrrrsr�rrrr�
ExplodingBool�sr�z<>!=)rrrrr%�test�rlg���ArKz encoded bool is not one byte: %r)�msgz2Expected OSError: struct.pack(%r, ExplodingBool()))rM������z>?)r�r_rNr'r(r5r&ZassertFalserOr3r�r�)r)r�r?Zfalse�trueZfalseFormatZpackedFalseZ
unpackedFalseZ
trueFormatZ
packedTrueZunpackedTruer>r�r<rrr�	test_bool�s:



zStructTest.test_boolcCsPd�tjd�}|�tjtj|�d�tjdtjd�}|�tjtj|�dS)Nz{}br%z{}b{}Hr0)r@r�r�r1r'r2r3)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)Nrsd                                                                                                    Z12345rErZc12345ri�xZ14s42z
spam and eggss
spam and eggs)r�r1r'r2r(r5r�r�)r)�storerrr�test_trailing_counters"z StructTest.test_trailing_countercCst�d�}|�d�dS)Nr	r/)r'r�r[)r)rrrr�test_Struct_reinitialization)s
z'StructTest.test_Struct_reinitializationcCs8t�d�}|t�d�|d7}t�|t�|�|�dS)NZ2n3PZP3n0Pr%)rZcalcobjsizer'r3�check_sizeofr�)r)Z
format_strZnumber_of_codesZ	totalsizerrrr�0s
zStructTest.check_sizeofcCs�xtD]}|�|d�qW|�dd�|�dd�|�dd�|�dd	�|�d
d�|�dd�|�dd�|�d
d�|�dd	�dS)Nr%Z	BHILfdspP�	A�BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB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BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBi��fdr0ZxxxxxxxxxxxxxxrZ100HZ187sZ20prDZ0c)rr�)r)rrrr�test__sizeof__7s
zStructTest.test__sizeof__c	Cs6d}|�tj|��t�dtd�dd�WdQRXdS)Nzkpack_into requires a buffer of at least 6 bytes for packing 1 bytes at offset 5 \(actual buffer size is 1\)rr%r�)�assertRaisesRegexr'r2r�r�)r)�regexrrr�test_boundary_error_messageEsz&StructTest.test_boundary_error_messagec	Cs`td�}|�tjd��t�d|dd�WdQRX|�tjd��t�d|dd�WdQRXdS)	Nryz%no space to pack 4 bytes at offset -2z<I����{z*offset -11 out of range for 10-byte bufferz<Bi����)r�r�r'r2r�)r)Z	byte_listrrr�0test_boundary_error_message_with_negative_offsetNsz;StructTest.test_boundary_error_message_with_negative_offsetc	CsXdttjd�dttj�d}|�tj|��t�dtd�tjd�WdQRXdS)Nz(pack_into requires a buffer of at least rSz% bytes for packing 4 bytes at offset z \(actual buffer size is 10\)z<Iryr%)r�r�r�r�r'r2r�r�)r)r�rrr�-test_boundary_error_message_with_large_offsetZsz8StructTest.test_boundary_error_message_with_large_offsetc	Cs:|�t��t�dd�WdQRX|�t�dd�d�dS)Nrrr8)�a)r1r4r'r5r&)r)rrr�test_issue29802dszStructTest.test_issue29802cCs<t�d�}|�|jd�t�|j���}|�|j|j�dS)Nz=i2H)r'r�r&r@rg)r)r�s2rrr�test_format_attrms
zStructTest.test_format_attrc
Cs6x0dD](}|�tjd��t�|�WdQRXqWdS)N)�z2irLzembedded null character)r�r'r2r3)r)rrrr�test_issue35714us
zStructTest.test_issue35714N)rqrrrsr*r7rCrRrXr�r�r�r�r�r�r�r�r�r�r�r�r�r�rZcpython_onlyr�r�r�r�r�r�r�rrrrr$ s65"
!+	
	r$c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�UnpackIteratorTestc	s��fdd�}t�d�}|�d�}||�|�d�}||���tj��|�d�WdQRX��tj��|�d�WdQRXt�d�}��tj��|�d�WdQRX��tj��|�d	�WdQRXdS)
Ncs ��|tj���|tj�dS)N)ZassertIsInstancer�Iterator�Iterable)�it)r)rr�_check_iterator�sz:UnpackIteratorTest.test_construct.<locals>._check_iteratorz>ibcprEs1234567s123456s12345678rs12)r'r��iter_unpackr1r2)r)r�rr�r)r)r�test_construct�s



z!UnpackIteratorTest.test_constructcCsrt�d�}ttdd��}|�|�}|�t|�d�|�t|�d�|�t|�d�|�tt|�|�tt|�dS)Nz>IBr%�)ir�)i	ry)i
�)	r'r�r�r}r�r&�nextr1�
StopIteration)r)rrr�rrr�test_iterate�s

zUnpackIteratorTest.test_iteratecCsft�d�}ttdd��}|�t|��}|�t|�d�|�t|�d�|�t	t|�|�t	t|�dS)Nz>IBr%�)ir�)i	ry)
r'r�r�r}r�r�r&r�r1r�)r)rrr�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)Nz>IBr%r�r,r0r)�operator�length_hintr'r�r�r}r�r&r�r1r�)r)Zlhrrr�rrr�test_length_hint�s

z#UnpackIteratorTest.test_length_hintcCsVt�dttdd���}|�t|�d�|�t|�d�|�tt|�|�tt|�dS)Nz>IBr%r�)ir�)i	ry)r'r�r�r}r&r�r1r�)r)r�rrr�test_module_func�s
z#UnpackIteratorTest.test_module_funccCszddddddddtd	�fd
td�fdg
}x�|D]�\}}|ddd
�}|�|t�d|�d�|�|t�d|��|�|t�d|�d�|�|t�d|��tjdkr�|�|t�d|�d�|�|t�d|��q.|�|t�d|�d�|�|t�d|��q.Wddddddg}xT|D]L\}}|�t�	t�d|�d��|�t�	t�d|ddd
��d���qWt�dtj
�}|�|dd@d�t�dtj
�}|�|dd@d�dddddd d!d"d#d$d%d&d'd(d)d*d+d,d-g}	x(|	D] \}}}|�|t�||���q�Wd.d/d0d1d2d3d4d5d6d7d8d9g}
x$|
D]\}}|�ttj||��q&Wd:g}x(|D] \}}}|�|t�||���qRWdS);N)s<g�?)s�g�)s�{g��@)sg?)sgp>)sg)s�g�s|z+infs�z-inf)sU5gT�?rz<erz>e�little�e)z<es�)z<es�)z<es��)z<es|)z<es~)z<es�r%�~)z>esg`>)z>esg`>)z>esgP>)z>es�g�?)z>es�g������?)z>esg�?)z>esg?)z>es<g�?)z>es<g�?)z>es<g�?)z>es{�i�)z>es{�i�)z>es�g`�)z>es�g`�)z>es�gP�)z>es�g�)z>es�g�)z>es�g�)z>es��i��)z>eg��@)z>eg�@)z>eg�u�<�7~)z>eg��)z>eg�)z>eg�u�<�7�)z<eg��@)z<eg�@)z<eg�u�<�7~)z<eg��)z<eg�)z<eg�u�<�7�)z>esg�g�����@)
�floatr&r'r5r(r�rrOr�Zisnan�nanr1rh)r)Z&format_bits_float__cleanRoundtrip_listZle_bitsr=Zbe_bitsZformat_bits__nan_listZ
formatcode�bitsr�Z format_bits_float__rounding_listZ%format_bits_float__roundingError_listZ+format_bits_float__doubleRoundingError_listrrr�test_half_float�s�


,z"UnpackIteratorTest.test_half_floatN)	rqrrrsr�r�r�r�r�r�rrrrr�}s
	r��__main__)�collectionsrr�r�r�r�r'r�r�rrr!rrrr r#r�r$r�rq�mainrrrr�<module>s,
a.