
    g.                         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mZ d dlZej                  rd dlmZ  G d d	e      Z G d
 dej&                        Zy)    N)StringIO)mock)OptionParserError)basestring_type)subTest)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     N/var/www/openai/venv/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/   r1   )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>.callback6   s
    DKr   r&   )final)r   r>   add_parse_callbackr)   assertFalse
assertTrue)r   r,   r?   s   `  r   test_parse_callbacksz OptionsTest.test_parse_callbacks2   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_helpI   s    .	%**K!CJ"":.**Ix+@A /JJ'')E$CJh& /. %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$   r0   type)r&   	--verbose
subcommand	--foo=barrT   rU   barrS   )r   r(   r   r)   r*   rC   rP   r0   rF   rG   r   rH   r   )r   base_optionssub_optionsrestrest2rL   s         r   test_subcommandzOptionsTest.test_subcommandU   s    #~Iu5"n5s+..?
 	k:;,,-..t4#%0	%**K!CJ""5)..k/JK * %CJ *) %CJs$   8D- 9D!D- !D*&D- -D:c                     t               }|j                  ddt               d|_        | j	                  |j                  d       y Nr0      r%   rR      )r   r(   intr0   r*   r+   s     r   test_setattrzOptionsTest.test_setattrl   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)Nr0   r^   r_   2)r   r(   ra   rH   r   r0   r+   s     r   test_setattr_type_checkz#OptionsTest.test_setattr_type_checkr   s>     .uac2u%GK &%%s   A		Ac                     g }t               }|j                  ddt        |j                         d|_        | j                  |dg       y )Nr0   r^   )r%   rR   r?   r`   )r   r(   ra   appendr0   r*   )r   valuesr,   s      r   test_setattr_with_callbackz&OptionsTest.test_setattr_with_callbackz   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                     | j                         }| j                  t        g d      t        t        |                   y )Nrk   rl   help)rm   r*   setiterr+   s     r   	test_iterzOptionsTest.test_iter   s/    &&(/0#d7m2DEr   c                 N    | j                         }| j                  d|d          y )Nr^   rk   )rm   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(   ra   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)rk   r^   )rl   r`   rp   )rm   rp   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`   ro   )rm   rp   r*   as_dict)r   r,   r{   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                  t        dd	|g      |j                                |j                  d      }| j                  ddi|       | j                  i |j                  d
             y )Nrk   r^   r$   rl   b_groupr`   )groupr%   r    nonexistent)
r   r(   rF   	_getframef_codeco_filenamer*   rq   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,,	iY78'..:JK)))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)Nr0   r^   r$   r&   z--foo=2r`               )	r   r(   r)   r*   r0   r   patchobjectmockabler+   s     r   test_mock_patchzOptionsTest.test_mock_patch   s`   .ua(""Iy#9:a(ZZw//15!<W[[!, =a( ZZw//15!<W[[!,GKW[[!,""7#3#3#5ua@  a0 AW[[!, = 	a( =< A@	 =<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   rQ   
basestringra   floatdatetime	timedeltaemailzlist-of-intTrR   multiplezlist-of-str)	r   r(   r   r   ra   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   rk   rl   c)r*   r   r   ra   r   r   r   r   r   rC   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   r9   r3   r4   r5   r6   r8   r   )r   config_file_namer,   s      r   test_types_with_conf_filez%OptionsTest.test_types_with_conf_file   s]    !
 **,G%%RWW__X68HI &&w/!
r   c                     t               }|j                  dt        d       |j                  ddg       | j	                  |j
                  g d       y )Nr0   Tr   r&   z--foo=a,b,cr   )r   r(   r   r)   r*   r0   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 )Nr0   Tr   r&   z--foo=1,3,5:7)r^   r   r   r      )r   r(   ra   r)   r*   r0   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)Nr0   zOption.*foo.*already defined)r   r(   rH   r   assertRegexr   	exception)r   r,   cms      r   test_error_redefinezOptionsTest.test_error_redefine  sY    .uu%NN5! &R\\*,JK &%s   A11A:c                 \   g d}|D ]  \  }}t        | ||      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   )rk   rl   z Option.*foo.bar.*already defined)r   r   r(   rH   r   r   r   r   )r   testsrk   rl   r,   r   s         r   test_error_redefine_underscorez*OptionsTest.test_error_redefine_underscore  s    
 DAqa(&.q!&&u-NN1% .  R\\!24VW )(  .- )(s#   1B"B-B"BB""B+	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&   rk   r   r   )r   r(   r)   r*   r   )r   defined_nameflagr,   s       r   test_dash_underscore_cliz$OptionsTest.test_dash_underscore_cli  sz    2L6&.|,**It+<=  #6  !3S9  !3S9 7 3r   c                     dD ]  }t               }|j                  |       |j                  t        j                  j                  t        j                  j                  t              d             | j                  |j                  d        y )Nr   r2   rk   )
r   r(   r9   r3   r4   r5   r6   r8   r*   r   )r   r   r,   s      r   test_dash_underscore_filez%OptionsTest.test_dash_underscore_file,  se     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)rp   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*   ry   rz   r   keysr   r   
print_helprK   rJ   )r   r,   all_optionsbufs       r   "test_dash_underscore_introspectionz.OptionsTest.test_dash_underscore_introspection7  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;   rD   rN   r[   rb   re   ri   rm   rs   ru   rw   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r       s    ,7%.
'%.)&F
*,+6
@)*
?,$	077LX":	3;r   r    )r   ior   r3   rF   unittestr   tornado.optionsr   r   tornado.utilr   tornado.test.utilr   typingTYPE_CHECKINGr	   r   r   TestCaser    r   r   r   <module>r      sO      	 
   / ( % 		F 	k;(## k;r   