o
    v݋j	                     @  sV   d dl mZ d dlZd dlm  mZ d dlZd dl	m
Z dd Zdd Zdd ZdS )	    )annotationsNc                  C  sb  t ddt ddt ddg} t | d}t | d}dd |D }dd |D }||k}|sTtd|fd||ft|t|d	 }d
d|i }tt|d  } }}dd |D }t|}g d}	||	k}
|
std|
fd||	fdt	
 v sttrttndt|t|t|	d }dd|i }tt|d  } } }
}	d S )Ndebian1debian2debian3/tmp/example-track.wavc                 S  s   g | ]}|j qS  name.0br   r   D/home/user/Projects/AutoRemaster/tests/test_remote_fleet_contract.py
<listcomp>   s    zEtest_worker_affinity_is_deterministic_and_rotates.<locals>.<listcomp>==)z%(py1)s == %(py4)s)py1py4zassert %(py6)spy6c                 s  s    | ]}|j V  qd S Nr   r
   r   r   r   	<genexpr>   s    zDtest_worker_affinity_is_deterministic_and_rotates.<locals>.<genexpr>)r   r   r   )z0%(py4)s
{%(py4)s = %(py0)s(%(py2)s)
} == %(py7)ssorted)py0py2r   py7zassert %(py9)spy9)fleetBuildbox_ordered_for_input
@pytest_ar_call_reprcompare	_safereprAssertionError_format_explanationr   @py_builtinslocals_should_repr_global_name)boxesfirstsecond@py_assert0@py_assert3@py_assert2@py_format5@py_format7@py_assert1@py_assert6@py_assert5@py_format8@py_format10r   r   r   1test_worker_affinity_is_deterministic_and_rotates   s
   "zr3   c              	     s  t ddt ddt ddg | t d fdd | t ddd  | t d	d
d  t j  t jdd  D  g fdd}t j}d}|||}d}||k}|std|fd||fdt	
 v smtt rrtt ndt|t|dt	
 v st|rt|ndt|t|d }dd|i }tt|d  } } } }}ddg}	|	k}|std|fd|	fdt	
 v strtndt|	d }
dd|
i }tt|d  }}	d S )Nr   r   r   Zload_buildboxesc                     s    S r   r   r   )r&   r   r   <lambda>       z6test_failover_preserves_worker_order.<locals>.<lambda>r   c                 S  s   | S r   r   )r&   pathr   r   r   r4      r5   Z_prepare_boxc                 S  s   d S r   r   boxr   r   r   r4      r5   c                 S  s   i | ]}|j t qS r   )r	   	threadingLock)r   r8   r   r   r   
<dictcomp>   s    z8test_failover_preserves_worker_order.<locals>.<dictcomp>c                   s$     | j | jdkrtd| jS )Nr   zsynthetic failure)appendr	   RuntimeErrorr7   )seenr   r   	operation   s   
z7test_failover_preserves_worker_order.<locals>.operationr   r   )zb%(py7)s
{%(py7)s = %(py2)s
{%(py2)s = %(py0)s._run_with_failover
}(%(py4)s, %(py5)s)
} == %(py10)sr   r?   )r   r   r   py5r   py10zassert %(py12)spy12)z%(py0)s == %(py3)sr>   )r   py3zassert %(py5)sr@   )r   r   setattrZ
_box_locksclearupdateZ_run_with_failoverr   r   r#   r$   r%   r    r!   r"   )monkeypatchr?   r.   r*   r/   @py_assert9@py_assert8@py_format11@py_format13r+   @py_format4@py_format6r   )r&   r>   r   $test_failover_preserves_worker_order   s   "
rN   c                   sB  |d }| d tdd}g ddi | tddd   fd	d
}fdd}| td| | td| t|t|}t|t|}||k}|std|fd||fdt	 v sct
|rht|nddt	 v stt
|ryt|ndd }	dd|	i }
tt|
d }|j}d}||}|sddt	 v st
|rt|ndt|t|t|d }tt|d  } }}t}d}||k}|std|fd||fdt	 v st
trttnddt	 v st
rtndt|t|d }dd|i }tt|d  } }}d S ) Nz	track.wavs   audio-bytesr   valueFget_file_hashc                 S  s   dS )NZabc123r   )r6   r   r   r   r4   *   r5   z;test_source_cache_uploads_once_and_reuses.<locals>.<lambda>c                   sR   | r| d dkr| d nd}| dr d rddfS ddfS d|v r'd	 d< d
S )Nr   Zssh ztest -s rO      zmv T)r   rR   )
startswith)argvkwargscommand)cache_existsr   r   fake_run,   s   
z;test_source_cache_uploads_once_and_reuses.<locals>.fake_runc                   s     | j||f d S r   )r<   r	   )Zbox_arg
local_pathremote_path)uploadedr   r   fake_upload4   s   z>test_source_cache_uploads_once_and_reuses.<locals>.fake_upload_runZ_uploadr   )z%(py0)s == %(py2)sr'   r(   )r   r   zassert %(py4)sr   z/source-cache/abc123.wavzJassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.endswith
}(%(py4)s)
})r   r   r   r   rS   )z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)slenr\   )r   r   rC   r   zassert %(py8)spy8)write_bytesr   r   rD   Z_cached_remote_sourcestrr   r   r#   r$   r%   r    r!   r"   endswithr_   )rG   tmp_pathsourcer8   rY   r]   r'   r(   r.   @py_format3r,   r*   r0   r-   r+   @py_assert4@py_format9r   )rX   r\   r   )test_source_cache_uploads_once_and_reuses#   s   
tri   )
__future__r   builtinsr#   _pytest.assertion.rewrite	assertionrewriter   r9   engine.remote_fleetZremote_fleetr   r3   rN   ri   r   r   r   r   <module>   s    "