
    Xhi.                         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                  rd dlmZ  G d d      Z G d	 d
ej                         Zy)    N)StringIO)mock)OptionParserError)basestring_type)Listc                   "    e Zd Zd Zed        Zy)Emailc                 N    t        |t              rd|v r|| _        y t               )N@)
isinstancestr_value
ValueError)selfvalues     M/var/www/html/myenv/lib/python3.12/site-packages/tornado/test/options_test.py__init__zEmail.__init__   s!    eS!cUlDK,    c                     | j                   S N)r   r   s    r   r   zEmail.value   s    {{r   N)__name__
__module____qualname__r   propertyr    r   r   r
   r
      s      r   r
   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)OptionsTestc                     t               }|j                  dd       |j                  ddg       | j                  |j                  d       y )NportP   defaultmain.pyz
--port=443  )r   defineparse_command_lineassertEqualr!   r   optionss     r   test_parse_command_linez#OptionsTest.test_parse_command_line   s@    .vr*""I|#<=s+r   c                    t               }|j                  dd       |j                  dd       |j                  d       t        j                  j	                  t        j                  j                  t        j                  j                  t                    d      }|j                  |       | j                  |j                  d       | j                  |j                  d	       | j                  |j                  |       y )
Nr!   r"   r#   usernamefoomy_pathoptions_test.cfgr&   u   李康)r   r'   ospathjoindirnameabspath__file__parse_config_filer)   r!   r.   r0   )r   r+   config_paths      r   test_parse_config_filez"OptionsTest.test_parse_config_file$   s    .vr*z51y!ggllGGOOBGGOOH568J
 	!!+.s+))84+6r   c                 t    t               }d _         fd}|j                  |       |j                  dgd        j	                   j                         |j                  dg        j                   j                         d _        |j                  dg        j                   j                         y )NFc                      d _         y )NT)calledr   s   r   callbackz2OptionsTest.test_parse_callbacks.<locals>.callback5   s
    DKr   r%   )final)r   r=   add_parse_callbackr(   assertFalse
assertTrue)r   r+   r>   s   `  r   test_parse_callbacksz OptionsTest.test_parse_callbacks1   s    .	 	""8, 	""I;e"<% 	""I;/$ ""I;/$r   c                 p   t               }	 t        j                  }t               t        _        | j	                  t
              5  |j                  ddg       d d d        t        j                  j                         }|t        _        | j                  d|       y # 1 sw Y   ExY w# t        _        w xY w)Nr%   z--helpzUsage:)	r   sysstderrr   assertRaises
SystemExitr(   getvalueassertIn)r   r+   orig_stderrusages       r   	test_helpzOptionsTest.test_helpH   s    .	%**K!CJ"":. B**Ix+@ABJJ'')E$CJh&B B %CJs#   8B( B&B( B%!B( (B5c                 z   t               }|j                  dd       t               }|j                  dt               |j                  g d      }| j	                  |ddg       | j                  |j                         |j                  |      }| j	                  |g        | j	                  |j                  d	       	 t        j                  }t               t        _	        | j                  t              5  |j                  dd
g       d d d        |t        _	        y # 1 sw Y   xY w# t        _	        w xY w)NverboseFr#   r/   type)r%   	--verbose
subcommand	--foo=barrS   rT   barrR   )r   r'   r   r(   r)   rB   rO   r/   rE   rF   r   rG   r   )r   base_optionssub_optionsrestrest2rK   s         r   test_subcommandzOptionsTest.test_subcommandT   s
   #~Iu5"n5s+..?
 	k:;,,-..t4#%0	%**K!CJ""5) L..k/JKL %CJL L %CJs$   8D- 9D!D- !D*&D- -D:c                     t               }|j                  ddt               d|_        | j	                  |j                  d       y Nr/      r$   rQ      )r   r'   intr/   r)   r*   s     r   test_setattrzOptionsTest.test_setattrk   s6    .uac2a(r   c                     t               }|j                  ddt               | j                  t              5  d|_        d d d        y # 1 sw Y   y xY w)Nr/   r]   r^   2)r   r'   r`   rG   r   r/   r*   s     r   test_setattr_type_checkz#OptionsTest.test_setattr_type_checkq   sG     .uac2u% 	GK	 	 	s   A		Ac                     g }t               }|j                  ddt        |j                         d|_        | j                  |dg       y )Nr/   r]   )r$   rQ   r>   r_   )r   r'   r`   appendr/   r)   )r   valuesr+   s      r   test_setattr_with_callbackz&OptionsTest.test_setattr_with_callbacky   s?    .uacFMMJ!%r   c                 f    t               }|j                  dd       |j                  dd       |S )Nar]   r#   br_   )r   r'   r*   s     r   _sample_optionszOptionsTest._sample_options   s.    .sA&sA&r   c                 p    | j                         }| j                  h dt        t        |                   y )N>   rj   rk   help)rl   r)   setiterr*   s     r   	test_iterzOptionsTest.test_iter   s*    &&(+Sg-?@r   c                 N    | j                         }| j                  d|d          y )Nr]   rj   )rl   r)   r*   s     r   test_getitemzOptionsTest.test_getitem   s$    &&(GCL)r   c                 |    t               }|j                  ddt               d|d<   | j                  |d   d       y r\   )r   r'   r`   r)   r*   s     r   test_setitemzOptionsTest.test_setitem   s8    .uac2+r   c                     | j                         }ddd|j                  fg}t        |j                               }| j	                  ||       y )N)rj   r]   )rk   r_   rn   )rl   rn   sorteditemsr)   )r   r+   expectedactuals       r   
test_itemszOptionsTest.test_items   sE    &&(h(>?(6*r   c                     | j                         }dd|j                  d}| j                  ||j                                y )Nr]   r_   )rj   rk   rn   )rl   rn   r)   as_dict)r   r+   ry   s      r   test_as_dictzOptionsTest.test_as_dict   s7    &&(GLL97??#45r   c                    t               }|j                  dd       |j                  ddd       t        j                  d      }|j                  j
                  }| j                  dd	|h|j                                |j                  d      }| j                  ddi|       | j                  i |j                  d
             y )Nrj   r]   r#   rk   b_groupr_   )groupr$   r    nonexistent)	r   r'   rE   	_getframef_codeco_filenamer)   groups
group_dict)r   r+   frame	this_fileb_group_dicts        r   test_group_dictzOptionsTest.test_group_dict   s    .sA&s)Q7a LL,,	)R3W^^5EF)))4#q<0W//>?r   c                    t               }|j                  dd       |j                  ddg       | j                  |j                  d       t
        j                  j                  |j                         dd      5  | j                  |j                  d       d d d        | j                  |j                  d       t
        j                  j                  |j                         dd      5  | j                  |j                  d       d	|_        | j                  |j                  d	       t
        j                  j                  |j                         dd
      5  | j                  |j                  d
       d d d        | j                  |j                  d	       d d d        | j                  |j                  d       y # 1 sw Y   *xY w# 1 sw Y   WxY w# 1 sw Y   ?xY w)Nr/   r]   r#   r%   z--foo=2r_               )	r   r'   r(   r)   r/   r   patchobjectmockabler*   s     r   test_mock_patchzOptionsTest.test_mock_patch   ss   .ua(""Iy#9:a(ZZw//15!< 	-W[[!,	-a( ZZw//15!< 	-W[[!,GKW[[!,""7#3#3#5ua@ 1  a01W[[!,	- 	a(	- 	-1 1		- 	-s1   <G,A/GG8$GGG	GG#c                    t               }|j                  dt               |j                  dt               |j                  dt               |j                  dt
               |j                  dt        j                         |j                  dt        j                         |j                  dt               |j                  d	t        d
       |j                  dt        d
       |S )Nr   rP   
basestringr`   floatdatetime	timedeltaemailzlist-of-intTrQ   multiplezlist-of-str)	r   r'   r   r   r`   r   r   r   r
   r*   s     r   _define_optionszOptionsTest._define_options   s    .u3'|/:u3'wU+z(9(9:{););<wU+}3>}3>r   c           
         | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j
                  t        j
                  ddddd	             | j                  |j                  t        j                  d
             | j                  |j                  j                  d       | j                  t        |j                  t                     | j                  |j                  g d       | j                  |j                  g d       y )Nasdfqwer*   g      ?i  r      r      -   )secondsztornado@web.com)r]   r_   r   rj   rk   c)r)   r   r   r`   r   r   r   r   r   rB   r   r
   list_of_intlist_of_strr*   s     r   _check_options_valuesz!OptionsTest._check_options_values   s    f-++V4b),))8+<+<T1b!R+PQ**H,>,>r,JK,,.?@
7==%89,,i8,,o>r   c                 l    | j                         }|j                  g d       | j                  |       y )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*   s     r   
test_typeszOptionsTest.test_types   s3    &&(""	
 	""7+r   c                     dD ]s  }| j                         }|j                  t        j                  j	                  t        j                  j                  t              |             | j                  |       u y )N)zoptions_test_types.cfgzoptions_test_types_str.cfg)r   r8   r2   r3   r4   r5   r7   r   )r   config_file_namer+   s      r   test_types_with_conf_filez%OptionsTest.test_types_with_conf_file   sb    !
 	0 **,G%%RWW__X68HI &&w/	0r   c                     t               }|j                  dt        d       |j                  ddg       | j	                  |j
                  g d       y )Nr/   Tr   r%   z--foo=a,b,cr   )r   r'   r   r(   r)   r/   r*   s     r   test_multiple_stringz OptionsTest.test_multiple_string   sB    .u36""I}#=>o6r   c                     t               }|j                  dt        d       |j                  ddg       | j	                  |j
                  g d       y )Nr/   Tr   r%   z--foo=1,3,5:7)r]   r   r   r      )r   r'   r`   r(   r)   r/   r*   s     r   test_multiple_intzOptionsTest.test_multiple_int   sB    .u36""I#?@o6r   c                     t               }|j                  d       | j                  t              5 }|j                  d       d d d        | j	                  t        j                        d       y # 1 sw Y   /xY w)Nr/   zOption.*foo.*already defined)r   r'   rG   r   assertRegexr   	exception)r   r+   cms      r   test_error_redefinezOptionsTest.test_error_redefine  s`    .uu% 	"NN5!	"R\\*,JK	" 	"s   A11A:c                 h   g d}|D ]  \  }}| j                  | ||      5  t               }|j                  |       | j                  t              5 }|j                  |       d d d        | j                  t        j                        d       d d d         y # 1 sw Y   9xY w# 1 sw Y   xY w)N))foo-barr   )foo_barr   r   r   )r   r   )rj   rk   z Option.*foo.bar.*already defined)subTestr   r'   rG   r   r   r   r   )r   testsrj   rk   r+   r   s         r   test_error_redefine_underscorez*OptionsTest.test_error_redefine_underscore  s    
  	XDAqda1- X&.q!&&u- &NN1%&  R\\!24VWX X	X& &X Xs#   1B(B$-B(B%!B((B1	c                    dD ]}  }dD ]v  }t               }|j                  |       |j                  d|g       | j                  |j                  d       | j                  |d   d       | j                  |d   d       x  y )Nr   )z--foo-bar=az--foo_bar=ar%   rj   r   r   )r   r'   r(   r)   r   )r   defined_nameflagr+   s       r   test_dash_underscore_cliz$OptionsTest.test_dash_underscore_cli  s    2 		:L6 :&.|,**It+<=  #6  !3S9  !3S9:		:r   c                     dD ]  }t               }|j                  |       |j                  t        j                  j                  t        j                  j                  t              d             | j                  |j                  d        y )Nr   r1   rj   )
r   r'   r8   r2   r3   r4   r5   r7   r)   r   )r   r   r+   s      r   test_dash_underscore_filez%OptionsTest.test_dash_underscore_file+  sj     3 	3L"nGNN<(%%RWW__X68JK W__c2	3r   c                 ~   t               }|j                  dd       |j                  dd       g d}| j                  t        |      |       | j                  t        d |j	                         D              |       | j                  t        |j                         j                               |       | j                  t        |j                  d            ddg       t               }|j                  |       | j                  d|j                                | j                  d|j                                y )	N	with-dashg)r   with_underscore)rn   r   r   c              3   &   K   | ]	  \  }}|  y wr   r   ).0kvs      r   	<genexpr>zAOptionsTest.test_dash_underscore_introspection.<locals>.<genexpr>=  s     @fq!@s   z--with-dashz--with-underscore)r   r'   r)   rw   rx   r}   keysr   r   
print_helprJ   rI   )r   r+   all_optionsbufs       r   "test_dash_underscore_introspectionz.OptionsTest.test_dash_underscore_introspection6  s    .{#.(4>+6@@@+N 1 6 6 89;G7%%c*+k;L-M	

 j3mS\\^4)3<<>:r   N)r   r   r   r,   r:   rC   rM   rZ   ra   rd   rh   rl   rq   rs   ru   r{   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s    ,7%.
'%.)&A
*,+6
@)*
?,$	077LX":	3;r   r   )r   ior   r2   rE   unittestr   tornado.optionsr   r   tornado.utilr   typingTYPE_CHECKINGr   r
   TestCaser   r   r   r   <module>r      sJ      	 
   / ( 		 	k;(## k;r   