
    vg7                       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j                  Z G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  Z  G d dej                  Z! G d dej                  Z" G d dej                  Z# G d d ej                  Z$ G d! d"ej                  Z% G d# d$ej                  Z& G d% d&ej                  Z'd' Z(e)d(k    r ej*        d)*           dS dS )+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dS )OptionTestsc                     ddl m} |S )Nr   Options)supervisor.optionsr   )selfr   s     Z/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/supervisor/tests/test_options.py_getTargetClasszOptionTests._getTargetClass   s    ......    Fc                    |                                  ddlm}  G fdd          } |            }t                      |_        |                    ddddd	           |                    d
d
ddd|           |S )Nr   )integerc                   ,    e Zd ZddiZf fd	Zd ZdS )+OptionTests._makeOptions.<locals>.MyOptionsother)   c                     || _                             |             G d dt                    } |            | _        d S )Nc                       e Zd ZdS )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__*   sI    ",  &&&'''''&'''"%#%%r   c                     | j         rt          | j                   | j        j                            | j                   | j        j                            | j                   d S N)r*   
ValueErrorr-   __dict__updatedefault_mapmaster)r   fps     r   read_configz7OptionTests._makeOptions.<locals>.MyOptions.read_config0   sY    ? 6$T_555(//0@AAA(//<<<<<r   N)r%   r&   r'   r4   r+   r6   )r   r*   s   r   	MyOptionsr   '   sQ        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#   s    &&((000000	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=  )++%ZZjHi 	 	A 	A 	A7Xw 	 	@ 	@ 	@r   c                     |                                  } |            }|                     t          |j        dd           d S )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?   sC    ""$$suu*dhT4HHHHHr   c                     |                                  } |            }|                     t          |j        ddd           d S )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   sV    ""$$suuH 	 	 	 	 	 	r   c                     |                                  } |            }|                     t          |j        ddd           d S )NTF:rQ   rJ   rL   s      r   +test_add_flag_not_None_short_endswith_colonz7OptionTests.test_add_flag_not_None_short_endswith_colonO   sV    ""$$suuH 	 	 	 	 	 	r   c                     |                                  } |            }|                     t          |j        ddd           d S )NT=FrQ   rJ   rL   s      r   *test_add_flag_not_None_long_endswith_equalz6OptionTests.test_add_flag_not_None_long_endswith_equalZ   sV    ""$$suuH 	 	 	 	 	 	r   c                     |                                  } |            }|                     t          |j        dd           d S )NrW   abcr?   r>   rJ   rL   s      r   (test_add_inconsistent_short_long_optionsz4OptionTests.test_add_inconsistent_short_long_optionse   sS    ""$$suuH	 	 	 	 	 	 	r   c                     |                                  } |            }|                     t          |j        dd           d S )NF-abcr[   rJ   rL   s      r   %test_add_short_option_startswith_dashz1OptionTests.test_add_short_option_startswith_dasho   sS    ""$$suuH	 	 	 	 	 	 	r   c                     |                                  } |            }|                     t          |j        dd           d S )NFrZ   r[   rJ   rL   s      r   test_add_short_option_too_longz*OptionTests.test_add_short_option_too_longy   sS    ""$$suuH	 	 	 	 	 	 	r   c                     |                                  } |            }ddi|_        |                     t          |j        dd           d S )Nz-aTFar[   r   options_maprK   r0   rE   rL   s      r   #test_add_duplicate_short_option_keyz/OptionTests.test_add_duplicate_short_option_key   s_    ""$$suu ;H	 	 	 	 	 	 	r   c                     |                                  } |            }|                     t          |j        dd           d S )Nr^   Fr[   rJ   rL   s      r   $test_add_long_option_startswith_dashz0OptionTests.test_add_long_option_startswith_dash   sS    ""$$suuH	 	 	 	 	 	 	r   c                     |                                  } |            }ddi|_        |                     t          |j        dd           d S )Nz--abcTrZ   Fr[   rd   rL   s      r   "test_add_duplicate_long_option_keyz.OptionTests.test_add_duplicate_long_option_key   s_    ""$$suu#D>H	 	 	 	 	 	 	r   c                     |                                  }|                     t          |j                  d           |                     |j        dd          g d           d S )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   ss    ##%%W0111555,RSS1 4 4 4 	 	 	 	 	r   c                    |                                  }|                    g            |                     |j        d           |                     |j        d           |                                  }dt
          j        d<   |                    g            |                     |j        d           |                                  }|                    ddg           |                     |j        d           t
          j        d= d S )	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55+++ ##%%"
7+++ ##%%t%%%+++Jwr   c                     |                                  }|                    g            |                     |j        d           d|j        d<   |                                 |                     |j        d           d S )Nr    rv   r   )rG   rz   ro   r   r4   process_configrr   s     r   test_config_reloadzOptionTests.test_config_reload   sy    ##%%+++"$w   +++++r   c                 t    |                      d          }|                     t          |j        d           d S )Nerrorr*   F)rG   rK   r0   r   rr   s     r   !test_config_reload_do_usage_falsez-OptionTests.test_config_reload_do_usage_false   sD    ##w#77*g&<	! 	! 	! 	! 	!r   c                 
   |                      d          }g fd|_        t                      x|_        |_        d|j        _        d|j        _        |                    d           | 	                    dg           d S )Nr   r   c                 .                         |           S r/   appendx	exitcodess    r   <lambda>z>OptionTests.test_config_reload_do_usage_true.<locals>.<lambda>       !1!1!!4!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   s    ##w#77	4444*2**4&'##$ ---QC(((((r   c                 |   ddl m}  |            }|                    ddd           |                     |j        d           |                     |j        d         d           |                    ddd           |                     |j        d           |                     |j        d         d           |                    ddd           |                     |j        d           |                     |j        d         d           |                    ddd           |                     |j        d           d S )Nr   r   foobarbazr   gazonk)r   r   _setro   r   attr_priorities)r   r   rF   s      r   	test__setzOptionTests.test__set   s7   ......'))UE1%%%e,,,07;;;UE1%%%e,,,07;;;UHa(((e,,,07;;;UHa(((h/////r   c                 T   |                                  }g |_        g fd|_        t                      |_        |                                 |                     dg           d}|                     |j                                        	                    |                     d S )Nc                 .                         |           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   s    ##%% 	4444!""$$$QC(((<//11<<SAABBBBBr   c                     |                                  }t          j                    5 }|j        g|_        |                                }|                     ||j                   d d d            d S # 1 swxY w Y   d S r/   )rG   tempfileNamedTemporaryFiler<   rq   r   ro   )r   rF   fconfigs       r   test_default_configzOptionTests.test_default_config   s    ##%%(** 	-a#$6(G//11FVQV,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   =A22A69A6c                 @   |                                  }g fd|_        t                      |_        d|_        d|_        |                    d           |                     dg           d}|                     |j                                        |           d S )Nc                 .                         |           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   s    ##%%	4444!&1RQC(((20022C8888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      sZ            8I I I
	 	 		 	 		 	 	      	 	 	  	 	 	       &, , ,! ! !
) ) )0 0 0	C 	C 	C- - -
9 
9 
9 
9 
9r   r   c                   b    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S )ClientOptionsTestsc                     ddl m} |S )Nr   )ClientOptions)r   r   )r   r   s     r   r   z"ClientOptionsTests._getTargetClass      444444r   c                 :     |                                              S r/   r   r   s    r   _makeOnezClientOptionsTests._makeOne	      %t##%%'''r   c                    |                                  }g |_        g fd|_        |                    g d           |                     g            |                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           dS )	z(Making sure config file is not required.c                 .                         |           S r/   r   r   s    r   r   z8ClientOptionsTests.test_no_config_file.<locals>.<lambda>  s    )"2"21"5"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555 , , , 	- 	- 	- 	B'''-q111+-DEEE*G444*E22222r   c                    t          j                    }t          d|z            }t          |          }|                                 }||_        |                    g            |                     |j        d           t          j
                            |d          }|                     |j        |           |j        j        }|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     |j        |           d S )	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44w||G\::.===%3888*,CDDD)7333)5111-|<<<<<r   c                     t          d          }|                                 }t          |          |_        |                    g            |j        j        }|                     |j        d           d S )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  u        ==??&tnnb!!!%3*,CDDDDDr   c                     t          d          }|                                 }t          |          |_        |                    g            |j        j        }|                     |j        d           d S )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          }|                                 }t          |          |_        |                    g            d S )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  sP        ==??&tnnb!!!!!r   c                 @   t          d          }t          |          }|                                 }t          j                    ddddddd|_        ||_        |                    g 	           |                     |j	        d
           |j
        j        }|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           d S )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;3F3H3H3<:@:D:H<I>E'( '(# !b!!!-t444%3777*,CDDD):666)>:::-/UVVVVVr   c                    |                                  }t          d          }t          j                    }t          j                            |d          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   	 ||_	        |
                    g            t          j        |d           n# t          j        |d           w xY w|j        j        }|                     |j        t          j                            |d                     |                     |j        dt          j                            |d	          z              d S )
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   ==??   
 !!7<<.@AA"C(( 	AGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 		4"2H"%%%M$d33333FM$d33333%3-7<<l++	- 	- 	-*rw||D*<===	? 	? 	? 	? 	?   'B		BBC	 	C!c                 |   t           j                            t           j                            t                    d          }|                                 }	 |                    |           |                     d           d S # t          $ r-}| 	                    d|j
        d         v            Y d }~d S 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      gll27??8#<#<mLL==??	I  ---II&''''' 	I 	I 	IOO8CHQKGHHHHHHHHH	I   *B 
B;"B66B;c                    |                                  }d }||_        	 |                    t                     |                     d           d S # t
          $ r-}|                     d|j        d         v            Y d }~d S 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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  s    ==??	F 	F 	F"	I  ***II*+++++ 	I 	I 	IOO8CHQKGHHHHHHHHH	I   /A 
B"BBc                    |                                  }	 |                    t                                 |                     d           d S # t          $ r,}|                     |j        d         d           Y d }~d S 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  s    ==??	D  ,,,II&''''' 	D 	D 	DSXa[BD D D D D D D D D	D   6A 
B!A??Bc                     t          d          }|                                 }||_        |                    ddg           |                     |j        d           d S )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  sb    '((==?? }.@ABBB+-?@@@@@r   c                     t          d          }t          |          }|                                 }||_        |                    g            |                     |j        d           d S )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  so        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     s          ( ( (3 3 3 = = =0	E 	E 	E	E 	E 	E
" 
" 
"W W W<? ? ?,I I I
I 
I 
ID D DA A AA A A 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 ZdS )ServerOptionsTestsc                     ddl m} |S )Nr   )ServerOptions)r   r-  )r   r-  s     r   r   z"ServerOptionsTests._getTargetClass  r   r   c                 :     |                                              S r/   r   r   s    r   r   zServerOptionsTests._makeOne  r   r   c                    ddl m} |                                 }t                      |_        |                     t          |j        d            |                     |j        	                                |dz              d S )Nr   )VERSION
)
r   r0  r   r   r   rK   
SystemExitversionro   r   )r   r0  rF   s      r   test_versionzServerOptionsTests.test_version  st    ......--//!*got<<<0022GdNCCCCCr   c                 L$   t          ddt          j                    iz            }ddlm} t          |          }|                                 }||_        |                    g            |j	        j
        }|                     |j        t          j                               |                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d	           |                     |j        d
           |                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     |j        t          j                               |                     t/          |j                  d           |                     |j        d         d         t2          j                   |                     |j        d         d         d           |                     |j        d         d         d           |                     |j        d         d         d           |                     |j        d         d         d           |                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     t/          |j                  d	           |                     |j        tA          d                     |j        d         }|                     |j!        d           |                     |j"        d           |                     t/          |j#                  d           |j#        d         }|                     |j!        d           |                     |j$        d           |                     |j"        d           |                     |j%        d           |                     |j&        |j'                   |                     |j(        d	           |                     |j)        d           |                     |j*        d           |                     |j+        d           |                     |j,        tZ          j.                   |                     |j/        d	           |                     |j0        d            |                     |j1        d            |                     |j2        |3                    d!                     |                     |j4        d           |                     |j5        dg           |                     |j        d"           |                     |j        d#           |                     |j        tA          d                     |j        d         }|                     |j!        d$           |                     |j"        d#           |                     t/          |j#                  d           |j#        d         }	|                     |	j!        d$           |                     |	j$        d           |                     |	j"        d#           |                     |	j%        d           |                     |	j&        d            |                     |	j*        d            |                     |	j+        d%           |                     |	j,        tZ          j6                   |                     |	j0        d            |                     |	j1        d            |                     |	j2        d&           |                     |	j4        d#           |                     |	j5        dg           |                     |	j        d            |j        d#         }
|                     |
j!        d'           |                     |
j"        d(           |                     t/          |
j#                  d           |
j#        d         }|                     |j!        d)           |                     |j$        d           |                     |j"        d(           |                     |j%        d           |                     |j&        |j7                   |                     |j*        d            |                     |j+        |j8                   |                     |j2        |3                    d!                     |                     |j4        d           |                     |j5        g d*           |                     |j,        tZ          j6                   |                     |j0        d           |                     |j1        d           |j        d(         }|                     |j!        d+           |                     |j"        d,           |                     t/          |j#                  d#           |j#        d         }|                     |j!        d-           |                     |j$        d           |                     |j"        d,           |                     |j%        d           |                     |j&        |j'                   |                     |j*        d            |                     |j+        |j8                   |                     |j2        |3                    d!                     |                     |j4        d           |                     |j5        dg           |                     |j,        tZ          j6                   |                     |j0        d            |                     |j1        d            |                     |j        d            |j#        d         }|                     |j!        d.           |                     |j$        d           |                     |j"        d,           |                     |j%        d           |                     |j&        |j'                   |                     |j*        d            |                     |j+        |j8                   |                     |j2        |3                    d!                     |                     |j4        d           |                     |j5        dg           |                     |j,        tZ          j6                   |                     |j0        d            |                     |j1        d            |                     |j        d            |j        d,         }|                     |j!        d/           |                     |j"        d	           |                     t/          |j#                  d#           |j#        d         }|                     |j!        d0           |                     |j        d1           |j#        d         }|                     |j!        d2           |                     |j        d3           tr          j:        ;                    ts          j<                              }|                     |j*        d           |                     |j=        d           |                     |j        t          j                               |                     |j        d           |                     |j        tr          j:        >                    |d                     |                     |j        d           |                     |j        d	           |                     |j        d
           |                     |j        tr          j:        >                    |d                     |                     |j        d           |                     |j        d           |                     |j?        d            |                     |j        d           |                     |j        t          j                               |                     t/          |j                  d           |                     |j        d         d         t2          j                   |                     |j        d         d         d           |                     |j        d         d         d           |                     |j        d         d         d           |                     |j        d         d         d           |                     |j        d           |                     |j        d           |                     |j        d           d S )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   
supervisorr7  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   r7  r5   r   rF   rE  proc1rK  proc2rM  proc3rQ  proc4_aproc4_brU  proc5_aproc5_br   s                      r   r   zServerOptionsTests.test_options  s>    FL ,../MF0 F1 F1P 	)(((((a[[==?? b!!!%1*H,?,A,ABBB---*;<<<13EFFF0!444)2...*;<<<)4000...+W555,h.A.C.CDDDW344a888/28<fnMMM/26:KHHH/26:DAAA/2:>III/2:>FFF*D111...)3///*D111W:;;Q???,d.M.M.MNNN,Q/F+++***T122A666$Q'V,,,
333+++$///*I,OPPP!,,,+R000A&&&-~>>>)6>:::+Q///*E222*E2226",,V44	6 	6 	65r:::1#...&111a(((*Dl,K,K,KLLL,Q/F+++***T122A666$Q'V,,,
333+++$///*E222D)))-???)6>:::*E222*E2226===5q9991#...$///,Q/F+++***T122A666$Q'Z000
333+++$///*I,LMMMD)))-y/BCCC6",,V44	6 	6 	65r:::)))444)6>:::*D111*D111,Q/F+++***T122A666&q)y111*555)1---*D111,"<	> 	> 	>d+++/1DEEE8",,V44	6 	6 	67<<<*QC000+V^<<<,e444,e444*D111&q)y111*555)1---*D111,"<	> 	> 	>d+++/1DEEE8",,V44	6 	6 	67<<<*QC000+V^<<<,e444,e444*D111,Q/F+++***T122A666&q)x000*,?@@@&q)x000*,?@@@wry{{++q)))q)))+X-@-B-BCCC...)27<<=N+O+OPPP24FGGG11555*B///)27<<=N+O+OPPP*D111$///,d333,g666-x/B/D/DEEEX455q99903H=v~NNN03F;[III03F;TBBB03J?JJJ03J?GGG+T222$///*C00000r   c                 $   t          d          }|                                 }t          |          |_        |                    g            |j        j        }|                     |j        d           |                     |j	        d           d S )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-   rY  ro   r\  ri  r   s       r   r   zFServerOptionsTests.test_options_ignores_space_prefixed_inline_comments  s       
 ==??&tnnb!!!%1*@AAA-----r   c                     t          d          }|                                 }t          |          |_        |                    g            |j        j        }|                     |j        d           d S )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-   rY  ro   ri  r   s       r   r   zDServerOptionsTests.test_options_ignores_tab_prefixed_inline_comments  ss       
 ==??&tnnb!!!%1-----r   c                     t          d          }|                                 }t          |          |_        |                    g            d S )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  sP        ==??&tnnb!!!!!r   c                    t          d          }|                                 }t          |          |_        |                    g            |j        j        }|                     t          |j	                  d           |j	        d         }|                     t          |j
                  d           |j	        d         }|                     t          |j
                  d           |                     |j	        |j	        u            t          d          }t          |          |_        |                    d           |j        j        }|                     t          |j	                  d           |j	        d         }|                     t          |j
                  d           |j
        d         }|                     |j        d	           |                     |j        d
           |                     |j	        |j	        u            |j	        d         }|                     t          |j
                  d           |j
        d         }|                     |j        d           |                     |j        d           d S )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   onerF  threez/bin/pig)r   r   r   rD   rz   r-   rY  ro   rp   rk  ro  r   r   r<   rp  )r   r   r   sectioncatprocs         r   test_reloadzServerOptionsTests.test_reload  se      " ==??&tnnb!!!%1W:;;Q???+A.S0111555+A.S01115555 67 	8 	8 	8     'tnn///%1W:;;Q???+A.S0111555"1%E***z2225 67 	8 	8 	8 +A.S0111555"1%G,,,z22222r   c                 |   |                                  }d}|g|_        |g|_        |g|_        t	          d          }t          |          |_        |                    g            |                     ||j        v            |                     ||j        v            |                     ||j        v            d S )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    'tnnb!!!H$<<===H$;;<<<H$8899999r   c                     |                                  }d}|g|_        t          d          }t          |          |_        |                    g            |                     ||j        v            d S )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  sz    ==??2"    'tnnb!!!X%99:::::r   c                 |   t           j                            t           j                            t                    d          }|                                 }	 |                    |           |                     d           d S # t          $ r-}| 	                    d|j
        d         v            Y d }~d S d }~ww xY wr  r  r
  s       r   r  z-ServerOptionsTests.test_read_config_not_foundW  r  r  c                    |                                  }d }||_        	 |                    t                     |                     d           d S # t
          $ r-}|                     d|j        d         v            Y d }~d S 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`  s    ==??	F 	F 	F"	I  ***II&''''' 	I 	I 	IOO8CHQKGHHHHHHHHH	Ir  c                    |                                  }t          j        d          5 }	 |                    d           |                                 |                    |j                   |                     d           n`# t          $ rS}| 	                    d|j
        d         v            | 	                    |j        |j
        d         v            Y d }~nd }~ww xY wd d d            d S # 1 swxY w Y   d S )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33 	7q7-...			$$QV,,,		*++++ 7 7 7 :chqk IJJJ#(1+ 5666666667	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s<   C2ABC2
C"A	CC2C""C22C69C6c                    |                                  }t          j                            t          j                            t
                    dd          }t          d|z            }	 |                    t          |                     | 	                    d           d S # t          $ r/}|                     |j        d         d|z             Y d }~d S d }~ww xY w)Nr  r9  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    ==??')w||GOOH%%}( ($   ++ , ,	  $000II&''''' 	 	 	SXa[K,-        	s   +7B$ $
C.$CCc                    |                                  }	 |                    t                                 |                     d           d S # t          $ r,}|                     |j        d         d           Y d }~d S 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  s    ==??	B  ,,,II&''''' 	B 	B 	BSXa[@B B B B B B B B B	Br$  c                 .   |                                  }t          d          }	 |                    t          |                     |                     d           d S # t
          $ r,}|                     |j        d         d           Y d }~d S 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  s    ==??   	I  $000II&''''' 	I 	I 	ISXa[GI I I I I I I I I	Is   7A 
B(!BBc                     |                                  }t          d          }|                    t          |                     |                     |j        dg           d S )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  sq    ==??    	Xd^^,,,0IJ	L 	L 	L 	L 	Lr   c                    t          j                    }t          j                            |d          }t          j        |           t          j                            |d          }t          d|d|d          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   t          j                            |d          }t          |d          5 }|                    d           d d d            n# 1 swxY w Y   t          j                            |d	          }t          |d          5 }|                    d
           d d d            n# 1 swxY w Y   | 	                                }	 |
                    |           t          j        |d           n# t          j        |d           w xY w|j        j        }	|                     t!          |	j                  d           d|z  }
|                     |
|j        v            d|z  }
|                     |
|j        v            d S )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-   rY  ro   rp   re  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0
7<<1CDDv
 ww! " " "C(( 	AGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 GLL22	)S!! 	7QGG5666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 7<<00(C   	<AGG:;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< ==??	7  !1222M'66666FM'66666%1W344a8887)Cx334447(Bx3344444sB   B00B47B4+DDDE**E.1E.
F6 6Gc           	         t          j                    }t          j                            |d          }t          j        |           t          j                            |d          }t          d|z            }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   ddl	m
} |d d         }t          |          D ]i}t          j                            |d|z            }	t          |	d          5 }|                    d	|d
|d           d d d            n# 1 swxY w Y   j|                                 }
	 |
                    |           t          j        |d           n# t          j        |d           w xY wg }t!          |          D ]=}t          j                            |d|z            }	|                    d|	z             >|                     |
j        |           d S )Nr  rn   P        [supervisord]

        [include]
        files=%s/conf.d/*.conf
        r   r   )letters   %s.confz	[program:z]
command=/bin/r1  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0
7<<1CDD 
    "C(( 	AGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	.-----crclsmm 	@ 	@Fw||FI,>??Hh$$ @/5vvvvv? @ @ @@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ ==??	7  !1222M'66666FM'66666Skk 	F 	FFw||FI,>??H  9HDF F F F-}=====s0   
B,,B03B0D44D8	;D8	F Fc                    t          j                    }t          j                            |d          }t          j        |           t          j                            |d          }t          d|z            }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   t          j                            |d          }t          |d          5 }|                    d           d d d            n# 1 swxY w Y   | 	                                }	 |
                    |           |                     d           n|# t          $ ro}|                     d|j        d	         v            |                     ||j        d	         v            d
|z  }	|                     |	|j        v            Y d }~nd }~ww xY wt!          j        |d           d S # 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  sn   "$$gx00
7<<1CDD 
    "C(( 	AGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 fh77.#&& 	2!GG0111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 ==??		7  !1222II&'''' 	9 	9 	9OO6#(1+EFFFOONchqk9:::;nLCOOC8#7788888888		9 M'666666FM'66666sU   
B,,B03B0'D		DD)*E G( 
GA%GG( GG( (H c                    t          j                    }t          j                            |d          }t          j        |           t          j                            |d          }t          d|ddd          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   t          j                            |dt          j
                    z            }t          |d          5 }|                    d	           d d d            n# 1 swxY w Y   |                                 }	 |                    |           t          j        |d
           n# t          j        |d
           w xY w|j        j        }|                     t%          |j                  d           d|z  }	|                     |	|j        v            d S )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-   rY  ro   rp   re  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  s1   "$$gx00
7<<1CDDv
 ww,,,. / / "C(( 	AGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 GLLX]__)DEE	)S!! 	7QGG5666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 ==??	7  !1222M'66666FM'66666%1W344a8887)Cx3344444s0   B00B47B4?D!!D%(D%E- -Fc                 (   t           j                            t           j                            t           j                            t
                              dd          }t           j                            |          }t           j                            |d          }|                                 }||_        |                    d           |j	        j
        }|                     |j        |           |                     |j        |           d S )Nfixtureszinclude.confexampleT)r{   r   r   r  r  r  r   rD   process_config_filer-   rY  ro   r\  rd  )r   conf	root_hereinclude_hereparserr  s         r   %test_read_config_include_expands_herez8ServerOptionsTests.test_read_config_include_expands_here2  s    w||GOOBGOOH5566
  GOOD))	w||Iy99 ""4(((#/)444,l;;;;;r   c                     ddl m} 	  |ddd           t          d          # t          $ r,}|                     |j        d         d           Y d }~d S d }~ww xY w)Nr   )readFilez	/notthererG  zDidn't raiseFAILED)r   r  AssertionErrorr0   ro   r   )r   r  rN   s      r   test_readFile_failedz'ServerOptionsTests.test_readFile_failed?  s    //////	1H[!R((( !000  	5 	5 	5TYq\8444444444	5s   $ 
A!AAc                     |                                  }|                     t          j                    |                                           d S r/   )r   ro   r{   getpidget_pidr   r   s     r   test_get_pidzServerOptionsTests.test_get_pidH  s=    ==??h&6&6&8&899999r   c                    |                                  }|j                            t          j        d            |j                            t          j        d            |                     |                                t          j                   |                     |                                t          j                   |                     |                                d            d S r/   )r   signal_receiverreceivery  r  SIGCHLDro   
get_signalr  s     r   ,test_get_signal_delegates_to_signal_receiverz?ServerOptionsTests.test_get_signal_delegates_to_signal_receiverL  s    ==?? ((>>> ((>>>,,..???,,..???,,..55555r   c                 v    |                                  }ddlm} |                     ||j        dd d            d S )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  sQ    ==??//////(H$=&d	4 	4 	4 	4 	4r   c           	          |                                  }ddlm} |                     ||j        ddgt          j        d                     d S )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  sc    ==??444444-"3]'."'-*@*@	B 	B 	B 	B 	Br   c           	          |                                  }ddlm} |                     ||j        ddgt          j        d                     d S )Nr   r  /r  r  s      r   test_check_execv_args_isdirz.ServerOptionsTests.test_check_execv_args_isdira  s\    ==??444444-"3S%	/ 	/ 	/ 	/ 	/r   c                 ,   |                                  }g fd}||_        t          d          |_        ddg}|                    |           |                     t                    d           |                     d         d|z             d S )	Nc                 2                         |            d S 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  s    ==??	% 	% 	% 	% 	%%$_55u~d###X***!84?	A 	A 	A 	A 	Ar   c                     |                                  }g fd}||_        t          d          |_        |                    dg           |                     t                    d           |                     d         d           d S )Nc                 2                         |            d S 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  s    ==??	% 	% 	% 	% 	%%$_55yk***X***!&CDDDDDr   c                     t          d          }|                                 }t          |          |_        |                    ddg           |                     |j        d           d S )NzC
        [supervisord]
        identifier=from_config_file
        z-i	from_argsr   )r   r   r   rD   rz   ro   rc  r   s      r   )test_realize_prefers_identifier_from_argsz<ServerOptionsTests.test_realize_prefers_identifier_from_args  sn        ==??&tnnt[1222,k:::::r   c                    |                                  }t          d          }ddlm}  |            }|                    |           t          |          |_        |                    t          |                     |                    g            |j	        j
        }|                     |j        d         d         t          j                   |                     |j        d         d         d           |                     |j        d         d         d	           |                     |j        d         d
         d           d S )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-   rY  ro   re  rf  AF_UNIXr   r   r   r  r   rF   s         r   test_options_afunixz&ServerOptionsTests.test_options_afunix  s8   ==??    	;:::::$$&&4   &tnnXd^^,,,b!!!%1/28<fnMMM/26:<PQQQ/27;SAAA/27;WEEEEEr   c                 D   |                                  }t          d          }ddlm}  |            }|                    |           t          |          |_        |                    t          |                     |                    g            |j	        j
        }|                     |j        d         d         t          j                   |                     |j        d         d         d           |                     |j        d         d         d	           d S )
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   &tnnXd^^,,,b!!!%1/28<fnMMM/26:<PQQQ/27;SAAAAAr   c                 V   |                                  }t          d          }t          |          |_        	 |                    t          |                     |                     d           d S # t          $ r,}|                     |j        d         d           Y d }~d S 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    ==??    'tnn	+  $000II&''''' 	+ 	+ 	+SXa[)+ + + + + + + + +	+   7A2 2
B(<!B##B(c                 V   |                                  }t          d          }t          |          |_        	 |                    t          |                     |                     d           d S # t          $ r,}|                     |j        d         d           Y d }~d S 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    ==??    'tnn	?  $000II&''''' 	? 	? 	?SXa[=? ? ? ? ? ? ? ? ?	?r"  c                 V   |                                  }t          d          }t          |          |_        	 |                    t          |                     |                     d           d S # t          $ r,}|                     |j        d         d           Y d }~d S 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      ==??    'tnn	@  $000II&''''' 	@ 	@ 	@SXa[>@ @ @ @ @ @ @ @ @	@r"  c                 V   |                                  }t          d          }t          |          |_        	 |                    t          |                     |                     d           d S # t          $ r,}|                     |j        d         d           Y d }~d S 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      ==??    'tnn	   $000II&''''' 	  	  	 SXa[                 	 r"  c                 V   |                                  }t          d          }t          |          |_        	 |                    t          |                     |                     d           d S # t          $ r,}|                     |j        d         d           Y d }~d S 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                    |                                  }t          d          }t          j                    }t          j                            |d          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   	 ||_	        |
                    g            t          j        |d           n# t          j        |d           w xY w|j        j        }|j        d         }|                     |d         t"          j                   |                     |d	         t          j                            |d
                     d S )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-   rY  re  ro   rf  r  )r   r   r   r   r   r   rF   
serverconfs           r   %test_options_afunix_file_expands_herez8ServerOptionsTests.test_options_afunix_file_expands_here  s   ==??    !!7<<.@AA"C(( 	AGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 		4"2H"%%%M$d33333FM$d33333%1+A.
H-v~>>>F+GLL122	4 	4 	4 	4 	4r  c                 V   |                                  }t          d          }t          |          |_        	 |                    t          |                     |                     d           d S # t          $ r,}|                     |j        d         d           Y d }~d S 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                 V   |                                  }t          d          }t          |          |_        	 |                    t          |                     |                     d           d S # t          $ r,}|                     |j        d         d           Y d }~d S d }~ww xY w)Nzn        [supervisord]

        [inet_http_server]
        password=passwordhere
        ;no username=
        r  r   r2  r   r  s       r   -test_options_afinet_password_without_usernamez@ServerOptionsTests.test_options_afinet_password_without_usernameJ  s    ==??    'tnn	   $000II&''''' 	  	  	 SXa[                 	 r"  c                 V   |                                  }t          d          }t          |          |_        	 |                    t          |                     |                     d           d S # t          $ r,}|                     |j        d         d           Y d }~d S 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        }|                    d           d d d            n# 1 swxY w Y   |                                 }d|_         G d d          }t          j        |d |            fg|_        d|_	        |
                                 |                     t          j                            |                     d S )	NFdelete   fooTc                       e Zd ZdS )=ServerOptionsTests.test_cleanup_afunix_unlink.<locals>.ServerNr$   r(   r   r   Serverr=  t  s        Dr   r>  r>  r  r   )r   r   r<   r   r   unlink_socketfilesrf  r  httpserversr`  cleanupr  r{   r   existsr   r   r  r   r>  s        r   test_cleanup_afunix_unlinkz-ServerOptionsTests.test_cleanup_afunix_unlinkn  s$   (666 	!BGGFOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ==??&*#	 	 	 	 	 	 	 	+1>"!E!E!'!+  ,++,,,,,s   ?AAc                 b   t          j        d          5 }|j        }|                    d           d d d            n# 1 swxY w Y   	 |                                 } G d d          }t
          j        |d |            fg|_        d|_        d|_	        |
                                 |                     t          j                            |                     	 t          j        |           d S # t           $ r Y d S w xY w# 	 t          j        |           w # t           $ r Y w w xY wxY w)NFr9  r;  c                       e Zd ZdS )?ServerOptionsTests.test_cleanup_afunix_nounlink.<locals>.ServerNr$   r(   r   r   r>  rH            r   r>  r?  r   )r   r   r<   r   r   rf  r  rA  r`  r@  rB  r   r{   r   rC  unlinkOSErrorrD  s        r   test_cleanup_afunix_nounlinkz/ServerOptionsTests.test_cleanup_afunix_nounlink|  s   (666 	!BGGFOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 		}}H       /5~b%I%I%+VXX%/ $0H !H*/H'OOBGNN2..///	"   	"   sR   ?AABD  C6 6
DDD.	DD.
D+(D.*D++D.c                    t           j                            t           j                            t                    d          }t          j        d          5 }|j        }|                    d           d d d            n# 1 swxY w Y   	 | 	                                }d|_
         G d d          }t          j        |d |            ft          j        |d |            fg|_        d	|_        |                                 |                     t           j                            |                     	 t          j        |           d S # t&          $ r Y d S w xY w# 	 t          j        |           w # t&          $ r Y w w xY wxY w)
NnotfoundFr9  r;  Tc                       e Zd ZdS )MServerOptionsTests.test_cleanup_afunix_ignores_oserror_enoent.<locals>.ServerNr$   r(   r   r   r>  rP    rI  r   r>  r?  r   )r{   r   r   r  r  r   r   r<   r   r   r@  rf  r  rA  r`  rB  r  rC  rJ  rK  )r   rN  r   
socketnamer   r>  s         r   *test_cleanup_afunix_ignores_oserror_enoentz=ServerOptionsTests.test_cleanup_afunix_ignores_oserror_enoent  s   7<< 9 9:FF(666 	!JGGFOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 		}}H*.H'        #NH==vvxxH"NJ??J$H   "HRW^^J77888	*%%%%%   	*%%%%   sU   BBBB,E! :E 
EE!F#E87F8
FFFFc                 ~   t          j        d          5 }|j        }|                    d           d d d            n# 1 swxY w Y   	 |                                 }||_        t                      |_        |                                 | 	                    |j
                   |                                 |                     t          j                            |                     	 t          j        |           d S # t"          $ r Y d S w xY w# 	 t          j        |           w # t"          $ r Y w w xY wxY wNFr9     2)r   r   r<   r   r   r`  r
   loggerwrite_pidfiler   unlink_pidfilerB  r  r{   r   rC  rJ  rK  r   r   r`  r   s       r   test_cleanup_removes_pidfilez/ServerOptionsTests.test_cleanup_removes_pidfile  sw   (666 	!fGGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 		}}H&H)mmHO""$$$OOH3444RW^^G44555	'"""""   	'""""   sR   ?AAB"D .D 
DDD<D,+D<,
D96D<8D99D<c                     t           j                            t           j                            t                    d          }|                                 }||_        |                                 d S )NrN  )r{   r   r   r  r  r   r`  rB  )r   rN  r   s      r   +test_cleanup_pidfile_ignores_oserror_enoentz>ServerOptionsTests.test_cleanup_pidfile_ignores_oserror_enoent  sR    7<< 9 9:FF==??#r   c                 0   t          j        d          5 }|j        }|                    d           d d d            n# 1 swxY w Y   	 |                                 }||_        |                     |j                   |                                 | 	                    t          j                            |                     	 t          j        |           d S # t          $ r Y d S w xY w# 	 t          j        |           w # t          $ r Y w w xY wxY w)NFr9  s   1234)r   r   r<   r   r   r`  r  rX  rB  r   r{   r   rC  rJ  rK  rY  s       r   =test_cleanup_does_not_remove_pidfile_from_another_supervisordzPServerOptionsTests.test_cleanup_does_not_remove_pidfile_from_another_supervisord  s_   (666 	!fGGGG	 	 	 	 	 	 	 	 	 	 	 	 	 	 		}}H  'HX4555OOBGNN733444	'"""""   	'""""   sR   ?AAA;C. C 
C+*C+.D0DD
DDDDc                 ,   t          j        d          5 }|j        }|                    d           d d d            n# 1 swxY w Y   	 |                                 }||_        t          i           }||_        |                     |j	                   |
                                 |                     |j	                   	 t          j        |           d S # t          $ r Y d S w xY w# 	 t          j        |           w # t          $ r Y w w xY wxY wrT  )r   r   r<   r   r   r`  r   pollerr  closedrB  r   r{   rJ  rK  )r   r   r`  r   r`  s        r   test_cleanup_closes_pollerz-ServerOptionsTests.test_cleanup_closes_poller  s_   (666 	!fGGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 		}}H&H __F$HOV]+++OOFM***	'"""""   	'""""   sR   ?AAA9C, C 
C)(C),D.DD
DDDDzos.closerangec                     |                                  d_        fd} |             t          j                            dd           d S )NrG  c                  0                                       d S r/   )cleanup_fds)r   s   r   r   zCServerOptionsTests.test_cleanup_fds_closes_5_upto_minfds.<locals>.f  s      """""r   r:  )r   ri  r{   
closerangeassert_called_with)r   r   r   s     @r   %test_cleanup_fds_closes_5_upto_minfdsz8ServerOptionsTests.test_cleanup_fds_closes_5_upto_minfds  sY    ==??	# 	# 	# 	# 	#	
((B/////r   c                     |                                  } G d d          } |            }i |fg|_        |                                 |                     |j        d           d S )Nc                       e Zd ZdZd ZdS )9ServerOptionsTests.test_close_httpservers.<locals>.ServerFc                     d| _         d S NT)ra  r   s    r   closez?ServerOptionsTests.test_close_httpservers.<locals>.Server.close  s    "r   N)r%   r&   r'   ra  rn  r(   r   r   r>  rk    s(        F# # # # #r   r>  T)r   rA  close_httpserversro   ra  )r   r   r>  servers       r   test_close_httpserversz)ServerOptionsTests.test_close_httpservers  s    ==??	# 	# 	# 	# 	# 	# 	# 	# !#V~""$$$-----r   c                     |                                  }t                      }||_        |                                 |                     |j        d           d S rm  )r   r
   rV  close_loggerro   ra  r   r   rV  s      r   test_close_loggerz$ServerOptionsTests.test_close_logger  sO    ==?? -----r   c                     |                                  }g fd}||_        ddddddd}|                    |           |                     t	                    g d	           d S )
Nc                 2                         |            d S r/   r   fdra  s    r   close_fdz<ServerOptionsTests.test_close_parent_pipes.<locals>.close_fd      MM"r   r   r   r   rN  rR  r:  stdinr   r   child_stdinchild_stdoutchild_stderr)r   r   r   r   rz  close_parent_pipesro   r  r   r   rz  pipesra  s       @r   test_close_parent_pipesz*ServerOptionsTests.test_close_parent_pipes  s    ==??	 	 	 	 	$qA !1aI I##E***33333r   c                     |                                  }g fd}||_        dd i}|                    |           |                     g            d S )Nc                 2                         |            d S r/   r   rx  s    r   rz  zOServerOptionsTests.test_close_parent_pipes_ignores_fd_of_none.<locals>.close_fd  r{  r   r}  )r   rz  r  ro   r  s       @r   *test_close_parent_pipes_ignores_fd_of_nonez=ServerOptionsTests.test_close_parent_pipes_ignores_fd_of_none  so    ==??	 	 	 	 	$$##E***$$$$$r   c                     |                                  }g fd}||_        ddddddd}|                    |           |                     t	                    g d	           d S )
Nc                 2                         |            d S r/   r   rx  s    r   rz  z;ServerOptionsTests.test_close_child_pipes.<locals>.close_fd  r{  r   r   r   r   rN  rR  r:  r|  )rN  rR  r:  )r   rz  close_child_pipesro   r  r  s       @r   test_close_child_pipesz)ServerOptionsTests.test_close_child_pipes  s    ==??	 	 	 	 	$qA !1aI I""5)))33333r   c                     |                                  }g fd}||_        dd i}|                    |           |                     t	                    g            d S )Nc                 2                         |            d S r/   r   rx  s    r   rz  zNServerOptionsTests.test_close_child_pipes_ignores_fd_of_none.<locals>.close_fd%  r{  r   r~  r  r  s       @r   )test_close_child_pipes_ignores_fd_of_nonez<ServerOptionsTests.test_close_child_pipes_ignores_fd_of_none"  sv    ==??	 	 	 	 	$%##E***,,,,,r   c                 6   |                                  }t                      }t                      g|_        ||_        |                                 |                     |j        d         j        d           |                     |j        d         d           d S )Nr   Tzsupervisord logreopen)r   r
   handlersrV  
reopenlogsro   reopeneddatart  s      r   test_reopenlogsz"ServerOptionsTests.test_reopenlogs,  s    ==??&==/ +4d;;;Q)@AAAAAr   c                    t          j        d          5 }|j        }d d d            n# 1 swxY w Y   |                     t          j                            |                     	 |                                 }t                      |_	        ||_
        |                                 |                     t          j                            |                     t          |d          5 }t          |                                                                          }d d d            n# 1 swxY w Y   |                     |t	          j                               |j	        j        d         }|                     |                    d                     |                     |j                   	 t	          j        |           d S # t.          $ r Y d S w xY w# 	 t	          j        |           w # t.          $ r Y w w xY wxY w)NTr9  rr   zsupervisord started with pid)r   r   r<   r  r{   r   rC  r   r
   rV  r`  rW  r   r   intreadstripro   r  r  r   rX  rJ  rK  )r   r   r  r   pidr   s         r   test_write_pidfile_okz(ServerOptionsTests.test_write_pidfile_ok5  s6   (555 	B	 	 	 	 	 	 	 	 	 	 	 	 	 	 	++,,,	}}H)mmHO!H""$$$OOBGNN2..///b# ,!!&&((..**++, , , , , , , , , , , , , , ,S")++.../&q)COOCNN+IJJKKKOOH3444	"   	"   st   *..(BG ,4D, G ,D00G 3D04A>G 3G	 	
GGHG10H1
G>;H=G>>Hc                 6   d}|                                  }t                      |_        ||_        |                                 |j        j        d         }|                     |                    d                     |                     |j	                   d S )Nz/cannot/possibly/existr   zcould not write pidfile)
r   r
   rV  r`  rW  r  r   r   r  rX  )r   r  r   r   s       r   test_write_pidfile_failz*ServerOptionsTests.test_write_pidfile_failL  s    %==??%--   o"1%'@AABBB011111r   c                    |                                  }t          j                    \  }}t          j        |d           t          j        |t          d                     |                    |           |                     t          t          j        |d           |                    |           |                     t          t          j        |t          d                     d S )Nr   r   )	r   r{   piper  r   r   rz  rK   rK  )r   r   innieouties       r   test_close_fdz ServerOptionsTests.test_close_fdV  s    ==??wyyu
q
(((%   '27E1555%   '28UHUOODDDDDr   zos.close)side_effectc                 X    |                                  }|                    d           d S )Nr   )r   rz  r  s     r   test_close_fd_ignores_oserrorz0ServerOptionsTests.test_close_fd_ignores_oserror`  s)    ==??!r   c                    |                                  }t          d          }ddlm}  |            }|                    |           |                    |dd          }|                     t          |          d           |d         }|                     |j        d           |                     |j	        d           |                     |j
        d	           |                     |j        d	           |                     |j        d
           |                     |j        d
           |                     |j        d           |                     |j        d            |                     |j        d           |                     |j        d           |                     |j        d           |                     |j        t(          j                   |                     |j        d	           |                     |j        d           |                     |j        d
           |                     |j        ddg           |                     |j        d	           |                     |j        dddd           d S )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_00rF  Fd   i  @Tr   rR  val1val20)KEY1KEY2KEY3)r   r   r   r  r  processes_from_sectionro   rp   r<   rp  rq  rr  rt  ru  rv  rw  stdout_capture_maxbytesr~  stdout_events_enabledrx  ry  rz  r|  r}  r{  r   redirect_stderrrl  r   r   r   r  r   pconfigspconfigs          r   test_processes_from_sectionz.ServerOptionsTests.test_processes_from_sectione  sz   ==??   , 	;:::::$$&&4   226=%PPX***1+|444*555*E222,e444*C000-s333a(((/6668!<<<8)DDD6===+V^<<<,e444,d333-s333*QqE2220%888,!'sCC	E 	E 	E 	E 	Er   c                 2   |                                  }t          d          }ddlm}  |            }|                    |           |                    |dd          }dt          j                    z   }|                     |d         j	        |           d S )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   rp  r   r   r   r  r   r  expecteds          r   4test_processes_from_section_host_node_name_expansionzGServerOptionsTests.test_processes_from_section_host_node_name_expansion  s    ==??    	;:::::$$&&4   226=%PP%7!,h77777r   c                    |                                  }t          d          }ddlm}  |            }|                    |           |                    |dd          }|                     t          |          d           dD ]}|                     ||         j        d|z             |                     ||         j	        d	|z             |                     ||         j
        d
|z             |                     ||         j        d|z             |                     ||         j        d|z             |                     ||         j        dd|z  i           d S )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<   rp  rZ  stderr_logfilerw  rl  r   r   r   r  r   r  nums          r   1test_processes_from_section_process_num_expansionzDServerOptionsTests.test_processes_from_section_process_num_expansion  s   ==?? 	 	 	 	;:::::$$&&4   226=%PPX*** 	M 	MCXc]/C@@@Xc]24G#4MNNNXc]4mc6IJJJXc]9$s*, , ,Xc]9$s*, , ,Xc]6s
8KLLLL	M 	Mr   c                    |                                  }t          d          }ddlm}  |            }|                    |           |                    |dd          }|                     t          |          d           dD ]J}|                     ||         j        d|z             |                     ||         j	        d	dz             Kd S )
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<   rp  r  s          r   .test_processes_from_section_numprocs_expansionzAServerOptionsTests.test_processes_from_section_numprocs_expansion  s    ==??    	;:::::$$&&4   226=%PPX*** 	R 	RCXc]/C@@@Xc]24Lq4PQQQQ	R 	Rr   c                    |                                  }t          d          }ddlm}  |            }ddi|_        |                    |           |                    |dd          }|                     |d         j        d           d S )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   rZ  r   r   r   r  r   r  s         r   -test_processes_from_section_expands_directoryz@ServerOptionsTests.test_processes_from_section_expands_directory  s    ==??   
 	;:::::$$&&&.4   226=%PP!.
;;;;;r   c                 0   |                                  }t          d          }ddlm}  |            }|                    |           |                    |dd          }dt          j        d         z  }|                     |d         j	        |           d S )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   rp  r  s          r   ;test_processes_from_section_environment_variables_expansionzNServerOptionsTests.test_processes_from_section_environment_variables_expansion  s    ==??    	;:::::$$&&4   226=%PP)BJv,>>!,h77777r   c                 <   |                                  }t          d          }ddlm}  |            }|                    |           |                    |dd          }dt          j        d         z  }|                     |d         j	        d         |           d S )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   rl  r  s          r   6test_processes_from_section_expands_env_in_environmentzIServerOptionsTests.test_processes_from_section_expands_env_in_environment  s    ==??   
 	;:::::$$&&4   226=%PP 2:f#55!08(CCCCCr   c                 H   |                                  }t          d          }ddlm}  |            }|                    |           |                    |dd          }|                     |j        d         d           |                     |d         j        d            d S )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P03I	J 	J 	J 	!3T:::::r   c                    |                                  }t          d          }ddlm}  |            }|                    |           |                    |dd          }|                     |j        d         d           |                     |d         j        d            |                     |d         j	        d           d S )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  rw  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P03	 	 	 	!3T:::!2D99999r   c                    |                                  }t          d          }ddlm}  |            }|                    |           |                    |dd          }|                     |j        d         d           |                     |d         j        d            |                     |d         j	        d           d S )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                 <   |                                  }t          d          }ddlm}  |            }|                    |           |                    |dd          }|                     |j        g            |                     |d         j        d            d S )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P0"555!3T:::::r   c                 j   |                                  }t          dt          j        z            }ddlm}  |            }|                    |           |                    |dd          }|                     |j	        g            |                     |d         j
        t          j                   d S )NzQ        [program:foo]
        command = /bin/foo
        stopsignal = %d
        r   r  r  r   )r   r   ry  SIGQUITr   r  r  r  ro   r  rx  r  s         r   9test_processes_from_section_accepts_number_for_stopsignalzLServerOptionsTests.test_processes_from_section_accepts_number_for_stopsignal=  s    ==??  n	  
 	;:::::$$&&4   226=%PP0"555!/@@@@@r   c                    t          d          }ddlm} ddlm} |                                 }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        |_	        |
                    |           t          |          |_        |                    t          |                     |                    g -           |                     |j        d.|j	        z             |                     |j        d/|j	        z             |                     |j        d0           |                     |j        d1           |                     |j        t*          j                   |                     |j        d2           |                     |j        d2           |                     |j        d3           |                     |j        d4           |                     |j        d5           |                     |j        |j	        d                    |                     |j        d2           |j        j        }|                     |j         d         d6         tB          j"                   |                     |j         d         d7         d8           |                     |j         d         d9         d:           |                     |j         d         d;         d           |                     |j         d         d<         d           |j#        d         }|                     |j$        d=           |                     |j%        d>           |                     tM          |j'                  d?           |j'        d         }|                     |j$        d=           |                     |j(        d@           |                     |j%        d>           |                     |j)        d5           |                     |j*        |j+                   |                     |j,        dA           |                     |j-        d1           |                     |j.        d           |                     |j/        d&           |                     |j0        tb          j2                   |                     |j3        dA           |                     |j4        d2           |                     |j5        d2           |                     |j6        |7                    d'                     |                     |j8        dB           |                     |j9        dg           |                     |j:        d+           |                     |j;        dB           |                     |j<        t{          dCD                     d S )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   r6  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rootrH  78KB2KILL5rJ  )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rG  FrL     Tr>  r?  r   r@  i#  r   r   rE  rN  r   z%/bin/customcat --logdir=/path/to/logsr:  r   rB  rC  )>r   rX  r7  r   r  r   r   r   r   r  r  r   rD   r6   rz   ro   r\  rc  r]  r^  r_  r   INFOra  rb  ri  rj  rh  rd  
strip_ansir-   rY  re  rf  rg  rk  r<   rn  rp   ro  rp  rq  rr  rs  rt  ru  rv  rw  rx  ry  rz  r{  r|  r}  r~  r  r  r   rZ  r[  rl  rm  )	r   r   r7  r  r   r   rF   rE  r  s	            r   r   z;ServerOptionsTests.test_options_with_environment_expansionsK  sR    # # #H 	)(((((::::::==??'+--'	' f' j	'
 n' (' ''  '  ' w' v'  ' e' !&' "7'   0!'" &#'$ "%"(#'506/2#)!$"%%)"#;' ' '#> %$&&$74   &tnnXd^^,,,b!!!)7&:KK	M 	M 	M,2V5FF	H 	H 	H2H===12666*L,=>>>*E222%000$///*C000+T222-v/@/LMMM,e444%1/28<fnMMM/26:B???/26:DAAA/2:>
KKK/2:>OOO,Q/F+++***T122A666$Q'V,,,@	B 	B 	B+++$///*I,OPPP!,,,+R000A&&&-~>>>)6>:::+Q///*E222*E2226",,V44	6 	6 	65q9991#...&111a(((*Dl,K,K,KLLLLLr   c                    |                                  }t          d          }t          j                    }t          j                            |d          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   	 ||_	        |
                    g            t          j        |d           n# t          j        |d           w xY w|                     |j        t          j                            |                     |                     |j        t          j                            |                     |                     |j        t          j                            |d                     |                     |j        t          j                            |d                     d S )	Nz        [supervisord]
        childlogdir=%(here)s
        directory=%(here)s
        logfile=%(here)s/supervisord.log
        pidfile=%(here)s/supervisord.pid
        rn   r   r   Tr   r9  r<  )r   r   r   r   r{   r   r   r   r   rD   rz   r   r   ro   rd  rZ  r\  r`  )r   r   r   r   r   r   s         r   -test_options_supervisord_section_expands_herez@ServerOptionsTests.test_options_supervisord_section_expands_here  s   ==??    !!7<<.@AA"C(( 	AGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 		4"2H"%%%M$d33333FM$d33333-GLL	  	  	 +GLL	  	  	 )GLL011	3 	3 	3)GLL011	3 	3 	3 	3 	3r  c                    |                                  }t          d          }t          j                    }t          j                            |d          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   	 ||_	        |
                    g            t          j        |d           n# t          j        |d           w xY w|j        j        }|j        d         }|                     |j        d           |j        d         }|                     |j        t          j                            |d	                     d S )
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-   rY  rk  ro   r<   ro  rp  	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   ==??    !!7<<.@AA"C(( 	AGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 		4"2H"%%%M$d33333FM$d33333%1-a0U+++$Q'GLL>??	A 	A 	A 	A 	Ar  c                    |                                  }t          d          }t          j                    }t          j                            |d          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   	 ||_	        |
                    g            t          j        |d           n# t          j        |d           w xY w|j        j        }|j        d         }|                     |j        d           |j        d         }|                     |j        t          j                            |d	                     d S )
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   ==??    !!7<<.@AA"C(( 	AGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 		4"2H"%%%M$d33333FM$d33333%1-a0U+++$Q'GLL:;;	= 	= 	= 	= 	=r  c                    |                                  }t          d          }t          j                    }t          j                            |d          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   	 ||_	        |
                    g            t          j        |d           n# t          j        |d           w xY w|j        j        }|j        d         }|                     |j        d           |j        d         }|                     |j        t          j                            |d	                     |                     |j        t          j                            |d
                     |                     |j        dt          j                            |d          i           |                     |j        dt          j                            |d          z              |                     |j        t          j                            |d                     |                     |j        t          j                            |d                     d S )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-   rY  rk  ro   r<   ro  rZ  rp  rl  r   rw  r  r  s	            r   )test_options_program_section_expands_herez<ServerOptionsTests.test_options_program_section_expands_here  s   ==?? 
 
 
 !!7<<.@AA"C(( 	AGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 		4"2H"%%%M$d33333FM$d33333%1-a0U+++$Q'GLL~..	0 	0 	0GLLy))	+ 	+ 	+)BGLLu--.	0 	0 	0T+=>>>	@ 	@ 	@,GLL|,,	. 	. 	.,GLL|,,	. 	. 	. 	. 	.r  c                    |                                  }t          d          }t          j                    }t          j                            |d          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   	 ||_	        |
                    g            t          j        |d           n# t          j        |d           w xY w|j        j        }|j        d         }|                     |j        d           |j        d         }|                     |j        t          j                            |d	                     |                     |j        t          j                            |d
                     |                     |j        dt          j                            |d          i           |                     |j        dt          j                            |d          z              |                     |j        t          j                            |d                     |                     |j        t          j                            |d                     d S )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   ==??    !!7<<.@AA"C(( 	AGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 		4"2H"%%%M$d33333FM$d33333%1-a0X...$Q'GLL~..	0 	0 	0GLL|,,	. 	. 	.)BGLLu--.	0 	0 	0T+=>>>	@ 	@ 	@,GLL|,,	. 	. 	.,GLL|,,	. 	. 	. 	. 	.r  c                 J   |                                  }t          d          }|dz  }t          j                    }t          j                            |d          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   	 ddd|_	        ||_
        |                    g            t          j        |d	
           n# t          j        |d	
           w xY w|j        j        }|                     |j        t          j                            |d                     |j        d         }|j        d         }t          j                            |d          dt)          j                    }	|                     |j        |	           d S )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-   rY  ro   r\  rk  ro  r  r  rp  )
r   r   r   r   r   r   r  	cat_groupcat_0r  s
             r   (test_options_expands_combined_expansionsz;ServerOptionsTests.test_options_expands_combined_expansionsg  s   ==??    	 C 	D !!7<<.@AA"C(( 	AGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 		4( + +H' #3H"%%%M$d33333FM$d33333%1GLL}--	/ 	/ 	/ 1!4	)!,GLLy))))MOOO 	11111s   ,BBB'C C0c                    t          j                    }t          j                            |d          }t          d          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   |                                 }	 ||_	        	 |
                    d           |                     d           nH# t          $ r;}|                     t          |j        d                   d|z             Y d }~nd }~ww xY wt!          j        |d	
           d S # 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   "$$7<<1CDD    "C(( 	AGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ==??
	7"2HN'''777		*++++ N N N  QVAY:<LMN N N N N N N NN
 M'666666FM'66666sH   A55A9<A9D) +C	 D) 	
D1D	D) 	DD) )Ec                    t          j                    }t          j                            |d          }t          d|z            }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   t          j                            |d          }t          j        |           t          j                            |d          }t          d          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   | 	                                }	 ||_
        	 |                    d           |                     d	           nH# t          $ r;}|                     t          |j        d
                   d|z             Y d }~nd }~ww xY wt#          j        |d           d S # 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{   "$$7<<1CDD 
    "C(( 	AGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 gx00
V_==   
 -%% 	GGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ==??
	7"2HK'''777		*++++ K K K  QVAY:<IJK K K K K K K KK
 M'666666FM'66666sZ   A88A<?A<6DDD8G  +E, +G ,
F161F,'G ,F11G G$c                     |                                  }t          d          }ddlm}  |            }|                    |           |                     t          |j        |dd            d S )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      ==??    	;:::::$$&&4   *h&E ":D	B 	B 	B 	B 	Br   c                     |                                  }t          d          }ddlm}  |            }|                    |           |                     t          |j        |dd            d S )Nz)        [program:colons:are:bad]
        r   r  zprogram:colons:are:badr1  r2  s        r   3test_processes_from_section_bad_program_name_colonszFServerOptionsTests.test_processes_from_section_bad_program_name_colons  r4  r   c                     |                                  }t          d          }ddlm}  |            }|                    |           |                     t          |j        |dd            d S )NzN        [program:foo]
        command = /bin/cat
        numprocs = 2
        r   r  r  r1  r2  s        r   5test_processes_from_section_no_procnum_in_processnamezHServerOptionsTests.test_processes_from_section_no_procnum_in_processname      ==??   
 	;:::::$$&&4   *h&E -	7 	7 	7 	7 	7r   c                    |                                  }t          d          }ddlm}  |            }|                    |           	 |                    |dd            |                     d           d S # t          $ r>}|                     |j	        d         
                    d                     Y d }~d S 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HHII&''''' 	K 	K 	KOOCHQK22HJ J K K K K K K K K K	Ks   
,A8 8
C 3B;;C c                     |                                  }t          d          }ddlm}  |            }|                    |           |                     t          |j        |dd            d S )Nz^        [program:foo]
        command = /bin/cat
        process_name = %(not_there)s
        r   r  r  r1  r2  s        r   ?test_processes_from_section_missing_replacement_in_process_namezRServerOptionsTests.test_processes_from_section_missing_replacement_in_process_name  r9  r   c                     |                                  }t          d          }ddlm}  |            }|                    |           |                     t          |j        |dd            d S )Nz`        [program:foo]
        command = /bin/cat
        process_name = %(program_name)
        r   r  r  r1  r2  s        r   :test_processes_from_section_bad_expression_in_process_namezMServerOptionsTests.test_processes_from_section_bad_expression_in_process_name		  r9  r   c                     |                                  }t          d          }ddlm}  |            }|                    |           |                     t          |j        |dd            d S )Nz_        [program:foo]
        command = /bin/cat
        process_name = colons:are:bad
        r   r  r  r1  r2  s        r   5test_processes_from_section_bad_chars_in_process_namezHServerOptionsTests.test_processes_from_section_bad_chars_in_process_name	  r9  r   c                    |                                  }t          d          }ddlm}  |            }|                    |           |                    |dd          }|                     t          |          d           |d         }|                     |j        d           |                     |j	        d           d S )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PX***1+,d333,d33333r   c                     |                                  }t          d          }ddlm}  |            }|                    |           |                     t          |j        |dd            d S )Nz        [program:foo]
        command = /bin/cat
        process_name = %(program_name)s
        stopasgroup = true
        killasgroup = false
        r   r  r  r1  r2  s        r   >test_processes_from_section_killasgroup_mismatch_w_stopasgroupzQServerOptionsTests.test_processes_from_section_killasgroup_mismatch_w_stopasgroup4	  s    ==??    	;:::::$$&&4   *h&E -	7 	7 	7 	7 	7r   c                 h   |                                  }t          d          }ddlm}  |            }|                    |           	 |                    |dd            |                     d           d S # t          $ r/}|                     dt          |          v            Y d }~d S 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HH II + , , , , ,  	 	 	OOFq66        	s   
A8 8
B1$B,,B1c                 *   |                                  }t          d          }t          j        d          5 }	 |                    |           |                                 ddlm}  |            }|                    |j	                   |
                    |dd            |                     d           n@# t          $ r3}|                     |j        d         d|j	        z             Y d }~nd }~ww xY wd d d            d S # 1 swxY w Y   d S )	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33 	,q,			BBBBBB,,..AF###//tLLL 		*++++  D D D  :<=FCD D D D D D D DD	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s;   DA*B;%D;
C8)C3.D3C88DDDc                 n   |                                  }t          d          }ddlm}  |            }t	                      |_        |                    |           |                    |dd            |                     |j	        d         d           |                     |j	        d         d           d S )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
   rV  r  r  ro   r  r2  s        r   4test_processes_from_section_autolog_without_rolloverzGServerOptionsTests.test_processes_from_section_autolog_without_rolloverm	  s    ==??    	;:::::$$&&%--4   ''tDDD03+	, 	, 	, 	03+	, 	, 	, 	, 	,r   c                    t          d          }ddlm}  |            }|                    |           |                                 }|                    |          }|                     t          |          d           |d         }|                     |j        d           |                     |j	        d           |                     t          |j
                  d           d S )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<   rn  ro  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55q99999r   c                    t          d          }ddlm} ddlm}  |            }|                    |           |                                 }|                    |          }|                     t          |          d           |d         }|                     |j
        d           |                     |j        |           |                     t          |j                  d           |d         }|                     |j
        d	           |                     |j        d
           |                     |j        |           |                     t          |j                  d           |d         }|                     |j
        d           |                     |j        d           |                     |j        |           |                     t          |j                  d           d S )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_handlerrN  bizr   r   r  r  dog)r   r   r  supervisor.dispatchersrV  r  r   rO  ro   rp   r<   result_handlerro  rn  )r   r   r  rV  r   r   rQ  gconfig1s           r   %test_event_listener_pools_from_parserz8ServerOptionsTests.test_event_listener_pools_from_parser	  s      ( 	;:::::::::::$$&&4   ==??66v>>X***A;...0/BBBX566:::A;...*B///0/BBBX566:::A;...*A...0/BBBX566:::::r   c                    t          d          }ddlm} ddlm} |                                 }t          j                    ddddd	d
|_         |            }|j        |_	        |
                    |           |                    |          }|                     t          |          d           |d         }|                     |j        d           |                     |j        d           |                     |j        |           |                     t          |j                  d           |d         }|                     |j        d           |                     |j        d           |                     |j        |           |                     t          |j                  d           |j        d         }	|                     |	j        d           |                     |	j        d           |                     |	j        d           |j        d         }
|                     |
j        d           |                     |
j        d           |                     |
j        d           d S )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  rU  r   myeventlistenerz/bin/dogr  1)r   r   ENV_EL1_PROCNAMEENV_EL1_COMMANDENV_EL1_NUMPROCSENV_EL1_PRIORITYr   r  r  rN  r   rX  myeventlistener_dog_0myeventlistener_dog_1)r   r   r  rY  rV  r   r   r   r   r  r  rO  ro   rp   r<   rn  rZ  ro  rp  )r   r   r  rV  r   r   rQ  gconfig0r[  dog0dog1s              r   Atest_event_listener_pools_from_parser_with_environment_expansionszTServerOptionsTests.test_event_listener_pools_from_parser_with_environment_expansions	  sk       	;:::::::::::==??3;3F3H3H3<;L:D;>;>'( '(# %$&&$74   66v>>X***A;...*B///0/BBBX566:::A;...*A...0/BBBX566:::'*$;<<<z222***'*$;<<<z222*****r   c                 ^   t          d          }ddlm}  |            }|                    |           |                                 }	 |                    |           |                     d           d S # t          $ r,}|                     |j	        d         d           Y d }~d S 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   rO  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77II&''''' 	+ 	+ 	+SXa[ +* + + + + + + + + +	+   
*A6 6
B, !B''B,c                 ^   t          d          }ddlm}  |            }|                    |           |                                 }	 |                    |           |                     d           d S # t          $ r,}|                     |j	        d         d           Y d }~d S 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 protocolrk  rl  s         r   2test_event_listener_pool_disallows_redirect_stderrzEServerOptionsTests.test_event_listener_pool_disallows_redirect_stderr
  s        	;:::::$$&&4   ==??	B//777II&''''' 	B 	B 	BSXa[ +A B B B B B B B B B	Brn  c                 X   t          d          }ddlm} ddlm}  |            }|                    |           |                                 }|                    |          }|                     t          |          d           |d         }|                     |j
        |           d S )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.baserr  r  r   rO  ro   rp   rZ  )r   r   r  rr  r   r   rQ  r[  s           r   2test_event_listener_pool_with_event_result_handlerzEServerOptionsTests.test_event_listener_pool_with_event_result_handler
  s        	;:::::777777$$&&4   ==??66v>>X***A;0-@@@@@r   c                 ^   t          d          }ddlm}  |            }|                    |           |                                 }	 |                    |           |                     d           d S # t          $ r,}|                     |j	        d         d           Y d }~d S 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]rk  rl  s         r   4test_event_listener_pool_result_handler_unimportablezGServerOptionsTests.test_event_listener_pool_result_handler_unimportable1
  s        	;:::::$$&&4   ==??	7//777II&''''' 	7 	7 	7SXa[67 7 7 7 7 7 7 7 7	7rn  c                     t          d          }ddlm}  |            }|                    |           |                                 }|                     t          |j        |           d S )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   rO  r   r   r  r   r   s        r   %test_event_listener_pool_noeventslinez8ServerOptionsTests.test_event_listener_pool_noeventslineD
  z        	;:::::$$&&4   ==??*X%HPPPPPr   c                     t          d          }ddlm}  |            }|                    |           |                                 }|                     t          |j        |           d S )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  rx  ry  s        r   *test_event_listener_pool_unknown_eventtypez=ServerOptionsTests.test_event_listener_pool_unknown_eventtypeR
  z        	;:::::$$&&4   ==??*X%HPPPPPr   c                 $	   ddl m} ddl m} t          d          }ddl m}  |            }|                    |           |                                 }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}|                     t          |
          d
           |
d         }|                     |j        |           |                     |j        d           |                     |j        d           |                     |j        j        d           |                     ||j                                                   |                     d|j                                                   |                     d|j                                                   |                     t          |j                  d           |j        d         }|                     |j        |           |
d         }|                     |j        d           |                     |j        d           |                     |j        j        d           |                     ||j                                                   |                     d|j                                                   |                     t          |j                  d           |
d         }|                     |j        d           |                     |j        j        d           |                     t          |j                  d           |
d         }|                     |j        d           |                     |j        j        d           |                     d |j                                                   |                     d|j                                                   |                     t          |j                  d           d S )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                 ,    |                      |          S r/   rO  r   r   s     r   get_process_groupszMServerOptionsTests.test_fcgi_programs_from_parser.<locals>.get_process_groups
       66v>>>r   rR  r   r   zunix:///tmp/foo.sock    r   r     zunix:///tmp/bar.sockr  rN  cubztcp://localhost:6000flubzunix:///tmp/flub.sock)r   r  r  r   r  r  r   r   r   rv  r  return_valuer   ro   rp   	__class__r<   rn  socket_configurl	get_ownerget_modeget_backlogro  )r   r  r  r   r  r   r   pwd_mockgrp_mockr  rQ  	exp_owner	gconf_foopconfig_foo	gconf_bar	gconf_cub
gconf_flubs                    r   test_fcgi_programs_from_parserz1ServerOptionsTests.test_fcgi_programs_from_parsera
  sS   999999;;;;;;   4 	;:::::$$&&4   ==??
 66!%tX\8< H66!%tX\ :	~x	(	(	~x	(	(	~x	(	(	? 	? 
)	( 
)	( 
)	(	? &%h77\8<0	X***QK	,.@AAA///+Q///04 6	8 	8 	8I$;$E$E$G$GHHH	 7 @ @ B BCCC	 7 C C E EFFFY677;;;/2.0DEEEQK	///+S11104/	1 	1 	1I$;$E$E$G$GHHH	 7 @ @ B BCCCY677;;;QK	///04/	1 	1 	1Y677;;;a[
&111150	2 	2 	2z7AACCDDD
 8 A A C CDDDZ788!<<<<<r   c                 v   ddl m} ddl m} t          d          }ddl m} |                                 }dddd	d
dddddd
|_         |            }|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}|                     t!          |
          d           |
d         }|                     |j        |           |                     |j        d           |                     |j        d           |                     |j        j        d           |                     ||j                                                   |                     d|j                                                   |                     d|j                                                   |                     t!          |j                  d           |j        d         }|                     |j        |           |                     |j        d           d S )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  rJ  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                 ,    |                      |          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   rv  r  r  r   ro   rp   r  r<   rn  r  r  r  r  r  ro  rp  )r   r  r  r   r  r   r   r  r  r  rQ  r  r  r  s                 r   :test_fcgi_programs_from_parser_with_environment_expansionszMServerOptionsTests.test_fcgi_programs_from_parser_with_environment_expansions
  s   999999;;;;;; 
 
 
 	;:::::==??39:@=E>H>DAHAH?D;>;>
'( 
'(# %$&&$74   
 66!%tX\8< H66!%tX\ :	~x	(	(	~x	(	(	~x	(	(	? 	? 
)	( 
)	( 
)	(	? &%h77\8<0	X***QK	,.@AAA///+Q///04 7	9 	9 	9I$;$E$E$G$GHHH	 7 @ @ B BCCC	 7 C C E EFFFY677;;;/2.0DEEE,.CDDDDDr   c                     t          d          }ddlm}  |            }|                    |           |                                 }|                     t          |j        |           d S )Nz        [fcgi-program:foo]
        process_name = %(program_name)s_%(process_num)s
        command = /bin/foo
        numprocs = 2
        priority = 1
        r   r  rx  ry  s        r   test_fcgi_program_no_socketz.ServerOptionsTests.test_fcgi_program_no_socket
  r{  r   c                     t          d          }ddlm}  |            }|                    |           |                                 }|                     t          |j        |           d S )Nz        [fcgi-program:foo]
        socket=junk://blah
        process_name = %(program_name)s_%(process_num)s
        command = /bin/foo
        numprocs = 2
        priority = 1
        r   r  rx  ry  s        r   )test_fcgi_program_unknown_socket_protocolz<ServerOptionsTests.test_fcgi_program_unknown_socket_protocol  r~  r   c                     t          d          }ddlm}  |            }|                    |           |                                 }|                     t          |j        |           d S )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  rx  ry  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}  |            }|                    |           |                                 }|                     t          |j        |           d S )Nz        [fcgi-program:foo]
        socket=tcp://missingport
        process_name = %(program_name)s_%(process_num)s
        command = /bin/foo
        numprocs = 2
        priority = 1
        r   r  rx  ry  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}  |            }|                    |           |                                 }|                     t          |j        |           d S )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  rx  ry  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}  |            }|                    |           |                                 }|                     t          |j        |           d S )Nz        [fcgi-program:foo]
        socket=tcp://localhost:8000
        socket_owner=nobody:nobody
        command = /bin/foo
        r   r  rx  ry  s        r   *test_fcgi_program_socket_owner_set_for_tcpz=ServerOptionsTests.test_fcgi_program_socket_owner_set_for_tcpD  z        	;:::::$$&&4   ==??*X%HPPPPPr   c                     t          d          }ddlm}  |            }|                    |           |                                 }|                     t          |j        |           d S )Nz        [fcgi-program:foo]
        socket = tcp://localhost:8000
        socket_mode = 0777
        command = /bin/foo
        r   r  rx  ry  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}  |            }|                    |           |                                 }|                     t          |j        |           d S )Nz        [fcgi-program:foo]
        socket = unix:///tmp/foo.sock
        socket_owner = sometotaljunkuserthatshouldnobethere
        command = /bin/foo
        r   r  rx  ry  s        r   "test_fcgi_program_bad_socket_ownerz5ServerOptionsTests.test_fcgi_program_bad_socket_owner^  r  r   c                     t          d          }ddlm}  |            }|                    |           |                                 }|                     t          |j        |           d S )Nz        [fcgi-program:foo]
        socket = unix:///tmp/foo.sock
        socket_mode = junk
        command = /bin/foo
        r   r  rx  ry  s        r   !test_fcgi_program_bad_socket_modez4ServerOptionsTests.test_fcgi_program_bad_socket_modek  r  r   c                     t          d          }ddlm}  |            }|                    |           |                                 }|                     t          |j        |           d S )Nz        [fcgi-program:foo]
        socket = unix:///tmp/foo.sock
        socket_backlog = -1
        command = /bin/foo
        r   r  rx  ry  s        r   $test_fcgi_program_bad_socket_backlogz7ServerOptionsTests.test_fcgi_program_bad_socket_backlogx  r  r   c                    t          d          }ddlm}  |            }|                    |           |                                 }|                    |          }|                     t          |          d           |d         }|                     |j        d           |                     |j	        d           |                     t          |j
                  d           d S )Nz        [program:one]
        command = /bin/cat

        [program:two]
        command = /bin/cat

        [group:thegroup]
        programs = one,two
        priority = 5
        r   r  r   thegroupr:  r   rN  rP  s          r   -test_heterogeneous_process_groups_from_parserz@ServerOptionsTests.test_heterogeneous_process_groups_from_parser  s     
 
 
 	;:::::$$&&4   ==??66v>>X***1+z222)1---W455q99999r   c                    t          d          }ddlm}  |            }|                    |           |                                 }|                    |          }|                     t          |          d           |d         }|                     |j        d           |                     |j	        d           |                     t          |j
                  d           |d         }|                     |j        d           |                     |j	        d           |                     t          |j
                  d           d S )	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   rM  r   r  r:  rN  )r   r   r  r   r   rQ  
manyconfigrR  s           r   &test_mixed_process_groups_from_parser1z9ServerOptionsTests.test_mixed_process_groups_from_parser1  sD      " 	;:::::$$&&4   ==??66v>>X***a[
&111,a000Z788!<<<1+z222)1---W455q99999r   c                    t          d          }ddlm}  |            }|                    |           |                                 }|                    |          }|                     t          |          d           |d         }|                     |j        d           |                     |j	        d           |                     t          |j
                  d           d S )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  r:  rR  rN  rP  s          r   &test_mixed_process_groups_from_parser2z9ServerOptionsTests.test_mixed_process_groups_from_parser2  s       " 	;:::::$$&&4   ==??66v>>X***1+z222)1---W455q99999r   c                    t          d          }ddlm}  |            }|                    |           |                                 }|                    |          }|                     t          |          d           |d         }|                     |j        d           |                     |j	        d           |                     t          |j
                  d           d S )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  r:  rl   rN  rP  s          r   &test_mixed_process_groups_from_parser3z9ServerOptionsTests.test_mixed_process_groups_from_parser3  s       . 	;:::::$$&&4   ==??66v>>X***1+z222)1---W455q99999r   c                     t          d          }ddlm}  |            }|                    |           |                                 }|                     t          |j        |           d S )Nz        [program:one]
        command = /bin/cat

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

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

        [group:foo]
        programs = notthere
        r   r  rx  ry  s        r   +test_unknown_program_in_heterogeneous_groupz>ServerOptionsTests.test_unknown_program_in_heterogeneous_group  s        	;:::::$$&&4   ==??*h&I 	" 	" 	" 	" 	"r   c                    t          dt          z            }ddlm}  |            }|                    |           |                                 }|                    |dd          }|                     t          |          d           |d         }|                     |d         d           |                     |d         t          j
        t                              |                     |d         d	d
d           d S )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} |                                 } |            }t          dd|_        |                    |           |                    |dd          }|                     t          |          d           |d         }|                     |d         d	           |                     |d         t          j        t                              |                     |d
         ddi           d S )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^44444r   c                 b   t          d          }ddlm}  |            }|                    |           |                                 }	 |                    |dd           |                     d           d S # t          $ r,}|                     |j	        d         d           Y d }~d S 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   rl  s         r   .test_rpcinterfaces_from_parser_factory_missingzAServerOptionsTests.test_rpcinterfaces_from_parser_factory_missingI  s
       	;:::::$$&&4   ==??	F  !B!02 2 2 II&''''' 	F 	F 	FSXa[ +E F F F F F F F F F	F   
,A8 8
B.!B))B.c                 b   t          d          }ddlm}  |            }|                    |           |                                 }	 |                    |dd           |                     d           d S # t          $ r,}|                     |j	        d         d           Y d }~d S 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  rl  s         r   5test_rpcinterfaces_from_parser_factory_not_importablezHServerOptionsTests.test_rpcinterfaces_from_parser_factory_not_importable[  s        	;:::::$$&&4   ==??	/  !B!02 2 2 II&''''' 	/ 	/ 	/SXa[ +. / / / / / / / / /	/r  c                    t          j                    }	 |                                 }||_        d}||_        |                    d|d          }|dz   }|dz   }t          |d          }t          |d          }|                                 |                     t          j
                            |                     |                     t          j
                            |                     |                     t          j
                            |                     |                                 |                                 t          j        |d           d S # t          j        |d           w xY w)	NrX  r   r   z.1z.2r   Tr   )r   r   r   rd  rc  get_autochildlog_namer   clear_autochildlogdirr  r{   r   rC  rn  r   r   )	r   dnr   sidlogfnfirstsecondf1f2s	            r   test_clear_autochildlogdirz-ServerOptionsTests.test_clear_autochildlogdirm  sF   	2}}H#%H C"%H225#hGGEDLET\FeS!!Bfc""B**,,,RW^^E22333RW^^E22333RW^^F33444HHJJJHHJJJM"D111111FM"D11111s   D7E$ $E<c                     |                                  }d|_        t                      |_        |                                 |                     |j        j        dg           d S )Nz!/tmp/this/cant/possibly/existjjjjzCould not clear childlog dir)r   rd  r
   rV  r  ro   r  r  s     r   *test_clear_autochildlogdir_listdir_oserrorz=ServerOptionsTests.test_clear_autochildlogdir_listdir_oserror  sY    ==??B%--&&(((-0N/OPPPPPr   c                    t          j                    }|                                 }||_        |j        }t
          j                            |d|z            }t          |d          5 }|	                    d           d d d            n# 1 swxY w Y   d }||_
        t                      |_        |                                 |                     |j        j        d|z  g           d S )Nzcat-stdout---%s-ayWAp9.logr   logc                  4    t          t          j                  r/   )rK  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   rd  rc  r{   r   r   r   r   remover
   rV  r  ro   r  )r   r  r   identr  r   r  s          r   )test_clear_autochildlogdir_unlink_oserrorz<ServerOptionsTests.test_clear_autochildlogdir_unlink_oserror  s    "$$==??&#7<<)E)MNN(C   	AGGENNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 		( 	( 	('%--&&(((-&12	4 	4 	4 	4 	4s   )BBBc                 L   t                      }|                                 }d }||_        g fd}||_        |                    |           |                     t                    d           d}|                     d                             |                     d S )Nc                 >    t          j        t          j                  r/   )rf  r   r  
EADDRINUSErY  s    r   raise_eaddrinusezhServerOptionsTests.test_openhttpservers_reports_friendly_usage_when_eaddrinuse.<locals>.raise_eaddrinuse  s    ,u/000r   c                 2                         |            d S 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   rY  r   r  r  r  r  s         @r   ;test_openhttpservers_reports_friendly_usage_when_eaddrinusezNServerOptionsTests.test_openhttpservers_reports_friendly_usage_when_eaddrinuse  s    %''==??	1 	1 	1%5"	% 	% 	% 	% 	%%  ---X***9..x8899999r   c                 B   t                      }|                                 }d }||_        g fd}||_        |                    |           |                     t                    d           dt          j        z  }|                     d         |           d S )Nc                 >    t          j        t          j                  r/   )rf  r   r  EPERMr  s    r   r  zbServerOptionsTests.test_openhttpservers_reports_socket_error_with_errno.<locals>.make_http_servers  s    ,u{+++r   c                 2                         |            d S 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   rY  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                      }|                                 }d }||_        g fd}||_        |                    |           |                     t                    d           d}|                     d         |           d S )Nc                 *    t          j        d          )Nzuh oh)rf  r   r  s    r   r  z^ServerOptionsTests.test_openhttpservers_reports_other_socket_errors.<locals>.make_http_servers  s    ,w'''r   c                 2                         |            d S 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  s    %''==??	( 	( 	(%6"	% 	% 	% 	% 	%%  ---X***%!h/////r   c                 (   t                      }|                                 }d }||_        g fd}||_        |                    |           |                     t                    d           d}|                     d         |           d S )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66r   c                 2                         |            d S 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  s    %''==??	7 	7 	7%6"	% 	% 	% 	% 	%%  ---X***+!h/////r   c                     t                      }|                                 }d }||_        |                     t          |j        |           d S )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   rY  r   r  s       r   9test_openhttpservers_does_not_catch_other_exception_typeszLServerOptionsTests.test_openhttpservers_does_not_catch_other_exception_types  sd    %''==??	  	  	 %6" 	-"2K	A 	A 	A 	A 	Ar   c                     |                                  }|                    d           }|                     |d           d S )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                     |                                  }|                    t          j                              }|                     |d            d S r/   )r   r  r{   getuidro   r  s      r   &test_drop_privileges_nonroot_same_userz9ServerOptionsTests.test_drop_privileges_nonroot_same_user  sF     ==??&&ry{{33d#####r   )r   N7   r  c                     |                                  }|                    d          }|                     |d           d S )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  sA     ==??&&r**DEEEEEr   c                    |                                  }d |_        t                      |_        |                                 |j        j                                         |j        j                                         d S )Nc                      d S r/   r(   r(   r   r   r   zYServerOptionsTests.test_daemonize_notifies_poller_before_and_after_fork.<locals>.<lambda>  s    d 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  sj    ==??*l&&(@@BBB'??AAAAAr   N)r%   r&   r'   r   r   r4  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-  r0  r3  r5  r7  rE  rL  rR  rZ  r\  r^  rb  r   r   rh  rq  ru  r  r  r  r  r  r  r  r  rK  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r!  r'  r,  r/  r3  r6  r8  r;  r=  r?  rA  rC  rE  rG  rI  rK  rS  r\  ri  rm  rp  rt  rv  rz  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 D D|1 |1 |1|. . .
. 
. 
." " "B3 B3 B3H: : :(; ; ; I I I
I 
I 
I7 7 7  &B B BI I I
L 
L 
L!5 !5 !5F!> !> !>F7 7 7>5 5 5:< < <1 1 1: : :6 6 64 4 4B B B/ / /A A AE E E; ; ;F F F0B B B0+ + +"? ? ?"@ @ @      ,     ,4 4 40     ,     (@ @ @ - - -  (  .  $    (  & U?DDFF##0 0 $#0	. 	. 	.. . .	4 	4 	4% % %	4 	4 	4- - -B B B  .2 2 2E E E U:tt00011  210E 0E 0Ed8 8 8M M M6R R R"< < <8 8 8D D D; ; ;": : :$: : :$; ; ;A A A}M }M }M~3 3 36A A A2= = =4%. %. %.N&. &. &.P#2 #2 #2J7 7 74"7 "7 "7H	B 	B 	B	B 	B 	B7 7 7K K K7 7 77 7 77 7 74 4 4"7 7 7, , ,*, , ,*, , ,0: : :&,; ,; ,;\2+ 2+ 2+h+ + +$B B B&A A A$7 7 7&Q Q QQ Q QW= W= W=r>E >E >E@Q Q QQ Q QQ Q QQ Q QQ Q QQ Q QQ Q QQ Q QQ Q QQ Q Q: : :.!: !: !:F: : :<": ": ":H" " """ " "A A A(5 5 5(F F F$/ / /$2 2 2*Q Q Q4 4 4 : : :$0 0 0&0 0 0&0 0 0$A A AA A A
 U>44-B-B-BCCCDD
U;"---..$ $ /. ED$
 U>44-B-B-BCCCDD
U;"---..F F /. EDF
B B B B Br   r+  c                   J    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S )ProcessConfigTestsc                     ddl m} |S )Nr   )ProcessConfig)r   r0  )r   r0  s     r   r   z"ProcessConfigTests._getTargetClass  r   r   c                     i }dD ]}|||<   dD ]}d||<   |                     |            |                                 |i |S N)r<   rp  rZ  r[  rn  rq  rr  rt  ru  rv  rw  r  r  r  r  stderr_capture_maxbytesstderr_events_enabledr  rx  r{  r|  r}  r   r  rl  )r  r~  stderr_logfile_backupsstderr_logfile_maxbytesrG  r2   r   r   argkwdefaultsr<   s        r   r   zProcessConfigTests._makeOne  u    	$ 
	" 
	"D "HTNNJ 	  	 DHTNN%t##%%s7h777r   c                     t                      }|                     |d           }|                     |                                |                                           d S )Nrl  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#  sT    ..==d=;;**,,g.>.>.@.@AAAAAr   c                     t                      }|                     |ddi          }|                     |                                |                                           d S )Nr  r_  r>  r?  rA  s      r   8test_get_path_env_dict_with_no_PATH_delegates_to_optionszKProcessConfigTests.test_get_path_env_dict_with_no_PATH_delegates_to_options(  sX    ..==ucl=CC**,,g.>.>.@.@AAAAAr   c                    t                      }|                     |ddi          }|                     |                                |                                           |                     |                                g d           d S )Nr  z/a:/b:/cr>  )z/az/bz/c)r   r   assertNotEqualr@  ro   rA  s      r   (test_get_path_env_dict_with_PATH_uses_itz;ProcessConfigTests.test_get_path_env_dict_with_PATH_uses_it-  s    ..==vz6J=KKH--//1A1A1C1CDDD**,,.@.@.@AAAAAr   c                    t                      }|                     |          }ddlm} ||_        ||_        |                                 |                     |j        |j                   |                     |j        |j                   d S )Nr   )r  )	r   r   rC   r  rw  r  create_autochildlogsro   tempfile_name)r   rF   r   r  s       r   test_create_autochildlogsz,ProcessConfigTests.test_create_autochildlogs3  s    ..==))222222"+"+%%'''0'2GHHH0'2GHHHHHr   c                     t                      }|                     |          }|                                }ddlm} |                     |j        |           |                     |j        d            d S )Nr   
Subprocessr   r   make_processsupervisor.processrN  ro   r  r  r   rF   r   processrN  s        r   test_make_processz$ProcessConfigTests.test_make_process=  sv    ..==))''))111111*J777-----r   c                     t                      }|                     |          }|                    d          }ddlm} |                     |j        |           |                     |j        d           d S )NrZ   r   rM  rO  rR  s        r   test_make_process_with_groupz/ProcessConfigTests.test_make_process_with_groupE  sx    ..==))''..111111*J777.....r   c                    t                      }|                     |          }t          j                    5 }t          j                    5 }|j        |_        |j        |_        d|_        t          |          }|	                    |          \  }}| 
                    |d         j        d           ddlm} | 
                    |d         j        |           | 
                    |d         d           | 
                    |d         j        d           ddlm}	 | 
                    |d         j        |	           | 
                    |d         d           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )	NFr:  r   r   ProcessCommunicationStdoutEvent   r   ProcessCommunicationStderrEvent)r   r   r   r   r<   rw  r  r  r   make_dispatchersro   channelsupervisor.eventsrY  
event_typer\  
r   rF   r   rw  r  process1dispatchersr  rY  r\  s
             r   +test_make_dispatchers_stderr_not_redirectedz>ProcessConfigTests.test_make_dispatchers_stderr_not_redirectedM  s   ..==))(** 	5n,.. 5.*8*='*8*='+0('11%-%>%>x%H%H"U  Q!7BBBMMMMMM  Q!:!@B B B  x!444  Q!7BBBMMMMMM  Q!:!@B B B  x!4445 5 5 5 5 5 5 5 5 5 5 5 5 5 5	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s6   E>DE&E>&E*	*E>-E*	.E>>FFc                    t                      }|                     |          }t          j                    5 }|j        |_        t          |          }|                    |          \  }}|                     |d         j	        d           |                     |d         d           |                     |d         d            d d d            d S # 1 swxY w Y   d S )Nr:  r   r   )
r   r   r   r   r<   rw  r   r]  ro   r^  )r   rF   r   rw  rb  rc  r  s          r   'test_make_dispatchers_stderr_redirectedz:ProcessConfigTests.test_make_dispatchers_stderr_redirectedb  s   ..==))(** 	4n&4&9H##H--H!)!:!:8!D!DK[^3X>>>U8_a000U8_d333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s   BCCCN)r%   r&   r'   r   r   rB  rD  rG  rK  rT  rV  rd  rf  r(   r   r   r.  r.    s          8 8 8&B B B
B B B
B B BI I I. . ./ / /5 5 5*	4 	4 	4 	4 	4r   r.  c                        e Zd Zd Zd Zd ZdS )EventListenerConfigTestsc                     ddl m} |S )Nr   )EventListenerConfig)r   rj  )r   rj  s     r   r   z(EventListenerConfigTests._getTargetClassn      ::::::""r   c                     i }dD ]}|||<   dD ]}d||<   |                     |            |                                 |i |S r2  r7  r8  s        r   r   z!EventListenerConfigTests._makeOner  r<  r   c                    t                      }|                     |          }t          j                    5 }t          j                    5 }|j        |_        |j        |_        d|_        t          |          }|	                    |          \  }}| 
                    |d         j        d           | 
                    |d         j        d           | 
                    |d         j        d           ddlm} | 
                    |d         j        j        |j                   | 
                    |d         d           | 
                    |d         j        d	           dd
lm}	 | 
                    |d         j        |	           | 
                    |d	         d           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NFrR  r}  r:  r   r   )EventListenerStatesrZ  r   r[  )r   r   r   r   r<   rw  r  r  r   r]  ro   r^  ra  supervisor.statesrn  rS  listener_stateACKNOWLEDGEDr_  r\  r`  )
r   rF   r   rw  r  rb  rc  r  rn  r\  s
             r   test_make_dispatchersz.EventListenerConfigTests.test_make_dispatchers  sP   ..==))(** 	5n,.. 5.*8*='*8*='+0('11%-%>%>x%H%H"U  Q!7AAA  Q!6>>>  Q!7BBBAAAAAA  Q!7!F!4!AC C C  x!444  Q!7BBBMMMMMM  Q!:!@B B B  x!444#5 5 5 5 5 5 5 5 5 5 5 5 5 5 5	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s6   G
EF2&G
2F6	6G
9F6	:G

GGN)r%   r&   r'   r   r   rr  r(   r   r   rh  rh  m  sA        # # #8 8 8&5 5 5 5 5r   rh  c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )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||<   |                     |            |                                 |i |S r2  r7  r8  s        r   r   z"FastCGIProcessConfigTests._makeOne  r<  r   c                     t                      }|                     |          }|                     t          |j                   d S r/   )r   r   rK   NotImplementedErrorrP  rA  s      r   rT  z+FastCGIProcessConfigTests.test_make_process  s<    ..==))-x/DEEEEEr   c                     t                      }|                     |          }|                    d          }ddlm} |                     |j        |           |                     |j        d           d S )NrZ   r   )FastCGISubprocess)r   r   rP  rQ  rz  ro   r  r  )r   rF   r   rS  rz  s        r   rV  z6FastCGIProcessConfigTests.test_make_process_with_group  sy    ..==))''..888888*,=>>>.....r   c                    t                      }|                     |          }t          j                    5 }t          j                    5 }|j        |_        |j        |_        d|_        t          |          }|	                    |          \  }}| 
                    |d         j        d           | 
                    |d         j        d           | 
                    |d         j        d           ddlm} | 
                    |d         j        |           | 
                    |d         d           | 
                    |d	         j        d
           ddlm}	 | 
                    |d	         j        |	           | 
                    |d
         d	           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NFrR  r}  Tr:  r   r   rX  rZ  r   r[  )r   r   r   r   r<   rw  r  r  r   r]  ro   r^  ra  r_  rY  r`  r\  ra  s
             r   rr  z/FastCGIProcessConfigTests.test_make_dispatchers  sJ   ..==))(** 	5n,.. 5.*8*='*8*='+0('11%-%>%>x%H%H"U  Q!7AAA  Q!6===  Q!7BBBMMMMMM  Q!:!@B B B  x!444  Q!7BBBMMMMMM  Q!:!@B B B  x!444#5 5 5 5 5 5 5 5 5 5 5 5 5 5 5	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s6   G EF(G (F,	,G /F,	0G  GGN)r%   r&   r'   r   r   rT  rV  rr  r(   r   r   rt  rt    sb        $ $ $8 8 8&F F F
/ / /5 5 5 5 5r   rt  c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )ProcessGroupConfigTestsc                     ddl m} |S )Nr   )ProcessGroupConfig)r   r  )r   r  s     r   r   z'ProcessGroupConfigTests._getTargetClass      999999!!r   c                 B     |                                  ||||          S r/   r   )r   rF   r<   rn  r  s        r   r   z ProcessGroupConfigTests._makeOne  s$    %t##%%gtXxHHHr   c                 *   t                      }|                     |ddg           }|                     |j        |           |                     |j        d           |                     |j        d           |                     |j        g            d S )Nwhateverr  )r   r   ro   rF   r<   rn  ro  rA  s      r   	test_ctorz!ProcessGroupConfigTests.test_ctor  s    ..==*c2>>)7333
333*C0001266666r   c                     t                      }t          |dd          g}|                     |dd|          }|                                 |                     |d         j        d           d S )Nrb  /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  sk    .. *oFFG==*c8DD!:DAAAAAr   c                     t                      }t          |dd          g}|                     |dd|          }|                                }ddlm} |                     |j        |           d S )Nrb  r  r  r  r   )ProcessGroup)r   r   r   
make_grouprQ  r  ro   r  )r   rF   r  r   r  r  s         r   test_make_groupz'ProcessGroupConfigTests.test_make_group  sw    .. *oFFG==*c8DD##%%333333,77777r   N)r%   r&   r'   r   r   r  r  r  r(   r   r   r}  r}    se        " " "I I I7 7 7B B B8 8 8 8 8r   r}  c                   &    e Zd Zd Zd Zd Zd ZdS )EventListenerPoolConfigTestsc                     ddl m} |S )Nr   )EventListenerPoolConfig)r   r  )r   r  s     r   r   z,EventListenerPoolConfigTests._getTargetClass  s    >>>>>>&&r   c           	      H     |                                  |||||||          S r/   r   )r   rF   r<   rn  ro  buffer_sizepool_eventsrZ  s           r   r   z%EventListenerPoolConfigTests._makeOne  s5    %t##%%gtX&5{&1>C C 	Cr   c           	          t                      }t          |dd          g}|                     |dd|dg d           }|                                 |                     |d         j        d           d S )Nrb  r  r<   r  r   r   Tr  r  s       r   r  z.EventListenerPoolConfigTests.test_after_setuid  sq    .. *oFFG==&#xBMM!:DAAAAAr   c           	          t                      }t          |dd          g}|                     |dd|dg d           }|                                }ddlm} |                     |j        |           d S )Nrb  r  r<   r  r   r   )EventListenerPool)r   r   r   r  rQ  r  ro   r  )r   rF   r  r   r  r  s         r   r  z,EventListenerPoolConfigTests.test_make_group
  s~    .. *oFFG==&#xBMM##%%888888*;<<<<<r   N)r%   r&   r'   r   r   r  r  r(   r   r   r  r    sV        ' ' 'C C CB B B= = = = =r   r  c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )FastCGIGroupConfigTestsc                     ddl m} |S )Nr   r  )r   r  )r   r  s     r   r   z'FastCGIGroupConfigTests._getTargetClass  r  r   c                 6     |                                  |i |S r/   r   r   r   r:  s      r   r   z FastCGIGroupConfigTests._makeOne  #    %t##%%t2r222r   c                    t                      }t          d          }|                     |ddg |          }|                     |j        |           |                     |j        d           |                     |j        d           |                     |j        g            |                     |j        |           d S Nrl   r  r  )	r   r   r   ro   rF   r<   rn  ro  r  )r   rF   sock_configr   s       r   r  z!FastCGIGroupConfigTests.test_ctor  s    ..'**==*c2{KK)7333
333*C00012666/=====r   c                 &   t                      }t          d          }|                     |ddg |          }t          d          }|                     |ddg |          }|                     ||k               |                     ||k               d S 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$      ..(++MM':sBMM	(++MM':sBMM		Y.///i/00000r   c                 &   t                      }t          d          }|                     |ddg |          }t          d          }|                     |ddg |          }|                     ||k               |                     ||k               d S )Nrl   r  r  rZ  r  r  s         r   test_diff_sockets_are_not_equalz7FastCGIGroupConfigTests.test_diff_sockets_are_not_equal/  r  r   c                     t                      }t          d          }|                     |ddg |          }|                                }ddlm} |                     |j        |           d S )Nrl   r<   r  r   )FastCGIProcessGroup)r   r   r   r  rQ  r  ro   r  )r   rF   r  r   r  r  s         r   r  z'FastCGIGroupConfigTests.test_make_group:  ss    ..'**==&#r;GG##%%::::::*=>>>>>r   N)	r%   r&   r'   r   r   r  r  r  r  r(   r   r   r  r    sn        " " "3 3 3> > >	1 	1 	1	1 	1 	1? ? ? ? ?r   r  c                   &    e Zd Zd Zd Zd Zd ZdS )SignalReceiverTestsc                 v    ddl m}  |            }|                     |                                d            d S )Nr   SignalReceiver)r   r  ro   r  r   r  srs      r   test_returns_None_initiallyz/SignalReceiverTests.test_returns_None_initiallyC  sE    555555^$/////r   c                    ddl m}  |            }|                    t          j        d           |                    t          j        d           |                     |                                t          j                   |                     |                                t          j                   |                     |                                d            d S Nr   r  frame)r   r  r  ry  r  r  ro   r  r  s      r   &test_returns_signals_in_order_receivedz:SignalReceiverTests.test_returns_signals_in_order_receivedH  s    555555^


6>7+++


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


6>7+++


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


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


6>7+++&.999$/////r   N)r%   r&   r'   r  r  r  r  r(   r   r   r  r  B  sP        0 0 0
0 0 00 0 00 0 0 0 0r   r  c                   n    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S )UnhosedConfigParserTestsc                     ddl m} |S )Nr   r  )r   r  )r   r  s     r   r   z(UnhosedConfigParserTests._getTargetClassd  rk  r   c                 6     |                                  |i |S r/   r   r  s      r   r   z!UnhosedConfigParserTests._makeOneh  r  r   c                     |                                  }|                    d           ddlm} |                     |j        |j        dd           d S )N[supervisord]
r   )ConfigParserrY  missing)r   r  r  r  rK   NoOptionErrorsaneget)r   r  r  s      r   test_saneget_no_defaultz0UnhosedConfigParserTests.test_saneget_no_defaultk  sf    ,---222222,4NM9	6 	6 	6 	6 	6r   c                     |                                  }|                    d           |                    ddd          }|                     |d           d S )Nr  rY  r  rZ   r;   r   r  r  ro   r   r  results      r   test_saneget_with_defaultz2UnhosedConfigParserTests.test_saneget_with_defaultr  sW    ,---y%HH'''''r   c                     |                                  }ddi|_        |                    d           |                    ddd          }|                     |d           d S )Nr  rX  r  rY  r   %(pet)sr  r   r  r  r  ro   r  s      r   $test_saneget_with_default_and_expandz=UnhosedConfigParserTests.test_saneget_with_default_and_expandx  sc    "EN,---uiHH'''''r   c                     |                                  }ddi|_        |                    d           |                    dddd          }|                     |d           d S )	Nr  rX  r  rY  r   r  F)r;   	do_expandr  r  s      r   #test_saneget_with_default_no_expandz<UnhosedConfigParserTests.test_saneget_with_default_no_expand  sm    "EN,---u   0 0+++++r   c                     |                                  }|                    d           |                    ddd          }|                     |d           d S )N[supervisord]
foo=%(pet)s
rY  r   F)r  r  r  r  s      r   !test_saneget_no_default_no_expandz:UnhosedConfigParserTests.test_saneget_no_default_no_expand  sW    9:::uFF+++++r   c                     |                                  }ddi|_        |                    d           |                    dd          }|                     |d           d S )Nr  rX  r  rY  r   r  r  s      r   (test_saneget_expands_instance_expansionszAUnhosedConfigParserTests.test_saneget_expands_instance_expansions  s_    "EN9:::u55'''''r   c                     |                                  }ddi|_        |                    d           |                    ddddi          }|                     |d           d S )Nr  rX  r  rY  r   r  )r  r  r  s      r   #test_saneget_expands_arg_expansionsz<UnhosedConfigParserTests.test_saneget_expands_arg_expansions  so    "EN9:::uu~   ' ''''''r   c                     |                                  }|                    d|j        z             |                     |                    d          d           d S )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  sV    ,v/??@@@**511599999r   c                 F   |                                  }t          j        d          5 }|                    d           |                                 |                    |j                  }d d d            n# 1 swxY w Y   |                     ||j        g           d S 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  s    (d333 	/qGGIGGIII!;;qv..L	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	x00000s   AA::A>A>c                 H   |                                  }t          j        d          5 }|                    d           |                                 |                    |j        g          }d d d            n# 1 swxY w Y   |                     ||j        g           d S r  r  r  s       r   test_read_filenames_as_listz4UnhosedConfigParserTests.test_read_filenames_as_list  s    (d333 	1qGGIGGIII!;;x00L	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	x00000   AA;;A?A?c                    t           j                            t           j                            t                    d          }|                                 }t          j        d          5 }|                    d           |	                                 |
                    ||j        g          }d d d            n# 1 swxY w Y   |                     ||j        g           d S )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    gll27??8#<#<mLL(d333 	>qGGIGGIII!;;QV'<==L	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	x00000s   ,AB>>CCc                 d    |                                  }|                     |j        i            d S r/   )r   ro   section_to_filer  s     r   )test_read_section_to_file_initially_emptyzBUnhosedConfigParserTests.test_read_section_to_file_initially_empty  s.    /44444r   c                 \   |                                  }t          j        d          5 }|                    d           |                                 |                    |j        g           d d d            n# 1 swxY w Y   |                     |j        d         |j                   d S )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  s    (d333 	"qGGIGGIIIKK!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	/6?????r  c                 `   |                                  }t          j        d          5 }t          j        d          5 }|                    d           |                                 |                    d           |                                 |                    |j        |j        g           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     |j        d         |j                   |                     |j        d         |j                   d S )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33 	0r,$777 02###


###


RWbg.///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	/6@@@/6@@@@@s6   C A4C 4C C	CC	CCC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  s       # # #3 3 36 6 6( ( (( ( (, , ,, , ,( ( (( ( (: : :
1 1 11 1 11 1 15 5 5@ @ @
A 
A 
A 
A 
Ar   r  c                       e Zd Zd Zd ZdS )UtilFunctionsTestsc                     ddl m} |                      |dd          d           |                      |dd          d           d S )Nr   )make_namespecr  rS  zgroup:process)r   r  ro   )r   r  s     r   test_make_namespecz%UtilFunctionsTests.test_make_namespec  s^    444444w	::OLLLy)<<iHHHHHr   c                    ddl m} |}|                      |d          d           |                      |d          d           |                      |d          d           |                      |d	          d           d S )
Nr   )split_namespeczprocess:group)rS  r  rS  )rS  rS  zgroup:)r  Nzgroup:*)r   r  ro   )r   r  r   s      r   test_split_namespecz&UtilFunctionsTests.test_split_namespec  s    555555?++-ABBB9'=>>>8o666977777r   N)r%   r&   r'   r  r  r(   r   r   r  r    s5        I I I
8 8 8 8 8r   r  c                  T    t          j        t          j        t                             S r/   )unittestfindTestCasesr  r  r%   r(   r   r   
test_suiter    s    !#+h"7888r   __main__r  )defaultTest)+__doc__r{   r  r   rf  r  ry  r   r  r  r  r   r   rs  r   r   r   supervisor.loggersr   r	   r
   r   r   r   r   r   r   TestCaser   r   r+  r.  rh  rt  r}  r  r  r  r  r  r  r%   mainr(   r   r   <module>r
     s   ' ' 				 



        & & & & & & & & & & & & 7 7 7 7 7 7 7 7 7 7 + + + + + + 1 1 1 1 1 1 - - - - - - . . . . . . - - - - - - . . . . . . . . . . . . 3 3 3 3 3 3 ( ( ( ( ( (e9 e9 e9 e9 e9(# e9 e9 e9NtA tA tA tA tA* tA tA tAlO-B O-B O-B O-B O-B* O-B O-B O-BbZ`4 `4 `4 `4 `4* `4 `4 `4D-5 -5 -5 -5 -5x0 -5 -5 -5`:5 :5 :5 :5 :5 1 :5 :5 :5x8 8 8 8 8h/ 8 8 8>= = = = =8#4 = = =4.? .? .? .? .?h/ .? .? .?`0 0 0 0 0(+ 0 0 0BmA mA mA mA mAx0 mA mA mA^8 8 8 8 8* 8 8 89 9 9 zHMl++++++ r   