o
    rri                     @   s  d dl Z d dlmZ d dlZddlmZ ddlmZ ddlm	Z	 ded	dfd
dZ
ded	dfddZded	dfddZded	dfddZded	dfddZded	dfddZded	dfddZded	dfddZded	dfddZded	dfddZd ddZdS )!    N)Path   )debug)
test_slurm   )autotmp_pathreturnc                 C   sd  | tjddd  t  tj| d}W d    n1 sw   Y  |jdks+J |jdddd	 |j	j
}|d
ddks@J tt |jdd W d    n1 sVw   Y  tt |jdd W d    n1 sqw   Y  tt |jdd W d    n1 sw   Y  tjtdd |jddd W d    d S 1 sw   Y  d S )N_valid_parametersc                   S      dhS Nblabla r   r   r   K/home/ubuntu/.local/lib/python3.10/site-packages/submitit/auto/test_auto.py<lambda>       z%test_slurm_executor.<locals>.<lambda>folderslurmr   machinblublu)mem_gbnamedebug_blabla2GB)memjob_namez2.0GB)r   g       @)r   )slurm_host_filterz#debug_blublu.*\n.*local_num_threadsmatch   )debug_blublulocal_num_threads)setattrr   DebugExecutorr   mocked_slurmr   AutoExecutorclusterupdate_parameters	_executor
parameterspytestraisesAssertionError	NameError)r   monkeypatchexecutorparamsr   r   r   test_slurm_executor   s(   
"r2   c                 C   sH   t   tj| dd}W d    n1 sw   Y  |jdks"J d S )Nlocalr   r'   )r   r%   r   r&   r'   r   r0   r   r   r   test_local_executor*   s   
r6   c                 C   s$   t j| ddd}|jjdksJ d S )Nr3   gQ?)r   r'   local_max_pickle_size_gb)r   r&   r)   max_pickle_size_gb)r   exr   r   r   test_max_pickle_size_gb_in_auto0   s   r:   c                 C   s4   t j| dtjd}|dd }| dksJ d S )Nr3   )r   r'   local_pythonc                   S   s   dS )N   r   r   r   r   r   r   7   s    z&test_python_executor.<locals>.<lambda>r<   )r   r&   sys
executablesubmitresultr   r0   jobr   r   r   test_python_executor5   s   rC   c                 C   sv   t   tj| dd}W d    n1 sw   Y  t|jdd dks&J tj| ddd}t|jdd dks9J d S )N   )r   slurm_max_num_timeoutmax_num_timeoutr3   )r   r'   rE   )r   r%   r   r&   getattrr)   r5   r   r   r   test_executor_argument;   s   
rH   c              	   C   sv   t  - tt tj| dd W d    n1 sw   Y  W d    d S W d    d S 1 s4w   Y  d S )NrD   )r   slurm_foobar)r   r%   r+   r,   	TypeErrorr   r&   r   r   r   r   test_executor_unknown_argumentE   s   
"rL   c              	   C   sz   t  / tjtdd tj| dd W d    n1 sw   Y  W d    d S W d    d S 1 s6w   Y  d S )NrE   r   rD   )r   rF   )r   r%   r+   warnsUserWarningr   r&   rK   r   r   r   "test_executor_deprecated_argumentsK   s   
"rO   c                 C   s   | tjddd  t  tj| d}W d    n1 sw   Y  |jdks+J tj	t
dd |jdd	d
 W d    d S 1 sEw   Y  d S )Nr
   c                   S   r   r   r   r   r   r   r   r   R   r   z*test_deprecated_argument.<locals>.<lambda>r   r   zblabla.*debug_blablar   r   r   )r   r   )r#   r   r$   r   r%   r   r&   r'   r+   rM   rN   r(   )r   r/   r0   r   r   r   test_deprecated_argumentQ   s   
"rP   c                 C   s   t   tj| dd}W d    n1 sw   Y  |jddddd |jj}|dddks1J tj| d	d}|jddd
 d S )Nr   r4   <   x   r      )timeout_minslurm_timeout_mintasks_per_nodeslurm_ntasks_per_node)timentasks_per_noder3   )rT   
slurm_time)r   r%   r   r&   r(   r)   r*   )r   slurm_exslurm_paramslocal_exr   r   r   test_overriden_arguments\   s   
r^   c              	   C   sz   t  / tj| d}|  |td}W d    n1 s w   Y  | r+J W d    d S 1 s6w   Y  d S )Nr   hi)r   r%   r   r&   batchr?   printdonerA   r   r   r   test_auto_batch_watcherl   s   

"rc   c                 C   s   dd }| j dd | |}|  | d u sJ | }d|v s%J d|v s+J | j dd | |}|  d| v sBJ d| v sJJ d S )Nc                   S   s   t d t dtjd d S )Nhelloworld)file)ra   r=   stderrr   r   r   r   log_to_stderr_and_stdoutu   s   z=test_redirect_stdout_stderr.<locals>.log_to_stderr_and_stdoutT)stderr_to_stdoutrd   re   F)r(   r?   waitrg   stdout)r0   rh   rB   rk   r   r   r   test_redirect_stdout_stderrt   s   

rl   )r	   N)r=   pathlibr   r+   r3   r   r   r    r   r2   r6   r:   rC   rH   rL   rO   rP   r^   rc   rl   r   r   r   r   <module>   s"   
