Current File : //usr/lib64/python3.6/site-packages/borg/testsuite/__pycache__/remote.cpython-36.pyc
3

y��b�@s�ddlZddlZddlZddlZddlmZddlZddlmZm	Z	m
Z
ddlmZddl
mZddlmZddlmZd	d
lmZd	dlmZGdd
�d
�ZGdd�d�ZdS)�N)�patch�)�SleepingBandwidthLimiter�RepositoryCache�cache_if_remote)�
Repository)�PlaintextKey)�CompressionSpec)�IntegrityError�)�H)�TestKeyc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestSleepingBandwidthLimitercCs||_||_dS)N)�expected_fd�
expected_data)�self�fd�data�r�/usr/lib64/python3.6/remote.py�expect_writesz)TestSleepingBandwidthLimiter.expect_writecCs$||jkst�||jkst�t|�S)N)r�AssertionErrorr�len)rrrrrr�check_writesz(TestSleepingBandwidthLimiter.check_writecCs4|jtd|j�td�}|jdd�|jdd�dS)N�writer�stest)�setattr�osrrrr)r�monkeypatch�itrrr�test_write_unlimitedsz1TestSleepingBandwidthLimiter.test_write_unlimitedcs�|jtd|j�|jtd�fdd��|jtddd��d�td�}|jdd	�|jdd	�|jdd
�|jdd�|jdd
�|jdd
��d7�|jdd
�|jdd
��d7�|jdd
�|jdd
��d7�|jdd
�|jdd
�dS)NrZ	monotoniccs�S)Nrr)�nowrr�<lambda>%sz9TestSleepingBandwidthLimiter.test_write.<locals>.<lambda>ZsleepcSsdS)Nr)�xrrrr"&s�drstests123456s
1234567890�
�1)rrr�timerrr)rrrr)r!r�
test_write#s(z'TestSleepingBandwidthLimiter.test_writeN)�__name__�
__module__�__qualname__rrr r(rrrrrsrc@s�eZdZejdd��Zejdd��Zed�dd�Zed�dd	�Z	ed�d
d�Z
ejdd
��Zdd�Zejdd��Z
ejdd��Zejdd��Zejdd��Zed�dd�ZdS)�TestRepositoryCacheccsntjjt|�d�|_t|jddd��@}|jtd�d�|jtd�d�|jtd�td	��|VWdQRXdS)
N�
repositoryT)Z	exclusive�creaters1234rs5678�r$)	r�path�join�strZrepository_locationr�putr�bytes)rZtmpdirr-rrrr-IszTestRepositoryCache.repositorycCst|�S)N)r)rr-rrr�cacheRszTestRepositoryCache.cache)r5cCs�|jtd��dkst�|jdks$t�|jdks2t�t|jtd�g��dgksPt�|jdks^t�|jdkslt�t|jtd�g��dgks�t�|jdks�t�|jdks�t�|jtd��dks�t�|jdks�t�|jdks�t�dS)Nrs1234rr)�getrr�misses�hits�list�get_many)rr5rrr�test_simpleVszTestRepositoryCache.test_simplecs�fdd�}t�jtd�td�g��ddgks2t��jdks@t��jdksNt��jtd�td�td�g�}t|�dkszt��j}|�_�j�|�_�jdks�t�td��j	ks�t�td��j	ks�t�t|�t
d	�ks�t��jdks�t�t|�dks�t��jdk�st�dS)
Ncs
d�_dS)Nr)Z
size_limitr)r5rr�query_size_limitisz:TestRepositoryCache.test_backoff.<locals>.query_size_limitrrs1234s5678rr/r$)r9r:rrr7�	evictions�nextr<Zbackoffr5r4Zslow_misses)rr5r<�iteratorZqslr)r5r�test_backoffhs"&z TestRepositoryCache.test_backoffc
Cs�Gdd�d�}|jtd�td�td�g�}t|�dks:t�td|��2t|�dksVt�|jdksdt�|jd	ksrt�WdQRXt|�td
�ks�t�dS)Nc@s6eZdZdd�Zdd�Zdd�Zdd�Zdd
d�Zd	S)
z4TestRepositoryCache.test_enospc.<locals>.enospc_opencWsdS)Nr)r�argsrrr�__init__�sz=TestRepositoryCache.test_enospc.<locals>.enospc_open.__init__cSs|S)Nr)rrrr�	__enter__�sz>TestRepositoryCache.test_enospc.<locals>.enospc_open.__enter__cSsdS)Nr)r�exc_typeZexc_valZexc_tbrrr�__exit__�sz=TestRepositoryCache.test_enospc.<locals>.enospc_open.__exit__cSsttjd��dS)NZfoo)�OSError�errnoZENOSPC)rrrrrr�sz:TestRepositoryCache.test_enospc.<locals>.enospc_open.writeNcSsdS)Nr)r�nrrr�truncate�sz=TestRepositoryCache.test_enospc.<locals>.enospc_open.truncate)N)r)r*r+rBrCrErrIrrrr�enospc_open�s
rJrrr/s1234z
builtins.opens5678rr$)r:rr>rrZenospcr=r4)rr5rJr?rrr�test_enospc�szTestRepositoryCache.test_enospccCs,|jdd�tj|tj��}td�j|_|S)NZBORG_PASSPHRASEZtestZnone)Zsetenvrr.r
ZMockArgsr	Z
compressor)rr-r�keyrrrrL�szTestRepositoryCache.keycCs |j|�}|j||j|��|S)N)Zid_hashr3Zencrypt)rrLr-rZid_rrr�_put_encrypted_object�s
z)TestRepositoryCache._put_encrypted_objectcCs|j||d�S)Ns1234)rM)rrLr-rrr�H1�szTestRepositoryCache.H1cCs|j||d�S)Ns5678)rM)rrLr-rrr�H2�szTestRepositoryCache.H2cCs|j||td��S)Nr$)rMr4)rrLr-rrr�H3�szTestRepositoryCache.H3cCst||dd�S)NT)�decrypted_cacheZforce_cache)r)rrLr-rrrrQ�sz#TestRepositoryCache.decrypted_cache)rQcCs�t|j|||g��|j|||g�}t|�dks4t�t|j|�d��P}|jd	tj�t	j
|j�d�dAjdd�}|jd
tj�|j
|�|j�WdQRXtjt��t|�dks�t�WdQRXdS)N��1234za+br�littler�5678)rRrS���rV)rRrU)r9r:r>r�openZkey_filename�seek�io�SEEK_END�int�
from_bytes�read�to_bytesrrI�pytestZraisesr
)rrQrNrOrPr?rZ	corruptedrrr�test_cache_corruption�s
z)TestRepositoryCache.test_cache_corruptionN)r)r*r+r_Zfixturer-r5rr;r@rKrLrMrNrOrPrQr`rrrrr,Hs	r,)rGrrYr'Z
unittest.mockrr_Zremoterrrr-rZ
crypto.keyr�compressr	Zhelpersr
Z	hashindexrrLr
rr,rrrr�<module>s6