U
    øÕ/eQ  ã                   @   sf   d dl Z d dlZd dlZd dlZd dlZd dlmZ e d¡Zdd„ Z	ej
 ddddg¡d	d
„ ƒZdS )é    N)Ú	cpu_countÚpsutilc                  C   s4   t ƒ } t| tƒst‚| t  ¡ ks$t‚| dks0t‚d S )Né   )r   Ú
isinstanceÚintÚAssertionErrorÚos)Úcount© r
   ú:/tmp/pip-unpacked-wheel-dbjnr7gq/dask/tests/test_system.pyÚtest_cpu_count   s    r   Údirnamezcpuacct,cpuzcpu,cpuacctc                    s®   dd„ }|  td|¡ G dd„ dƒ}|  td|¡ | r†d|  t d¡d	|  t d
¡i‰tj‰ ‡ ‡fdd„}|  td|¡ |  tdd¡ tƒ }| rž|dksªt	‚n|dksªt	‚d S )Nc                   S   s   dS )Néú   r
   r
   r
   r
   r   Úmycpu_count   s    z+test_cpu_count_cgroups.<locals>.mycpu_countr   c                   @   s   e Zd Zdd„ ZdS )z)test_cpu_count_cgroups.<locals>.MyProcessc                 S   s   g S ©Nr
   )Úselfr
   r
   r   Úcpu_affinity   s    z6test_cpu_count_cgroups.<locals>.MyProcess.cpu_affinityN)Ú__name__Ú
__module__Ú__qualname__r   r
   r
   r
   r   Ú	MyProcess   s   r   ÚProcessz"/sys/fs/cgroup/%s/cpu.cfs_quota_usZ2005z#/sys/fs/cgroup/%s/cpu.cfs_period_usÚ10c                    s"   | ˆkrˆ  | ¡S ˆ | f|ž|ŽS r   )Úget)ÚpathÚargsÚkwargs©Zbuiltin_openÚpathsr
   r   Úmyopen*   s    
z&test_cpu_count_cgroups.<locals>.myopenÚopenÚplatformÚlinuxéÉ   r   )
Úsetattrr   r   ÚioÚStringIOÚbuiltinsr    Úsysr   r   )r   Zmonkeypatchr   r   r   r	   r
   r   r   Útest_cpu_count_cgroups   s$      þr)   )r'   r%   r   r(   ZpytestZdask.systemr   Zimportorskipr   r   ÚmarkZparametrizer)   r
   r
   r
   r   Ú<module>   s   
