
    Cc7                       d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZ ddl
mZ ddlmZmZ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dlmZ ddlmZ ddlmZ ddlmZ  G d dej6                        Z G d dej6                        Z G d dej6                        Z G d dej6                        Z G d dej6                        Z  G d dej6                        Z! G d dej6                        Z" G d dej6                        Z# G d d ej6                        Z$ G d! d"ej6                        Z% G d# d$ej6                        Z& G d% d&ej6                        Z'd' Z(e)d(k(  r ejT                  d)*       yy)+z!Test suite for supervisor.options    N)StringIO)as_bytes)Mocksentinelpatch)LevelsByName)DummySupervisor)DummyLogger)DummyOptions)DummyPoller)DummyPConfig)DummyProcess)DummySocketConfig)lstripc                       e Zd Zd Zd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)OptionTestsc                     ddl m} |S )Nr   Options)supervisor.optionsr   )selfr   s     ?/usr/lib/python3/dist-packages/supervisor/tests/test_options.py_getTargetClasszOptionTests._getTargetClass   s
    .    c                     | j                         ddlm}  G fdd      } |       }t               |_        |j                  ddddd	       |j                  d
d
ddd|       |S )Nr   )integerc                   ,    e Zd ZddiZW f fd	Zd Zy)+OptionTests._makeOptions.<locals>.MyOptionsother)   c                 l    || _         j                  |         G d dt              } |       | _        y )Nc                       e Zd Zy)AOptionTests._makeOptions.<locals>.MyOptions.__init__.<locals>.FooN__name__
__module____qualname__ r   r   Foor#   -   s    r   r)   )
read_error__init__object
configroot)r   r*   r)   r   s      r   r+   z4OptionTests._makeOptions.<locals>.MyOptions.__init__*   s)    ",  &'&'"%%r   c                    | j                   rt        | j                         | j                  j                  j	                  | j
                         | j                  j                  j	                  | j                         y N)r*   
ValueErrorr-   __dict__updatedefault_mapmaster)r   fps     r   read_configz7OptionTests._makeOptions.<locals>.MyOptions.read_config0   sR    ??$T__55((//0@0@A((//<r   N)r%   r&   r'   r4   r+   r6   )r   r*   s   r   	MyOptionsr   '   s    F*4 (=r   r7   anoptionooptiondefault)nameconfnameshortlongr;   r   OTHERzp:zother=)r<   r=   envr>   r?   handler)r   supervisor.datatypesr   r   
configfileadd)r   r*   r   r7   optionsr   s    `   @r   _makeOptionszOptionTests._makeOptions#   st    &&(0	= 	=  +%ZjHi 	 	A7Xw 	 	@r   c                 x    | j                         } |       }| j                  t        |j                  dd       y )NT)flagrB   r   assertRaisesr0   rE   r   clsinsts      r   'test_add_flag_not_None_handler_not_Nonez3OptionTests.test_add_flag_not_None_handler_not_None?   s2    ""$u*dhhT4Hr   c                 z    | j                         } |       }| j                  t        |j                  ddd       y )NTFrI   r?   r>   rJ   rL   s      r   -test_add_flag_not_None_long_false_short_falsez9OptionTests.test_add_flag_not_None_long_false_short_falseD   s=    ""$uHH 	 	r   c                 z    | j                         } |       }| j                  t        |j                  ddd       y )NTF:rQ   rJ   rL   s      r   +test_add_flag_not_None_short_endswith_colonz7OptionTests.test_add_flag_not_None_short_endswith_colonO   s=    ""$uHH 	 	r   c                 z    | j                         } |       }| j                  t        |j                  ddd       y )NT=FrQ   rJ   rL   s      r   *test_add_flag_not_None_long_endswith_equalz6OptionTests.test_add_flag_not_None_long_endswith_equalZ   s=    ""$uHH 	 	r   c                 x    | j                         } |       }| j                  t        |j                  dd       y )NrW   abcr?   r>   rJ   rL   s      r   (test_add_inconsistent_short_long_optionsz4OptionTests.test_add_inconsistent_short_long_optionse   s:    ""$uHH	 	 	r   c                 x    | j                         } |       }| j                  t        |j                  dd       y )NF-abcr[   rJ   rL   s      r   %test_add_short_option_startswith_dashz1OptionTests.test_add_short_option_startswith_dasho   s:    ""$uHH	 	 	r   c                 x    | j                         } |       }| j                  t        |j                  dd       y )NFrZ   r[   rJ   rL   s      r   test_add_short_option_too_longz*OptionTests.test_add_short_option_too_longy   s:    ""$uHH	 	 	r   c                     | j                         } |       }ddi|_        | j                  t        |j                  dd       y )Nz-aTFar[   r   options_maprK   r0   rE   rL   s      r   #test_add_duplicate_short_option_keyz/OptionTests.test_add_duplicate_short_option_key   sF    ""$u ;HH	 	 	r   c                 x    | j                         } |       }| j                  t        |j                  dd       y )Nr^   Fr[   rJ   rL   s      r   $test_add_long_option_startswith_dashz0OptionTests.test_add_long_option_startswith_dash   s:    ""$uHH	 	 	r   c                     | j                         } |       }ddi|_        | j                  t        |j                  dd       y )Nz--abcTrZ   Fr[   rd   rL   s      r   "test_add_duplicate_long_option_keyz.OptionTests.test_add_duplicate_long_option_key   sF    ""$u#D>HH	 	 	r   c                     | j                         }| j                  t        |j                        d       | j                  |j                  dd  g d       y )N   )supervisord.confzetc/supervisord.confz/etc/supervisord.confz /etc/supervisor/supervisord.conf)rG   assertEquallensearchpathsr   rF   s     r   test_searchpathszOptionTests.test_searchpaths   sM    ##%W00115,,RS1 4 	r   c                    | j                         }|j                  g        | j                  |j                  d       | j                  |j                  d       | j                         }dt
        j                  d<   |j                  g        | j                  |j                  d       | j                         }|j                  ddg       | j                  |j                  d       t
        j                  d= y )	Nr;   r    42r@   *   -p43+   )rG   realizero   r8   r   osenvironrr   s     r   test_options_and_args_orderz'OptionTests.test_options_and_args_order   s    ##%))95+ ##%"

7+ ##%t%+JJwr   c                     | j                         }|j                  g        | j                  |j                  d       d|j                  d<   |j                          | j                  |j                  d       y )Nr    rv   r   )rG   rz   ro   r   r4   process_configrr   s     r   test_config_reloadzOptionTests.test_config_reload   s^    ##%+"$w +r   c                 j    | j                  d      }| j                  t        |j                  d       y )Nerrorr*   F)rG   rK   r0   r   rr   s     r   !test_config_reload_do_usage_falsez-OptionTests.test_config_reload_do_usage_false   s0    ##w#7*g&<&<	!r   c                     | j                  d      }g fd|_        t               x|_        |_        d|j
                  _        d|j
                  _        |j                  d       | j                  dg       y )Nr   r   c                 &    j                  |       S r/   appendx	exitcodess    r   <lambda>z>OptionTests.test_config_reload_do_usage_true.<locals>.<lambda>       !1!1!!4 r      Tdo_usage   )
rG   exitr   stderrstdoutr-   r8   r   r   ro   )r   rF   r   s     @r    test_config_reload_do_usage_truez,OptionTests.test_config_reload_do_usage_true   sq    ##w#7	4*2*4&'##$ -QC(r   c                 P   ddl m}  |       }|j                  ddd       | j                  |j                  d       | j                  |j
                  d   d       |j                  ddd       | j                  |j                  d       | j                  |j
                  d   d       |j                  ddd       | j                  |j                  d       | j                  |j
                  d   d       |j                  ddd       | j                  |j                  d       y )Nr   r   foobarbazr   gazonk)r   r   _setro   r   attr_priorities)r   r   rF   s      r   	test__setzOptionTests.test__set   s    .)UE1%e,007;UE1%e,007;UHa(e,007;UHa(h/r   c                 $   | j                         }g |_        g fd|_        t               |_        |j                          | j                  dg       d}| j                  |j                  j                         j                  |             y )Nc                 &    j                  |       S r/   r   r   s    r   r   z9OptionTests.test_missing_default_config.<locals>.<lambda>   r   r   r   z,Error: No config file found at default paths)
rG   rq   r   r   r   default_configfilero   
assertTruegetvalue
startswithr   rF   msgr   s      @r   test_missing_default_configz'OptionTests.test_missing_default_config   su    ##% 	4!""$QC(<//1<<SABr   c                     | j                         }t        j                         5 }|j                  g|_        |j                         }| j                  ||j                         d d d        y # 1 sw Y   y xY wr/   )rG   tempfileNamedTemporaryFiler<   rq   r   ro   )r   rF   fconfigs       r   test_default_configzOptionTests.test_default_config   sc    ##%((* 	-a#$66(G//1FVQVV,	- 	- 	-s   ?A--A6c                    | j                         }g fd|_        t               |_        d|_        d|_        |j                  d       | j                  dg       d}| j                  |j                  j                         |       y )Nc                 &    j                  |       S r/   r   r   s    r   r   z'OptionTests.test_help.<locals>.<lambda>   r   r   	test_helpzA sample docstring for %s r   z!A sample docstring for test_help
)	rG   r   r   r   prognamedochelpro   r   r   s      @r   r   zOptionTests.test_help   su    ##%	4!&1RQC(2002C8r   N)F)r%   r&   r'   r   rG   rO   rR   rU   rX   r\   r_   ra   rf   rh   rj   rs   r}   r   r   r   r   r   r   r   r(   r   r   r   r      sm    8I
					 &,!
)0	C-
9r   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y)ClientOptionsTestsc                     ddl m} |S )Nr   )ClientOptions)r   r   )r   r   s     r   r   z"ClientOptionsTests._getTargetClass      4r   c                 ,     | j                                S r/   r   r   s    r   _makeOnezClientOptionsTests._makeOne	      %t##%''r   c                 x   | j                         }g |_        g fd|_        |j                  g d       | j	                  g        | j	                  |j
                  d       | j	                  |j                  d       | j	                  |j                  d       | j	                  |j                  d       y)	z(Making sure config file is not required.c                 &    j                  |       S r/   r   r   s    r   r   z8ClientOptionsTests.test_no_config_file.<locals>.<lambda>  s    )"2"21"5 r   )z-shttp://localhost:9001z-uchrisrw   123argsr   r   r   r   N)	r   rq   r   rz   ro   interactive	serverurlusernamepassword)r   instancer   s     @r   test_no_config_filez&ClientOptionsTests.test_no_config_file  s    ==?!	5 , 	- 	B'--q1++-DE**G4**E2r   c                    t        j                         }t        d|z        }t        |      }| j	                         }||_        |j                  g        | j                  |j                  d       t        j                  j                  |d      }| j                  |j                  |       |j                  j                  }| j                  |j                  d       | j                  |j                   d       | j                  |j"                  d       | j                  |j$                  d       | j                  |j                  |       y )	Nz[supervisorctl]
        serverurl=http://localhost:9001
        username=chris
        password=123
        prompt=mysupervisor
        history_file=%s/sc_history
        r   T
sc_historymysupervisorr   r   r   )r   
gettempdirr   r   r   rD   rz   ro   r   r{   pathjoinhistory_filer-   supervisorctlpromptr   r   r   )r   tempdirsr5   r   r   rF   s          r   test_optionszClientOptionsTests.test_options  s   %%'    a[==? b!--t4ww||G\:..=%%338**,CD))73))51--|<r   c                     t        d      }| j                         }t        |      |_        |j	                  g        |j
                  j                  }| j                  |j                  d       y )Nzx
        [supervisorctl]
        serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
        r   http://127.0.0.1:9001	r   r   r   rD   rz   r-   r   ro   r   r   textr   rF   s       r   3test_options_ignores_space_prefixed_inline_commentszFClientOptionsTests.test_options_ignores_space_prefixed_inline_comments4  c       ==?&tnb!%%33**,CDr   c                     t        d      }| j                         }t        |      |_        |j	                  g        |j
                  j                  }| j                  |j                  d       y )Nzw
        [supervisorctl]
        serverurl=http://127.0.0.1:9001	;use an http:// url to specify an inet socket
        r   r   r   r   s       r   1test_options_ignores_tab_prefixed_inline_commentszDClientOptionsTests.test_options_ignores_tab_prefixed_inline_comments?  r   r   c                 ~    t        d      }| j                         }t        |      |_        |j	                  g        y )Nz
        [supervisorctl]
        serverurl=http://localhost:9001 ;duplicate

        [supervisorctl]
        serverurl=http://localhost:9001 ;duplicate
        r   r   r   r   rD   rz   r   r   r   s      r   3test_options_parses_as_nonstrict_for_py2_py3_compatzFClientOptionsTests.test_options_parses_as_nonstrict_for_py2_py3_compatJ  s;       ==?&tnb!r   c                 @   t        d      }t        |      }| j                         }t        j                         ddddddd|_        ||_        |j                  g 	       | j                  |j                  d
       |j                  j                  }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                   d       y )Na  
        [supervisorctl]
        serverurl=http://localhost:%(ENV_SERVER_PORT)s
        username=%(ENV_CLIENT_USER)s
        password=%(ENV_CLIENT_PASS)s
        prompt=%(ENV_CLIENT_PROMPT)s
        history_file=/path/to/histdir/.supervisorctl%(ENV_CLIENT_HIST_EXT)s
        johndoe9210someuserpasswordherexsupervisorz.hist)ENV_HOMEENV_USERENV_SERVER_PORTENV_CLIENT_USERENV_CLIENT_PASSENV_CLIENT_PROMPTENV_CLIENT_HIST_EXTr   Tzhttp://localhost:9210z$/path/to/histdir/.supervisorctl.hist)r   r   r   r   r   environ_expansionsrD   rz   ro   r   r-   r   r   r   r   r   r   )r   r   r5   r   rF   s        r   (test_options_with_environment_expansionsz;ClientOptionsTests.test_options_with_environment_expansionsW  s       a[==?3;3F3F3H3<:@:D:H<I>E'(# !b!--t4%%337**,CD)):6))>:--/UVr   c                    | j                         }t        d      }t        j                         }t        j
                  j                  |d      }t        |d      5 }|j                  |       d d d        	 ||_	        |j                  g        t        j                  |d       |j                  j                  }| j                  |j                   t        j
                  j                  |d             | j                  |j"                  dt        j
                  j                  |d	      z          y # 1 sw Y   xY w# t        j                  |d       w xY w)
Nz}
        [supervisorctl]
        history_file=%(here)s/sc_history
        serverurl=unix://%(here)s/supervisord.sock
        rn   wr   Tignore_errorsr   unix://supervisord.sock)r   r   r   mkdtempr{   r   r   openwriterD   rz   shutilrmtreer-   r   ro   r   r   )r   r   r   heresupervisord_confr   rF   s          r   /test_options_supervisorctl_section_expands_herezBClientOptionsTests.test_options_supervisorctl_section_expands_hereu  s   ==?  
 !77<<.@A"C( 	AGGDM		4"2H"%MM$d3%%33--77<<l+	-**rww||D*<==	?	 	 MM$d3s   D57E 5D>Ec                 X   t         j                  j                  t         j                  j                  t              d      }| j                         }	 |j                  |       | j                  d       y # t        $ r*}| j                  d|j                  d   v        Y d }~y d }~ww xY wNnonexistentnothing raisedzcould not find config filer   r{   r   r   dirname__file__r   r6   failr0   r   r   r   r  r   excs       r   test_read_config_not_foundz-ClientOptionsTests.test_read_config_not_found  ~    ggll277??8#<mL==?	I  -II&' 	IOO8CHHQKGHH	I   "A6 6	B)? B$$B)c                     | j                         }d }||_        	 |j                  t               | j	                  d       y # t
        $ r*}| j                  d|j                  d   v        Y d }~y d }~ww xY w)Nc                 <    t        t        j                  d| z        NzPermission denied: %sIOErrorerrnoEACCESfnmodes     r   
dummy_openzBClientOptionsTests.test_read_config_unreadable.<locals>.dummy_open      %,,(?"(DEEr   zexpected exceptioncould not read config filer   r   r   r6   r  r  r0   r   r   r   r   r  r
  s       r   test_read_config_unreadablez.ClientOptionsTests.test_read_config_unreadable  sj    ==?	F"	I  *II*+ 	IOO8CHHQKGHH	I   &A 	A6 A11A6c                     | j                         }	 |j                  t                      | j                  d       y # t        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)Nr  r   z0.ini file does not include supervisorctl sectionr   r6   r   r  r0   ro   r   r   r   r
  s      r   9test_read_config_no_supervisord_section_raises_valueerrorzLClientOptionsTests.test_read_config_no_supervisord_section_raises_valueerror  sd    ==?	D  ,II&' 	DSXXa[BD D	D   *= 	A/A**A/c                     t        d      }| j                         }||_        |j                  ddg       | j	                  |j
                  d       y )Nz[supervisorctl]z--serverurlunix:///dev/nullr   )r   r   rD   rz   ro   r   )r   r5   r   s      r   test_options_unixsocket_cliz.ClientOptionsTests.test_options_unixsocket_cli  sN    '(==? }.@AB++-?@r   c                     t        d      }t        |      }| j                         }||_        |j	                  g        | j                  |j                  d       y )Nz;[supervisorctl]
        serverurl=unix:///dev/null
        r   r%  )r   r   r   rD   rz   ro   r   )r   r   r5   r   s       r   "test_options_unixsocket_configfilez5ClientOptionsTests.test_options_unixsocket_configfile  sW       a[==? b!++-?@r   N)r%   r&   r'   r   r   r   r   r   r   r   r   r   r  r  r"  r&  r(  r(   r   r   r   r     sP    (3 =0	E	E
"W<?,I
IDAA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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. Z0d/ Z1d0 Z2d1 Z3 e4d2 e5             d3        Z6d4 Z7d5 Z8d6 Z9d7 Z:d8 Z;d9 Z<d: Z=d; Z>d< Z?d= Z@ e4d> e5eA?            d@        ZBdA ZCdB ZDdC ZEdD ZFdE ZGdF ZHdG ZIdH ZJdI ZKdJ ZLdK ZMdL ZNdM ZOdN ZPdO ZQdP ZRdQ ZSdR ZTdS ZUdT ZVdU ZWdV ZXdW ZYdX ZZdY Z[dZ Z\d[ Z]d\ Z^d] Z_d^ Z`d_ Zad` Zbda Zcdb Zddc Zedd Zfde Zgdf Zhdg Zidh Zjdi Zkdj Zldk Zmdl Zndm Zodn Zpdo Zqdp Zrdq Zsdr Ztds Zudt Zvdu Zwdv Zxdw Zydx Zzdy Z{dz Z|d{ Z}d| Z~d} Zd~ Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z e4d e5g d             e4d e5d            d               Z e4d e5g d             e4d e5d            d               Zd Zy)ServerOptionsTestsc                     ddl m} |S )Nr   )ServerOptions)r   r,  )r   r,  s     r   r   z"ServerOptionsTests._getTargetClass  r   r   c                 ,     | j                                S r/   r   r   s    r   r   zServerOptionsTests._makeOne  r   r   c                     ddl m} | j                         }t               |_        | j                  t        |j                  d        | j                  |j                  j                         |dz          y )Nr   )VERSION
)
r   r/  r   r   r   rK   
SystemExitversionro   r   )r   r/  rF   s      r   test_versionzServerOptionsTests.test_version  sP    .--/!*goot<002GdNCr   c                 &%   t        ddt        j                         iz        }ddlm} t        |      }| j                         }||_        |j                  g        |j                  j                  }| j                  |j                  t        j                                | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                   d	       | j                  |j"                  d
       | j                  |j$                  d       | j                  |j&                  d       | j                  |j(                  d       | j                  |j*                  d       | j                  |j,                  t        j                                | j                  t/        |j0                        d       | j                  |j0                  d   d   t2        j4                         | j                  |j0                  d   d   d       | j                  |j0                  d   d   d       | j                  |j0                  d   d   d       | j                  |j0                  d   d   d       | j                  |j6                  d       | j                  |j8                  d       | j                  |j:                  d       | j                  |j6                  d       | j                  t/        |j<                        d	       | j                  |j>                  tA        d             |j<                  d   }| j                  |jB                  d       | j                  |jD                  d       | j                  t/        |jF                        d       |jF                  d   }| j                  |jB                  d       | j                  |jH                  d       | j                  |jD                  d       | j                  |jJ                  d       | j                  |jL                  |jN                         | j                  |jP                  d	       | j                  |jR                  d       | j                  |jT                  d       | j                  |jV                  d       | j                  |jX                  tZ        j\                         | j                  |j^                  d	       | j                  |j`                  d        | j                  |jb                  d        | j                  |jd                  |jg                  d!             | j                  |jh                  d       | j                  |jj                  dg       | j                  |j                  d"       | j                  |j                  d#       | j                  |j>                  tA        d             |j<                  d   }| j                  |jB                  d$       | j                  |jD                  d#       | j                  t/        |jF                        d       |jF                  d   }	| j                  |	jB                  d$       | j                  |	jH                  d       | j                  |	jD                  d#       | j                  |	jJ                  d       | j                  |	jL                  d        | j                  |	jT                  d        | j                  |	jV                  d%       | j                  |	jX                  tZ        jl                         | j                  |	j`                  d        | j                  |	jb                  d        | j                  |	jd                  d&       | j                  |	jh                  d#       | j                  |	jj                  dg       | j                  |	j                  d        |j<                  d#   }
| j                  |
jB                  d'       | j                  |
jD                  d(       | j                  t/        |
jF                        d       |
jF                  d   }| j                  |jB                  d)       | j                  |jH                  d       | j                  |jD                  d(       | j                  |jJ                  d       | j                  |jL                  |jn                         | j                  |jT                  d        | j                  |jV                  |jp                         | j                  |jd                  |jg                  d!             | j                  |jh                  d       | j                  |jj                  g d*       | j                  |jX                  tZ        jl                         | j                  |j`                  d       | j                  |jb                  d       |j<                  d(   }| j                  |jB                  d+       | j                  |jD                  d,       | j                  t/        |jF                        d#       |jF                  d   }| j                  |jB                  d-       | j                  |jH                  d       | j                  |jD                  d,       | j                  |jJ                  d       | j                  |jL                  |jN                         | j                  |jT                  d        | j                  |jV                  |jp                         | j                  |jd                  |jg                  d!             | j                  |jh                  d       | j                  |jj                  dg       | j                  |jX                  tZ        jl                         | j                  |j`                  d        | j                  |jb                  d        | j                  |j                  d        |jF                  d   }| j                  |jB                  d.       | j                  |jH                  d       | j                  |jD                  d,       | j                  |jJ                  d       | j                  |jL                  |jN                         | j                  |jT                  d        | j                  |jV                  |jp                         | j                  |jd                  |jg                  d!             | j                  |jh                  d       | j                  |jj                  dg       | j                  |jX                  tZ        jl                         | j                  |j`                  d        | j                  |jb                  d        | j                  |j                  d        |j<                  d,   }| j                  |jB                  d/       | j                  |jD                  d	       | j                  t/        |jF                        d#       |jF                  d   }| j                  |jB                  d0       | j                  |j                  d1       |jF                  d   }| j                  |jB                  d2       | j                  |j                  d3       tr        jt                  jw                  ts        jx                               }| j                  |jT                  d       | j                  |jz                  d       | j                  |j                  t        j                                | j                  |j                  d       | j                  |j                  tr        jt                  j}                  |d             | j                  |j                  d       | j                  |j                   d	       | j                  |j"                  d
       | j                  |j$                  tr        jt                  j}                  |d             | j                  |j&                  d       | j                  |j(                  d       | j                  |j~                  d        | j                  |j*                  d       | j                  |j,                  t        j                                | j                  t/        |j0                        d       | j                  |j0                  d   d   t2        j4                         | j                  |j0                  d   d   d       | j                  |j0                  d   d   d       | j                  |j0                  d   d   d       | j                  |j0                  d   d   d       | j                  |j6                  d       | j                  |j8                  d       | j                  |j:                  d       y )4Na  
        [supervisord]
        directory=%(tempdir)s
        backofflimit=10
        user=root
        umask=022
        logfile=supervisord.log
        logfile_maxbytes=1000MB
        logfile_backups=5
        loglevel=error
        pidfile=supervisord.pid
        nodaemon=true
        silent=true
        identifier=fleeb
        childlogdir=%(tempdir)s
        nocleanup=true
        minfds=2048
        minprocs=300
        environment=FAKE_ENV_VAR=/some/path

        [inet_http_server]
        port=127.0.0.1:8999
        username=chrism
        password=foo

        [program:cat1]
        command=/bin/cat
        priority=1
        autostart=true
        user=root
        stdout_logfile=/tmp/cat.log
        stopsignal=KILL
        stopwaitsecs=5
        startsecs=5
        startretries=10
        directory=/tmp
        umask=002

        [program:cat2]
        priority=2
        command=/bin/cat
        autostart=true
        autorestart=false
        stdout_logfile_maxbytes = 1024
        stdout_logfile_backups = 2
        stdout_logfile = /tmp/cat2.log

        [program:cat3]
        priority=3
        process_name = replaced
        command=/bin/cat
        autorestart=true
        exitcodes=0,1,127
        stopasgroup=true
        killasgroup=true

        [program:cat4]
        priority=4
        process_name = fleeb_%%(process_num)s
        numprocs = 2
        command = /bin/cat
        autorestart=unexpected

        [program:cat5]
        priority=5
        process_name = foo_%%(process_num)02d
        numprocs = 2
        numprocs_start = 1
        command = /bin/cat
        directory = /some/path/foo_%%(process_num)02d
        r   r   	datatypesr      supervisord.logi  >   (   supervisord.pidTfleebr   familyhostz	127.0.0.1porti'#  r   chrismr   r   i   i,  
/some/pathFAKE_ENV_VARcat1/bin/cat
   /tmp/cat.logF50MB/tmpr   cat2z/tmp/cat2.log   cat3   replaced)r   r      cat4   fleeb_0fleeb_1cat5foo_01z/some/path/foo_01foo_02z/some/path/foo_02)@r   r   r   
supervisorr6  r   r   rD   rz   r-   supervisordro   	directoryumasklogfilelogfile_maxbyteslogfile_backupsloglevelpidfilenodaemonsilent
identifierchildlogdirrp   server_configssocketAF_INET	nocleanupminfdsminprocsprocess_group_configsenvironmentdictr<   priorityprocess_configscommand	autostartautorestartRestartWhenExitUnexpected	startsecsstartretriesuidstdout_logfile
stopsignalsignalSIGKILLstopwaitsecsstopasgroupkillasgroupstdout_logfile_maxbytes	byte_sizestdout_logfile_backupsr   SIGTERMRestartUnconditionally	Automaticr{   r   abspathgetcwdgidr   
passwdfile)r   r   r6  r5   r   rF   rD  proc1rJ  proc2rL  proc3rP  proc4_aproc4_brT  proc5_aproc5_br   s                      r   r   zServerOptionsTests.test_options  sD    FL ,,./MF0 F1P 	)a[==? b!%%11**H,?,?,AB-*;<113EF00!4))2.*;<))40.++W5,,h.A.A.CDW334a8//28<fnnM//26:KH//26:DA//2:>I//2:>F**D1.))3/**D1W::;Q?,,d.MN,,Q/F+*T112A6$$Q'V,
3+$/**I,O,OP!,++R0A&--~>))6>>:++Q/**E2**E266",,V4	655r:1#.&1a(**Dl,KL,,Q/F+*T112A6$$Q'V,
3+$/**E2D)--?))6>>:**E2**E266=55q91#.$/,,Q/F+*T112A6$$Q'Z0
3+$/**I,L,LMD)--y/B/BC66",,V4	655r:)4))6>>:**D1**D1,,Q/F+*T112A6&&q)y1*5))1-**D1,,"<<	>d+//1D1DE88",,V4	677<**QC0++V^^<,,e4,,e4**D1&&q)y1*5))1-**D1,,"<<	>d+//1D1DE88",,V4	677<**QC0++V^^<,,e4,,e4**D1,,Q/F+*T112A6&&q)x0**,?@&&q)x0**,?@wwryy{+q)q)++X-@-@-BC.))277<<=N+OP224FG1115**B/))277<<=N+OP**D1$/,,d3,,g6--x/B/B/DEX445q9003H=v~~N003F;[I003F;TB003J?J003J?G++T2$/**C0r   c                    t        d      }| j                         }t        |      |_        |j	                  g        |j
                  j                  }| j                  |j                  d       | j                  |j                  d       y )Nz
        [supervisord]
        logfile=/tmp/supervisord.log ;(main log file;default $CWD/supervisord.log)
        minfds=123 ; (min. avail startup file descriptors;default 1024)
        r   z/tmp/supervisord.log{   )
r   r   r   rD   rz   r-   rX  ro   r[  rh  r   s       r   r   zFServerOptionsTests.test_options_ignores_space_prefixed_inline_comments  su      
 ==?&tnb!%%11*@A-r   c                     t        d      }| j                         }t        |      |_        |j	                  g        |j
                  j                  }| j                  |j                  d       y )Nz
        [supervisord]
        logfile=/tmp/supervisord.log	;(main log file;default $CWD/supervisord.log)
        minfds=123	; (min. avail startup file descriptors;default 1024)
        r   r  )	r   r   r   rD   rz   r-   rX  ro   rh  r   s       r   r   zDServerOptionsTests.test_options_ignores_tab_prefixed_inline_comments  s`      
 ==?&tnb!%%11-r   c                 ~    t        d      }| j                         }t        |      |_        |j	                  g        y )Nz
        [supervisord]

        [program:duplicate]
        command=/bin/cat

        [program:duplicate]
        command=/bin/cat
        r   r   r   s      r   r   zFServerOptionsTests.test_options_parses_as_nonstrict_for_py2_py3_compat  s;       ==?&tnb!r   c                    t        d      }| j                         }t        |      |_        |j	                  g        |j
                  j                  }| j                  t        |j                        d       |j                  d   }| j                  t        |j                        d       |j                  d   }| j                  t        |j                        d       | j                  |j                  |j                  u        t        d      }t        |      |_        |j                  d       |j
                  j                  }| j                  t        |j                        d       |j                  d   }| j                  t        |j                        d       |j                  d   }| j                  |j                  d	       | j                  |j                  d
       | j                  |j                  |j                  u        |j                  d   }| j                  t        |j                        d       |j                  d   }| j                  |j                  d       | j                  |j                  d       y )Nz        [supervisord]
        user=root

        [program:one]
        command = /bin/cat

        [program:two]
        command = /bin/dog

        [program:four]
        command = /bin/sheep

        [group:thegroup]
        programs = one,two
        r   r   r   r   z        [supervisord]
        user=root

        [program:one]
        command = /bin/cat

        [program:three]
        command = /bin/pig

        [group:thegroup]
        programs = three
        Fr   onerE  threez/bin/pig)r   r   r   rD   rz   r-   rX  ro   rp   rj  rn  r   r   r<   ro  )r   r   r   sectioncatprocs         r   test_reloadzServerOptionsTests.test_reload  s%     " ==?&tnb!%%11W::;Q?++A.S00115++A.S0011555 667 	8    'tn/%%11W::;Q?++A.S00115""1%E*z255 667 	8 ++A.S00115""1%G,z2r   c                 `   | j                         }d}|g|_        |g|_        |g|_        t	        d      }t        |      |_        |j                  g        | j                  ||j                  v        | j                  ||j                  v        | j                  ||j                  v        y )Nz Message from a prior config readb        [supervisord]
        user=root

        [program:cat]
        command = /bin/cat
        r   )	r   parse_criticalsparse_warningsparse_infosr   r   rD   rz   assertFalse)r   r   old_msgr   s       r   !test_reload_clears_parse_messagesz4ServerOptionsTests.test_reload_clears_parse_messages3  s    ==?4$+9 #*) 'y   'tnb!H$<$<<=H$;$;;<H$8$889r   c                     | j                         }d}|g|_        t        d      }t        |      |_        |j                  g        | j                  ||j                  v        y )NzInfo from a prior config readr  r   )r   infosr   r   rD   rz   r  r  )r   r   old_infor   s       r   test_reload_clears_parse_infosz1ServerOptionsTests.test_reload_clears_parse_infosG  sb    ==?2"   'tnb!X%9%99:r   c                 X   t         j                  j                  t         j                  j                  t              d      }| j                         }	 |j                  |       | j                  d       y # t        $ r*}| j                  d|j                  d   v        Y d }~y d }~ww xY wr  r  r	  s       r   r  z-ServerOptionsTests.test_read_config_not_foundW  r  r  c                     | j                         }d }||_        	 |j                  t               | j	                  d       y # t
        $ r*}| j                  d|j                  d   v        Y d }~y d }~ww xY w)Nc                 <    t        t        j                  d| z        r  r  r  s     r   r  zBServerOptionsTests.test_read_config_unreadable.<locals>.dummy_openb  r  r   r  r  r   r  r  s       r   r  z.ServerOptionsTests.test_read_config_unreadable`  sj    ==?	F"	I  *II&' 	IOO8CHHQKGHH	Ir  c                    | j                         }t        j                  d      5 }	 |j                  d       |j	                          |j                  |j                         | j                  d       d d d        y # t        $ rT}| j                  d|j                  d   v        | j                  |j                  |j                  d   v        Y d }~ad }~ww xY w# 1 sw Y   y xY w)Nw+r  z[supervisord]
junkr  contains parsing errors:r   )r   r   r   r   flushr6   r<   r  r0   r   r   )r   r   r   r
  s       r   8test_read_config_malformed_config_file_raises_valueerrorzKServerOptionsTests.test_read_config_malformed_config_file_raises_valueerrorl  s    ==?((d3 	7q7-.	$$QVV,		*+	7 	7  7 :chhqk IJ#((1+ 5667	7 	7s0   CAA??	CA
CCCCC(c                    | j                         }t        j                  j                  t        j                  j	                  t
              dd      }t        d|z        }	 |j                  t        |             | j                  d       y # t        $ r,}| j                  |j                  d   d|z         Y d }~y d }~ww xY w)Nr  r8  z1        [supervisord]
        logfile=%s
        r  r   z9The directory named as part of the path %s does not exist)r   r{   r   r   r  r  r   r6   r   r  r0   ro   r   )r   r   logfile_with_nonexistent_dirr   r
  s        r   1test_read_config_logfile_with_nonexistent_dirpathzDServerOptionsTests.test_read_config_logfile_with_nonexistent_dirpathy  s    ==?')ww||GGOOH%}($   ++ ,	  $0II&' 	SXXa[K,- 	s   "+B 	C"B>>Cc                     | j                         }	 |j                  t                      | j                  d       y # t        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)Nr  r   z..ini file does not include supervisord sectionr   r!  s      r   r"  zLServerOptionsTests.test_read_config_no_supervisord_section_raises_valueerror  sd    ==?	B  ,II&' 	BSXXa[@B B	Br#  c                     | j                         }t        d      }	 |j                  t        |             | j	                  d       y # t
        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)NzD        [supervisord]

        [include]
        ;no files=
        r  r   z5.ini file has [include] section, but no files setting)r   r   r6   r   r  r0   ro   r   r   r   r   r
  s       r   8test_read_config_include_with_no_files_raises_valueerrorzKServerOptionsTests.test_read_config_include_with_no_files_raises_valueerror  su    ==?  	I  $0II&' 	ISXXa[GI I	Is   +A	 		A;A66A;c                     | j                         }t        d      }|j                  t        |             | j	                  |j
                  dg       y )NzM        [supervisord]

        [include]
        files=nonexistent/*
        z-No file matches via include "./nonexistent/*")r   r   r6   r   ro   r  )r   r   r   s      r   <test_read_config_include_with_no_matching_files_logs_warningzOServerOptionsTests.test_read_config_include_with_no_matching_files_logs_warning  sM    ==?   	Xd^,00IJ	Lr   c                 R   t        j                         }t        j                  j	                  |d      }t        j
                  |       t        j                  j	                  |d      }t        d|d|d      }t        |d      5 }|j                  |       d d d        t        j                  j	                  |d      }t        |d      5 }|j                  d       d d d        t        j                  j	                  |d	      }t        |d      5 }|j                  d
       d d d        | j                         }	 |j                  |       t        j                  |d       |j                  j                  }	| j                  t!        |	j"                        d       d|z  }
| j%                  |
|j&                  v        d|z  }
| j%                  |
|j&                  v        y # 1 sw Y   OxY w# 1 sw Y   xY w# 1 sw Y   xY w# t        j                  |d       w xY w)Nconf.drn   7        [supervisord]

        [include]
        files=z/conf.d/*.conf z/conf.d/*.ini
        r   a.conf[inet_http_server]
port=8000
za.iniz"[unix_http_server]
file=/tmp/file
Tr   r   'Included extra file "%s" during parsing)r   r   r{   r   r   mkdirr   r   r   r   r6   r   r   r-   rX  ro   rp   rd  r   r  )r   r  conf_dr   r   r   	conf_fileini_filer   rF   r   s              r   *test_read_config_include_reads_extra_filesz=ServerOptionsTests.test_read_config_include_reads_extra_files  s   ""$gx0
77<<1CD
 ! " "C( 	AGGDM	 GGLL2	)S! 	7QGG56	7 77<<0(C  	<AGG:;	< ==?	7  !12MM'6%%11W334a87)Cx33347(Bx3334+	 		7 	7	< 	< MM'6s0   G'G4H?H 'G14G>H
H&c           	         t        j                         }t        j                  j	                  |d      }t        j
                  |       t        j                  j	                  |d      }t        d|z        }t        |d      5 }|j                  |       d d d        ddl	m
} |d d }t        |      D ]R  }t        j                  j	                  |d|z        }	t        |	d      5 }|j                  d	|d
|d       d d d        T | j                         }
	 |
j                  |       t        j                  |d       g }t!        |      D ]9  }t        j                  j	                  |d|z        }	|j#                  d|	z         ; | j%                  |
j&                  |       y # 1 sw Y   xY w# 1 sw Y   xY w# t        j                  |d       w xY w)Nr  rn   P        [supervisord]

        [include]
        files=%s/conf.d/*.conf
        r   r   )letters   %s.confz	[program:z]
command=/bin/r0  Tr   r  )r   r   r{   r   r   r  r   r   r   supervisor.compatr  reversedr   r6   r   r   sortedr   ro   r  )r   r  r  r   r   r   r  a_zletterfilenamer   expected_msgss               r   4test_read_config_include_reads_files_in_sorted_orderzGServerOptionsTests.test_read_config_include_reads_files_in_sorted_order  s   ""$gx0
77<<1CD 
   "C( 	AGGDM	 	.crlsm 	@Fww||FI,>?Hh$ @/5v? @@ @	@ ==?	7  !12MM'6Sk 	FFww||FI,>?H  9HDF	F 	--}=+	 	@ @ MM'6s$   F(&F5G (F25F?	Gc                    t        j                         }t        j                  j	                  |d      }t        j
                  |       t        j                  j	                  |d      }t        d|z        }t        |d      5 }|j                  |       d d d        t        j                  j	                  |d      }t        |d      5 }|j                  d       d d d        | j                         }	 |j                  |       | j                  d       t!        j"                  |d       y # 1 sw Y   xY w# 1 sw Y   `xY w# t        $ rl}| j                  d|j                  d	   v        | j                  ||j                  d	   v        d
|z  }	| j                  |	|j                  v        Y d }~d }~ww xY w# t!        j"                  |d       w xY w)Nr  rn   r  r   r  z[inet_http_server]
junk
r  r  r   r  Tr   )r   r   r{   r   r   r  r   r   r   r   r6   r  r0   r   r   r  r   r   )
r   r  r  r   r   r   malformed_filer   r
  r   s
             r   -test_read_config_include_extra_file_malformedz@ServerOptionsTests.test_read_config_include_extra_file_malformed  s   ""$gx0
77<<1CD 
   "C( 	AGGDM	 fh7.#& 	2!GG01	2 ==?		7  !12II&' MM'6#	 		2 	2  	9OO6#((1+EFOONchhqk9:;nLCOOC8#7#7788		9 MM'6sC   D/
D;5"E /D8;E	F<A"F72F? 7F<<F? ?Gc                    t        j                         }t        j                  j	                  |d      }t        j
                  |       t        j                  j	                  |d      }t        d|ddd      }t        |d      5 }|j                  |       d d d        t        j                  j	                  |dt        j                         z        }t        |d      5 }|j                  d	       d d d        | j                         }	 |j                  |       t        j                  |d
       |j                  j                   }| j#                  t%        |j&                        d       d|z  }	| j)                  |	|j*                  v        y # 1 sw Y   xY w# 1 sw Y   xY w# t        j                  |d
       w xY w)Nr  rn   r  z/conf.d/z%(host_node_name)sz.conf
        r   r  r  Tr   r   r  )r   r   r{   r   r   r  r   r   r   platformnoder   r6   r   r   r-   rX  ro   rp   rd  r   r  )
r   r  r  r   r   r   r  r   rF   r   s
             r   /test_read_config_include_expands_host_node_namezBServerOptionsTests.test_read_config_include_expands_host_node_name  sh   ""$gx0
77<<1CD
 ,. / "C( 	AGGDM	 GGLLX]]_)DE	)S! 	7QGG56	7 ==?	7  !12MM'6%%11W334a87)Cx3334	 		7 	7 MM'6s$   F#F F, F F),Gc                 ,   t         j                  j                  t         j                  j                  t         j                  j	                  t
                    dd      }t         j                  j	                  |      }t         j                  j                  |d      }| j                         }||_        |j                  d       |j                  j                  }| j                  |j                  |       | j                  |j                  |       y )Nfixtureszinclude.confexampleT)r{   r   r   r  r  r  r   rD   process_config_filer-   rX  ro   r[  rc  )r   conf	root_hereinclude_hereparserr  s         r   %test_read_config_include_expands_herez8ServerOptionsTests.test_read_config_include_expands_here2  s    ww||GGOOBGGOOH56
 GGOOD)	ww||Iy9 ""4(##//)4,,l;r   c                     ddl m} 	  |ddd       t        d      # t        $ r)}| j	                  |j
                  d   d       Y d }~y d }~ww xY w)Nr   )readFilez	/notthererF  zDidn't raiseFAILED)r   r  AssertionErrorr0   ro   r   )r   r  rN   s      r   test_readFile_failedz'ServerOptionsTests.test_readFile_failed?  sP    /	1[!R( !00  	5TYYq\844	5s   
 	AA

Ac                     | j                         }| j                  t        j                         |j	                                y r/   )r   ro   r{   getpidget_pidr   r   s     r   test_get_pidzServerOptionsTests.test_get_pidH  s,    ==?h&6&6&89r   c                    | j                         }|j                  j                  t        j                  d        |j                  j                  t        j
                  d        | j                  |j                         t        j                         | j                  |j                         t        j
                         | j                  |j                         d        y r/   )r   signal_receiverreceiverx  r  SIGCHLDro   
get_signalr  s     r   ,test_get_signal_delegates_to_signal_receiverz?ServerOptionsTests.test_get_signal_delegates_to_signal_receiverL  s    ==?  ((>  ((>,,.?,,.?,,.5r   c                 n    | j                         }ddlm} | j                  ||j                  dd d        y )Nr   )NotFoundz
/not/there)r   r   r  rK   check_execv_args)r   r   r  s      r   'test_check_execv_args_cant_find_commandz:ServerOptionsTests.test_check_execv_args_cant_find_commandT  s/    ==?/(H$=$=&d	4r   c           	          | j                         }ddlm} | j                  ||j                  ddgt        j                  d             y )Nr   NotExecutablez/etc/passwdz
etc/passwdr   r   r  rK   r  r{   statr   r   r  s      r   #test_check_execv_args_notexecutablez6ServerOptionsTests.test_check_execv_args_notexecutableZ  s<    ==?4-"33]'."''-*@	Br   c           	          | j                         }ddlm} | j                  ||j                  ddgt        j                  d             y )Nr   r  /r  r  s      r   test_check_execv_args_isdirz.ServerOptionsTests.test_check_execv_args_isdira  s:    ==?4-"33S%	/r   c                     | j                         }g fd}||_        t        d      |_        ddg}|j	                  |       | j                  t              d       | j                  d   d|z         y )	Nc                 (    j                  |        y r/   r   messagerecorders    r   record_usagezSServerOptionsTests.test_realize_positional_args_not_supported.<locals>.record_usagel      OOG$r   [supervisord]r   r   r   r   r   z*positional arguments are not supported: %sr   usager   rD   rz   ro   rp   )r   r   r  r   r  s       @r   *test_realize_positional_args_not_supportedz=ServerOptionsTests.test_realize_positional_args_not_supportedh  sw    ==?	%%$_5u~d#X*!84?	Ar   c                     | j                         }g fd}||_        t        d      |_        |j	                  dg       | j                  t              d       | j                  d   d       y )Nc                 (    j                  |        y r/   r   r  s    r   r  zBServerOptionsTests.test_realize_getopt_error.<locals>.record_usage{  r  r   r  z--bad=1r   r   r   zoption --bad not recognizedr  )r   r   r  r  s      @r   test_realize_getopt_errorz,ServerOptionsTests.test_realize_getopt_errorw  sh    ==?	%%$_5yk*X*!&CDr   c                     t        d      }| j                         }t        |      |_        |j	                  ddg       | j                  |j                  d       y )NzC
        [supervisord]
        identifier=from_config_file
        z-i	from_argsr   )r   r   r   rD   rz   ro   rb  r   s      r   )test_realize_prefers_identifier_from_argsz<ServerOptionsTests.test_realize_prefers_identifier_from_args  sV       ==?&tnt[12,,k:r   c                 F   | j                         }t        d      }ddlm}  |       }|j	                  |       t        |      |_        |j                  t        |             |j                  g        |j                  j                  }| j                  |j                  d   d   t        j                         | j                  |j                  d   d   d       | j                  |j                  d   d   d	       | j                  |j                  d   d
   d       y )Nz        [unix_http_server]
        file=/tmp/supvtest.sock
        username=johndoe
        password=passwordhere

        [supervisord]
        ; ...
        r   UnhosedConfigParserr   r=  file/tmp/supvtest.sockchmod  chown)r  r   r   r   r  read_stringr   rD   r6   rz   r-   rX  ro   rd  re  AF_UNIXr   r   r   r  r   rF   s         r   test_options_afunixz&ServerOptionsTests.test_options_afunix  s    ==?   	;$&4 &tnXd^,b!%%11//28<fnnM//26:<PQ//27;SA//27;WEr   c                    | j                         }t        d      }ddlm}  |       }|j	                  |       t        |      |_        |j                  t        |             |j                  g        |j                  j                  }| j                  |j                  d   d   t        j                         | j                  |j                  d   d   d       | j                  |j                  d   d   d	       y )
Nz        [unix_http_server]
        file=/tmp/supvtest.sock
        username=johndoe
        password=passwordhere
        chmod=0755

        [supervisord]
        ; ...
        r   r  r   r=  r  r  r  i  r  r  s         r   &test_options_afunix_chxxx_values_validz9ServerOptionsTests.test_options_afunix_chxxx_values_valid  s    ==? 	 	 	;$&4 &tnXd^,b!%%11//28<fnnM//26:<PQ//27;SAr   c                    | j                         }t        d      }t        |      |_        	 |j	                  t        |             | j                  d       y # t        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)Nzc        [supervisord]

        [unix_http_server]
        file=/tmp/file
        chmod=NaN
        r  r   zInvalid chmod value NaN	r   r   r   rD   r6   r  r0   ro   r   r  s       r   test_options_afunix_chmod_badz0ServerOptionsTests.test_options_afunix_chmod_bad  s~    ==?   'tn	+  $0II&' 	+SXXa[)+ +	+   +A 	B"BBc                    | j                         }t        d      }t        |      |_        	 |j	                  t        |             | j                  d       y # t        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)Nzs        [supervisord]

        [unix_http_server]
        file=/tmp/file
        chown=thisisnotavaliduser
        r  r   z+Invalid sockchown value thisisnotavaliduserr  r  s       r   test_options_afunix_chown_badz0ServerOptionsTests.test_options_afunix_chown_bad  s~    ==?   'tn	?  $0II&' 	?SXXa[=? ?	?r!  c                    | j                         }t        d      }t        |      |_        	 |j	                  t        |             | j                  d       y # t        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)NzL        [supervisord]

        [unix_http_server]
        ;no file=
        r  r   z,section [unix_http_server] has no file valuer  r  s       r   test_options_afunix_no_filez.ServerOptionsTests.test_options_afunix_no_file      ==?   'tn	@  $0II&' 	@SXXa[>@ @	@r!  c                    | j                         }t        d      }t        |      |_        	 |j	                  t        |             | j                  d       y # t        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)Nz        [supervisord]

        [unix_http_server]
        file=/tmp/supvtest.sock
        username=usernamehere
        ;no password=
        chmod=0755
        r  r   Section [unix_http_server] contains incomplete authentication: If a username or a password is specified, both the username and password must be specifiedr  r  s       r   -test_options_afunix_username_without_passwordz@ServerOptionsTests.test_options_afunix_username_without_password      ==?   'tn	   $0II&' 	 SXXa[   	 r!  c                    | j                         }t        d      }t        |      |_        	 |j	                  t        |             | j                  d       y # t        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)Nz        [supervisord]

        [unix_http_server]
        file=/tmp/supvtest.sock
        ;no username=
        password=passwordhere
        chmod=0755
        r  r   r(  r  r  s       r   -test_options_afunix_password_without_usernamez@ServerOptionsTests.test_options_afunix_password_without_username  r*  r!  c                    | j                         }t        d      }t        j                         }t        j
                  j                  |d      }t        |d      5 }|j                  |       d d d        	 ||_	        |j                  g        t        j                  |d       |j                  j                  }|j                  d   }| j!                  |d   t"        j$                         | j!                  |d	   t        j
                  j                  |d
             y # 1 sw Y   xY w# t        j                  |d       w xY w)Nza        [supervisord]

        [unix_http_server]
        file=%(here)s/supervisord.sock
        rn   r   r   Tr   r   r=  r  r   )r   r   r   r   r{   r   r   r   r   rD   rz   r   r   r-   rX  rd  ro   re  r  )r   r   r   r   r   r   rF   
serverconfs           r   %test_options_afunix_file_expands_herez8ServerOptionsTests.test_options_afunix_file_expands_here  s   ==?   !77<<.@A"C( 	AGGDM		4"2H"%MM$d3%%11++A.
H-v~~>F+GGLL12	4	 	 MM$d3s   D#7D/ #D,/Ec                    | j                         }t        d      }t        |      |_        	 |j	                  t        |             | j                  d       y # t        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)Nz        [supervisord]

        [inet_http_server]
        file=/tmp/supvtest.sock
        username=usernamehere
        ;no password=
        chmod=0755
        r  r   Section [inet_http_server] contains incomplete authentication: If a username or a password is specified, both the username and password must be specifiedr  r  s       r   -test_options_afinet_username_without_passwordz@ServerOptionsTests.test_options_afinet_username_without_password4  r*  r!  c                    | j                         }t        d      }t        |      |_        	 |j	                  t        |             | j                  d       y # t        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)Nzn        [supervisord]

        [inet_http_server]
        password=passwordhere
        ;no username=
        r  r   r1  r  r  s       r   -test_options_afinet_password_without_usernamez@ServerOptionsTests.test_options_afinet_password_without_usernameJ  s    ==?   'tn	   $0II&' 	 SXXa[   	 r!  c                    | j                         }t        d      }t        |      |_        	 |j	                  t        |             | j                  d       y # t        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)NzL        [supervisord]

        [inet_http_server]
        ;no port=
        r  r   z,section [inet_http_server] has no port valuer  r  s       r   test_options_afinet_no_portz.ServerOptionsTests.test_options_afinet_no_port^  r&  r!  c                    t        j                  d      5 }|j                  }|j                  d       d d d        | j	                         }d|_         G d d      }t        j                  d |       fg|_        d|_	        |j                          | j                  t        j                  j                  |             y # 1 sw Y   xY w)	NFdelete   fooTc                       e Zd Zy)=ServerOptionsTests.test_cleanup_afunix_unlink.<locals>.ServerNr$   r(   r   r   Serverr<  t  s    r   r=  r=  r  r   )r   r   r<   r   r   unlink_socketfilesre  r  httpserversr_  cleanupr  r{   r   existsr   r   r  r   r=  s        r   test_cleanup_afunix_unlinkz-ServerOptionsTests.test_cleanup_afunix_unlinkn  s    ((6 	!BGGFO	 ==?&*#	 	+1>>"!E!'!+  ,+,	 	s   CCc                 @   t        j                  d      5 }|j                  }|j                  d       d d d        	 | j	                         } G d d      }t
        j                  d |       fg|_        d|_        d|_	        |j                          | j                  t        j                  j                  |             	 t        j                  |       y # 1 sw Y   xY w# t         $ r Y y w xY w# 	 t        j                         w # t         $ r Y w w xY wxY w)NFr8  r:  c                       e Zd Zy)?ServerOptionsTests.test_cleanup_afunix_nounlink.<locals>.ServerNr$   r(   r   r   r=  rG        r   r=  r>  r   )r   r   r<   r   r   re  r  r@  r_  r?  rA  r   r{   r   rB  unlinkOSErrorrC  s        r   test_cleanup_afunix_nounlinkz/ServerOptionsTests.test_cleanup_afunix_nounlink|  s    ((6 	!BGGFO		}}H /5~~b%I%+X%/ $0H !H*/H'OOBGGNN2./		"	 	   		" sM   CBC6 C' C$'	C32C36D8DD	DDDDc                    t         j                  j                  t         j                  j                  t              d      }t        j                  d      5 }|j                  }|j                  d       d d d        	 | j                         }d|_
         G d d      }t        j                  |d |       ft        j                  d |       fg|_        d	|_        |j                          | j!                  t         j                  j#                  |             	 t        j$                  |       y # 1 sw Y   xY w# t&        $ r Y y w xY w# 	 t        j$                         w # t&        $ r Y w w xY wxY w)
NnotfoundFr8  r:  Tc                       e Zd Zy)MServerOptionsTests.test_cleanup_afunix_ignores_oserror_enoent.<locals>.ServerNr$   r(   r   r   r=  rO    rH  r   r=  r>  r   )r{   r   r   r  r  r   r   r<   r   r   r?  re  r  r@  r_  rA  r  rB  rI  rJ  )r   rM  r   
socketnamer   r=  s         r   *test_cleanup_afunix_ignores_oserror_enoentz=ServerOptionsTests.test_cleanup_afunix_ignores_oserror_enoent  s(   77<< 9:F((6 	!JGGFO		}}H*.H'  #NNH=vxH"NNJ?J$H   "HRWW^^J78		*%#	 	$  		*% sO   D5?BE E 5D>	EEE7E('E7(	E41E73E44E7c                 R   t        j                  d      5 }|j                  }|j                  d       d d d        	 | j	                         }|_        t               |_        |j                          | j                  |j                         |j                          | j                  t        j                  j                  |             	 t        j                   |       y # 1 sw Y   xY w# t"        $ r Y y w xY w# 	 t        j                          w # t"        $ r Y w w xY wxY wNFr8     2)r   r   r<   r   r   r_  r
   loggerwrite_pidfiler   unlink_pidfilerA  r  r{   r   rB  rI  rJ  r   r   r_  r   s       r   test_cleanup_removes_pidfilez/ServerOptionsTests.test_cleanup_removes_pidfile  s    ((6 	!ffGGGDM		}}H&H)mHO""$OOH334RWW^^G45		'"	 	  		'" sM   C$BC? C0 $C-0	C<;C<?D&DD&	D# D&"D##D&c                     t         j                  j                  t         j                  j                  t              d      }| j                         }||_        |j                          y )NrM  )r{   r   r   r  r  r   r_  rA  )r   rM  r   s      r   +test_cleanup_pidfile_ignores_oserror_enoentz>ServerOptionsTests.test_cleanup_pidfile_ignores_oserror_enoent  sB    77<< 9:F==?#r   c                    t        j                  d      5 }|j                  }|j                  d       d d d        	 | j	                         }|_        | j                  |j                         |j                          | j                  t        j                  j                  |             	 t        j                  |       y # 1 sw Y   xY w# t        $ r Y y w xY w# 	 t        j                         w # t        $ r Y w w xY wxY w)NFr8  s   1234)r   r   r<   r   r   r_  r  rW  rA  r   r{   r   rB  rI  rJ  rX  s       r   =test_cleanup_does_not_remove_pidfile_from_another_supervisordzPServerOptionsTests.test_cleanup_does_not_remove_pidfile_from_another_supervisord  s    ((6 	!ffGGGG		}}H  'HX445OOBGGNN734		'"	 	   		'" sM   CA0C  /C C	CC D"C87D8	DDDDc                    t        j                  d      5 }|j                  }|j                  d       d d d        	 | j	                         }|_        t        i       }||_        | j                  |j                         |j                          | j                  |j                         	 t        j                  |       y # 1 sw Y   xY w# t        $ r Y y w xY w# 	 t        j                         w # t        $ r Y w w xY wxY wrS  )r   r   r<   r   r   r_  r   pollerr  closedrA  r   r{   rI  rJ  )r   r   r_  r   r_  s        r   test_cleanup_closes_pollerz-ServerOptionsTests.test_cleanup_closes_poller  s    ((6 	!ffGGGDM		}}H&H _F$HOV]]+OOFMM*		'"	 	  		'" sM   CA/C .C C	CCD!C76D7	D DDDzos.closerangec                     | j                         d_        fd} |        t        j                  j	                  dd       y )NrF  c                  &     j                          y r/   )cleanup_fds)r   s   r   r   zCServerOptionsTests.test_cleanup_fds_closes_5_upto_minfds.<locals>.f  s      "r   r9  )r   rh  r{   
closerangeassert_called_with)r   r   r   s     @r   %test_cleanup_fds_closes_5_upto_minfdsz8ServerOptionsTests.test_cleanup_fds_closes_5_upto_minfds  s3    ==?	#	
((B/r   c                     | j                         } G d d      } |       }i |fg|_        |j                          | j                  |j                  d       y )Nc                       e Zd ZdZd Zy)9ServerOptionsTests.test_close_httpservers.<locals>.ServerFc                     d| _         y NT)r`  r   s    r   closez?ServerOptionsTests.test_close_httpservers.<locals>.Server.close  s	    "r   N)r%   r&   r'   r`  rm  r(   r   r   r=  rj    s    F#r   r=  T)r   r@  close_httpserversro   r`  )r   r   r=  servers       r   test_close_httpserversz)ServerOptionsTests.test_close_httpservers  sN    ==?	# 	# !#V~""$-r   c                     | j                         }t               }||_        |j                          | j	                  |j
                  d       y rl  )r   r
   rU  close_loggerro   r`  r   r   rU  s      r   test_close_loggerz$ServerOptionsTests.test_close_logger  s;    ==? -r   c                     | j                         }g fd}||_        ddddddd}|j                  |       | j                  t	              g d	       y )
Nc                 (    j                  |        y r/   r   fdr`  s    r   close_fdz<ServerOptionsTests.test_close_parent_pipes.<locals>.close_fd      MM"r   r   r   r   rM  rQ  r9  stdinr   r   child_stdinchild_stdoutchild_stderr)r   r   r   r   ry  close_parent_pipesro   r  r   r   ry  pipesr`  s       @r   test_close_parent_pipesz*ServerOptionsTests.test_close_parent_pipes  sX    ==?	$qA !1aI##E*3r   c                     | j                         }g fd}||_        dd i}|j                  |       | j                  g        y )Nc                 (    j                  |        y r/   r   rw  s    r   ry  zOServerOptionsTests.test_close_parent_pipes_ignores_fd_of_none.<locals>.close_fd  rz  r   r|  )r   ry  r  ro   r  s       @r   *test_close_parent_pipes_ignores_fd_of_nonez=ServerOptionsTests.test_close_parent_pipes_ignores_fd_of_none  sG    ==?	$$##E*$r   c                     | j                         }g fd}||_        ddddddd}|j                  |       | j                  t	              g d	       y )
Nc                 (    j                  |        y r/   r   rw  s    r   ry  z;ServerOptionsTests.test_close_child_pipes.<locals>.close_fd  rz  r   r   r   r   rM  rQ  r9  r{  )rM  rQ  r9  )r   ry  close_child_pipesro   r  r  s       @r   test_close_child_pipesz)ServerOptionsTests.test_close_child_pipes  sX    ==?	$qA !1aI""5)3r   c                     | j                         }g fd}||_        dd i}|j                  |       | j                  t	              g        y )Nc                 (    j                  |        y r/   r   rw  s    r   ry  zNServerOptionsTests.test_close_child_pipes_ignores_fd_of_none.<locals>.close_fd%  rz  r   r}  r  r  s       @r   )test_close_child_pipes_ignores_fd_of_nonez<ServerOptionsTests.test_close_child_pipes_ignores_fd_of_none"  sL    ==?	$%##E*,r   c                    | j                         }t               }t               g|_        ||_        |j	                          | j                  |j                  d   j                  d       | j                  |j                  d   d       y )Nr   Tzsupervisord logreopen)r   r
   handlersrU  
reopenlogsro   reopeneddatars  s      r   test_reopenlogsz"ServerOptionsTests.test_reopenlogs,  sj    ==?&=/ +44d;Q)@Ar   c                    t        j                  d      5 }|j                  }d d d        | j                  t        j
                  j                               	 | j                         }t               |_	        ||_
        |j                          | j                  t        j
                  j                  |             t        |d      5 }t        |j                         j!                               }d d d        | j#                  t	        j$                                |j                  j&                  d   }| j                  |j)                  d             | j                  |j*                         	 t	        j,                  |       y # 1 sw Y   hxY w# 1 sw Y   xY w# t.        $ r Y y w xY w# 	 t	        j,                  |       w # t.        $ r Y w w xY wxY w)NTr8  rr   zsupervisord started with pid)r   r   r<   r  r{   r   rB  r   r
   rU  r_  rV  r   r   intreadstripro   r  r  r   rW  rI  rJ  )r   r   r  r   pidr   s         r   test_write_pidfile_okz(ServerOptionsTests.test_write_pidfile_ok5  s_   ((5 	B	+,	}}H)mHO!H""$OOBGGNN2./b# ,!!&&(..*+,S"))+.//&&q)COOCNN+IJKOOH334		"%	 	, ,  		" sg   F
A0F2 (F3B F2 4F# 
FF F2 #	F/.F/2G4G
	G
	GGGGc                    d}| j                         }t               |_        ||_        |j	                          |j                  j
                  d   }| j                  |j                  d             | j                  |j                         y )Nz/cannot/possibly/existr   zcould not write pidfile)
r   r
   rU  r_  rV  r  r   r   r  rW  )r   r  r   r   s       r   test_write_pidfile_failz*ServerOptionsTests.test_write_pidfile_failL  sm    %==?%- oo""1%'@AB001r   c                    | j                         }t        j                         \  }}t        j                  |d       t        j                  |t        d             |j                  |       | j                  t        t        j                  |d       |j                  |       | j                  t        t        j                  |t        d             y )Nr   r   )	r   r{   piper  r   r   ry  rK   rJ  )r   r   innieouties       r   test_close_fdz ServerOptionsTests.test_close_fdV  s    ==?wwyu
q
(% '277E15% '288UHUODr   zos.close)side_effectc                 F    | j                         }|j                  d       y )Nr   )r   ry  r  s     r   test_close_fd_ignores_oserrorz0ServerOptionsTests.test_close_fd_ignores_oserror`  s    ==?!r   c                    | j                         }t        d      }ddlm}  |       }|j	                  |       |j                  |dd      }| j                  t        |      d       |d   }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d	       | j                  |j                  d	       | j                  |j                  d
       | j                  |j                  d
       | j                  |j                  d       | j                  |j                  d        | j                  |j                   d       | j                  |j"                  d       | j                  |j$                  d       | j                  |j&                  t(        j*                         | j                  |j,                  d	       | j                  |j.                  d       | j                  |j0                  d
       | j                  |j2                  ddg       | j                  |j4                  d	       | j                  |j6                  dddd       y )Na~          [program:foo]
        command = /bin/cat
        priority = 1
        autostart = false
        autorestart = false
        startsecs = 100
        startretries = 100
        user = root
        stdout_logfile = NONE
        stdout_logfile_backups = 1
        stdout_logfile_maxbytes = 100MB
        stdout_events_enabled = true
        stopsignal = KILL
        stopwaitsecs = 100
        killasgroup = true
        exitcodes = 1,4
        redirect_stderr = false
        environment = KEY1=val1,KEY2=val2,KEY3=%(process_num)s
        numprocs = 2
        process_name = %(group_name)s_%(program_name)s_%(process_num)02d
        r   r  program:foor   r   
bar_foo_00rE  Fd   i  @Tr   rQ  val1val20)KEY1KEY2KEY3)r   r   r   r  r  processes_from_sectionro   rp   r<   ro  rp  rq  rs  rt  ru  rv  stdout_capture_maxbytesr}  stdout_events_enabledrw  rx  ry  r{  r|  rz  r   redirect_stderrrk  r   r   r   r  r   pconfigspconfigs          r   test_processes_from_sectionz.ServerOptionsTests.test_processes_from_sectione  s   ==?  , 	;$&4 226=%PX*1+|4*5**E2,,e4**C0--s3a(//688!<88)D66=++V^^<,,e4,,d3--s3**QqE200%8,,!'sC	Er   c                    | j                         }t        d      }ddlm}  |       }|j	                  |       |j                  |dd      }dt        j                         z   }| j                  |d   j                  |       y )NzS        [program:foo]
        command = /bin/foo --host=%(host_node_name)s
        r   r  r  r   z/bin/foo --host=)
r   r   r   r  r  r  r  r  ro   ro  r   r   r   r  r   r  expecteds          r   4test_processes_from_section_host_node_name_expansionzGServerOptionsTests.test_processes_from_section_host_node_name_expansion  su    ==?   	;$&4 226=%P%7!,,h7r   c                 |   | j                         }t        d      }ddlm}  |       }|j	                  |       |j                  |dd      }| j                  t        |      d       dD ]  }| j                  ||   j                  d|z         | j                  ||   j                  d	|z         | j                  ||   j                  d
|z         | j                  ||   j                  d|z         | j                  ||   j                  d|z         | j                  ||   j                  dd|z  i        y )NaX          [program:foo]
        process_name = foo_%(process_num)d
        command = /bin/foo --num=%(process_num)d
        directory = /tmp/foo_%(process_num)d
        stderr_logfile = /tmp/foo_%(process_num)d_stderr
        stdout_logfile = /tmp/foo_%(process_num)d_stdout
        environment = NUM=%(process_num)d
        numprocs = 2
        r   r  r  r   r   r   r   foo_%dz/bin/foo --num=%dz/tmp/foo_%dz/tmp/foo_%d_stderrz/tmp/foo_%d_stdoutNUMz%d)r   r   r   r  r  r  ro   rp   r<   ro  rY  stderr_logfilerv  rk  r   r   r   r  r   r  nums          r   1test_processes_from_section_process_num_expansionzDServerOptionsTests.test_processes_from_section_process_num_expansion  s4   ==? 	 	 	;$&4 226=%PX* 	MCXc]//C@Xc]224G#4MNXc]44mc6IJXc]99$s*,Xc]99$s*,Xc]66s
8KL	Mr   c                 h   | j                         }t        d      }ddlm}  |       }|j	                  |       |j                  |dd      }| j                  t        |      d       dD ]F  }| j                  ||   j                  d|z         | j                  ||   j                  d	dz         H y )
Nz        [program:foo]
        process_name = foo_%(process_num)d
        command = /bin/foo --numprocs=%(numprocs)d
        numprocs = 2
        r   r  r  r   r   r  r  z/bin/foo --numprocs=%d)
r   r   r   r  r  r  ro   rp   r<   ro  r  s          r   .test_processes_from_section_numprocs_expansionzAServerOptionsTests.test_processes_from_section_numprocs_expansion  s    ==?   	;$&4 226=%PX* 	RCXc]//C@Xc]224Lq4PQ	Rr   c                     | j                         }t        d      }ddlm}  |       }ddi|_        |j                  |       |j                  |dd      }| j                  |d   j                  d       y )Nz^        [program:foo]
        command = /bin/cat
        directory = /tmp/%(ENV_FOO)s
        r   r  ENV_FOOr   r  z/tmp/bar)	r   r   r   r  
expansionsr  r  ro   rY  r   r   r   r  r   r  s         r   -test_processes_from_section_expands_directoryz@ServerOptionsTests.test_processes_from_section_expands_directory  sr    ==?  
 	;$&&.4 226=%P!..
;r   c                    | j                         }t        d      }ddlm}  |       }|j	                  |       |j                  |dd      }dt        j                  d   z  }| j                  |d   j                  |       y )NzO        [program:foo]
        command = /bin/foo --path='%(ENV_PATH)s'
        r   r  r  r   z/bin/foo --path='%s'PATH)
r   r   r   r  r  r  r{   r|   ro   ro  r  s          r   ;test_processes_from_section_environment_variables_expansionzNServerOptionsTests.test_processes_from_section_environment_variables_expansion  sx    ==?   	;$&4 226=%P)BJJv,>>!,,h7r   c                    | j                         }t        d      }ddlm}  |       }|j	                  |       |j                  |dd      }dt        j                  d   z  }| j                  |d   j                  d   |       y )Nzl        [program:foo]
        command = /bin/foo
        environment = PATH='/foo/bar:%(ENV_PATH)s'
        r   r  r  r   z/foo/bar:%sr  )
r   r   r   r  r  r  r{   r|   ro   rk  r  s          r   6test_processes_from_section_expands_env_in_environmentzIServerOptionsTests.test_processes_from_section_expands_env_in_environment  s}    ==?  
 	;$&4 226=%P 2::f#55!008(Cr   c                    | j                         }t        d      }ddlm}  |       }|j	                  |       |j                  |dd      }| j                  |j                  d   d       | j                  |d   j                  d        y )Nz~        [program:foo]
        command = /bin/foo
        redirect_stderr = true
        stderr_logfile = /tmp/logfile
        r   r  r  r   zyFor [program:foo], redirect_stderr=true but stderr_logfile has also been set to a filename, the filename has been ignored	r   r   r   r  r  r  ro   r  r  r  s         r   9test_processes_from_section_redirect_stderr_with_filenamezLServerOptionsTests.test_processes_from_section_redirect_stderr_with_filename  s    ==?   	;$&4 226=%P003I	J 	!33T:r   c                 V   | j                         }t        d      }ddlm}  |       }|j	                  |       |j                  |dd      }| j                  |j                  d   d       | j                  |d   j                  d        | j                  |d   j                  d       y )NzY        [program:foo]
        command = /bin/foo
        stdout_logfile = syslog
        r   r  r  r   zFor [program:foo], stdout_logfile=syslog but this is deprecated and will be removed.  Use stdout_syslog=true to enable syslog instead.T)
r   r   r   r  r  r  ro   r  rv  stdout_syslogr  s         r   =test_processes_from_section_rewrites_stdout_logfile_of_syslogzPServerOptionsTests.test_processes_from_section_rewrites_stdout_logfile_of_syslog
      ==?  
 	;$&4 226=%P003	 	!33T:!22D9r   c                 V   | j                         }t        d      }ddlm}  |       }|j	                  |       |j                  |dd      }| j                  |j                  d   d       | j                  |d   j                  d        | j                  |d   j                  d       y )NzY        [program:foo]
        command = /bin/foo
        stderr_logfile = syslog
        r   r  r  r   zFor [program:foo], stderr_logfile=syslog but this is deprecated and will be removed.  Use stderr_syslog=true to enable syslog instead.T)
r   r   r   r  r  r  ro   r  r  stderr_syslogr  s         r   =test_processes_from_section_rewrites_stderr_logfile_of_syslogzPServerOptionsTests.test_processes_from_section_rewrites_stderr_logfile_of_syslog  r  r   c                    | j                         }t        d      }ddlm}  |       }|j	                  |       |j                  |dd      }| j                  |j                  g        | j                  |d   j                  d        y )Nzv        [program:foo]
        command = /bin/foo
        redirect_stderr = true
        stderr_logfile = auto
        r   r  r  r   r  r  s         r   5test_processes_from_section_redirect_stderr_with_autozHServerOptionsTests.test_processes_from_section_redirect_stderr_with_auto.  s{    ==?   	;$&4 226=%P00"5!33T:r   c                 P   | j                         }t        dt        j                  z        }ddlm}  |       }|j                  |       |j                  |dd      }| j                  |j                  g        | j                  |d   j                  t        j                         y )NzQ        [program:foo]
        command = /bin/foo
        stopsignal = %d
        r   r  r  r   )r   r   rx  SIGQUITr   r  r  r  ro   r  rw  r  s         r   9test_processes_from_section_accepts_number_for_stopsignalzLServerOptionsTests.test_processes_from_section_accepts_number_for_stopsignal=  s    ==?  nn	 
 	;$&4 226=%P00"5!//@r   c                    t        d      }ddlm} ddlm} | j                         }i dt        j                         dddd	d
dddddddddddddddddddddddd d!d"d#d$dd%d&d'd(d)d*d*dd+dd,|_         |       }|j                  |_	        |j                  |       t        |      |_        |j                  t        |             |j                  g -       | j                  |j                   d.|j                  z         | j                  |j"                  d/|j                  z         | j                  |j$                  d0       | j                  |j&                  d1       | j                  |j(                  t*        j,                         | j                  |j.                  d2       | j                  |j0                  d2       | j                  |j2                  d3       | j                  |j4                  d4       | j                  |j6                  d5       | j                  |j8                  |j                  d          | j                  |j:                  d2       |j<                  j>                  }| j                  |j@                  d   d6   tB        jD                         | j                  |j@                  d   d7   d8       | j                  |j@                  d   d9   d:       | j                  |j@                  d   d;   d       | j                  |j@                  d   d<   d       |jF                  d   }| j                  |jH                  d=       | j                  |jJ                  d>       | j                  tM        |jN                        d?       |jN                  d   }| j                  |jH                  d=       | j                  |jP                  d@       | j                  |jJ                  d>       | j                  |jR                  d5       | j                  |jT                  |jV                         | j                  |jX                  dA       | j                  |jZ                  d1       | j                  |j\                  d       | j                  |j^                  d&       | j                  |j`                  tb        jd                         | j                  |jf                  dA       | j                  |jh                  d2       | j                  |jj                  d2       | j                  |jl                  |jo                  d'             | j                  |jp                  dB       | j                  |jr                  dg       | j                  |jt                  d+       | j                  |jv                  dB       | j                  |jx                  t{        dCD             y )ENa^          [supervisord]
        logfile = %(ENV_HOME)s/supervisord.log
        logfile_maxbytes = %(ENV_SUPD_LOGFILE_MAXBYTES)s
        logfile_backups = %(ENV_SUPD_LOGFILE_BACKUPS)s
        loglevel = %(ENV_SUPD_LOGLEVEL)s
        nodaemon = %(ENV_SUPD_NODAEMON)s
        minfds = %(ENV_SUPD_MINFDS)s
        minprocs = %(ENV_SUPD_MINPROCS)s
        umask = %(ENV_SUPD_UMASK)s
        identifier = supervisor_%(ENV_USER)s
        nocleanup = %(ENV_SUPD_NOCLEANUP)s
        childlogdir = %(ENV_HOME)s
        strip_ansi = %(ENV_SUPD_STRIP_ANSI)s
        environment = FAKE_ENV_VAR=/some/path

        [inet_http_server]
        port=*:%(ENV_HTSRV_PORT)s
        username=%(ENV_HTSRV_USER)s
        password=%(ENV_HTSRV_PASS)s

        [program:cat1]
        command=%(ENV_CAT1_COMMAND)s --logdir=%(ENV_CAT1_COMMAND_LOGDIR)s
        priority=%(ENV_CAT1_PRIORITY)s
        autostart=%(ENV_CAT1_AUTOSTART)s
        user=%(ENV_CAT1_USER)s
        stdout_logfile=%(ENV_CAT1_STDOUT_LOGFILE)s
        stdout_logfile_maxbytes = %(ENV_CAT1_STDOUT_LOGFILE_MAXBYTES)s
        stdout_logfile_backups = %(ENV_CAT1_STDOUT_LOGFILE_BACKUPS)s
        stopsignal=%(ENV_CAT1_STOPSIGNAL)s
        stopwaitsecs=%(ENV_CAT1_STOPWAIT)s
        startsecs=%(ENV_CAT1_STARTWAIT)s
        startretries=%(ENV_CAT1_STARTRETRIES)s
        directory=%(ENV_CAT1_DIR)s
        umask=%(ENV_CAT1_UMASK)s
        r   r5  r  r   r   r   ENV_HTSRV_PORTr   ENV_HTSRV_USERr   ENV_HTSRV_PASSr   ENV_SUPD_LOGFILE_MAXBYTES51MBENV_SUPD_LOGFILE_BACKUPS10ENV_SUPD_LOGLEVELinfoENV_SUPD_NODAEMONfalseENV_SUPD_SILENTENV_SUPD_MINFDS1024ENV_SUPD_MINPROCS200ENV_SUPD_UMASK002ENV_SUPD_NOCLEANUPtrueENV_SUPD_STRIP_ANSIENV_CAT1_COMMANDz/bin/customcatENV_CAT1_COMMAND_LOGDIRz/path/to/logs3rootrG  78KB2KILL5rI  )ENV_CAT1_PRIORITYENV_CAT1_AUTOSTARTENV_CAT1_USERENV_CAT1_STDOUT_LOGFILE ENV_CAT1_STDOUT_LOGFILE_MAXBYTESENV_CAT1_STDOUT_LOGFILE_BACKUPSENV_CAT1_STOPSIGNALENV_CAT1_STOPWAITENV_CAT1_STARTWAITENV_CAT1_STARTRETRIESENV_CAT1_DIRENV_CAT1_UMASKr   z%(ENV_HOME)s/supervisord.logzsupervisor_%(ENV_USER)si  0rF  FrK     Tr=  r>  r   r?  i#  r   r   rD  rM  r   z%/bin/customcat --logdir=/path/to/logsr9  r   rA  rB  )>r   rW  r6  r   r  r   r   r   r   r  r  r   rD   r6   rz   ro   r[  rb  r\  r]  r^  r   INFOr`  ra  rh  ri  rg  rc  
strip_ansir-   rX  rd  re  rf  rj  r<   rm  rp   rn  ro  rp  rq  rr  rs  rt  ru  rv  rw  rx  ry  rz  r{  r|  r}  r~  r  r   rY  rZ  rk  rl  )	r   r   r6  r  r   r   rF   rD  r  s	            r   r   z;ServerOptionsTests.test_options_with_environment_expansionsK  s    # #H 	):==?'++-'	' f' j	'
 n' (' ''  '  ' w' v'  ' e' !&' "7'   0!'" &#'$ "%"(#'506/2#)!$"%%)"#;'#> %&$774 &tnXd^,b!))7&:K:KK	M,,2V5F5FF	H22H=1126**L,=,=>**E2%0$/**C0++T2--v/@/@/LM,,e4%%11//28<fnnM//26:B?//26:DA//2:>
K//2:>O,,Q/F+*T112A6$$Q'V,@	B+$/**I,O,OP!,++R0A&--~>))6>>:++Q/**E2**E266",,V4	655q91#.&1a(**Dl,KLr   c                 n   | j                         }t        d      }t        j                         }t        j
                  j                  |d      }t        |d      5 }|j                  |       d d d        	 ||_	        |j                  g        t        j                  |d       | j                  |j                  t        j
                  j                  |             | j                  |j                  t        j
                  j                  |             | j                  |j                   t        j
                  j                  |d             | j                  |j"                  t        j
                  j                  |d             y # 1 sw Y   "xY w# t        j                  |d       w xY w)	Nz        [supervisord]
        childlogdir=%(here)s
        directory=%(here)s
        logfile=%(here)s/supervisord.log
        pidfile=%(here)s/supervisord.pid
        rn   r   r   Tr   r8  r;  )r   r   r   r   r{   r   r   r   r   rD   rz   r   r   ro   rc  rY  r[  r_  )r   r   r   r   r   r   s         r   -test_options_supervisord_section_expands_herez@ServerOptionsTests.test_options_supervisord_section_expands_here  sJ   ==?   !77<<.@A"C( 	AGGDM		4"2H"%MM$d3--GGLL	 ++GGLL	 ))GGLL01	3))GGLL01	3	 	 MM$d3s   F7F FF4c                    | j                         }t        d      }t        j                         }t        j
                  j                  |d      }t        |d      5 }|j                  |       d d d        	 ||_	        |j                  g        t        j                  |d       |j                  j                  }|j                  d   }| j!                  |j"                  d       |j$                  d   }| j!                  |j&                  t        j
                  j                  |d	             y # 1 sw Y   xY w# t        j                  |d       w xY w)
Nz
        [supervisord]
        environment=CMD=/bin/from/supervisord/section

        [program:cmd]
        command=%(ENV_CMD)s
        rn   r   r   Tr   r   cmdz/bin/from/supervisord/sectionr   r   r   r   r{   r   r   r   r   rD   rz   r   r   r-   rX  rj  ro   r<   rn  ro  	r   r   r   r   r   r   rF   groupr  s	            r   >test_options_program_section_expands_env_from_supervisord_sectzQServerOptionsTests.test_options_program_section_expands_env_from_supervisord_sect  s   ==?   !77<<.@A"C( 	AGGDM		4"2H"%MM$d3%%11--a0U+$$Q'GGLL>?	A	 	 MM$d3   D27D> 2D;>Ec                    | j                         }t        d      }t        j                         }t        j
                  j                  |d      }t        |d      5 }|j                  |       d d d        	 ||_	        |j                  g        t        j                  |d       |j                  j                  }|j                  d   }| j!                  |j"                  d       |j$                  d   }| j!                  |j&                  t        j
                  j                  |d	             y # 1 sw Y   xY w# t        j                  |d       w xY w)
Nz
        [supervisord]
        environment=CMD=/bin/from/supervisord/section

        [program:cmd]
        command=%(ENV_CMD)s
        environment=CMD=/bin/from/program/section
        rn   r   r   Tr   r   r  z/bin/from/program/sectionr  r  s	            r   :test_options_program_section_expands_env_from_program_sectzMServerOptionsTests.test_options_program_section_expands_env_from_program_sect  s   ==?   !77<<.@A"C( 	AGGDM		4"2H"%MM$d3%%11--a0U+$$Q'GGLL:;	=	 	 MM$d3r  c                    | j                         }t        d      }t        j                         }t        j
                  j                  |d      }t        |d      5 }|j                  |       d d d        	 ||_	        |j                  g        t        j                  |d       |j                  j                  }|j                  d   }| j!                  |j"                  d       |j$                  d   }| j!                  |j&                  t        j
                  j                  |d	             | j!                  |j(                  t        j
                  j                  |d
             | j!                  |j*                  dt        j
                  j                  |d      i       | j!                  |j,                  dt        j
                  j                  |d      z          | j!                  |j.                  t        j
                  j                  |d             | j!                  |j0                  t        j
                  j                  |d             y # 1 sw Y   xY w# t        j                  |d       w xY w)Na-  
        [supervisord]

        [program:cat]
        command=%(here)s/bin/cat
        directory=%(here)s/thedirectory
        environment=FOO=%(here)s/foo
        serverurl=unix://%(here)s/supervisord.sock
        stdout_logfile=%(here)s/stdout.log
        stderr_logfile=%(here)s/stderr.log
        rn   r   r   Tr   r   r  thedirectorybin/catFOOr   r   r   
stdout.log
stderr.logr   r   r   r   r{   r   r   r   r   rD   rz   r   r   r-   rX  rj  ro   r<   rn  rY  ro  rk  r   rv  r  r  s	            r   )test_options_program_section_expands_herez<ServerOptionsTests.test_options_program_section_expands_here  s   ==? 
 
 !77<<.@A"C( 	AGGDM		4"2H"%MM$d3%%11--a0U+$$Q'GGLL~.	0GGLLy)	+))BGGLLu-.	0T+=>>	@,,GGLL|,	.,,GGLL|,	.+	 	 MM$d3   I7I& I#&I?c                    | j                         }t        d      }t        j                         }t        j
                  j                  |d      }t        |d      5 }|j                  |       d d d        	 ||_	        |j                  g        t        j                  |d       |j                  j                  }|j                  d   }| j!                  |j"                  d       |j$                  d   }| j!                  |j&                  t        j
                  j                  |d	             | j!                  |j(                  t        j
                  j                  |d
             | j!                  |j*                  dt        j
                  j                  |d      i       | j!                  |j,                  dt        j
                  j                  |d      z          | j!                  |j.                  t        j
                  j                  |d             | j!                  |j0                  t        j
                  j                  |d             y # 1 sw Y   xY w# t        j                  |d       w xY w)NaP  
        [supervisord]

        [eventlistener:memmon]
        events=TICK_60
        command=%(here)s/bin/memmon
        directory=%(here)s/thedirectory
        environment=FOO=%(here)s/foo
        serverurl=unix://%(here)s/supervisord.sock
        stdout_logfile=%(here)s/stdout.log
        stderr_logfile=%(here)s/stderr.log
        rn   r   r   Tr   r   memmonr  z
bin/memmonr  r   r   r   r  r  r  r  s	            r   /test_options_eventlistener_section_expands_herezBServerOptionsTests.test_options_eventlistener_section_expands_here?  s   ==?   !77<<.@A"C( 	AGGDM		4"2H"%MM$d3%%11--a0X.$$Q'GGLL~.	0GGLL|,	.))BGGLLu-.	0T+=>>	@,,GGLL|,	.,,GGLL|,	.+	 	 MM$d3r  c                 B   | j                         }t        d      }|dz  }t        j                         }t        j
                  j                  |d      }t        |d      5 }|j                  |       d d d        	 ddd|_	        ||_
        |j                  g        t        j                  |d	
       |j                  j                  }| j!                  |j"                  t        j
                  j                  |d             |j$                  d   }|j&                  d   }t        j
                  j                  |d      dt)        j*                         }	| j!                  |j,                  |	       y # 1 sw Y   xY w# t        j                  |d	
       w xY w)Nze
        [supervisord]
        logfile = %(here)s/%(ENV_LOGNAME)s.log

        [program:cat]
        z\command = %(here)s/bin/cat --foo=%(ENV_FOO)s --num=%(process_num)d --node=%(host_node_name)srn   r   mainlogr   )ENV_LOGNAMEr  r   Tr   zmainlog.logr   r  z --foo=bar --num=0 --node=)r   r   r   r   r{   r   r   r   r   r   rD   rz   r   r   r-   rX  ro   r[  rj  rn  r  r  ro  )
r   r   r   r   r   r   r  	cat_groupcat_0r  s
             r   (test_options_expands_combined_expansionsz;ServerOptionsTests.test_options_expands_combined_expansionsg  sb   ==?   	 C 	D !77<<.@A"C( 	AGGDM		4( +H' #3H"%MM$d3%%11GGLL}-	/ 11!4	))!,GGLLy)MMO 	1-	 	 MM$d3s   !E8<#F 8FFc                 F   t        j                         }t        j                  j	                  |d      }t        d      }t        |d      5 }|j                  |       d d d        | j                         }	 ||_	        	 |j                  d       | j                  d       t!        j"                  |d	
       y # 1 sw Y   ]xY w# t        $ r5}| j                  t        |j                  d         d|z         Y d }~]d }~ww xY w# t!        j"                  |d	
       w xY w)Nrn   zq
        [supervisord]

        [program:cat]
        command = /bin/cat
        stopsignal = NOTASIGNAL
        r   Fr   r  r   Qvalue 'NOTASIGNAL' is not a valid signal name in section 'program:cat' (file: %r)Tr   )r   r   r{   r   r   r   r   r   r   rD   r   r  r0   ro   strr   r   r   )r   r  r   r   r   r   es          r   .test_options_error_handler_shows_main_filenamezAServerOptionsTests.test_options_error_handler_shows_main_filename  s   ""$77<<1CD   "C( 	AGGDM	 ==?
	7"2HN'''7		*+ MM'6	 	  N  QVVAY:<LMN NN
 MM'6s<   B:7D ?#C :C	D+C?:D ?DD D c                 p   t        j                         }t        j                  j	                  |d      }t        d|z        }t        |d      5 }|j                  |       d d d        t        j                  j	                  |d      }t        j                  |       t        j                  j	                  |d      }t        d      }t        |d      5 }|j                  |       d d d        | j                         }	 ||_
        	 |j                  d       | j                  d	       t#        j$                  |d       y # 1 sw Y   xY w# 1 sw Y   ixY w# t        $ r5}| j                  t        |j                   d
         d|z         Y d }~id }~ww xY w# t#        j$                  |d       w xY w)Nrn   r  r   r  zincluded.confzY        [program:cat]
        command = /bin/cat
        stopsignal = NOTASIGNAL
        Fr   r  r   r*  Tr   )r   r   r{   r   r   r   r   r   r  r   rD   r   r  r0   ro   r+  r   r   r   )	r   r  r   r   r   r  included_confr   r,  s	            r   2test_options_error_handler_shows_included_filenamezEServerOptionsTests.test_options_error_handler_shows_included_filename  s   ""$77<<1CD 
   "C( 	AGGDM	 gx0
V_=  
 -% 	GGDM	 ==?
	7"2HK'''7		*+ MM'63	 		 	  K  QVVAY:<IJK KK
 MM'6sH   EE F #E EE	F$+FF FF F5c                     | j                         }t        d      }ddlm}  |       }|j	                  |       | j                  t        |j                  |dd        y )Nz)        [program:spaces are bad]
        r   r  zprogram:spaces are badr   r   r   r  r  rK   r0   r  r   r   r   r  r   s        r   3test_processes_from_section_bad_program_name_spaceszFServerOptionsTests.test_processes_from_section_bad_program_name_spaces  X    ==?   	;$&4 *h&E&E ":D	Br   c                     | j                         }t        d      }ddlm}  |       }|j	                  |       | j                  t        |j                  |dd        y )Nz)        [program:colons:are:bad]
        r   r  zprogram:colons:are:badr2  r3  s        r   3test_processes_from_section_bad_program_name_colonszFServerOptionsTests.test_processes_from_section_bad_program_name_colons  r5  r   c                     | j                         }t        d      }ddlm}  |       }|j	                  |       | j                  t        |j                  |dd        y )NzN        [program:foo]
        command = /bin/cat
        numprocs = 2
        r   r  r  r2  r3  s        r   5test_processes_from_section_no_procnum_in_processnamezHServerOptionsTests.test_processes_from_section_no_procnum_in_processname  V    ==?  
 	;$&4 *h&E&E -	7r   c                 F   | j                         }t        d      }ddlm}  |       }|j	                  |       	 |j                  |dd        | j                  d       y # t        $ r7}| j                  |j                  d   j                  d             Y d }~y d }~ww xY w)Nz        [program:foo]
        r   r  r  r  z6program section program:foo does not specify a command)r   r   r   r  r  r  r  r0   r   r   r   )r   r   r   r  r   r
  s         r   &test_processes_from_section_no_commandz9ServerOptionsTests.test_processes_from_section_no_command  s    ==?   	;$&4 	K++FM4HII&' 	KOOCHHQK22HJ K K	Ks   $A   	B )-BB c                     | j                         }t        d      }ddlm}  |       }|j	                  |       | j                  t        |j                  |dd        y )Nz^        [program:foo]
        command = /bin/cat
        process_name = %(not_there)s
        r   r  r  r2  r3  s        r   ?test_processes_from_section_missing_replacement_in_process_namezRServerOptionsTests.test_processes_from_section_missing_replacement_in_process_name  r:  r   c                     | j                         }t        d      }ddlm}  |       }|j	                  |       | j                  t        |j                  |dd        y )Nz`        [program:foo]
        command = /bin/cat
        process_name = %(program_name)
        r   r  r  r2  r3  s        r   :test_processes_from_section_bad_expression_in_process_namezMServerOptionsTests.test_processes_from_section_bad_expression_in_process_name		  r:  r   c                     | j                         }t        d      }ddlm}  |       }|j	                  |       | j                  t        |j                  |dd        y )Nz_        [program:foo]
        command = /bin/cat
        process_name = colons:are:bad
        r   r  r  r2  r3  s        r   5test_processes_from_section_bad_chars_in_process_namezHServerOptionsTests.test_processes_from_section_bad_chars_in_process_name	  r:  r   c                 L   | j                         }t        d      }ddlm}  |       }|j	                  |       |j                  |dd      }| j                  t        |      d       |d   }| j                  |j                  d       | j                  |j                  d       y )Nz|        [program:foo]
        command = /bin/cat
        process_name = %(program_name)s
        stopasgroup = true
        r   r  r  r   r   T)
r   r   r   r  r  r  ro   rp   r{  r|  r  s          r   ;test_processes_from_section_stopasgroup_implies_killasgroupzNServerOptionsTests.test_processes_from_section_stopasgroup_implies_killasgroup#	  s    ==?   	;$&4 226=%PX*1+,,d3,,d3r   c                     | j                         }t        d      }ddlm}  |       }|j	                  |       | j                  t        |j                  |dd        y )Nz        [program:foo]
        command = /bin/cat
        process_name = %(program_name)s
        stopasgroup = true
        killasgroup = false
        r   r  r  r2  r3  s        r   >test_processes_from_section_killasgroup_mismatch_w_stopasgroupzQServerOptionsTests.test_processes_from_section_killasgroup_mismatch_w_stopasgroup4	  sV    ==?   	;$&4 *h&E&E -	7r   c                 $   | j                         }t        d      }ddlm}  |       }|j	                  |       	 |j                  |dd        | j                  d       y # t        $ r&}| j                  dt        |      v        Y d }~y d }~ww xY w)Nzh        [program:foo]
        command = /bin/cat
        environment = KEY1=val1,KEY2=val2,KEY3
        r   r  r  z9instance.processes_from_section should raise a ValueErrorz^Unexpected end of key/value pairs in value 'KEY1=val1,KEY2=val2,KEY3' in section 'program:foo')
r   r   r   r  r  r  r  r0   r   r+  )r   r   r   r  r   r,  s         r   =test_processes_from_section_unexpected_end_of_key_value_pairszPServerOptionsTests.test_processes_from_section_unexpected_end_of_key_value_pairsC	  s    ==?  
 	;$&4 		,++FM4H II + ,  	OOFq6 	s   A   	B)B

Bc                    | j                         }t        d      }t        j                  d      5 }	 |j	                  |       |j                          ddlm}  |       }|j                  |j                         |j                  |dd        | j                  d       d d d        y # t        $ r6}| j                  |j                  d   d|j                  z         Y d }~Cd }~ww xY w# 1 sw Y   y xY w)	Nz2        [program:foo]
        ;no command
        r  r  r   r  r  r  zZprogram section program:foo does not specify a command in section 'program:foo' (file: %r))r   r   r   r   r   r  r   r  r  r<   r  r  r0   ro   r   )r   r   r   r   r  r   r,  s          r   =test_processes_from_section_shows_conf_filename_on_valueerrorzPServerOptionsTests.test_processes_from_section_shows_conf_filename_on_valueerrorX	  s    ==?   ((d3 	,q,	B,.AFF#//tL 		*+	, 	,  D  :<=FFCD DD	, 	,s5   C,AB*C,*	C)3,C$C,$C))C,,C5c                 6   | j                         }t        d      }ddlm}  |       }t	               |_        |j                  |       |j                  |dd        | j                  |j                  d   d       | j                  |j                  d   d       y )Nz        [program:foo]
        command = /bin/foo
        stdout_logfile = AUTO
        stdout_logfile_maxbytes = 0
        stderr_logfile = AUTO
        stderr_logfile_maxbytes = 0
        r   r  r  zFor [program:foo], AUTO logging used for stdout_logfile without rollover, set maxbytes > 0 to avoid filling up filesystem unintentionallyr   zFor [program:foo], AUTO logging used for stderr_logfile without rollover, set maxbytes > 0 to avoid filling up filesystem unintentionally)
r   r   r   r  r
   rU  r  r  ro   r  r3  s        r   4test_processes_from_section_autolog_without_rolloverzGServerOptionsTests.test_processes_from_section_autolog_without_rolloverm	  s    ==?   	;$&%-4 ''tD003+	, 	003+	,r   c                    t        d      }ddlm}  |       }|j                  |       | j	                         }|j                  |      }| j                  t        |      d       |d   }| j                  |j                  d       | j                  |j                  d       | j                  t        |j                        d       y )Nz        [program:many]
        process_name = %(program_name)s_%(process_num)s
        command = /bin/cat
        numprocs = 2
        priority = 1
        r   r  r   manyr   r   r   r  r  r   process_groups_from_parserro   rp   r<   rm  rn  r   r   r  r   r   gconfigsgconfigs          r   +test_homogeneous_process_groups_from_parserz>ServerOptionsTests.test_homogeneous_process_groups_from_parser	  s       	;$&4 ==?66v>X*1+v.))1-W445q9r   c                    t        d      }ddlm} ddlm}  |       }|j                  |       | j                         }|j                  |      }| j                  t        |      d       |d   }| j                  |j                  d       | j                  |j                  |       | j                  t        |j                        d       |d   }| j                  |j                  d	       | j                  |j                  d
       | j                  |j                  |       | j                  t        |j                        d       |d   }| j                  |j                  d       | j                  |j                  d       | j                  |j                  |       | j                  t        |j                        d       y )Na          [eventlistener:dog]
        events=PROCESS_COMMUNICATION
        process_name = %(program_name)s_%(process_num)s
        command = /bin/dog
        numprocs = 2
        priority = 1

        [eventlistener:cat]
        events=PROCESS_COMMUNICATION
        process_name = %(program_name)s_%(process_num)s
        command = /bin/cat
        numprocs = 3

        [eventlistener:biz]
        events=PROCESS_COMMUNICATION
        process_name = %(program_name)s_%(process_num)s
        command = /bin/biz
        numprocs = 2
        r   r  default_handlerrM  bizr   r   r  r  dog)r   r   r  supervisor.dispatchersrW  r  r   rP  ro   rp   r<   result_handlerrn  rm  )r   r   r  rW  r   r   rR  gconfig1s           r   %test_event_listener_pools_from_parserz8ServerOptionsTests.test_event_listener_pools_from_parser	  st     ( 	;:$&4 ==?66v>X*A;.00/BX556:A;.**B/00/BX556:A;.**A.00/BX556:r   c                    t        d      }ddlm} ddlm} | j                         }t        j                         ddddd	d
|_         |       }|j                  |_	        |j                  |       |j                  |      }| j                  t        |      d       |d   }| j                  |j                  d       | j                  |j                  d       | j                  |j                   |       | j                  t        |j"                        d       |d   }| j                  |j                  d       | j                  |j                  d       | j                  |j                   |       | j                  t        |j"                        d       |j"                  d   }	| j                  |	j                  d       | j                  |	j$                  d       | j                  |	j                  d       |j"                  d   }
| j                  |
j                  d       | j                  |
j$                  d       | j                  |
j                  d       y )Na          [eventlistener:dog]
        events=PROCESS_COMMUNICATION
        process_name = %(ENV_EL1_PROCNAME)s_%(program_name)s_%(process_num)s
        command = %(ENV_EL1_COMMAND)s
        numprocs = %(ENV_EL1_NUMPROCS)s
        priority = %(ENV_EL1_PRIORITY)s

        [eventlistener:cat]
        events=PROCESS_COMMUNICATION
        process_name = %(program_name)s_%(process_num)s
        command = /bin/cat
        numprocs = 3

        r   r  rV  r   myeventlistenerz/bin/dogr  1)r   r   ENV_EL1_PROCNAMEENV_EL1_COMMANDENV_EL1_NUMPROCSENV_EL1_PRIORITYr   r  r  rM  r   rY  myeventlistener_dog_0myeventlistener_dog_1)r   r   r  rZ  rW  r   r   r   r   r  r  rP  ro   rp   r<   rm  r[  rn  ro  )r   r   r  rW  r   r   rR  gconfig0r\  dog0dog1s              r   Atest_event_listener_pools_from_parser_with_environment_expansionszTServerOptionsTests.test_event_listener_pools_from_parser_with_environment_expansions	  s      	;:==?3;3F3F3H3<;L:D;>;>'(# %&$774 66v>X*A;.**B/00/BX556:A;.**A.00/BX556:''*$;<z2*''*$;<z2*r   c                 &   t        d      }ddlm}  |       }|j                  |       | j	                         }	 |j                  |       | j                  d       y # t        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)Nzl        [eventlistener:dog]
        events=EVENT
        command = /bin/dog
        buffer_size = 0
        r   r  r  z8[eventlistener:dog] section sets invalid buffer_size (0)
r   r   r  r  r   rP  r  r0   ro   r   r   r   r  r   r   r
  s         r   3test_event_listener_pool_disallows_buffer_size_zerozFServerOptionsTests.test_event_listener_pool_disallows_buffer_size_zero	  s       	;$&4 ==?	+//7II&' 	+SXXa[ +* + +	+   "A 	B'BBc                 &   t        d      }ddlm}  |       }|j                  |       | j	                         }	 |j                  |       | j                  d       y # t        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)Nz        [eventlistener:dog]
        events=PROCESS_COMMUNICATION
        command = /bin/dog
        redirect_stderr = True
        r   r  r  z[eventlistener:dog] section sets redirect_stderr=true but this is not allowed because it will interfere with the eventlistener protocolrl  rm  s         r   2test_event_listener_pool_disallows_redirect_stderrzEServerOptionsTests.test_event_listener_pool_disallows_redirect_stderr
  s       	;$&4 ==?	B//7II&' 	BSXXa[ +A B B	Bro  c                    t        d      }ddlm} ddlm}  |       }|j                  |       | j                         }|j                  |      }| j                  t        |      d       |d   }| j                  |j                  |       y )Nz        [eventlistener:dog]
        events=PROCESS_COMMUNICATION
        command = /bin/dog
        result_handler = supervisor.tests.base:dummy_handler
        r   r  )dummy_handlerr   )r   r   r  supervisor.tests.basers  r  r   rP  ro   rp   r[  )r   r   r  rs  r   r   rR  r\  s           r   2test_event_listener_pool_with_event_result_handlerzEServerOptionsTests.test_event_listener_pool_with_event_result_handler
  s}       	;7$&4 ==?66v>X*A;00-@r   c                 &   t        d      }ddlm}  |       }|j                  |       | j	                         }	 |j                  |       | j                  d       y # t        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)Nz        [eventlistener:cat]
        events=PROCESS_COMMUNICATION
        command = /bin/cat
        result_handler = supervisor.tests.base:nonexistent
        r   r  r  zOsupervisor.tests.base:nonexistent cannot be resolved within [eventlistener:cat]rl  rm  s         r   4test_event_listener_pool_result_handler_unimportablezGServerOptionsTests.test_event_listener_pool_result_handler_unimportable1
  s       	;$&4 ==?	7//7II&' 	7SXXa[67 7	7ro  c                     t        d      }ddlm}  |       }|j                  |       | j	                         }| j                  t        |j                  |       y )Nz        [eventlistener:dog]
        process_name = %(program_name)s_%(process_num)s
        command = /bin/dog
        numprocs = 2
        priority = 1
        r   r  r   r   r  r  r   rK   r0   rP  r   r   r  r   r   s        r   %test_event_listener_pool_noeventslinez8ServerOptionsTests.test_event_listener_pool_noeventslineD
  O       	;$&4 ==?*X%H%HPr   c                     t        d      }ddlm}  |       }|j                  |       | j	                         }| j                  t        |j                  |       y )Nz        [eventlistener:dog]
        events=PROCESS_COMMUNICATION,THIS_EVENT_TYPE_DOESNT_EXIST
        process_name = %(program_name)s_%(process_num)s
        command = /bin/dog
        numprocs = 2
        priority = 1
        r   r  ry  rz  s        r   *test_event_listener_pool_unknown_eventtypez=ServerOptionsTests.test_event_listener_pool_unknown_eventtypeR
  O       	;$&4 ==?*X%H%HPr   c                    ddl m} ddl m} t        d      }ddl m}  |       }|j                  |       | j                         }t               }d d t        j                  t        j                  f|_        t               }d d t        j                  f|_        t        d|      t        d|      t        d|      d	                      }	 |	||      }
t        j                  t        j                  f}| j                  t        |
      d
       |
d   }| j                  |j                  |       | j                  |j                   d       | j                  |j"                  d       | j                  |j$                  j&                  d       | j                  ||j$                  j)                                | j                  d|j$                  j+                                | j                  d|j$                  j-                                | j                  t        |j.                        d       |j.                  d   }| j                  |j                  |       |
d   }| j                  |j                   d       | j                  |j"                  d       | j                  |j$                  j&                  d       | j                  ||j$                  j)                                | j                  d|j$                  j+                                | j                  t        |j.                        d       |
d   }| j                  |j                   d       | j                  |j$                  j&                  d       | j                  t        |j.                        d       |
d   }| j                  |j                   d       | j                  |j$                  j&                  d       | j                  d |j$                  j)                                | j                  d|j$                  j+                                | j                  t        |j.                        d       y )Nr   FastCGIGroupConfigFastCGIProcessConfiga          [fcgi-program:foo]
        socket = unix:///tmp/%(program_name)s.sock
        socket_owner = testuser:testgroup
        socket_mode = 0666
        socket_backlog = 32676
        process_name = %(program_name)s_%(process_num)s
        command = /bin/foo
        numprocs = 2
        priority = 1

        [fcgi-program:bar]
        socket = unix:///tmp/%(program_name)s.sock
        process_name = %(program_name)s_%(process_num)s
        command = /bin/bar
        user = testuser
        numprocs = 3

        [fcgi-program:flub]
        socket = unix:///tmp/%(program_name)s.sock
        command = /bin/flub

        [fcgi-program:cub]
        socket = tcp://localhost:6000
        command = /bin/cub
        r  pwd.getpwuidpwd.getpwnamgrp.getgrnamc                 $    | j                  |      S r/   rP  r   r   s     r   get_process_groupszMServerOptionsTests.test_fcgi_programs_from_parser.<locals>.get_process_groups
       66v>>r   rQ  r   r   zunix:///tmp/foo.sock    r   r     zunix:///tmp/bar.sockr  rM  cubztcp://localhost:6000flubzunix:///tmp/flub.sock)r   r  r  r   r  r  r   r   r   ru  r  return_valuer   ro   rp   	__class__r<   rm  socket_configurl	get_ownerget_modeget_backlogrn  )r   r  r  r   r  r   r   pwd_mockgrp_mockr  rR  	exp_owner	gconf_foopconfig_foo	gconf_bar	gconf_cub
gconf_flubs                    r   test_fcgi_programs_from_parserz1ServerOptionsTests.test_fcgi_programs_from_parsera
  s   9;  4 	;$&4 ==?
 6!%tX\\8<< H6!%tX\\ :	~x	(	~x	(	~x	(	? 
) 
) 
)	? &h7\\8<<0	X*QK	,,.@A/++Q/0044 6	8I$;$;$E$E$GH	 7 7 @ @ BC	 7 7 C C EFY667;//2..0DEQK	/++S10044/	1I$;$;$E$E$GH	 7 7 @ @ BCY667;QK	/0044/	1Y667;a[
&111550	2z77AACD
 8 8 A A CDZ778!<r   c                 4   ddl m} ddl m} t        d      }ddl m} | j                         }dddd	d
dddddd
|_         |       }|j                  |_        |j                  |       t               }d d t        j                  t        j                  f|_        t               }d d t        j                  f|_        t        d|      t        d|      t        d|      d                      }	 |	||      }
t        j                  t        j                  f}| j                  t!        |
      d       |
d   }| j                  |j"                  |       | j                  |j$                  d       | j                  |j&                  d       | j                  |j(                  j*                  d       | j                  ||j(                  j-                                | j                  d|j(                  j/                                | j                  d|j(                  j1                                | j                  t!        |j2                        d       |j2                  d   }| j                  |j"                  |       | j                  |j4                  d       y )Nr   r  r  a          [fcgi-program:foo]
        socket = unix:///tmp/%(program_name)s%(ENV_FOO_SOCKET_EXT)s
        socket_owner = %(ENV_FOO_SOCKET_USER)s:testgroup
        socket_mode = %(ENV_FOO_SOCKET_MODE)s
        socket_backlog = %(ENV_FOO_SOCKET_BACKLOG)s
        process_name = %(ENV_FOO_PROCESS_PREFIX)s_%(program_name)s_%(process_num)s
        command = /bin/foo --arg1=%(ENV_FOO_COMMAND_ARG1)s
        numprocs = %(ENV_FOO_NUMPROCS)s
        priority = %(ENV_FOO_PRIORITY)s
        r  rI  r   z.usocktestuser066632676zfcgi-r   r  r`  )
r   r   ENV_FOO_SOCKET_EXTENV_FOO_SOCKET_USERENV_FOO_SOCKET_MODEENV_FOO_SOCKET_BACKLOGENV_FOO_PROCESS_PREFIXENV_FOO_COMMAND_ARG1ENV_FOO_NUMPROCSENV_FOO_PRIORITYr  r  r  c                 $    | j                  |      S r/   r  r  s     r   r  ziServerOptionsTests.test_fcgi_programs_from_parser_with_environment_expansions.<locals>.get_process_groups
  r  r   r   r   zunix:///tmp/foo.usockr  r  r   z/bin/foo --arg1=bar)r   r  r  r   r  r   r   r  r  r   r   ru  r  r  r   ro   rp   r  r<   rm  r  r  r  r  r  rn  ro  )r   r  r  r   r  r   r   r  r  r  rR  r  r  r  s                 r   :test_fcgi_programs_from_parser_with_environment_expansionszMServerOptionsTests.test_fcgi_programs_from_parser_with_environment_expansions
  s;   9; 
 
 	;==?39:@=E>H>DAHAH?D;>;>
'(# %&$774 
 6!%tX\\8<< H6!%tX\\ :	~x	(	~x	(	~x	(	? 
) 
) 
)	? &h7\\8<<0	X*QK	,,.@A/++Q/0044 7	9I$;$;$E$E$GH	 7 7 @ @ BC	 7 7 C C EFY667;//2..0DE,,.CDr   c                     t        d      }ddlm}  |       }|j                  |       | j	                         }| j                  t        |j                  |       y )Nz        [fcgi-program:foo]
        process_name = %(program_name)s_%(process_num)s
        command = /bin/foo
        numprocs = 2
        priority = 1
        r   r  ry  rz  s        r   test_fcgi_program_no_socketz.ServerOptionsTests.test_fcgi_program_no_socket
  r|  r   c                     t        d      }ddlm}  |       }|j                  |       | j	                         }| j                  t        |j                  |       y )Nz        [fcgi-program:foo]
        socket=junk://blah
        process_name = %(program_name)s_%(process_num)s
        command = /bin/foo
        numprocs = 2
        priority = 1
        r   r  ry  rz  s        r   )test_fcgi_program_unknown_socket_protocolz<ServerOptionsTests.test_fcgi_program_unknown_socket_protocol  r  r   c                     t        d      }ddlm}  |       }|j                  |       | j	                         }| j                  t        |j                  |       y )Nz        [fcgi-program:foo]
        socket=unix://relative/path
        process_name = %(program_name)s_%(process_num)s
        command = /bin/foo
        numprocs = 2
        priority = 1
        r   r  ry  rz  s        r   $test_fcgi_program_rel_unix_sock_pathz7ServerOptionsTests.test_fcgi_program_rel_unix_sock_path  r  r   c                     t        d      }ddlm}  |       }|j                  |       | j	                         }| j                  t        |j                  |       y )Nz        [fcgi-program:foo]
        socket=tcp://missingport
        process_name = %(program_name)s_%(process_num)s
        command = /bin/foo
        numprocs = 2
        priority = 1
        r   r  ry  rz  s        r   %test_fcgi_program_bad_tcp_sock_formatz8ServerOptionsTests.test_fcgi_program_bad_tcp_sock_format&  r  r   c                     t        d      }ddlm}  |       }|j                  |       | j	                         }| j                  t        |j                  |       y )Nz        [fcgi-program:foo]
        socket=unix:///tmp/%(process_num)s.sock
        process_name = %(program_name)s_%(process_num)s
        command = /bin/foo
        numprocs = 2
        priority = 1
        r   r  ry  rz  s        r   (test_fcgi_program_bad_expansion_proc_numz;ServerOptionsTests.test_fcgi_program_bad_expansion_proc_num5  r  r   c                     t        d      }ddlm}  |       }|j                  |       | j	                         }| j                  t        |j                  |       y )Nz        [fcgi-program:foo]
        socket=tcp://localhost:8000
        socket_owner=nobody:nobody
        command = /bin/foo
        r   r  ry  rz  s        r   *test_fcgi_program_socket_owner_set_for_tcpz=ServerOptionsTests.test_fcgi_program_socket_owner_set_for_tcpD  O       	;$&4 ==?*X%H%HPr   c                     t        d      }ddlm}  |       }|j                  |       | j	                         }| j                  t        |j                  |       y )Nz        [fcgi-program:foo]
        socket = tcp://localhost:8000
        socket_mode = 0777
        command = /bin/foo
        r   r  ry  rz  s        r   )test_fcgi_program_socket_mode_set_for_tcpz<ServerOptionsTests.test_fcgi_program_socket_mode_set_for_tcpQ  r  r   c                     t        d      }ddlm}  |       }|j                  |       | j	                         }| j                  t        |j                  |       y )Nz        [fcgi-program:foo]
        socket = unix:///tmp/foo.sock
        socket_owner = sometotaljunkuserthatshouldnobethere
        command = /bin/foo
        r   r  ry  rz  s        r   "test_fcgi_program_bad_socket_ownerz5ServerOptionsTests.test_fcgi_program_bad_socket_owner^  r  r   c                     t        d      }ddlm}  |       }|j                  |       | j	                         }| j                  t        |j                  |       y )Nz        [fcgi-program:foo]
        socket = unix:///tmp/foo.sock
        socket_mode = junk
        command = /bin/foo
        r   r  ry  rz  s        r   !test_fcgi_program_bad_socket_modez4ServerOptionsTests.test_fcgi_program_bad_socket_modek  r  r   c                     t        d      }ddlm}  |       }|j                  |       | j	                         }| j                  t        |j                  |       y )Nz        [fcgi-program:foo]
        socket = unix:///tmp/foo.sock
        socket_backlog = -1
        command = /bin/foo
        r   r  ry  rz  s        r   $test_fcgi_program_bad_socket_backlogz7ServerOptionsTests.test_fcgi_program_bad_socket_backlogx  r  r   c                    t        d      }ddlm}  |       }|j                  |       | j	                         }|j                  |      }| j                  t        |      d       |d   }| j                  |j                  d       | j                  |j                  d       | j                  t        |j                        d       y )Nz        [program:one]
        command = /bin/cat

        [program:two]
        command = /bin/cat

        [group:thegroup]
        programs = one,two
        priority = 5
        r   r  r   thegroupr9  r   rO  rQ  s          r   -test_heterogeneous_process_groups_from_parserz@ServerOptionsTests.test_heterogeneous_process_groups_from_parser  s     
 
 	;$&4 ==?66v>X*1+z2))1-W445q9r   c                 V   t        d      }ddlm}  |       }|j                  |       | j	                         }|j                  |      }| j                  t        |      d       |d   }| j                  |j                  d       | j                  |j                  d       | j                  t        |j                        d       |d   }| j                  |j                  d       | j                  |j                  d       | j                  t        |j                        d       y )	NaJ          [program:one]
        command = /bin/cat

        [program:two]
        command = /bin/cat

        [program:many]
        process_name = %(program_name)s_%(process_num)s
        command = /bin/cat
        numprocs = 2
        priority = 1

        [group:thegroup]
        programs = one,two
        priority = 5
        r   r  r   rN  r   r  r9  rO  )r   r   r  r   r   rR  
manyconfigrS  s           r   &test_mixed_process_groups_from_parser1z9ServerOptionsTests.test_mixed_process_groups_from_parser1  s      " 	;$&4 ==?66v>X*a[
&1,,a0Z778!<1+z2))1-W445q9r   c                    t        d      }ddlm}  |       }|j                  |       | j	                         }|j                  |      }| j                  t        |      d       |d   }| j                  |j                  d       | j                  |j                  d       | j                  t        |j                        d       y )NaP          [program:one]
        command = /bin/cat

        [program:two]
        command = /bin/cat

        [program:many]
        process_name = %(program_name)s_%(process_num)s
        command = /bin/cat
        numprocs = 2
        priority = 1

        [group:thegroup]
        programs = one,two, many
        priority = 5
        r   r  r   r  r9  rQ  rO  rQ  s          r   &test_mixed_process_groups_from_parser2z9ServerOptionsTests.test_mixed_process_groups_from_parser2  s      " 	;$&4 ==?66v>X*1+z2))1-W445q9r   c                    t        d      }ddlm}  |       }|j                  |       | j	                         }|j                  |      }| j                  t        |      d       |d   }| j                  |j                  d       | j                  |j                  d       | j                  t        |j                        d       y )Na          [program:one]
        command = /bin/cat

        [fcgi-program:two]
        command = /bin/cat

        [program:many]
        process_name = %(program_name)s_%(process_num)s
        command = /bin/cat
        numprocs = 2
        priority = 1

        [fcgi-program:more]
        process_name = %(program_name)s_%(process_num)s
        command = /bin/cat
        numprocs = 2
        priority = 1

        [group:thegroup]
        programs = one,two,many,more
        priority = 5
        r   r  r   r  r9  rl   rO  rQ  s          r   &test_mixed_process_groups_from_parser3z9ServerOptionsTests.test_mixed_process_groups_from_parser3  s      . 	;$&4 ==?66v>X*1+z2))1-W445q9r   c                     t        d      }ddlm}  |       }|j                  |       | j	                         }| j                  t        |j                  |       y )Nz        [program:one]
        command = /bin/cat

        [fcgi-program:one]
        command = /bin/cat

        [group:thegroup]
        programs = oner   r  ry  rz  s        r   -test_ambiguous_process_in_heterogeneous_groupz@ServerOptionsTests.test_ambiguous_process_in_heterogeneous_group  sR       	;$&4 ==?*h&I&I 	"r   c                     t        d      }ddlm}  |       }|j                  |       | j	                         }| j                  t        |j                  |       y )Nzj        [program:one]
        command = /bin/cat

        [group:foo]
        programs = notthere
        r   r  ry  rz  s        r   +test_unknown_program_in_heterogeneous_groupz>ServerOptionsTests.test_unknown_program_in_heterogeneous_group  sR       	;$&4 ==?*h&I&I 	"r   c                    t        dt        z        }ddlm}  |       }|j	                  |       | j                         }|j                  |dd      }| j                  t        |      d       |d   }| j                  |d   d       | j                  |d   t        j                  t                  | j                  |d   d	d
d       y )Nzv        [rpcinterface:dummy]
        supervisor.rpcinterface_factory = %s
        foo = bar
        baz = qux
        r   r  supervisor.rpcinterface_factoryrpcinterface:r   dummyr   r   qux)r   r   )r   r%   r   r  r  r   get_pluginsro   rp   sysmodules)r   r   r  r   r   	factoriesfactorys          r   test_rpcinterfaces_from_parserz1ServerOptionsTests.test_rpcinterfaces_from_parser!  s     
   	;$&4 ==?(()J)8:	 	Y+A,W-S[[%:;E%?@r   c                    t        d      }ddlm} | j                         } |       }t        dd|_        |j                  |       |j                  |dd      }| j                  t        |      d       |d   }| j                  |d   d	       | j                  |d   t        j                  t                  | j                  |d
   ddi       y )Nzq        [rpcinterface:dummy]
        supervisor.rpcinterface_factory = %(factory)s
        foo = %(pet)s
        r   r  r  )r  petr  r  r   r  r   r   )r   r   r  r   r%   r  r  r  ro   rp   r  r  )r   r   r  r   r   r  r  s          r   1test_rpcinterfaces_from_parser_factory_expansionszDServerOptionsTests.test_rpcinterfaces_from_parser_factory_expansions5  s      
 	;==?$&(0?4 (()J)8:	 	Y+A,W-S[[%:;eU^4r   c                 *   t        d      }ddlm}  |       }|j                  |       | j	                         }	 |j                  |dd       | j                  d       y # t        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)Nz]        [rpcinterface:dummy]
        # note: no supervisor.rpcinterface_factory here
        r   r  r  r  r  zOsection [rpcinterface:dummy] does not specify a supervisor.rpcinterface_factory
r   r   r  r  r   r  r  r0   ro   r   rm  s         r   .test_rpcinterfaces_from_parser_factory_missingzAServerOptionsTests.test_rpcinterfaces_from_parser_factory_missingI  s       	;$&4 ==?	F  !B!02 II&' 	FSXXa[ +E F F	F   $A   	B)BBc                 *   t        d      }ddlm}  |       }|j                  |       | j	                         }	 |j                  |dd       | j                  d       y # t        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)Nz[        [rpcinterface:dummy]
        supervisor.rpcinterface_factory = nonexistent
        r   r  r  r  r  z:nonexistent cannot be resolved within [rpcinterface:dummy]r  rm  s         r   5test_rpcinterfaces_from_parser_factory_not_importablezHServerOptionsTests.test_rpcinterfaces_from_parser_factory_not_importable[  s       	;$&4 ==?	/  !B!02 II&' 	/SXXa[ +. / /	/r  c                    t        j                         }	 | j                         }||_        d}||_        |j                  d|d      }|dz   }|dz   }t        |d      }t        |d      }|j                          | j                  t        j                  j                  |             | j                  t        j                  j                  |             | j                  t        j                  j                  |             |j                          |j                          t        j                  |d       y # t        j                  |d       w xY w)	NrW  r   r   z.1z.2r   Tr   )r   r   r   rc  rb  get_autochildlog_namer   clear_autochildlogdirr  r{   r   rB  rm  r   r   )	r   dnr   sidlogfnfirstsecondf1f2s	            r   test_clear_autochildlogdirz-ServerOptionsTests.test_clear_autochildlogdirm  s    	2}}H#%H C"%H225#hGEDLET\FeS!Bfc"B**,RWW^^E23RWW^^E23RWW^^F34HHJHHJMM"D1FMM"D1s   DD= =Ec                     | j                         }d|_        t               |_        |j	                          | j                  |j                  j                  dg       y )Nz!/tmp/this/cant/possibly/existjjjjzCould not clear childlog dir)r   rc  r
   rU  r  ro   r  r  s     r   *test_clear_autochildlogdir_listdir_oserrorz=ServerOptionsTests.test_clear_autochildlogdir_listdir_oserror  sH    ==?B%-&&(--0N/OPr   c                    t        j                         }| j                         }||_        |j                  }t
        j                  j                  |d|z        }t        |d      5 }|j                  d       d d d        d }||_
        t               |_        |j                          | j                  |j                  j                  d|z  g       y # 1 sw Y   ]xY w)Nzcat-stdout---%s-ayWAp9.logr   logc                  4    t        t        j                        r/   )rJ  r  ENOENTr   s    r   raise_oserrorzSServerOptionsTests.test_clear_autochildlogdir_unlink_oserror.<locals>.raise_oserror  s    %,,''r   zFailed to clean up '%s')r   r   r   rc  rb  r{   r   r   r   r   remover
   rU  r  ro   r  )r   r  r   identr  r   r  s          r   )test_clear_autochildlogdir_unlink_oserrorz<ServerOptionsTests.test_clear_autochildlogdir_unlink_oserror  s    ""$==?&##77<<)E)MN(C  	AGGEN		('%-&&(--&12	4	 	s   'CCc                    t               }| j                         }d }||_        g fd}||_        |j	                  |       | j                  t              d       d}| j                  d   j                  |             y )Nc                 H    t        j                  t        j                        r/   )re  r   r  
EADDRINUSErX  s    r   raise_eaddrinusezhServerOptionsTests.test_openhttpservers_reports_friendly_usage_when_eaddrinuse.<locals>.raise_eaddrinuse  s    ,,u//00r   c                 (    j                  |        y r/   r   r  s    r   r  zdServerOptionsTests.test_openhttpservers_reports_friendly_usage_when_eaddrinuse.<locals>.record_usage  r  r   r   z$Another program is already listeningr   )	r	   r   make_http_serversr  openhttpserversro   rp   r   r   )r   rX  r   r   r  r  r  s         @r   ;test_openhttpservers_reports_friendly_usage_when_eaddrinusezNServerOptionsTests.test_openhttpservers_reports_friendly_usage_when_eaddrinuse  sv    %'==?	1%5"	%%  -X*9..x89r   c                    t               }| j                         }d }||_        g fd}||_        |j	                  |       | j                  t              d       dt        j                  z  }| j                  d   |       y )Nc                 H    t        j                  t        j                        r/   )re  r   r  EPERMr  s    r   r  zbServerOptionsTests.test_openhttpservers_reports_socket_error_with_errno.<locals>.make_http_servers  s    ,,u{{++r   c                 (    j                  |        y r/   r   r  s    r   r  z]ServerOptionsTests.test_openhttpservers_reports_socket_error_with_errno.<locals>.record_usage  r  r   r   zBCannot open an HTTP server: socket.error reported errno.EPERM (%d)r   )	r	   r   r  r  r  ro   rp   r  r  r   rX  r   r  r  r  r  s         @r   4test_openhttpservers_reports_socket_error_with_errnozGServerOptionsTests.test_openhttpservers_reports_socket_error_with_errno  s}    %'==?	,%6"	%%  -X*027++>!h/r   c                     t               }| j                         }d }||_        g fd}||_        |j	                  |       | j                  t              d       d}| j                  d   |       y )Nc                 ,    t        j                  d      )Nzuh oh)re  r   r  s    r   r  z^ServerOptionsTests.test_openhttpservers_reports_other_socket_errors.<locals>.make_http_servers  s    ,,w''r   c                 (    j                  |        y r/   r   r  s    r   r  zYServerOptionsTests.test_openhttpservers_reports_other_socket_errors.<locals>.record_usage  r  r   r   z7Cannot open an HTTP server: socket.error reported uh ohr   r	   r   r  r  r  ro   rp   r	  s         @r   0test_openhttpservers_reports_other_socket_errorszCServerOptionsTests.test_openhttpservers_reports_other_socket_errors  sq    %'==?	(%6"	%%  -X*%!h/r   c                     t               }| j                         }d }||_        g fd}||_        |j	                  |       | j                  t              d       d}| j                  d   |       y )Nc                     t        d      )Nnot prefixed with help)r0   r  s    r   r  zWServerOptionsTests.test_openhttpservers_reports_value_errors.<locals>.make_http_servers  s    566r   c                 (    j                  |        y r/   r   r  s    r   r  zRServerOptionsTests.test_openhttpservers_reports_value_errors.<locals>.record_usage  r  r   r   r  r   r  r	  s         @r   )test_openhttpservers_reports_value_errorsz<ServerOptionsTests.test_openhttpservers_reports_value_errors  so    %'==?	7%6"	%%  -X*+!h/r   c                     t               }| j                         }d }||_        | j                  t        |j
                  |       y )Nc                     t         r/   )OverflowErrorr  s    r   r  zgServerOptionsTests.test_openhttpservers_does_not_catch_other_exception_types.<locals>.make_http_servers  s    r   )r	   r   r  rK   r  r  )r   rX  r   r  s       r   9test_openhttpservers_does_not_catch_other_exception_typeszLServerOptionsTests.test_openhttpservers_does_not_catch_other_exception_types  s@    %'==?	 %6" 	-"22K	Ar   c                 j    | j                         }|j                  d       }| j                  |d       y )NzNo user specified to setuid to!r   drop_privilegesro   r   r   r   s      r   test_drop_privileges_user_nonez1ServerOptionsTests.test_drop_privileges_user_none  s.    ==?&&t,?@r   r  )r   N   "   )r  z	os.getuidr  c                     | j                         }|j                  t        j                               }| j	                  |d        y r/   )r   r  r{   getuidro   r  s      r   &test_drop_privileges_nonroot_same_userz9ServerOptionsTests.test_drop_privileges_nonroot_same_user  s5     ==?&&ryy{3d#r   )r   N7   r  c                 j    | j                         }|j                  d      }| j                  |d       y )Nrv   z$Can't drop privilege as nonroot userr  r  s      r   +test_drop_privileges_nonroot_different_userz>ServerOptionsTests.test_drop_privileges_nonroot_different_user  s0     ==?&&r*DEr   c                    | j                         }d |_        t               |_        |j	                          |j                  j
                  j                          |j                  j                  j                          y )Nc                       y r/   r(   r(   r   r   r   zYServerOptionsTests.test_daemonize_notifies_poller_before_and_after_fork.<locals>.<lambda>  s    r   )r   
_daemonizer   r_  	daemonizebefore_daemonizeassert_called_once_withafter_daemonizer  s     r   4test_daemonize_notifies_poller_before_and_after_forkzGServerOptionsTests.test_daemonize_notifies_poller_before_and_after_fork  sV    ==?*&((@@B''??Ar   N)r%   r&   r'   r   r   r3  r   r   r   r   r  r  r  r  r  r  r  r"  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  r   r#  r%  r)  r,  r/  r2  r4  r6  rD  rK  rQ  rY  r[  r]  ra  r   r   rg  rp  rt  r  r  r  r  r  r  r  r  rJ  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r"  r(  r-  r0  r4  r7  r9  r<  r>  r@  rB  rD  rF  rH  rJ  rL  rT  r]  rj  rn  rq  ru  rw  r{  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  r  r"  r%  r-  r(   r   r   r*  r*    s   (D|1|.
."B3H:(; I
I7&BI
L!5F!>F7>5:<1:64B/AE;F0B0+"?"@  , ,40 , (@ -(.$(& ?DF#0 $0	..	4%	4-B.2E :t01 20Ed8M6R"<8D;":$:$;A}M~36A2=4%.N&.P#2J74"7H	B	B7K7774"7,*,*,0:&,;\2+h+$B&A$7&QQW=r>E@QQQQQQQQQQ:.!:F:<":H"""A(5(F$/$2*Q4 :$0&0&0$AA
 >4-BCD
;"-.$ / E$
 >4-BCD
;"-.F / EF
Br   r*  c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)ProcessConfigTestsc                     ddl m} |S )Nr   )ProcessConfig)r   r1  )r   r1  s     r   r   z"ProcessConfigTests._getTargetClass  r   r   c                     i }dD ]  }|||<   	 dD ]  }d||<   	 |j                  |        | j                         |i |S N)r<   ro  rY  rZ  rm  rp  rq  rs  rt  ru  rv  r  r  r  r  stderr_capture_maxbytesstderr_events_enabledr  rw  rz  r{  r|  r   r  rk  )r  r}  stderr_logfile_backupsstderr_logfile_maxbytesrF  r2   r   r   argkwdefaultsr<   s        r   r   zProcessConfigTests._makeOne  g    	$ 
	"D "HTN
	"J 	 DHTN	  	%t##%s7h77r   c                     t               }| j                  |d       }| j                  |j                         |j                                y )Nrk  r   r   ro   get_pathr   rF   r   s      r   .test_get_path_env_is_None_delegates_to_optionszAProcessConfigTests.test_get_path_env_is_None_delegates_to_options#  s=    .==d=;**,g.>.>.@Ar   c                     t               }| j                  |ddi      }| j                  |j                         |j                                y )Nr  r`  r?  r@  rB  s      r   8test_get_path_env_dict_with_no_PATH_delegates_to_optionszKProcessConfigTests.test_get_path_env_dict_with_no_PATH_delegates_to_options(  sA    .==ucl=C**,g.>.>.@Ar   c                     t               }| j                  |ddi      }| j                  |j                         |j                                | j	                  |j                         g d       y )Nr  z/a:/b:/cr?  )z/az/bz/c)r   r   assertNotEqualrA  ro   rB  s      r   (test_get_path_env_dict_with_PATH_uses_itz;ProcessConfigTests.test_get_path_env_dict_with_PATH_uses_it-  s\    .==vz6J=KH--/1A1A1CD**,.@Ar   c                    t               }| j                  |      }ddlm} ||_        ||_        |j                          | j                  |j                  |j                         | j                  |j
                  |j                         y )Nr   )r  )	r   r   rC   r  rv  r  create_autochildlogsro   tempfile_name)r   rF   r   r  s       r   test_create_autochildlogsz,ProcessConfigTests.test_create_autochildlogs3  sn    .==)2"+"+%%'00'2G2GH00'2G2GHr   c                     t               }| j                  |      }|j                         }ddlm} | j                  |j                  |       | j                  |j                  d        y )Nr   
Subprocessr   r   make_processsupervisor.processrO  ro   r  r  r   rF   r   processrO  s        r   test_make_processz$ProcessConfigTests.test_make_process=  sR    .==)'')1**J7-r   c                     t               }| j                  |      }|j                  d      }ddlm} | j                  |j                  |       | j                  |j                  d       y )NrZ   r   rN  rP  rS  s        r   test_make_process_with_groupz/ProcessConfigTests.test_make_process_with_groupE  sT    .==)''.1**J7.r   c                    t               }| j                  |      }t        j                         5 }t        j                         5 }|j                  |_        |j                  |_        d|_        t        |      }|j                  |      \  }}| j                  |d   j                  d       ddlm} | j                  |d   j                  |       | j                  |d   d       | j                  |d   j                  d       ddlm}	 | j                  |d   j                  |	       | j                  |d   d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)	NFr9  r   r   ProcessCommunicationStdoutEvent   r   ProcessCommunicationStderrEvent)r   r   r   r   r<   rv  r  r  r   make_dispatchersro   channelsupervisor.eventsrZ  
event_typer]  
r   rF   r   rv  r  process1dispatchersr  rZ  r]  s
             r   +test_make_dispatchers_stderr_not_redirectedz>ProcessConfigTests.test_make_dispatchers_stderr_not_redirectedM  sC   .==)((* 	5n,,. 5.*8*=*='*8*=*='+0('1%-%>%>x%H"U  Q!7!7BM  Q!:!:!@B  x!4  Q!7!7BM  Q!:!:!@B  x!45	5 	55 5	5 	5s$   EC;E EE	EE&c                 ~   t               }| j                  |      }t        j                         5 }|j                  |_        t        |      }|j                  |      \  }}| j                  |d   j                  d       | j                  |d   d       | j                  |d   d        d d d        y # 1 sw Y   y xY w)Nr9  r   r   )
r   r   r   r   r<   rv  r   r^  ro   r_  )r   rF   r   rv  rc  rd  r  s          r   'test_make_dispatchers_stderr_redirectedz:ProcessConfigTests.test_make_dispatchers_stderr_redirectedb  s    .==)((* 	4n&4&9&9H##H-H!)!:!:8!DK[^33X>U8_a0U8_d3	4 	4 	4s   A:B33B<N)r%   r&   r'   r   r   rC  rE  rH  rL  rU  rW  re  rg  r(   r   r   r/  r/    s8    8&B
B
BI./5*	4r   r/  c                       e Zd Zd Zd Zd Zy)EventListenerConfigTestsc                     ddl m} |S )Nr   )EventListenerConfig)r   rk  )r   rk  s     r   r   z(EventListenerConfigTests._getTargetClassn      :""r   c                     i }dD ]  }|||<   	 dD ]  }d||<   	 |j                  |        | j                         |i |S r3  r8  r9  s        r   r   z!EventListenerConfigTests._makeOner  r=  r   c                 v   t               }| j                  |      }t        j                         5 }t        j                         5 }|j                  |_        |j                  |_        d|_        t        |      }|j                  |      \  }}| j                  |d   j                  d       | j                  |d   j                  d       | j                  |d   j                  d       ddlm} | j                  |d   j                  j                   |j"                         | j                  |d   d       | j                  |d   j                  d	       dd
lm}	 | j                  |d   j(                  |	       | j                  |d	   d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NFrQ  r|  r9  r   r   )EventListenerStatesr[  r   r\  )r   r   r   r   r<   rv  r  r  r   r^  ro   r_  r`  supervisor.statesro  rT  listener_stateACKNOWLEDGEDr`  r]  ra  )
r   rF   r   rv  r  rc  rd  r  ro  r]  s
             r   test_make_dispatchersz.EventListenerConfigTests.test_make_dispatchers  s   .==)((* 	5n,,. 5.*8*=*='*8*=*='+0('1%-%>%>x%H"U  Q!7!7A  Q!6!6>  Q!7!7BA  Q!7!7!F!F!4!A!AC  x!4  Q!7!7BM  Q!:!:!@B  x!4#5	5 	55 5	5 	5s$   F/EF#F/#F,	(F//F8N)r%   r&   r'   r   r   rs  r(   r   r   ri  ri  m  s    #8&5r   ri  c                   *    e Zd Zd Zd Zd Zd Zd Zy)FastCGIProcessConfigTestsc                     ddl m} |S )Nr   r  )r   r  )r   r  s     r   r   z)FastCGIProcessConfigTests._getTargetClass  s    ;##r   c                     i }dD ]  }|||<   	 dD ]  }d||<   	 |j                  |        | j                         |i |S r3  r8  r9  s        r   r   z"FastCGIProcessConfigTests._makeOne  r=  r   c                 z    t               }| j                  |      }| j                  t        |j                         y r/   )r   r   rK   NotImplementedErrorrQ  rB  s      r   rU  z+FastCGIProcessConfigTests.test_make_process  s.    .==)-x/D/DEr   c                     t               }| j                  |      }|j                  d      }ddlm} | j                  |j                  |       | j                  |j                  d       y )NrZ   r   )FastCGISubprocess)r   r   rQ  rR  r{  ro   r  r  )r   rF   r   rT  r{  s        r   rW  z6FastCGIProcessConfigTests.test_make_process_with_group  sU    .==)''.8**,=>.r   c                 N   t               }| j                  |      }t        j                         5 }t        j                         5 }|j                  |_        |j                  |_        d|_        t        |      }|j                  |      \  }}| j                  |d   j                  d       | j                  |d   j                  d       | j                  |d   j                  d       ddlm} | j                  |d   j                  |       | j                  |d   d       | j                  |d	   j                  d
       ddlm}	 | j                  |d	   j                  |	       | j                  |d
   d	       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NFrQ  r|  Tr9  r   r   rY  r[  r   r\  )r   r   r   r   r<   rv  r  r  r   r^  ro   r_  r`  r`  rZ  ra  r]  rb  s
             r   rs  z/FastCGIProcessConfigTests.test_make_dispatchers  sw   .==)((* 	5n,,. 5.*8*=*='*8*=*='+0('1%-%>%>x%H"U  Q!7!7A  Q!6!6=  Q!7!7BM  Q!:!:!@B  x!4  Q!7!7BM  Q!:!:!@B  x!4#5	5 	55 5	5 	5s$   FD9F>FF	FF$N)r%   r&   r'   r   r   rU  rW  rs  r(   r   r   ru  ru    s    $8&F
/5r   ru  c                   *    e Zd Zd Zd Zd Zd Zd Zy)ProcessGroupConfigTestsc                     ddl m} |S )Nr   )ProcessGroupConfig)r   r  )r   r  s     r   r   z'ProcessGroupConfigTests._getTargetClass      9!!r   c                 4     | j                         ||||      S r/   r   )r   rF   r<   rm  r  s        r   r   z ProcessGroupConfigTests._makeOne  s    %t##%gtXxHHr   c                     t               }| j                  |ddg       }| j                  |j                  |       | j                  |j                  d       | j                  |j
                  d       | j                  |j                  g        y )Nwhateverr  )r   r   ro   rF   r<   rm  rn  rB  s      r   	test_ctorz!ProcessGroupConfigTests.test_ctor  ss    .==*c2>))73
3**C01126r   c                     t               }t        |dd      g}| j                  |dd|      }|j                          | j	                  |d   j
                  d       y )Nrc  /bin/process1r  r  r   Tr   r   r   after_setuidro   autochildlogs_createdr   rF   r  r   s       r   test_after_setuidz)ProcessGroupConfigTests.test_after_setuid  sT    . *oFG==*c8D!::DAr   c                     t               }t        |dd      g}| j                  |dd|      }|j                         }ddlm} | j                  |j                  |       y )Nrc  r  r  r  r   )ProcessGroup)r   r   r   
make_grouprR  r  ro   r  )r   rF   r  r   r  r  s         r   test_make_groupz'ProcessGroupConfigTests.test_make_group  sS    . *oFG==*c8D##%3,7r   N)r%   r&   r'   r   r   r  r  r  r(   r   r   r~  r~    s    "I7B8r   r~  c                   $    e Zd Zd Zd Zd Zd Zy)EventListenerPoolConfigTestsc                     ddl m} |S )Nr   )EventListenerPoolConfig)r   r  )r   r  s     r   r   z,EventListenerPoolConfigTests._getTargetClass  s    >&&r   c           	      :     | j                         |||||||      S r/   r   )r   rF   r<   rm  rn  buffer_sizepool_eventsr[  s           r   r   z%EventListenerPoolConfigTests._makeOne  s,    %t##%gtX&5{&1>C 	Cr   c           	          t               }t        |dd      g}| j                  |dd|dg d       }|j                          | j	                  |d   j
                  d       y )Nrc  r  r<   r  r   r   Tr  r  s       r   r  z.EventListenerPoolConfigTests.test_after_setuid  sZ    . *oFG==&#xBM!::DAr   c           	          t               }t        |dd      g}| j                  |dd|dg d       }|j                         }ddlm} | j                  |j                  |       y )Nrc  r  r<   r  r   r   )EventListenerPool)r   r   r   r  rR  r  ro   r  )r   rF   r  r   r  r  s         r   r  z,EventListenerPoolConfigTests.test_make_group
  sZ    . *oFG==&#xBM##%8*;<r   N)r%   r&   r'   r   r   r  r  r(   r   r   r  r    s    'CB=r   r  c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)FastCGIGroupConfigTestsc                     ddl m} |S )Nr   r  )r   r  )r   r  s     r   r   z'FastCGIGroupConfigTests._getTargetClass  r  r   c                 .     | j                         |i |S r/   r   r   r   r;  s      r   r   z FastCGIGroupConfigTests._makeOne      %t##%t2r22r   c                 p   t               }t        d      }| j                  |ddg |      }| j                  |j                  |       | j                  |j
                  d       | j                  |j                  d       | j                  |j                  g        | j                  |j                  |       y Nrl   r  r  )	r   r   r   ro   rF   r<   rm  rn  r  )r   rF   sock_configr   s       r   r  z!FastCGIGroupConfigTests.test_ctor  s    .'*==*c2{K))73
3**C01126//=r   c                     t               }t        d      }| j                  |ddg |      }t        d      }| j                  |ddg |      }| j                  ||k(         | j	                  ||k7         y r  r   r   r   r   r  r   rF   sock_config1	instance1sock_config2	instance2s         r   test_same_sockets_are_equalz3FastCGIGroupConfigTests.test_same_sockets_are_equal$  m    .(+MM':sBM	(+MM':sBM		Y./i/0r   c                     t               }t        d      }| j                  |ddg |      }t        d      }| j                  |ddg |      }| j                  ||k7         | j	                  ||k(         y )Nrl   r  r  r[  r  r  s         r   test_diff_sockets_are_not_equalz7FastCGIGroupConfigTests.test_diff_sockets_are_not_equal/  r  r   c                     t               }t        d      }| j                  |ddg |      }|j                         }ddlm} | j                  |j                  |       y )Nrl   r<   r  r   )FastCGIProcessGroup)r   r   r   r  rR  r  ro   r  )r   rF   r  r   r  r  s         r   r  z'FastCGIGroupConfigTests.test_make_group:  sO    .'*==&#r;G##%:*=>r   N)	r%   r&   r'   r   r   r  r  r  r  r(   r   r   r  r    s     "3>	1	1?r   r  c                   $    e Zd Zd Zd Zd Zd Zy)SignalReceiverTestsc                 ^    ddl m}  |       }| j                  |j                         d        y )Nr   SignalReceiver)r   r  ro   r  r   r  srs      r   test_returns_None_initiallyz/SignalReceiverTests.test_returns_None_initiallyC  s#    5$/r   c                    ddl m}  |       }|j                  t        j                  d       |j                  t        j
                  d       | j                  |j                         t        j                         | j                  |j                         t        j
                         | j                  |j                         d        y Nr   r  frame)r   r  r  rx  r  r  ro   r  r  s      r   &test_returns_signals_in_order_receivedz:SignalReceiverTests.test_returns_signals_in_order_receivedH  s{    5


6>>7+


6>>7+&..9&..9$/r   c                 :   ddl m}  |       }|j                  t        j                  d       |j                  t        j                  d       | j                  |j                         t        j                         | j                  |j                         d        y r  )r   r  r  rx  r  ro   r  r  s      r   %test_does_not_queue_duplicate_signalsz9SignalReceiverTests.test_does_not_queue_duplicate_signalsQ  sa    5


6>>7+


6>>7+&..9$/r   c                    ddl m}  |       }|j                  t        j                  d       | j                  |j                         t        j                         | j                  |j                         d        |j                  t        j                  d       | j                  |j                         t        j                         | j                  |j                         d        y r  )r   r  r  rx  r  ro   r  r  r  s      r   %test_queues_again_after_being_emptiedz9SignalReceiverTests.test_queues_again_after_being_emptiedY  s    5


6>>7+&..9$/


6>>7+&..9$/r   N)r%   r&   r'   r  r  r  r  r(   r   r   r  r  B  s    0
000r   r  c                   l    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y)UnhosedConfigParserTestsc                     ddl m} |S )Nr   r  )r   r  )r   r  s     r   r   z(UnhosedConfigParserTests._getTargetClassd  rl  r   c                 .     | j                         |i |S r/   r   r  s      r   r   z!UnhosedConfigParserTests._makeOneh  r  r   c                     | j                         }|j                  d       ddlm} | j	                  |j
                  |j                  dd       y )N[supervisord]
r   )ConfigParserrX  missing)r   r  r  r  rK   NoOptionErrorsaneget)r   r  r  s      r   test_saneget_no_defaultz0UnhosedConfigParserTests.test_saneget_no_defaultk  s@    ,-2,44NNM9	6r   c                     | j                         }|j                  d       |j                  ddd      }| j                  |d       y )Nr  rX  r  rZ   r;   r   r  r  ro   r   r  results      r   test_saneget_with_defaultz2UnhosedConfigParserTests.test_saneget_with_defaultr  s@    ,-y%H'r   c                     | j                         }ddi|_        |j                  d       |j                  ddd      }| j	                  |d       y )Nr  rY  r  rX  r   %(pet)sr  r   r  r  r  ro   r  s      r   $test_saneget_with_default_and_expandz=UnhosedConfigParserTests.test_saneget_with_default_and_expandx  sL    "EN,-uiH'r   c                     | j                         }ddi|_        |j                  d       |j                  dddd      }| j	                  |d       y )	Nr  rY  r  rX  r   r  F)r;   	do_expandr  r  s      r   #test_saneget_with_default_no_expandz<UnhosedConfigParserTests.test_saneget_with_default_no_expand  sT    "EN,-u   0+r   c                     | j                         }|j                  d       |j                  ddd      }| j                  |d       y )N[supervisord]
foo=%(pet)s
rX  r   F)r  r  r  r  s      r   !test_saneget_no_default_no_expandz:UnhosedConfigParserTests.test_saneget_no_default_no_expand  s@    9:uF+r   c                     | j                         }ddi|_        |j                  d       |j                  dd      }| j	                  |d       y )Nr  rY  r  rX  r   r  r  s      r   (test_saneget_expands_instance_expansionszAUnhosedConfigParserTests.test_saneget_expands_instance_expansions  sH    "EN9:u5'r   c                     | j                         }ddi|_        |j                  d       |j                  ddddi      }| j	                  |d       y )Nr  rY  r  rX  r   r  )r  r  r  s      r   #test_saneget_expands_arg_expansionsz<UnhosedConfigParserTests.test_saneget_expands_arg_expansions  sV    "EN9:uu~   ''r   c                     | j                         }|j                  d|j                  z         | j                  |j	                  d      d       y )Nz[%s]
foo=bar
r   r   )r   r  	mysectionro   
getdefaultr   r  s     r   +test_getdefault_does_saneget_with_mysectionzDUnhosedConfigParserTests.test_getdefault_does_saneget_with_mysection  sB    ,v/?/??@**5159r   c                 ,   | j                         }t        j                  d      5 }|j                  d       |j	                          |j                  |j                        }d d d        | j                  j                  g       y # 1 sw Y   'xY wNr  r  [foo]
r   r   r   r   r  r  r<   ro   r   r  r   ok_filenamess       r   test_read_filenames_as_stringz6UnhosedConfigParserTests.test_read_filenames_as_string  sq    ((d3 	/qGGIGGI!;;qvv.L	/ 	x0		/ 	/s   =B

Bc                 .   | j                         }t        j                  d      5 }|j                  d       |j	                          |j                  |j                  g      }d d d        | j                  j                  g       y # 1 sw Y   'xY wr  r  r  s       r   test_read_filenames_as_listz4UnhosedConfigParserTests.test_read_filenames_as_list  ss    ((d3 	1qGGIGGI!;;x0L	1 	x0		1 	1s   >BBc                    t         j                  j                  t         j                  j                  t              d      }| j                         }t        j                  d      5 }|j                  d       |j                          |j                  ||j                  g      }d d d        | j                  j                  g       y # 1 sw Y   'xY w)Nr  r  r  r  )r{   r   r   r  r  r   r   r   r   r  r  r<   ro   )r   r  r  r   r  s        r   3test_read_returns_ok_filenames_like_rawconfigparserzLUnhosedConfigParserTests.test_read_returns_ok_filenames_like_rawconfigparser  s    ggll277??8#<mL((d3 	>qGGIGGI!;;QVV'<=L	> 	x0		> 	>s   (?CCc                 \    | j                         }| j                  |j                  i        y r/   )r   ro   section_to_filer  s     r   )test_read_section_to_file_initially_emptyzBUnhosedConfigParserTests.test_read_section_to_file_initially_empty  s#    //4r   c                 F   | j                         }t        j                  d      5 }|j                  d       |j	                          |j                  |j                  g       d d d        | j                  |j                  d   j                         y # 1 sw Y   3xY w)Nr  r  r  r   	r   r   r   r   r  r  r<   ro   r  )r   r  r   s      r   'test_read_section_to_file_read_one_filez@UnhosedConfigParserTests.test_read_section_to_file_read_one_file  sz    ((d3 	"qGGIGGIKK!	" 	//6?		" 	"s   >BB c                 F   | j                         }t        j                  d      5 }t        j                  d      5 }|j                  d       |j	                          |j                  d       |j	                          |j                  |j                  |j                  g       d d d        d d d        | j                  |j                  d   j                         | j                  |j                  d   j                         y # 1 sw Y   dxY w# 1 sw Y   hxY w)Nr  r  r  z[bar]
r   r   r  )r   r  r  r  s       r   -test_read_section_to_file_read_multiple_fileszFUnhosedConfigParserTests.test_read_section_to_file_read_multiple_files  s    ((d3 	0r,,$7 02#
#
RWWbgg./0	0 	//6@//6@0 0	0 	0s#   DA*D(DD	DD N)r%   r&   r'   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r(   r   r   r  r  c  sT    #36((,,((:
1115@
Ar   r  c                       e Zd Zd Zd Zy)UtilFunctionsTestsc                 t    ddl m} | j                   |dd      d       | j                   |dd      d       y )Nr   )make_namespecr  rT  zgroup:process)r   r  ro   )r   r  s     r   test_make_namespecz%UtilFunctionsTests.test_make_namespec  s3    4w	:OLy)<iHr   c                     ddl m} |}| j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d	      d       y )
Nr   )split_namespeczprocess:group)rT  r  rT  )rT  rT  zgroup:)r  Nzgroup:*)r   r  ro   )r   r  r   s      r   test_split_namespecz&UtilFunctionsTests.test_split_namespec  s]    5?+-AB9'=>8o697r   N)r%   r&   r'   r  r  r(   r   r   r  r    s    I
8r   r  c                  V    t        j                  t        j                  t                 S r/   )unittestfindTestCasesr  r  r%   r(   r   r   
test_suiter    s    !!#++h"788r   __main__r  )defaultTest)+__doc__r{   r  r   re  r  rx  r   r  r  r  r   r   rt  r   r   r   supervisor.loggersr   r	   r
   r   r   r   r   r   r   TestCaser   r   r*  r/  ri  ru  r~  r  r  r  r  r  r  r%   mainr(   r   r   <module>r
     s^   ' 	 
        & & 7 7 + 1 - . - . . 3 (e9(## e9NtA** tAlO-B** O-BbZ`4** `4D-5x00 -5`:5 1 1 :5x8h// 8>=8#4#4 =4.?h// .?`0(++ 0BmAx00 mA^8** 89 zHMMl+ r   