Your IP : 216.73.217.129


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_hash.cpython-35.pyc



��Yf�-�@s�ddlZddlZddlZddlZddlmZddlmZejd9kZ	ddd�Z
d	d
�Zdd�ZGd
d�dej
�ZejZGdd�de�ZdZGdd�de�ZGdd�de�ZGdd�de�ZGdd�dee�ZGdd�dee�ZGdd�de�ZGdd�dej
�ZGd d!�d!e�ZGd"d#�d#ej
�ZGd$d%�d%�ZGd&d'�d'e�ZGd(d)�d)eej
�ZGd*d+�d+eej
�Z Gd,d-�d-eej
�Z!Gd.d/�d/e�Z"Gd0d1�d1e"ej
�Z#Gd2d3�d3e"ej
�Z$Gd4d5�d5e"ej
�Z%Gd6d7�d7ej
�Z&e'd8kr�ej(�dS):�N)�assert_python_ok)�Hashable�� �cCsg|dkrt|�St|�}x8t|�D]*}d|dd@}|d?d@||<q/Wt|�S)zLinear congruential generatorri�CiÞ&i���r�)�bytes�	bytearray�range)�x�length�out�i�r�3/opt/alt/python35/lib64/python3.5/test/test_hash.py�lcgs
rcCs|d|kodkns"t�|d
kr;|d}n|}||d?Ad@}|d
krl|d}n|}||fS)z*Convert SipHash24 output to Py_hash_t
    r��@�?rl���lll����lli���l)�AssertionError)Zuint64Zint64Zuint32Zint32rrr�	pysiphashs"

rcCs5tjjdk}d}|r"|Stj|�|�S)z8Skip decorator for tests that depend on SipHash24 or FNV�fnv�	siphash24zRequires SipHash24 or FNV>rr)�sys�	hash_info�	algorithm�unittest�skip)Ztest�ok�msgrrr�skip_unless_internalhash+sr!c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�HashEqualityTestCasecGsXttt|��}x<|dd�D]*}||dkr&|jd|f�q&WdS)Nrrzhashed values differ: %r)�list�map�hashZfail)�selfZobjlistZhashed�hrrr�	same_hash4szHashEqualityTestCase.same_hashcCsS|jdddd�|jddd	�|jd
dd
�|jddd�dS)Nrg�?yrgrg@y�?y���g�g�y����g�g�y�)r()r&rrr�test_numeric_literals<sz*HashEqualityTestCase.test_numeric_literalscCs�|jtd�td�td�td�td�td��|jtd�td
��|jtd�td��|jtd�td��|jtd�td��|jtd�td��|jtd�td��dS)Nr�1z1.0rrrli�li�li�li�li���li���llll����ll����ll)r(�int�float�complex)r&rrr�test_coerced_integersBs*z*HashEqualityTestCase.test_coerced_integerscCs?|jtd�td��|jtd�tdd��dS)Ng�쏈�b=~g�?g)r(r-r.r/)r&rrr�test_coerced_floatsMsz(HashEqualityTestCase.test_coerced_floatscCs�dd}xutd�D]g}x^td�D]P}||d|�}t|�|d|�}|jt|�t|��q*WqWdS)Ns#123456789abcdefghijklmnopqrstuvwxyz�r)r
�
memoryview�assertEqualr%)r&�br�jZalignedZ	unalignedrrr�test_unaligned_buffersQs
z+HashEqualityTestCase.test_unaligned_buffersN)�__name__�
__module__�__qualname__r(r+r0r1r7rrrrr"2s
r"c@seZdZdS)�DefaultHashN)r8r9r:rrrrr;]sr;�*c@seZdZdd�ZdS)�	FixedHashcCstS)N)�_FIXED_HASH_VALUE)r&rrr�__hash__aszFixedHash.__hash__N)r8r9r:r?rrrrr=`sr=c@seZdZdd�ZdS)�OnlyEqualitycCs
||kS)Nr)r&�otherrrr�__eq__eszOnlyEquality.__eq__N)r8r9r:rBrrrrr@dsr@c@seZdZdd�ZdS)�OnlyInequalitycCs
||k	S)Nr)r&rArrr�__ne__iszOnlyInequality.__ne__N)r8r9r:rDrrrrrChsrCc@seZdZdS)�InheritedHashWithEqualityN)r8r9r:rrrrrElsrEc@seZdZdS)�InheritedHashWithInequalityN)r8r9r:rrrrrFmsrFc@seZdZdZdS)�NoHashN)r8r9r:r?rrrrrGosrGc@s�eZdZe�e�e�gZe�e�e	�gZ
e�e�gZ
dd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�HashInheritanceTestCasecCs4x-|jD]"}|jt|�t|��q
WdS)N)�default_expectedr4r%�
_default_hash)r&�objrrr�test_default_hashsz)HashInheritanceTestCase.test_default_hashcCs.x'|jD]}|jt|�t�q
WdS)N)�fixed_expectedr4r%r>)r&rKrrr�test_fixed_hash�sz'HashInheritanceTestCase.test_fixed_hashcCs+x$|jD]}|jtt|�q
WdS)N)�error_expectedZassertRaises�	TypeErrorr%)r&rKrrr�test_error_hash�sz'HashInheritanceTestCase.test_error_hashcCs5|j|j}x|D]}|j|t�qWdS)N)rIrMZassertIsInstancer)r&ZobjectsrKrrr�
test_hashable�s

z%HashInheritanceTestCase.test_hashablecCs(x!|jD]}|j|t�q
WdS)N)rOZassertNotIsInstancer)r&rKrrr�test_not_hashable�sz)HashInheritanceTestCase.test_not_hashableN)r8r9r:�objectr;rCrIr=rErFrMrGr@rOrLrNrQrRrSrrrrrHrsrHc@s4eZdZed�Zdd�Zdd�ZdS)�DefaultIterSeq�
cCs
t|j�S)N)�len�seq)r&rrr�__len__�szDefaultIterSeq.__len__cCs|j|S)N)rX)r&�indexrrr�__getitem__�szDefaultIterSeq.__getitem__N)r8r9r:r
rXrYr[rrrrrU�srUc@sOeZdZeed��ee��edd�d�gZdd�ZdS)�HashBuiltinsTestCaserVcCsdS)Nrrrrrr�<lambda>�szHashBuiltinsTestCase.<lambda>rcCs=tj}x-|jD]"}|jt|�||��qWdS)N)rTr?�hashes_to_checkr4r%)r&rJrKrrr�test_hashes�s	z HashBuiltinsTestCase.test_hashesN)	r8r9r:�	enumerater
�iterrUr^r_rrrrr\�sr\c@s7eZdZdd�Zddd�Zdd�ZdS)�HashRandomizationTestscCsd|S)Nzprint(hash(eval(%a)))r)r&�repr_rrr�get_hash_command�sz'HashRandomizationTests.get_hash_commandNcCs}tjj�}d|d<|dk	r8t|�|d<n|jdd�td|j|�|�}|dj�}t|�S)NTZ
__cleanenvZPYTHONHASHSEEDz-cr)	�os�environ�copy�str�poprrd�stripr-)r&rc�seed�envr
�stdoutrrr�get_hash�s
	zHashRandomizationTests.get_hashcCsD|j|jdd�}|j|jdd�}|j||�dS)NrkZrandom)rnrc�assertNotEqual)r&Zrun1Zrun2rrr�test_randomized_hash�sz+HashRandomizationTests.test_randomized_hash)r8r9r:rdrnrprrrrrb�srbc
@s$eZdZdZdZdddddgd2dd3d4ggdd	d
d	d
gdd5dd6gd7dd8dgddd9d:gd;d<d=d>ggdd?dd@dgdAdBdCdDgddEdFdGgd"d#dHdIgdJdKdLdMggiZd*d+�Zd,d-�Zed.d/��Z	ed0d1��Z
dS)N� StringlikeHashRandomizationTestsN�djba33xi�\�i�3x(lLL//+�?i���0lqU:~�@[ri��pGl�n�YD~i�SljxY_oW�siQ�hl� �/��li�Jkl�J�:�8`~i�)�;l�)�wJ�i ��cl .�G�UJGi���nl��]�D]ri]/l_l�P'ABS!i{Hlm]]�R�iiy8	=l�T�e]i�X0l�'�W�=>0i��l�;u�i���lg,��gi�ۙtl�`�bTN�Vi�?�l�9�\R>|i�m4l�kT<�h4cCs�|tjjkrd}ntjj}tjdkrKtrBdnd}n'tjdks`t�trldnd}|j|||S)Nrr�littlerrZbig�r)rr�cutoffr�	byteorder�IS_64BITr�known_hashes)r&Zpositionrr�platformrrr�get_expected_hash�s	z2StringlikeHashRandomizationTests.get_expected_hashcCsT|jdd�}|j|j|j�|�|j|j|jdd�|�dS)Nrrtrk)rzrornrcr4)r&Zknown_hash_of_objrrr�test_null_hash�sz/StringlikeHashRandomizationTests.test_null_hashcCs8|jdd�}|j|j|jdd�|�dS)Nrrtrkr<)rzr4rnrc)r&r'rrrrNsz0StringlikeHashRandomizationTests.test_fixed_hashcCsK|jdkrdS|jdd�}|j|j|jdd�|�dS)Nr�rkr<)�	repr_longrzr4rn)r&r'rrr�test_long_fixed_hashsz5StringlikeHashRandomizationTests.test_long_fixed_hashiL̇�iTS�l����qU:~�@[l����jxY_oW�sl����jxY_oW�si� ��i� ��i��l�����)�wJ�i�Q	�l���� .�G�UJGiO{�l������]�D]i�Г�i�Г�i����l����m]]�R�ii���l�����T�e]l�����'�W�=>0i�e�l�����;u�i5$f�l�����`�bTN�Vi� �l�����9�\R>|iQ���l�����kT<�h4)r8r9r:rcr}rxrzr{r!rNr~rrrrrq�s4					
rqc@sXeZdZed�Zed�Zed�Zedd��Zedd��Z	dS)	�StrHashRandomizationTests�abcZabcdefghijku
äú∑ℇcCs|jtd�d�dS)N�r)r4r%)r&rrr�test_empty_stringsz+StrHashRandomizationTests.test_empty_stringcCsl|jdd�}|j|j|jdd�|�|jdd�}|j|j|jdd�|�dS)Nrt�rkr�r<)rzr4rn�	repr_ucs2)r&r'rrr�test_ucs2_string s"z*StrHashRandomizationTests.test_ucs2_stringN)
r8r9r:�reprrcr}r�r!r�r�rrrrrs
rc@s:eZdZed�Zed�Zedd��ZdS)�BytesHashRandomizationTestssabcsabcdefghijkcCs|jtd�d�dS)N�r)r4r%)r&rrrr�,sz-BytesHashRandomizationTests.test_empty_stringN)r8r9r:r�rcr}r!r�rrrrr�'sr�c@s.eZdZdZdZedd��ZdS)� MemoryviewHashRandomizationTestszmemoryview(b'abc')zmemoryview(b'abcdefghijk')cCs |jttd��d�dS)Nr�r)r4r%r3)r&rrrr�5sz2MemoryviewHashRandomizationTests.test_empty_stringN)r8r9r:rcr}r!r�rrrrr�0sr�c@seZdZdd�ZdS)�
DatetimeTestscCsd|S)Nz import datetime; print(hash(%s))r)r&rcrrrrd:szDatetimeTests.get_hash_commandN)r8r9r:rdrrrrr�9sr�c@s+eZdZeejddd��ZdS)�DatetimeDateTestsi*rV�N)r8r9r:r��datetimeZdatercrrrrr�=sr�c	@s7eZdZeejddddddd��ZdS)	�DatetimeDatetimeTestsrrrtr��r��N)r8r9r:r�r�rcrrrrr�@sr�c@s%eZdZeejd��ZdS)�DatetimeTimeTestsrN)r8r9r:r�r�Ztimercrrrrr�Csr�c@seZdZdd�ZdS)�HashDistributionTestCasec
Cs�d}x�tdt|��D]�}|d|�}|jd|���t�}t�}xLtd�D]>}t|t|��}|j|d@�|j|d@�qdW|jt|�d|�|jt|�d|�WdQRXqWdS)	NZabcdefghabcdefgr�prefix��r�r2)r
rWZsubTest�setr%�chr�addZ
assertGreater)r&�baserr�Zs15Zs255�cr'rrr�test_hash_distributionIs		z/HashDistributionTestCase.test_hash_distributionN)r8r9r:r�rrrrr�Gsr��__main__l))r�rerrZtest.support.script_helperr�collectionsr�maxsizerwrrr!ZTestCaser"rTr?rJr;r>r=r@rCrErFrGrHrUr\rbrqrr�r�r�r�r�r�r�r8�mainrrrr�<module>sJ
*	%Q