a
    ø£Beã  ã                   @   sX   d Z ddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ G dd	„ d	eƒZdS )
zTest yarn registry replacementé    N)Újoin)Úpatch)Úcommandsé   )ÚAppHandlerTestc                   @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚTestAppHandlerRegistryc                 C   sf   t dƒ�J}tdƒ|_t d¡}t |¡}| d¡ |  |i i dœ¡ W d   ƒ n1 sX0    Y  d S )Nzjupyterlab.commands.whichzCommand not foundÚ
jupyterlabÚnode©zyarn configz
npm config)	r   Ú
ValueErrorÚside_effectÚloggingÚ	getLoggerr   Ú_yarn_configZassert_called_once_withÚassertDictEqual)ÚselfÚwhichÚloggerÚconfig© r   úa/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/jupyterlab/tests/test_registry.pyÚtest_node_not_available   s    




z.TestAppHandlerRegistry.test_node_not_availablec              
   C   sŽ   t dƒ�r}d}d ddt|dƒ d ddt|dƒ d g¡|_t d	¡}t |¡}|  |d
|id
|idœ¡ W d   ƒ n1 s€0    Y  d S )Núsubprocess.check_outputúhttps://private.yarn/manageró   
ó$   {"type":"info","data":"yarn config"}ó&   {"type":"inspect","data":{"registry":"úutf-8ó   "}}ó#   {"type":"info","data":"npm config"}r   Úregistryr
   )	r   r   ÚbytesÚreturn_valuer   r   r   r   r   )r   Úcheck_outputÚyarn_registryr   r   r   r   r   Útest_yarn_config   s2    
ÿþÿþúÿ

þþz'TestAppHandlerRegistry.test_yarn_configc                 C   sj   t dƒ�N}tjdg d¢ddd�|_t d¡}t |¡}|  |i i dœ¡ W d   ƒ n1 s\0    Y  d S )	Nr   r   )Úyarnr   Úlistó    s   yarn config failed.)Ústderrr   r
   )	r   Ú
subprocessÚCalledProcessErrorr   r   r   r   r   r   )r   r#   r   r   r   r   r   Útest_yarn_config_failure7   s    
ÿ

z/TestAppHandlerRegistry.test_yarn_config_failurec              
   C   sv   t dƒ�Z}d}d ddt|dƒ d ddt|dƒ d g¡|_t ¡ }|  |j|¡ W d   ƒ n1 sh0    Y  d S )	Nr   r   r   r   r   r   r   r   )r   r   r!   r"   r   Ú
AppOptionsÚassertEqualr    )r   r#   r$   Úhandlerr   r   r   Útest_get_registryB   s&    
ÿþÿþúÿz(TestAppHandlerRegistry.test_get_registryc              
   C   sÖ   t dƒ�º}d}d ddt|dƒ d ddt|dƒ d g¡|_t| jd	ƒ}t t ¡ ¡}| 	¡  t|d
ƒ}t
|ƒ�}| ¡ }W d   ƒ n1 s�0    Y  |  tj|¡ |  ||¡ W d   ƒ n1 sÈ0    Y  d S )Nr   r   r   r   r   r   r   r   Ústagingz	yarn.lock)r   r   r!   r"   ÚpjoinZapp_dirr   Z_AppHandlerr-   Z_populate_stagingÚopenÚreadZassertNotInZYARN_DEFAULT_REGISTRY)r   r#   r$   r1   r/   Z	lock_pathÚfÚlockr   r   r   Útest_populate_stagingV   s2    
ÿþÿþúÿ

&z,TestAppHandlerRegistry.test_populate_stagingN)Ú__name__Ú
__module__Ú__qualname__r   r%   r,   r0   r7   r   r   r   r   r      s
   r   )Ú__doc__r   r*   Úos.pathr   r2   Zunittest.mockr   r   r   Ztest_jupyterlabr   r   r   r   r   r   Ú<module>   s   