o
    E¾±hi.  ã                   @   s’   d dl Z d dlmZ d dlZd dlZd dlmZ d dlZd dlmZm	Z	 d dl
mZ d dlZejr7d dlmZ G dd„ dƒZG d	d
„ d
ejƒZdS )é    N)ÚStringIO)Úmock)ÚOptionParserÚError)Úbasestring_type)ÚListc                   @   s    e Zd Zdd„ Zedd„ ƒZdS )ÚEmailc                 C   s"   t |tƒrd|v r|| _d S tƒ ‚)Nú@)Ú
isinstanceÚstrÚ_valueÚ
ValueError)ÚselfÚvalue© r   úZ/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/tornado/test/options_test.pyÚ__init__   s   
zEmail.__init__c                 C   s   | j S ©N)r   ©r   r   r   r   r      s   zEmail.valueN)Ú__name__Ú
__module__Ú__qualname__r   Úpropertyr   r   r   r   r   r      s    r   c                   @   sä   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7S )8ÚOptionsTestc                 C   s4   t ƒ }|jddd | ddg¡ |  |jd¡ d S )NÚportéP   ©Údefaultúmain.pyz
--port=443é»  )r   ÚdefineÚparse_command_lineÚassertEqualr   ©r   Úoptionsr   r   r   Útest_parse_command_line   s   z#OptionsTest.test_parse_command_linec                 C   s‚   t ƒ }|jddd |jddd | d¡ tj tj tj t¡¡d¡}| |¡ |  	|j
d¡ |  	|jd	¡ |  	|j|¡ d S )
Nr   r   r   ÚusernameÚfooÚmy_pathúoptions_test.cfgr   u   æŽåº·)r   r    ÚosÚpathÚjoinÚdirnameÚabspathÚ__file__Úparse_config_filer"   r   r&   r(   )r   r$   Úconfig_pathr   r   r   Útest_parse_config_file$   s   
ÿ
z"OptionsTest.test_parse_config_filec                    sx   t ƒ }dˆ _‡ fdd„}| |¡ |jdgdd ˆ  ˆ j¡ | dg¡ ˆ  ˆ j¡ dˆ _| dg¡ ˆ  ˆ j¡ d S )NFc                      s
   dˆ _ d S )NT)Úcalledr   r   r   r   Úcallback5   s   
z2OptionsTest.test_parse_callbacks.<locals>.callbackr   )Úfinal)r   r3   Úadd_parse_callbackr!   ÚassertFalseÚ
assertTrue)r   r$   r4   r   r   r   Útest_parse_callbacks1   s   
z OptionsTest.test_parse_callbacksc                 C   sz   t ƒ }z-tj}tƒ t_|  t¡ | ddg¡ W d   ƒ n1 s"w   Y  tj ¡ }W |t_n|t_w |  d|¡ d S )Nr   z--helpzUsage:)	r   ÚsysÚstderrr   ÚassertRaisesÚ
SystemExitr!   ÚgetvalueÚassertIn)r   r$   Úorig_stderrÚusager   r   r   Ú	test_helpH   s   ÿzOptionsTest.test_helpc                 C   sÞ   t ƒ }|jddd t ƒ }|jdtd | g d¢¡}|  |ddg¡ |  |j¡ | |¡}|  |g ¡ |  |jd	¡ z/tj	}t
ƒ t_	|  t¡ | dd
g¡ W d   ƒ n1 sZw   Y  W |t_	d S W |t_	d S |t_	w )NÚverboseFr   r'   ©Útype)r   ú	--verboseÚ
subcommandú	--foo=barrG   rH   ÚbarrF   )r   r    r   r!   r"   r8   rC   r'   r:   r;   r   r<   r   )r   Úbase_optionsÚsub_optionsÚrestÚrest2r@   r   r   r   Útest_subcommandT   s*   ÿ
ÿ
ýzOptionsTest.test_subcommandc                 C   s.   t ƒ }|jddtd d|_|  |jd¡ d S ©Nr'   é   ©r   rE   é   )r   r    Úintr'   r"   r#   r   r   r   Útest_setattrk   s   zOptionsTest.test_setattrc                 C   sL   t ƒ }|jddtd |  t¡ d|_W d   ƒ d S 1 sw   Y  d S )Nr'   rP   rQ   Ú2)r   r    rS   r<   r   r'   r#   r   r   r   Útest_setattr_type_checkq   s
   "ÿz#OptionsTest.test_setattr_type_checkc                 C   s6   g }t ƒ }|jddt|jd d|_|  |dg¡ d S )Nr'   rP   )r   rE   r4   rR   )r   r    rS   Úappendr'   r"   )r   Úvaluesr$   r   r   r   Útest_setattr_with_callbacky   s
   z&OptionsTest.test_setattr_with_callbackc                 C   s&   t ƒ }|jddd |jddd |S )NÚarP   r   ÚbrR   )r   r    r#   r   r   r   Ú_sample_options€   s   zOptionsTest._sample_optionsc                 C   s$   |   ¡ }|  h d£tt|ƒƒ¡ d S )N>   rZ   r[   Úhelp)r\   r"   ÚsetÚiterr#   r   r   r   Ú	test_iter†   s   zOptionsTest.test_iterc                 C   s   |   ¡ }|  d|d ¡ d S )NrP   rZ   )r\   r"   r#   r   r   r   Útest_getitem‹   s   zOptionsTest.test_getitemc                 C   s2   t ƒ }|jddtd d|d< |  |d d¡ d S rO   )r   r    rS   r"   r#   r   r   r   Útest_setitem   s   zOptionsTest.test_setitemc                 C   s4   |   ¡ }ddd|jfg}t| ¡ ƒ}|  ||¡ d S )N)rZ   rP   )r[   rR   r]   )r\   r]   ÚsortedÚitemsr"   )r   r$   ÚexpectedÚactualr   r   r   Ú
test_items•   s   zOptionsTest.test_itemsc                 C   s*   |   ¡ }dd|jdœ}|  || ¡ ¡ d S )NrP   rR   )rZ   r[   r]   )r\   r]   r"   Úas_dict)r   r$   re   r   r   r   Útest_as_dictœ   s   zOptionsTest.test_as_dictc                 C   s|   t ƒ }|jddd |jdddd t d¡}|jj}|  dd	|h| ¡ ¡ | d¡}|  ddi|¡ |  i | d
¡¡ d S )NrZ   rP   r   r[   Úb_grouprR   )Úgroupr   r   Ú Únonexistent)	r   r    r:   Ú	_getframeÚf_codeÚco_filenamer"   ÚgroupsÚ
group_dict)r   r$   ÚframeÚ	this_fileÚb_group_dictr   r   r   Útest_group_dict¡   s   

zOptionsTest.test_group_dictc              	   C   s8  t ƒ }|jddd | ddg¡ |  |jd¡ tj | ¡ dd¡ |  |jd¡ W d   ƒ n1 s4w   Y  |  |jd¡ tj | ¡ dd¡A |  |jd¡ d	|_|  |jd	¡ tj | ¡ dd
¡ |  |jd
¡ W d   ƒ n1 sxw   Y  |  |jd	¡ W d   ƒ n1 sŽw   Y  |  |jd¡ d S )Nr'   rP   r   r   z--foo=2rR   é   é   é   é   )	r   r    r!   r"   r'   r   ÚpatchÚobjectÚmockabler#   r   r   r   Útest_mock_patch¯   s$   ÿÿúzOptionsTest.test_mock_patchc                 C   s   t ƒ }|jdtd |jdtd |jdtd |jdtd |jdtjd |jdtjd |jdtd |jd	td
d |jdtd
d |S )Nr   rD   Ú
basestringrS   ÚfloatÚdatetimeÚ	timedeltaÚemailzlist-of-intT©rE   Úmultiplezlist-of-str)	r   r    r   r   rS   r€   r   r‚   r   r#   r   r   r   Ú_define_optionsÄ   s   zOptionsTest._define_optionsc              
   C   s´   |   |jd¡ |   |jd¡ |   |jd¡ |   |jd¡ |   |jt ddddd	¡¡ |   |jtjd
d¡ |   |jjd¡ |  	t
|jtƒ¡ |   |jg d¢¡ |   |jg d¢¡ d S )NÚasdfÚqweré*   g      ø?iÝ  rx   é   ry   é   é-   )Úsecondsztornado@web.com)rP   rR   rw   ©rZ   r[   Úc)r"   r   r   rS   r€   r   r‚   rƒ   r   r8   r
   r   Úlist_of_intÚlist_of_strr#   r   r   r   Ú_check_options_valuesÑ   s   z!OptionsTest._check_options_valuesc                 C   s$   |   ¡ }| g d¢¡ |  |¡ d S )N)
r   z
--str=asdfz--basestring=qwerz--int=42z--float=1.5z--datetime=2013-04-28 05:16z--timedelta=45sz--email=tornado@web.comz--list-of-int=1,2,3z--list-of-str=a,b,c)r†   r!   r’   r#   r   r   r   Ú
test_typesÝ   s
   ÿzOptionsTest.test_typesc                 C   s<   dD ]}|   ¡ }| tj tj t¡|¡¡ |  |¡ qd S )N)zoptions_test_types.cfgzoptions_test_types_str.cfg)r†   r0   r*   r+   r,   r-   r/   r’   )r   Úconfig_file_namer$   r   r   r   Útest_types_with_conf_fileï   s   ÿøz%OptionsTest.test_types_with_conf_filec                 C   ó:   t ƒ }|jdtdd | ddg¡ |  |jg d¢¡ d S )Nr'   Tr„   r   z--foo=a,b,crŽ   )r   r    r   r!   r"   r'   r#   r   r   r   Útest_multiple_stringú   ó   z OptionsTest.test_multiple_stringc                 C   r–   )Nr'   Tr„   r   z--foo=1,3,5:7)rP   rw   ry   rz   é   )r   r    rS   r!   r"   r'   r#   r   r   r   Útest_multiple_int   r˜   zOptionsTest.test_multiple_intc                 C   sZ   t ƒ }| d¡ |  t¡}| d¡ W d   ƒ n1 sw   Y  |  t|jƒd¡ d S )Nr'   zOption.*foo.*already defined)r   r    r<   r   ÚassertRegexr   Ú	exception)r   r$   Úcmr   r   r   Útest_error_redefine  s   
ÿzOptionsTest.test_error_redefinec              
   C   s    g d¢}|D ]G\}}| j | ||d3 tƒ }| |¡ |  t¡}| |¡ W d   ƒ n1 s0w   Y  |  t|jƒd¡ W d   ƒ n1 sHw   Y  qd S )N))úfoo-barrŸ   )Úfoo_barr    ©rŸ   r    )r    rŸ   )rZ   r[   z Option.*foo.bar.*already defined)ÚsubTestr   r    r<   r   r›   r   rœ   )r   ÚtestsrZ   r[   r$   r   r   r   r   Útest_error_redefine_underscore  s   
ÿû€ÿz*OptionsTest.test_error_redefine_underscorec                 C   sd   dD ]-}dD ](}t ƒ }| |¡ | d|g¡ |  |jd¡ |  |d d¡ |  |d d¡ qqd S )Nr¡   )z--foo-bar=az--foo_bar=ar   rZ   rŸ   r    )r   r    r!   r"   r    )r   Údefined_nameÚflagr$   r   r   r   Útest_dash_underscore_cli  s   
øÿz$OptionsTest.test_dash_underscore_clic                 C   sH   dD ]}t ƒ }| |¡ | tj tj t¡d¡¡ |  |j	d¡ qd S )Nr¡   r)   rZ   )
r   r    r0   r*   r+   r,   r-   r/   r"   r    )r   r¥   r$   r   r   r   Útest_dash_underscore_file+  s   
ÿúz%OptionsTest.test_dash_underscore_filec                 C   s¾   t ƒ }|jddd |jddd g d¢}|  t|ƒ|¡ |  tdd„ | ¡ D ƒƒ|¡ |  t| ¡  ¡ ƒ|¡ |  t| d¡ƒddg¡ tƒ }| 	|¡ |  
d| ¡ ¡ |  
d	| ¡ ¡ d S )
Nú	with-dashÚg)rk   Úwith_underscore)r]   r©   r«   c                 s   s    | ]\}}|V  qd S r   r   )Ú.0ÚkÚvr   r   r   Ú	<genexpr>=  s   € zAOptionsTest.test_dash_underscore_introspection.<locals>.<genexpr>z--with-dashz--with-underscore)r   r    r"   rc   rd   rh   Úkeysrr   r   Ú
print_helpr?   r>   )r   r$   Úall_optionsÚbufr   r   r   Ú"test_dash_underscore_introspection6  s   ÿ
z.OptionsTest.test_dash_underscore_introspectionN)r   r   r   r%   r2   r9   rB   rN   rT   rV   rY   r\   r`   ra   rb   rg   ri   rv   r~   r†   r’   r“   r•   r—   rš   rž   r¤   r§   r¨   r´   r   r   r   r   r      s8    r   )r   Úior   r*   r:   Úunittestr   Útornado.optionsr   r   Útornado.utilr   ÚtypingÚTYPE_CHECKINGr   r   ÚTestCaser   r   r   r   r   Ú<module>   s    