B
    u9aÀ  ã               @   sJ   d Z ddlZddlZddlZddlZG dd„ dejƒZedkrFe 	¡  dS )z'Unit tests for code in urllib.response.é    Nc               @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚTestResponsec             C   s0   t   t jt j¡| _| j d¡| _dddœ| _d S )NÚrbzwww.python.orgÚclose)ZHostZ
Connection)ÚsocketZAF_INETZSOCK_STREAMÚsockZmakefileÚfpÚtest_headers)Úself© r
   ú*/usr/lib/python3.7/test_urllib_response.pyÚsetUp
   s    zTestResponse.setUpc                sZ   t j | j¡‰ |  ˆ tj¡ ‡ fdd„}|  | jj¡ |ƒ  |  	| jj¡ |  
t|¡ d S )Nc           	      s   ˆ } W d Q R X d S )Nr
   )Zspam)Úaddbaser
   r   Úf   s    z!TestResponse.test_with.<locals>.f)ÚurllibÚresponser   r   ZassertIsInstanceÚtempfileZ_TemporaryFileWrapperZassertFalseÚclosedÚ
assertTrueZassertRaisesÚ
ValueError)r	   r   r
   )r   r   Ú	test_with   s    zTestResponse.test_withc                sD   d‰ ‡ fdd„}t j | j|¡}| ¡  |  | jj¡ |  ˆ ¡ d S )NFc                  s   d‰ d S )NTr
   r
   )Úclosehook_calledr
   r   Ú	closehook    s    z1TestResponse.test_addclosehook.<locals>.closehook)r   r   Zaddclosehookr   r   r   r   )r	   r   r
   )r   r   Útest_addclosehook   s    zTestResponse.test_addclosehookc             C   s(   t j | j| j¡}|  | ¡ | j¡ d S )N)r   r   Zaddinfor   r   ÚassertEqualÚinfo)r	   r   r
   r
   r   Útest_addinfo*   s    zTestResponse.test_addinfoc             C   sT   d}d}t j | j| j||¡}|  | ¡ | j¡ |  | ¡ |¡ |  | ¡ |¡ d S )Nzhttp://www.python.orgéÈ   )	r   r   Z
addinfourlr   r   r   r   ZgeturlZgetcode)r	   ZurlÚcodeZinfourlr
   r
   r   Útest_addinfourl.   s    zTestResponse.test_addinfourlc             C   s   | j  ¡  d S )N)r   r   )r	   r
   r
   r   ÚtearDown7   s    zTestResponse.tearDownN)	Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r
   r
   r
   r   r      s   	r   Ú__main__)
Ú__doc__r   r   Zurllib.responser   ZunittestZTestCaser   r    Úmainr
   r
   r
   r   Ú<module>   s   2