B
    È S]  ã               @   s´   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 ddl	m
Z
 ddlmZ d	Zd
ZdZG dd„ de
je
je
jejƒZG dd„ deƒZdd„ Zedkr°eeƒ ƒ dS )z"Tests for distutils.pypirc.pypirc.é    N)ÚPyPIRCCommand)ÚDistribution)Úset_threshold)ÚWARN)Úsupport)Úrun_unittestzÿ[distutils]

index-servers =
    server1
    server2
    server3

[server1]
username:me
password:secret

[server2]
username:meagain
password: secret
realm:acme
repository:http://another.pypi/

[server3]
username:cbiggles
password:yh^%#rest-of-my-password
z.[server-login]
username:tarek
password:secret
zI[distutils]
index-servers =
    pypi

[pypi]
username:tarek
password:xxx
c                   s(   e Zd Z‡ fdd„Z‡ fdd„Z‡  ZS )ÚBasePyPIRCCommandTestCasec                sb   t t| ƒ ¡  |  ¡ | _| jtjd< tj | jd¡| _	t
ƒ | _G dd„ dtƒ}|| _ttƒ| _dS )zPatches the environment.ÚHOMEz.pypircc               @   s    e Zd Zdd„ Zdd„ ZeZdS )z0BasePyPIRCCommandTestCase.setUp.<locals>.commandc             S   s   t  | |¡ d S )N)r   Ú__init__)ÚselfÚdist© r   ú,lib/python3.7/distutils/tests/test_config.pyr
   C   s    z9BasePyPIRCCommandTestCase.setUp.<locals>.command.__init__c             S   s   d S )Nr   )r   r   r   r   Úinitialize_optionsE   s    zCBasePyPIRCCommandTestCase.setUp.<locals>.command.initialize_optionsN)Ú__name__Ú
__module__Ú__qualname__r
   r   Zfinalize_optionsr   r   r   r   ÚcommandB   s   r   N)Úsuperr   ÚsetUpZmkdtempZtmp_dirÚosÚenvironÚpathÚjoinÚrcr   r   r   Ú_cmdr   r   Úold_threshold)r   r   )Ú	__class__r   r   r   :   s    
zBasePyPIRCCommandTestCase.setUpc                s   t | jƒ tt| ƒ ¡  dS )zRemoves the patch.N)r   r   r   r   ÚtearDown)r   )r   r   r   r   L   s    
z"BasePyPIRCCommandTestCase.tearDown)r   r   r   r   r   Ú__classcell__r   r   )r   r   r   5   s   r   c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚPyPIRCCommandTestCasec             C   s   |   | jt¡ |  | j¡}| ¡ }tt| ¡ ƒƒ}dddddg}|  	||¡ |   | jt
¡ | ¡ }tt| ¡ ƒƒ}dddddg}|  	||¡ d S )N)ÚpasswordZsecret)ÚrealmÚpypi)Ú
repositoryzhttps://upload.pypi.org/legacy/)ÚserverZserver1)ÚusernameÚme)r%   zserver-login)r&   Útarek)Ú
write_filer   ÚPYPIRCr   r   Ú_read_pypircÚlistÚsortedÚitemsÚassertEqualÚ
PYPIRC_OLD)r   ÚcmdÚconfigÚwaitedr   r   r   Útest_server_registrationT   s    z.PyPIRCCommandTestCase.test_server_registrationc             C   st   |   | j¡}| ¡ }|  tj |¡¡ | dd¡ |  tj |¡¡ t	|ƒ}z| 
¡ }|  |t¡ W d | ¡  X d S )Nr(   Zxxx)r   r   Z_get_rc_fileZassertFalser   r   ÚexistsZ_store_pypircZ
assertTrueÚopenÚreadr/   ÚWANTEDÚclose)r   r1   r   ÚfZcontentr   r   r   Útest_server_empty_registrationm   s    z4PyPIRCCommandTestCase.test_server_empty_registrationc             C   sV   |   | jt¡ |  | j¡}d|_| ¡ }tt| 	¡ ƒƒ}dddddg}|  
||¡ d S )NÚserver3)r!   zyh^%#rest-of-my-password)r"   r#   )r$   zhttps://upload.pypi.org/legacy/)r%   r<   )r&   Zcbiggles)r)   r   r*   r   r   r$   r+   r,   r-   r.   r/   )r   r1   r2   r3   r   r   r   Útest_config_interpolationz   s    z/PyPIRCCommandTestCase.test_config_interpolationN)r   r   r   r4   r;   r=   r   r   r   r   r    R   s   r    c               C   s
   t  t¡S )N)ÚunittestZ	makeSuiter    r   r   r   r   Ú
test_suiteˆ   s    r?   Ú__main__)Ú__doc__r   r>   Zdistutils.corer   r   Zdistutils.logr   r   Zdistutils.testsr   Ztest.supportr   r*   r0   r8   ZTempdirManagerZLoggingSilencerZEnvironGuardZTestCaser   r    r?   r   r   r   r   r   Ú<module>   s&   
6