o
    ׹i1:                    @   s  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 dejZG dd dejZG dd dejZG dd dejZG dd dejZ G dd dejZ!G dd dejZ"G dd dejZ#G dd  d ejZ$G d!d" d"ejZ%G d#d$ d$ejZ&G d%d& d&ejZ'dS )'z!Test suite for supervisor.options    N)StringIO)as_bytes)Mocksentinelpatch)LevelsByName)DummySupervisor)DummyLogger)DummyOptions)DummyPoller)DummyPConfig)DummyProcess)DummySocketConfig)lstripc                   @   s   e Zd Zdd Zd-ddZdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,S ).OptionTestsc                 C      ddl m} |S )Nr   Options)supervisor.optionsr   )selfr    r   Z/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/supervisor/tests/test_options.py_getTargetClass      zOptionTests._getTargetClassFc                    sf   |    ddlm} G  fddd }| }t |_|jdddddd	 |jd
d
ddd|d |S )Nr   )integerc                       s,   e Zd ZddiZf fdd	Zdd ZdS )z+OptionTests._makeOptions.<locals>.MyOptionsother)   c                    s,   || _  |  G dd dt}| | _d S )Nc                   @      e Zd ZdS )zAOptionTests._makeOptions.<locals>.MyOptions.__init__.<locals>.FooN__name__
__module____qualname__r   r   r   r   Foo-   s    r"   )
read_error__init__object
configroot)r   r#   r"   r   r   r   r$   *   s   
z4OptionTests._makeOptions.<locals>.MyOptions.__init__c                 S   s4   | j rt| j | jj| j | jj| j d S N)r#   
ValueErrorr&   __dict__updatedefault_mapmaster)r   fpr   r   r   read_config0   s   
z7OptionTests._makeOptions.<locals>.MyOptions.read_configN)r   r    r!   r,   r$   r.   r   r   r#   r   r   	MyOptions'   s
    r0   anoptionooptiondefault)nameconfnameshortlongr4   r   OTHERzp:zother=)r5   r6   envr7   r8   handler)r   supervisor.datatypesr   r   
configfileadd)r   r#   r   r0   optionsr   r/   r   _makeOptions#   s   
zOptionTests._makeOptionsc                 C   s&   |   }| }| jt|jddd d S )NT)flagr;   r   assertRaisesr(   r>   r   clsinstr   r   r   'test_add_flag_not_None_handler_not_None?   s   z3OptionTests.test_add_flag_not_None_handler_not_Nonec                 C   s(   |   }| }| jt|jdddd d S )NTFrA   r8   r7   rB   rD   r   r   r   -test_add_flag_not_None_long_false_short_falseD      
z9OptionTests.test_add_flag_not_None_long_false_short_falsec                 C   (   |   }| }| jt|jdddd d S )NTF:rH   rB   rD   r   r   r   +test_add_flag_not_None_short_endswith_colonO   rJ   z7OptionTests.test_add_flag_not_None_short_endswith_colonc                 C   rK   )NT=FrH   rB   rD   r   r   r   *test_add_flag_not_None_long_endswith_equalZ   rJ   z6OptionTests.test_add_flag_not_None_long_endswith_equalc                 C   &   |   }| }| jt|jddd d S )NrN   abcr8   r7   rB   rD   r   r   r   (test_add_inconsistent_short_long_optionse      
z4OptionTests.test_add_inconsistent_short_long_optionsc                 C   rP   )NF-abcrR   rB   rD   r   r   r   %test_add_short_option_startswith_dasho   rT   z1OptionTests.test_add_short_option_startswith_dashc                 C   rP   )NFrQ   rR   rB   rD   r   r   r   test_add_short_option_too_longy   rT   z*OptionTests.test_add_short_option_too_longc                 C   0   |   }| }ddi|_| jt|jddd d S )Nz-aTFarR   r   options_maprC   r(   r>   rD   r   r   r   #test_add_duplicate_short_option_key      

z/OptionTests.test_add_duplicate_short_option_keyc                 C   rP   )NrU   FrR   rB   rD   r   r   r   $test_add_long_option_startswith_dash   rT   z0OptionTests.test_add_long_option_startswith_dashc                 C   rX   )Nz--abcTrQ   FrR   rZ   rD   r   r   r   "test_add_duplicate_long_option_key   r]   z.OptionTests.test_add_duplicate_long_option_keyc                 C   s8   |   }| t|jd | |jdd  g d d S )N   )supervisord.confzetc/supervisord.confz/etc/supervisord.confz /etc/supervisor/supervisord.conf)r@   assertEquallensearchpathsr   r?   r   r   r   test_searchpaths   s   zOptionTests.test_searchpathsc                 C   s   |   }|g  | |jd | |jd |   }dtjd< |g  | |jd |   }|ddg | |jd tjd= d S )	Nr4   r   42r9   *   -p43+   )r@   realizerc   r1   r   osenvironrf   r   r   r   test_options_and_args_order   s   


z'OptionTests.test_options_and_args_orderc                 C   sD   |   }|g  | |jd d|jd< |  | |jd d S )Nr   ri   r   )r@   rm   rc   r   r,   process_configrf   r   r   r   test_config_reload   s   

zOptionTests.test_config_reloadc                 C   s    | j dd}| t|jd d S )Nerrorr#   F)r@   rC   r(   rq   rf   r   r   r   !test_config_reload_do_usage_false   s   
z-OptionTests.test_config_reload_do_usage_falsec                    sZ   | j dd}g   fdd|_t  |_|_d|j_d|j_|jdd | 	 dg d S )	Nrs   rt   c                    
     | S r'   appendx	exitcodesr   r   <lambda>      
 z>OptionTests.test_config_reload_do_usage_true.<locals>.<lambda>   Tdo_usage   )
r@   exitr   stderrstdoutr&   r1   r   rq   rc   rf   r   r{   r    test_config_reload_do_usage_true   s   z,OptionTests.test_config_reload_do_usage_truec                 C   s   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   _setrc   r   attr_priorities)r   r   r?   r   r   r   	test__set   s   zOptionTests.test__setc                    s\   |   }g |_g   fdd|_t |_|  |  dg d}| |j 	| d S )Nc                    rv   r'   rw   ry   r{   r   r   r}      r~   z9OptionTests.test_missing_default_config.<locals>.<lambda>r   z,Error: No config file found at default paths)
r@   re   r   r   r   default_configfilerc   
assertTruegetvalue
startswithr   r?   msgr   r{   r   test_missing_default_config   s   z'OptionTests.test_missing_default_configc                 C   sV   |   }t }|jg|_| }| ||j W d    d S 1 s$w   Y  d S r'   )r@   tempfileNamedTemporaryFiler5   re   r   rc   )r   r?   fconfigr   r   r   test_default_config   s   

"zOptionTests.test_default_configc                    s`   |   }g   fdd|_t |_d|_d|_|d |  dg d}| |j | d S )Nc                    rv   r'   rw   ry   r{   r   r   r}      r~   z'OptionTests.test_help.<locals>.<lambda>	test_helpzA sample docstring for %s r   z!A sample docstring for test_help
)	r@   r   r   r   prognamedochelprc   r   r   r   r{   r   r      s   
zOptionTests.test_helpN)F)r   r    r!   r   r@   rG   rI   rM   rO   rS   rV   rW   r\   r^   r_   rg   rp   rr   ru   r   r   r   r   r   r   r   r   r   r      s,    






r   c                   @   s|   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd ZdS )ClientOptionsTestsc                 C   r   )Nr   )ClientOptions)r   r   )r   r   r   r   r   r     r   z"ClientOptionsTests._getTargetClassc                 C   
   |    S r'   r   r   r   r   r   _makeOne	     
zClientOptionsTests._makeOnec                    sx   |   }g |_g   fdd|_|jg dd |  g  | |jd | |jd | |jd | |jd d	S )
z(Making sure config file is not required.c                    rv   r'   rw   ry   r{   r   r   r}     r~   z8ClientOptionsTests.test_no_config_file.<locals>.<lambda>)z-shttp://localhost:9001z-uchrisrj   123argsr   r   r   r   N)	r   re   r   rm   rc   interactive	serverurlusernamepasswordr   instancer   r{   r   test_no_config_file  s   z&ClientOptionsTests.test_no_config_filec                 C   s   t  }td| }t|}|  }||_|jg d | |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   r=   rm   rc   r   rn   pathjoinhistory_filer&   supervisorctlpromptr   r   r   )r   tempdirsr-   r   r   r?   r   r   r   test_options  s"   zClientOptionsTests.test_optionsc                 C   @   t d}|  }t||_|jg d |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   r=   rm   r&   r   rc   r   r   textr   r?   r   r   r   3test_options_ignores_space_prefixed_inline_comments4     
zFClientOptionsTests.test_options_ignores_space_prefixed_inline_commentsc                 C   r   )Nzw
        [supervisorctl]
        serverurl=http://127.0.0.1:9001	;use an http:// url to specify an inet socket
        r   r   r   r   r   r   r   1test_options_ignores_tab_prefixed_inline_comments?  r   zDClientOptionsTests.test_options_ignores_tab_prefixed_inline_commentsc                 C   *   t d}|  }t||_|jg d d S )Nz
        [supervisorctl]
        serverurl=http://localhost:9001 ;duplicate

        [supervisorctl]
        serverurl=http://localhost:9001 ;duplicate
        r   r   r   r   r=   rm   r   r   r   r   r   r   3test_options_parses_as_nonstrict_for_py2_py3_compatJ  s   
zFClientOptionsTests.test_options_parses_as_nonstrict_for_py2_py3_compatc                 C   s   t d}t|}|  }t ddddddd|_||_|jg d	 | |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_expansionsr=   rm   rc   r   r&   r   r   r   r   r   r   )r   r   r-   r   r?   r   r   r   (test_options_with_environment_expansionsW  s(   	z;ClientOptionsTests.test_options_with_environment_expansionsc              
   C   s   |   }td}t }tj|d}t|d}|| W d    n1 s(w   Y  z||_	|j
g d W tj|dd ntj|dd w |jj}| |jtj|d | |jdtj|d	  d S )
Nz}
        [supervisorctl]
        history_file=%(here)s/sc_history
        serverurl=unix://%(here)s/supervisord.sock
        rb   wr   Tignore_errorsr   unix://supervisord.sock)r   r   r   mkdtemprn   r   r   openwriter=   rm   shutilrmtreer&   r   rc   r   r   )r   r   r   heresupervisord_confr   r?   r   r   r   /test_options_supervisorctl_section_expands_hereu  s$    zBClientOptionsTests.test_options_supervisorctl_section_expands_herec              
   C   t   t jt jtd}|  }z|| | d W d S  ty9 } z| 	d|j
d v  W Y d }~d S d }~ww Nnonexistentnothing raisedzcould not find config filer   rn   r   r   dirname__file__r   r.   failr(   r   r   r   r   r   excr   r   r   test_read_config_not_found     
"z-ClientOptionsTests.test_read_config_not_foundc              
   C   l   |   }dd }||_z|t | d W d S  ty5 } z| d|jd v  W Y d }~d S d }~ww )Nc                 S      t tjd|  NzPermission denied: %sIOErrorerrnoEACCESfnmoder   r   r   
dummy_open     zBClientOptionsTests.test_read_config_unreadable.<locals>.dummy_openzexpected exceptioncould not read config filer   r   r   r.   r   r   r(   r   r   r   r   r   r   r   r   r   test_read_config_unreadable     
"z.ClientOptionsTests.test_read_config_unreadablec              
   C   ^   |   }z|t  | d W d S  ty. } z| |jd d W Y d }~d S d }~ww )Nr   r   z0.ini file does not include supervisorctl sectionr   r.   r   r   r(   rc   r   r   r   r   r   r   r   9test_read_config_no_supervisord_section_raises_valueerror     zLClientOptionsTests.test_read_config_no_supervisord_section_raises_valueerrorc                 C   s8   t d}|  }||_|jddgd | |jd d S )Nz[supervisorctl]z--serverurlunix:///dev/nullr   )r   r   r=   rm   rc   r   )r   r-   r   r   r   r   test_options_unixsocket_cli  s
   z.ClientOptionsTests.test_options_unixsocket_clic                 C   s<   t d}t|}|  }||_|jg d | |jd d S )Nz;[supervisorctl]
        serverurl=unix:///dev/null
        r   r  )r   r   r   r=   rm   rc   r   )r   r   r-   r   r   r   r   "test_options_unixsocket_configfile  s   z5ClientOptionsTests.test_options_unixsocket_configfileN)r   r    r!   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r   r   r   r   r     s    		r   c                   @   s
  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dSdT Z,dUdV Z-dWdX Z.dYdZ Z/d[d\ Z0d]d^ Z1d_d` Z2dadb Z3e4dce5 ddde Z6dfdg Z7dhdi Z8djdk Z9dldm Z:dndo Z;dpdq Z<drds Z=dtdu Z>dvdw Z?dxdy Z@e4dze5eAd{d|d} ZBd~d ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd Zadd Zbdd Zcdd ZdddÄ Zeddń ZfddǄ ZgddɄ Zhdd˄ Zidd̈́ Zjddτ Zkddф Zlddӄ ZmddՄ Znddׄ Zoddل Zpddۄ Zqdd݄ Zrdd߄ Zsdd Ztdd Zudd Zvdd Zwdd Zxdd Zydd Zzdd Z{dd Z|dd Z}dd Z~dd Zdd Zdd Zdd Zdd Zd d Zdd Zdd Zdd Zdd	 Zd
d Zdd Zdd Zdd Ze4de5g dde4de5dddd Ze4de5g dde4de5dddd Zdd ZdS (  ServerOptionsTestsc                 C   r   )Nr   )ServerOptions)r   r
  )r   r
  r   r   r   r     r   z"ServerOptionsTests._getTargetClassc                 C   r   r'   r   r   r   r   r   r     r   zServerOptionsTests._makeOnec                 C   sF   ddl m} |  }t |_| t|jd  | |j	 |d  d S )Nr   )VERSION
)
r   r  r   r   r   rC   
SystemExitversionrc   r   )r   r  r?   r   r   r   test_version  s
   zServerOptionsTests.test_versionc                 C   sP	  t ddt i }ddlm} t|}|  }||_|jg d |j	j
}| |jt  | |jd | |jd | |jd | |jd	 | |jd
 | |jd | |jd | |jd | |jd | |jt  | t|jd | |jd d t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t d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,t-j. | |j/d	 | |j0d  | |j1d  | |j2|3d! | |j4d | |j5dg | |jd" | |jd# | |jt d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,t-j6 | |	j0d  | |	j1d  | |	j2d& | |	j4d# | |	j5d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|3d! | |j4d | |j5g d* | |j,t-j6 | |j0d | |j1d |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|3d! | |j4d | |j5dg | |j,t-j6 | |j0d  | |j1d  | |jd  |j#d }| |j!d. | |j$d | |j"d, | |j%d | |j&|j' | |j*d  | |j+|j8 | |j2|3d! | |j4d | |j5dg | |j,t-j6 | |j0d  | |j1d  | |jd  |jd, }| |j!d/ | |j"d	 | t|j#d# |j#d }| |j!d0 | |jd1 |j#d }| |j!d2 | |jd3 t9j:;t9< }| |j*d | |j=d | |jt  | |jd | |jt9j:>|d | |jd | |jd	 | |jd
 | |jt9j:>|d | |jd | |jd | |j?d  | |jd | |jt  | t|jd | |jd d t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   
supervisorr  r   r   r=   rm   r&   supervisordrc   	directoryumasklogfilelogfile_maxbyteslogfile_backupsloglevelpidfilenodaemonsilent
identifierchildlogdirrd   server_configssocketAF_INET	nocleanupminfdsminprocsprocess_group_configsenvironmentdictr5   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	Automaticrn   r   abspathgetcwdgidr   
passwdfile)r   r   r  r-   r   r?   r  proc1r%  proc2r'  proc3r+  proc4_aproc4_br/  proc5_aproc5_br   r   r   r   r     sZ  
FH











zServerOptionsTests.test_optionsc                 C   sN   t d}|  }t||_|jg d |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   r=   rm   r&   r3  rc   r6  rC  r   r   r   r   r     s   
zFServerOptionsTests.test_options_ignores_space_prefixed_inline_commentsc                 C   r   )Nz
        [supervisord]
        logfile=/tmp/supervisord.log	;(main log file;default $CWD/supervisord.log)
        minfds=123	; (min. avail startup file descriptors;default 1024)
        r   ri  )	r   r   r   r=   rm   r&   r3  rc   rC  r   r   r   r   r     s   
zDServerOptionsTests.test_options_ignores_tab_prefixed_inline_commentsc                 C   r   )Nz
        [supervisord]

        [program:duplicate]
        command=/bin/cat

        [program:duplicate]
        command=/bin/cat
        r   r   r   r   r   r   r     s   	
zFServerOptionsTests.test_options_parses_as_nonstrict_for_py2_py3_compatc                 C   s\  t d}|  }t||_|jg d |jj}| t|j	d |j	d }| t|j
d |j	d }| t|j
d | |j	|j	u  t d}t||_|jd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   oner   threez/bin/pig)r   r   r   r=   rm   r&   r3  rc   rd   rE  rI  r   rq   r5   rJ  )r   r   r   sectioncatprocr   r   r   test_reload  s>   







zServerOptionsTests.test_reloadc                 C   sv   |   }d}|g|_|g|_|g|_td}t||_|jg d | ||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   r=   rm   assertFalse)r   r   old_msgr   r   r   r   !test_reload_clears_parse_messages3  s   
z4ServerOptionsTests.test_reload_clears_parse_messagesc                 C   sF   |   }d}|g|_td}t||_|jg d | ||jv  d S )NzInfo from a prior config readrp  r   )r   infosr   r   r=   rm   rt  rs  )r   r   old_infor   r   r   r   test_reload_clears_parse_infosG  s   
z1ServerOptionsTests.test_reload_clears_parse_infosc              
   C   r   r   r   r   r   r   r   r   W  r   z-ServerOptionsTests.test_read_config_not_foundc              
   C   r   )Nc                 S   r   r   r   r   r   r   r   r   b  r   zBServerOptionsTests.test_read_config_unreadable.<locals>.dummy_openr   r   r   r   r   r   r   r   r   `  r   z.ServerOptionsTests.test_read_config_unreadablec                 C   s   |   }tjddO}z|d |  ||j | d W n' tyH } z| 	d|j
d v  | 	|j|j
d v  W Y d }~nd }~ww W d    d S W d    d S 1 s\w   Y  d S )Nw+r   z[supervisord]
junkr   contains parsing errors:r   )r   r   r   r   flushr.   r5   r   r(   r   r   )r   r   r   r   r   r   r   8test_read_config_malformed_config_file_raises_valueerrorl  s    
""zKServerOptionsTests.test_read_config_malformed_config_file_raises_valueerrorc              
   C   s   |   }tjtjtdd}td| }z|t| | 	d W d S  t
yC } z| |jd d|  W Y d }~d S d }~ww )Nr   r  z1        [supervisord]
        logfile=%s
        r   r   z9The directory named as part of the path %s does not exist)r   rn   r   r   r   r   r   r.   r   r   r(   rc   r   )r   r   logfile_with_nonexistent_dirr   r   r   r   r   1test_read_config_logfile_with_nonexistent_dirpathy  s&   zDServerOptionsTests.test_read_config_logfile_with_nonexistent_dirpathc              
   C   r  )Nr   r   z..ini file does not include supervisord sectionr  r  r   r   r   r    r  zLServerOptionsTests.test_read_config_no_supervisord_section_raises_valueerrorc              
   C   sh   |   }td}z|t| | d W d S  ty3 } z| |jd d W Y d }~d S d }~ww )NzD        [supervisord]

        [include]
        ;no files=
        r   r   z5.ini file has [include] section, but no files setting)r   r   r.   r   r   r(   rc   r   r   r   r   r   r   r   r   8test_read_config_include_with_no_files_raises_valueerror  s   zKServerOptionsTests.test_read_config_include_with_no_files_raises_valueerrorc                 C   s2   |   }td}|t| | |jdg d S )NzM        [supervisord]

        [include]
        files=nonexistent/*
        z-No file matches via include "./nonexistent/*")r   r   r.   r   rc   rr  )r   r   r   r   r   r   <test_read_config_include_with_no_matching_files_logs_warning  s   zOServerOptionsTests.test_read_config_include_with_no_matching_files_logs_warningc              
   C   sz  t  }tj|d}t| tj|d}td||f }t|d}|| W d    n1 s4w   Y  tj|d}t|d}|d W d    n1 sUw   Y  tj|d}t|d}|d W d    n1 svw   Y  | 	 }z|
| W tj|d	d
 ntj|d	d
 w |jj}	| t|	jd d| }
| |
|jv  d| }
| |
|jv  d S )Nconf.drb   z`        [supervisord]

        [include]
        files=%s/conf.d/*.conf %s/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   rn   r   r   mkdirr   r   r   r   r.   r   r   r&   r3  rc   rd   r?  r   rs  )r   r   conf_dr   r   r   	conf_fileini_filer   r?   r   r   r   r   *test_read_config_include_reads_extra_files  s8   
 z=ServerOptionsTests.test_read_config_include_reads_extra_filesc              
   C   s\  t  }tj|d}t| tj|d}td| }t|d}|| W d    n1 s2w   Y  ddl	m
} |d d }t|D ])}tj|d| }	t|	d}|d	||f  W d    n1 skw   Y  qG|  }
z|
| W tj|d
d ntj|d
d w g }t|D ]}tj|d| }	|d|	  q| |
j| d S )Nr  rb   P        [supervisord]

        [include]
        files=%s/conf.d/*.conf
        r   r   )letters   %s.confz[program:%s]
command=/bin/%s
Tr   r  )r   r   rn   r   r   r  r   r   r   supervisor.compatr  reversedr   r.   r   r   sortedrx   rc   rs  )r   r   r  r   r   r   r  a_zletterfilenamer   expected_msgsr   r   r   4test_read_config_include_reads_files_in_sorted_order  s>   
 zGServerOptionsTests.test_read_config_include_reads_files_in_sorted_orderc           
   
   C   sp  t  }tj|d}t| tj|d}td| }t|d}|| W d    n1 s2w   Y  tj|d}t|d}|d W d    n1 sSw   Y  | 	 }zSz|
| | d W n2 ty } z&| d|jd	 v  | ||jd	 v  d
| }	| |	|jv  W Y d }~nd }~ww W tj|dd d S W tj|dd d S tj|dd w )Nr  rb   r  r   r  z[inet_http_server]
junk
r   r|  r   r  Tr   )r   r   rn   r   r   r  r   r   r   r   r.   r   r(   r   r   rs  r   r   )
r   r   r  r   r   r   malformed_filer   r   r   r   r   r   -test_read_config_include_extra_file_malformed  s:   

"z@ServerOptionsTests.test_read_config_include_extra_file_malformedc           
   
   C   s(  t  }tj|d}t| tj|d}td|df }t|d}|| W d    n1 s4w   Y  tj|dt	
  }t|d}|d W d    n1 sYw   Y  |  }z|| W tj|dd	 ntj|dd	 w |jj}| t|jd
 d| }	| |	|jv  d S )Nr  rb   zQ        [supervisord]

        [include]
        files=%s/conf.d/%s.conf
        z%(host_node_name)sr   r  r  Tr   r   r  )r   r   rn   r   r   r  r   r   r   platformnoder   r.   r   r   r&   r3  rc   rd   r?  r   rs  )
r   r   r  r   r   r   r  r   r?   r   r   r   r   /test_read_config_include_expands_host_node_name  s,   
 zBServerOptionsTests.test_read_config_include_expands_host_node_namec                 C   sz   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)rn   r   r   r^  r   r   r   r=   process_config_filer&   r3  rc   r6  r>  )r   conf	root_hereinclude_hereparserrl  r   r   r   %test_read_config_include_expands_here2  s   
z8ServerOptionsTests.test_read_config_include_expands_herec              
   C   s\   ddl m} z|ddd W td ty- } z| |jd d W Y d }~d S d }~ww )Nr   )readFilez	/nottherer!  FAILEDzDidn't raise)r   r  r(   rc   r   AssertionError)r   r  rF   r   r   r   test_readFile_failed?  s    z'ServerOptionsTests.test_readFile_failedc                 C   s    |   }| t |  d S r'   )r   rc   rn   getpidget_pidr   r   r   r   test_get_pidH  s   zServerOptionsTests.test_get_pidc                 C   s`   |   }|jtjd  |jtjd  | | tj | | tj | | d  d S r'   )r   signal_receiverreceiverS  r[  SIGCHLDrc   
get_signalr   r   r   r   ,test_get_signal_delegates_to_signal_receiverL  s   z?ServerOptionsTests.test_get_signal_delegates_to_signal_receiverc                 C   s,   |   }ddlm} | ||jdd d  d S )Nr   )NotFoundz
/not/there)r   r   r  rC   check_execv_args)r   r   r  r   r   r   'test_check_execv_args_cant_find_commandT  s
   
z:ServerOptionsTests.test_check_execv_args_cant_find_commandc              	   C   s4   |   }ddlm} | ||jddgtd d S )Nr   NotExecutablez/etc/passwdz
etc/passwdr   r   r  rC   r  rn   statr   r   r  r   r   r   #test_check_execv_args_notexecutableZ     z6ServerOptionsTests.test_check_execv_args_notexecutablec              	   C   s4   |   }ddlm} | ||jddgtd d S )Nr   r  /r  r  r   r   r   test_check_execv_args_isdira  r  z.ServerOptionsTests.test_check_execv_args_isdirc                    sd   |   }g   fdd}||_td|_ddg}|j|d | t d |  d d	|  d S )
Nc                         |  d S r'   rw   messagerecorderr   r   record_usagel     zSServerOptionsTests.test_realize_positional_args_not_supported.<locals>.record_usage[supervisord]r   r   r   r   r   z*positional arguments are not supported: %sr   usager   r=   rm   rc   rd   )r   r   r  r   r   r  r   *test_realize_positional_args_not_supportedh  s   

z=ServerOptionsTests.test_realize_positional_args_not_supportedc                    sZ   |   }g   fdd}||_td|_|jdgd | t d |  d d d S )	Nc                    r  r'   rw   r  r  r   r   r  {  r  zBServerOptionsTests.test_realize_getopt_error.<locals>.record_usager  z--bad=1r   r   r   zoption --bad not recognizedr  )r   r   r  r   r  r   test_realize_getopt_errorw  s   
z,ServerOptionsTests.test_realize_getopt_errorc                 C   s<   t d}|  }t||_|jddgd | |jd d S )NzC
        [supervisord]
        identifier=from_config_file
        z-i	from_argsr   )r   r   r   r=   rm   rc   r=  r   r   r   r   )test_realize_prefers_identifier_from_args  s
   
z<ServerOptionsTests.test_realize_prefers_identifier_from_argsc                 C   s   |   }td}ddlm} | }|| t||_|t| |jg d |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   r=   r.   rm   r&   r3  rc   r?  r@  AF_UNIXr   r   r   r  r   r?   r   r   r   test_options_afunix  s   	

z&ServerOptionsTests.test_options_afunixc                 C   s   |   }td}ddlm} | }|| t||_|t| |jg d |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  r   r   r   &test_options_afunix_chxxx_values_valid  s   


z9ServerOptionsTests.test_options_afunix_chxxx_values_validc              
   C   r   |   }td}t||_z|t| | d W d S  ty8 } z| |jd d W Y d }~d S d }~ww )Nzc        [supervisord]

        [unix_http_server]
        file=/tmp/file
        chmod=NaN
        r   r   zInvalid chmod value NaN	r   r   r   r=   r.   r   r(   rc   r   r  r   r   r   test_options_afunix_chmod_bad     
z0ServerOptionsTests.test_options_afunix_chmod_badc              
   C   r  )Nzs        [supervisord]

        [unix_http_server]
        file=/tmp/file
        chown=thisisnotavaliduser
        r   r   z+Invalid sockchown value thisisnotavaliduserr  r  r   r   r   test_options_afunix_chown_bad  r  z0ServerOptionsTests.test_options_afunix_chown_badc              
   C   r  )NzL        [supervisord]

        [unix_http_server]
        ;no file=
        r   r   z,section [unix_http_server] has no file valuer  r  r   r   r   test_options_afunix_no_file     
z.ServerOptionsTests.test_options_afunix_no_filec              
   C   r  )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  r   r   r   -test_options_afunix_username_without_password     
	z@ServerOptionsTests.test_options_afunix_username_without_passwordc              
   C   r  )Nz        [supervisord]

        [unix_http_server]
        file=/tmp/supvtest.sock
        ;no username=
        password=passwordhere
        chmod=0755
        r   r   r  r  r  r   r   r   -test_options_afunix_password_without_username  r  z@ServerOptionsTests.test_options_afunix_password_without_usernamec              
   C   s   |   }td}t }tj|d}t|d}|| W d    n1 s(w   Y  z||_	|j
g d W tj|dd ntj|dd w |jj}|jd }| |d tj | |d	 tj|d
 d S )Nza        [supervisord]

        [unix_http_server]
        file=%(here)s/supervisord.sock
        rb   r   r   Tr   r   r  r  r   )r   r   r   r   rn   r   r   r   r   r=   rm   r   r   r&   r3  r?  rc   r@  r  )r   r   r   r   r   r   r?   
serverconfr   r   r   %test_options_afunix_file_expands_here  s"    

z8ServerOptionsTests.test_options_afunix_file_expands_herec              
   C   r  )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  r   r   r   -test_options_afinet_username_without_password4  r  z@ServerOptionsTests.test_options_afinet_username_without_passwordc              
   C   r  )Nzn        [supervisord]

        [inet_http_server]
        password=passwordhere
        ;no username=
        r   r   r  r  r  r   r   r   -test_options_afinet_password_without_usernameJ  r  z@ServerOptionsTests.test_options_afinet_password_without_usernamec              
   C   r  )NzL        [supervisord]

        [inet_http_server]
        ;no port=
        r   r   z,section [inet_http_server] has no port valuer  r  r   r   r   test_options_afinet_no_port^  r  z.ServerOptionsTests.test_options_afinet_no_portc                 C   s   t jdd}|j}|d W d    n1 sw   Y  |  }d|_G dd d}tj|d| fg|_d|_	|
  | tj| d S )	NFdelete   fooTc                   @   r   )z=ServerOptionsTests.test_cleanup_afunix_unlink.<locals>.ServerNr   r   r   r   r   Servert      r  r  r  r   )r   r   r5   r   r   unlink_socketfilesr@  r  httpserversr:  cleanuprt  rn   r   existsr   r   r   r   r  r   r   r   test_cleanup_afunix_unlinkn  s   
z-ServerOptionsTests.test_cleanup_afunix_unlinkc                 C   s   t jdd}|j}|d W d    n1 sw   Y  z=|  }G dd d}tj|d| fg|_d|_d|_	|
  | tj| W zt| W d S  ty[   Y d S w zt| W w  tyl   Y w w )NFr  r  c                   @   r   )z?ServerOptionsTests.test_cleanup_afunix_nounlink.<locals>.ServerNr   r   r   r   r   r    r  r  r  r   )r   r   r5   r   r   r@  r  r  r:  r  r  r   rn   r   r  unlinkOSErrorr  r   r   r   test_cleanup_afunix_nounlink|  s0   
z/ServerOptionsTests.test_cleanup_afunix_nounlinkc                 C   s   t jt jtd}tjdd}|j}|d W d    n1 s$w   Y  zE| 	 }d|_
G dd d}tj|d| ftj|d| fg|_d	|_|  | t j| W zt | W d S  tyn   Y d S w zt | W w  ty   Y w w )
NnotfoundFr  r  Tc                   @   r   )zMServerOptionsTests.test_cleanup_afunix_ignores_oserror_enoent.<locals>.ServerNr   r   r   r   r   r    r  r  r  r   )rn   r   r   r   r   r   r   r5   r   r   r  r@  r  r  r:  r  rt  r  r  r  )r   r  r   
socketnamer   r  r   r   r   *test_cleanup_afunix_ignores_oserror_enoent  s2   z=ServerOptionsTests.test_cleanup_afunix_ignores_oserror_enoentc                 C   s   t jdd}|j}|d W d    n1 sw   Y  z6|  }||_t |_|  | 	|j
 |  | tj| W zt| W d S  tyT   Y d S w zt| W w  tye   Y w w NFr     2)r   r   r5   r   r   r:  r	   loggerwrite_pidfiler   unlink_pidfiler  rt  rn   r   r  r  r  r   r   r:  r   r   r   r   test_cleanup_removes_pidfile  s,   z/ServerOptionsTests.test_cleanup_removes_pidfilec                 C   s0   t jt jtd}|  }||_|  d S )Nr  )rn   r   r   r   r   r   r:  r  )r   r  r   r   r   r   +test_cleanup_pidfile_ignores_oserror_enoent  s   z>ServerOptionsTests.test_cleanup_pidfile_ignores_oserror_enoentc                 C   s   t jdd}|j}|d W d    n1 sw   Y  z.|  }||_| |j |  | 	t
j| W zt
| W d S  tyL   Y d S w zt
| W w  ty]   Y w w )NFr  s   1234)r   r   r5   r   r   r:  rt  r  r  r   rn   r   r  r  r  r  r   r   r   =test_cleanup_does_not_remove_pidfile_from_another_supervisord  s(   zPServerOptionsTests.test_cleanup_does_not_remove_pidfile_from_another_supervisordc                 C   s   t jdd}|j}|d W d    n1 sw   Y  z2|  }||_ti }||_| |j	 |
  | |j	 W zt| W d S  tyP   Y d S w zt| W w  tya   Y w w r  )r   r   r5   r   r   r:  r   pollerrt  closedr  r   rn   r  r  )r   r   r:  r   r  r   r   r   test_cleanup_closes_poller  s,   z-ServerOptionsTests.test_cleanup_closes_pollerzos.closerangec                    s2   |    d _ fdd}|  tjdd d S )Nr!  c                      s       d S r'   )cleanup_fdsr   r   r   r   r        zCServerOptionsTests.test_cleanup_fds_closes_5_upto_minfds.<locals>.fr  )r   rC  rn   
closerangeassert_called_with)r   r   r   r
  r   %test_cleanup_fds_closes_5_upto_minfds  s
   z8ServerOptionsTests.test_cleanup_fds_closes_5_upto_minfdsc                 C   sB   |   }G dd d}| }i |fg|_|  | |jd d S )Nc                   @   s   e Zd ZdZdd ZdS )z9ServerOptionsTests.test_close_httpservers.<locals>.ServerFc                 S   s
   d| _ d S NTr  r   r   r   r   close  r   z?ServerOptionsTests.test_close_httpservers.<locals>.Server.closeN)r   r    r!   r  r  r   r   r   r   r    s    r  T)r   r  close_httpserversrc   r  )r   r   r  serverr   r   r   test_close_httpservers  s   z)ServerOptionsTests.test_close_httpserversc                 C   s.   |   }t }||_|  | |jd d S r  )r   r	   r  close_loggerrc   r  r   r   r  r   r   r   test_close_logger  s
   z$ServerOptionsTests.test_close_loggerc                    R   |   }g   fdd}||_ddddddd	}|| | t g d
 d S )Nc                    r  r'   rw   fdr  r   r   close_fd  r  z<ServerOptionsTests.test_close_parent_pipes.<locals>.close_fdr   r   r   r(  r,  r  stdinr   r   child_stdinchild_stdoutchild_stderr)r   r   r   r   r  close_parent_pipesrc   r  r   r   r  pipesr   r  r   test_close_parent_pipes     
z*ServerOptionsTests.test_close_parent_pipesc                    s@   |   }g   fdd}||_dd i}|| |  g  d S )Nc                    r  r'   rw   r  r  r   r   r    r  zOServerOptionsTests.test_close_parent_pipes_ignores_fd_of_none.<locals>.close_fdr  )r   r  r"  rc   r#  r   r  r   *test_close_parent_pipes_ignores_fd_of_none  s   
z=ServerOptionsTests.test_close_parent_pipes_ignores_fd_of_nonec                    r  )Nc                    r  r'   rw   r  r  r   r   r    r  z;ServerOptionsTests.test_close_child_pipes.<locals>.close_fdr   r   r   r(  r,  r  r  )r(  r,  r  )r   r  close_child_pipesrc   r  r#  r   r  r   test_close_child_pipes  r&  z)ServerOptionsTests.test_close_child_pipesc                    sD   |   }g   fdd}||_dd i}|| | t g  d S )Nc                    r  r'   rw   r  r  r   r   r  %  r  zNServerOptionsTests.test_close_child_pipes_ignores_fd_of_none.<locals>.close_fdr  r!  r#  r   r  r   )test_close_child_pipes_ignores_fd_of_none"  s   
z<ServerOptionsTests.test_close_child_pipes_ignores_fd_of_nonec                 C   sP   |   }t }t g|_||_|  | |jd jd | |jd d d S )Nr   Tzsupervisord logreopen)r   r	   handlersr  
reopenlogsrc   reopeneddatar  r   r   r   test_reopenlogs,  s   
z"ServerOptionsTests.test_reopenlogsc                 C   s2  t jdd}|j}W d    n1 sw   Y  | tj| ze|  }t |_	||_
|  | tj| t|d}t|  }W d    n1 sSw   Y  | |t  |j	jd }| |d | |j W zt| W d S  ty   Y d S w zt| W w  ty   Y w w )NTr  rr   zsupervisord started with pid)r   r   r5   rt  rn   r   r  r   r	   r  r:  r   r   r   intreadstriprc   r  r.  r   r  r  r  )r   r   r   r   pidr   r   r   r   test_write_pidfile_ok5  s6   z(ServerOptionsTests.test_write_pidfile_okc                 C   sN   d}|   }t |_||_|  |jjd }| |d | |j	 d S )Nz/cannot/possibly/existr   zcould not write pidfile)
r   r	   r  r:  r   r.  r   r   rt  r  )r   r   r   r   r   r   r   test_write_pidfile_failL  s   z*ServerOptionsTests.test_write_pidfile_failc                 C   sp   |   }t \}}t|d t|td || | ttj|d || | ttj|td d S )Nr   r   )	r   rn   piper2  r   r   r  rC   r  )r   r   innieoutier   r   r   test_close_fdV  s   

z ServerOptionsTests.test_close_fdzos.close)side_effectc                 C   s   |   }|d d S )Nr   )r   r  r   r   r   r   test_close_fd_ignores_oserror`  s   z0ServerOptionsTests.test_close_fd_ignores_oserrorc                 C   s`  |   }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_00r   Fd   i  @Tr   r,  val1val20)KEY1KEY2KEY3)r   r   r   r  r  processes_from_sectionrc   rd   r5   rJ  rK  rL  rN  rO  rP  rQ  stdout_capture_maxbytesrX  stdout_events_enabledrR  rS  rT  rV  rW  rU  r|   redirect_stderrrF  r   r   r   r  r   pconfigspconfigr   r   r   test_processes_from_sectione  s8   

z.ServerOptionsTests.test_processes_from_sectionc                 C   s\   |   }td}ddlm} | }|| ||dd}dt  }| |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  rF  r  r  rc   rJ  r   r   r   r  r   rK  expectedr   r   r   4test_processes_from_section_host_node_name_expansion  s   
zGServerOptionsTests.test_processes_from_section_host_node_name_expansionc                 C   s   |   }td}ddlm} | }|| ||dd}| t|d dD ]F}| || jd|  | || j	d	|  | || j
d
|  | || jd|  | || jd|  | || jdd| i q'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  rF  rc   rd   r5   rJ  r4  stderr_logfilerQ  rF  r   r   r   r  r   rK  numr   r   r   1test_processes_from_section_process_num_expansion  s&   

zDServerOptionsTests.test_processes_from_section_process_num_expansionc                 C   s   |   }td}ddlm} | }|| ||dd}| t|d dD ]}| || jd|  | || j	d	d  q'd S )
Nz        [program:foo]
        process_name = foo_%(process_num)d
        command = /bin/foo --numprocs=%(numprocs)d
        numprocs = 2
        r   r  r=  r   r   rQ  rR  z/bin/foo --numprocs=%d)
r   r   r   r  r  rF  rc   rd   r5   rJ  rU  r   r   r   .test_processes_from_section_numprocs_expansion  s   
zAServerOptionsTests.test_processes_from_section_numprocs_expansionc                 C   sZ   |   }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  rF  rc   r4  r   r   r   r  r   rK  r   r   r   -test_processes_from_section_expands_directory  s   

z@ServerOptionsTests.test_processes_from_section_expands_directoryc                 C   s^   |   }td}ddlm} | }|| ||dd}dtjd  }| |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  rF  rn   ro   rc   rJ  rN  r   r   r   ;test_processes_from_section_environment_variables_expansion  s   
zNServerOptionsTests.test_processes_from_section_environment_variables_expansionc                 C   sb   |   }td}ddlm} | }|| ||dd}dtjd  }| |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  rF  rn   ro   rc   rF  rN  r   r   r   6test_processes_from_section_expands_env_in_environment  s   
zIServerOptionsTests.test_processes_from_section_expands_env_in_environmentc                 C   sb   |   }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  rF  rc   rr  rT  r[  r   r   r   9test_processes_from_section_redirect_stderr_with_filename  s   
zLServerOptionsTests.test_processes_from_section_redirect_stderr_with_filenamec                 C   t   |   }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  rF  rc   rr  rQ  stdout_syslogr[  r   r   r   =test_processes_from_section_rewrites_stdout_logfile_of_syslog
     
zPServerOptionsTests.test_processes_from_section_rewrites_stdout_logfile_of_syslogc                 C   rb  )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  rF  rc   rr  rT  stderr_syslogr[  r   r   r   =test_processes_from_section_rewrites_stderr_logfile_of_syslog  re  zPServerOptionsTests.test_processes_from_section_rewrites_stderr_logfile_of_syslogc                 C   s^   |   }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[  r   r   r   5test_processes_from_section_redirect_stderr_with_auto.  s   
zHServerOptionsTests.test_processes_from_section_redirect_stderr_with_autoc                 C   sf   |   }tdtj }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   rS  SIGQUITr   r  r  rF  rc   rr  rR  r[  r   r   r   9test_processes_from_section_accepts_number_for_stopsignal=  s   
zLServerOptionsTests.test_processes_from_section_accepts_number_for_stopsignalc           	      C   s  t d}ddlm} ddlm} |  }i dt 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| |jg d- | |jd.|j	  | |jd/|j	  | |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 t!j" | |j d d7 d8 | |j d d9 d: | |j d d; d | |j d d< d |j#d }| |j$d= | |j%d> | t&|j'd? |j'd }| |j$d= | |j(d@ | |j%d> | |j)d5 | |j*|j+ | |j,dA | |j-d1 | |j.d | |j/d& | |j0t1j2 | |j3dA | |j4d2 | |j5d2 | |j6|7d' | |j8dB | |j9dg | |j:d+ | |j;dB | |j<t=dCdD 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   r  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rootr"  78KB2KILL5r$  )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r!  Fr&     Tr  r  r   r  i#  r   r   r  r(  r   z%/bin/customcat --logdir=/path/to/logsr  r   r  r  )>r   r2  r  r   r  r   r   r   r   rZ  r  r   r=   r.   rm   rc   r6  r=  r7  r8  r9  r   INFOr;  r<  rC  rD  rB  r>  
strip_ansir&   r3  r?  r@  rA  rE  r5   rH  rd   rI  rJ  rK  rL  rM  rN  rO  rP  rQ  rR  rS  rT  rU  rV  rW  rX  rY  rZ  r|   r4  r5  rF  rG  )	r   r   r  r  r   r   r?   r  rb  r   r   r   r   K  s   $	





z;ServerOptionsTests.test_options_with_environment_expansionsc              
   C   s   |   }td}t }tj|d}t|d}|| W d    n1 s(w   Y  z||_	|j
g d W tj|dd ntj|dd 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
        rb   r   r   Tr   r  r  )r   r   r   r   rn   r   r   r   r   r=   rm   r   r   rc   r>  r4  r6  r:  )r   r   r   r   r   r   r   r   r   -test_options_supervisord_section_expands_here  s.    

z@ServerOptionsTests.test_options_supervisord_section_expands_herec           	   
   C      |   }td}t }tj|d}t|d}|| W d    n1 s(w   Y  z||_	|j
g d W tj|dd ntj|dd 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
        rb   r   r   Tr   r   cmdz/bin/from/supervisord/sectionr   r   r   r   rn   r   r   r   r   r=   rm   r   r   r&   r3  rE  rc   r5   rI  rJ  	r   r   r   r   r   r   r?   grouprn  r   r   r   >test_options_program_section_expands_env_from_supervisord_sect  s$    

zQServerOptionsTests.test_options_program_section_expands_env_from_supervisord_sectc           	   
   C   r  )
Nz
        [supervisord]
        environment=CMD=/bin/from/supervisord/section

        [program:cmd]
        command=%(ENV_CMD)s
        environment=CMD=/bin/from/program/section
        rb   r   r   Tr   r   r  z/bin/from/program/sectionr  r  r   r   r   :test_options_program_section_expands_env_from_program_sect  s$    

zMServerOptionsTests.test_options_program_section_expands_env_from_program_sectc           	   
   C   V  |   }td}t }tj|d}t|d}|| W d    n1 s(w   Y  z||_	|j
g d W tj|dd ntj|dd 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  | |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
        rb   r   r   Tr   r   rm  thedirectorybin/catFOOr   r   r   
stdout.log
stderr.logr   r   r   r   rn   r   r   r   r   r=   rm   r   r   r&   r3  rE  rc   r5   rI  r4  rJ  rF  r   rQ  rT  r  r   r   r   )test_options_program_section_expands_here  sB    

z<ServerOptionsTests.test_options_program_section_expands_herec           	   
   C   r  )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
        rb   r   r   Tr   r   memmonr  z
bin/memmonr  r   r   r   r  r  r  r  r   r   r   /test_options_eventlistener_section_expands_here?  sB    

zBServerOptionsTests.test_options_eventlistener_section_expands_herec           
   
   C   s  |   }td}|d7 }t }tj|d}t|d}|| W d    n1 s,w   Y  zddd|_	||_
|jg d W tj|d	d
 ntj|d	d
 w |jj}| |jtj|d |jd }|jd }dtj|dt f }	| |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)srb   r   mainlogr   )ENV_LOGNAMErY  r   Tr   zmainlog.logr   z%s --foo=bar --num=0 --node=%sr  )r   r   r   r   rn   r   r   r   r   r   r=   rm   r   r   r&   r3  rc   r6  rE  rI  r  r  rJ  )
r   r   r   r   r   r   rl  	cat_groupcat_0rO  r   r   r   (test_options_expands_combined_expansionsg  s4    

z;ServerOptionsTests.test_options_expands_combined_expansionsc              
   C   s   t  }tj|d}td}t|d}|| W d    n1 s$w   Y  |  }zD||_	z|j
dd | d W n ty] } z| t|jd d|  W Y d }~nd }~ww W tj|d	d
 d S W tj|d	d
 d S tj|d	d
 w )Nrb   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   rn   r   r   r   r   r   r   r=   rq   r   r(   rc   strr   r   r   )r   r   r   r   r   r   er   r   r   .test_options_error_handler_shows_main_filename  s0   "zAServerOptionsTests.test_options_error_handler_shows_main_filenamec           	   
   C   sZ  t  }tj|d}td| }t|d}|| W d    n1 s&w   Y  tj|d}t| tj|d}td}t|d}|| W d    n1 sWw   Y  | 	 }zD||_
z|jdd | d	 W n ty } z| t|jd
 d|  W Y d }~nd }~ww W tj|dd d S W tj|dd d S tj|dd w )Nrb   r  r   r  zincluded.confzY        [program:cat]
        command = /bin/cat
        stopsignal = NOTASIGNAL
        Fr   r   r   r  Tr   )r   r   rn   r   r   r   r   r   r  r   r=   rq   r   r(   rc   r  r   r   r   )	r   r   r   r   r   r  included_confr   r  r   r   r   2test_options_error_handler_shows_included_filename  sB   
"zEServerOptionsTests.test_options_error_handler_shows_included_filenamec                 C   D   |   }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  rC   r(   rF  r   r   r   r  r   r   r   r   3test_processes_from_section_bad_program_name_spaces     

zFServerOptionsTests.test_processes_from_section_bad_program_name_spacesc                 C   r  )Nz)        [program:colons:are:bad]
        r   r  zprogram:colons:are:badr  r  r   r   r   3test_processes_from_section_bad_program_name_colons  r  zFServerOptionsTests.test_processes_from_section_bad_program_name_colonsc                 C   r  )NzN        [program:foo]
        command = /bin/cat
        numprocs = 2
        r   r  r=  r  r  r   r   r   5test_processes_from_section_no_procnum_in_processname     

zHServerOptionsTests.test_processes_from_section_no_procnum_in_processnamec              
   C   s   |   }td}ddlm} | }|| z||dd  | d W d S  tyC } z| |j	d 
d W Y d }~d S d }~ww )Nz        [program:foo]
        r   r  r=  r   z6program section program:foo does not specify a command)r   r   r   r  r  rF  r   r(   r   r   r   )r   r   r   r  r   r   r   r   r   &test_processes_from_section_no_command  s   
z9ServerOptionsTests.test_processes_from_section_no_commandc                 C   r  )Nz^        [program:foo]
        command = /bin/cat
        process_name = %(not_there)s
        r   r  r=  r  r  r   r   r   ?test_processes_from_section_missing_replacement_in_process_name  r  zRServerOptionsTests.test_processes_from_section_missing_replacement_in_process_namec                 C   r  )Nz`        [program:foo]
        command = /bin/cat
        process_name = %(program_name)
        r   r  r=  r  r  r   r   r   :test_processes_from_section_bad_expression_in_process_name		  r  zMServerOptionsTests.test_processes_from_section_bad_expression_in_process_namec                 C   r  )Nz_        [program:foo]
        command = /bin/cat
        process_name = colons:are:bad
        r   r  r=  r  r  r   r   r   5test_processes_from_section_bad_chars_in_process_name	  r  zHServerOptionsTests.test_processes_from_section_bad_chars_in_process_namec                 C   sr   |   }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  rF  rc   rd   rV  rW  rJ  r   r   r   ;test_processes_from_section_stopasgroup_implies_killasgroup#	  s   
zNServerOptionsTests.test_processes_from_section_stopasgroup_implies_killasgroupc                 C   r  )Nz        [program:foo]
        command = /bin/cat
        process_name = %(program_name)s
        stopasgroup = true
        killasgroup = false
        r   r  r=  r  r  r   r   r   >test_processes_from_section_killasgroup_mismatch_w_stopasgroup4	  s   

zQServerOptionsTests.test_processes_from_section_killasgroup_mismatch_w_stopasgroupc              
   C   s   |   }td}ddlm} | }|| z	||dd  W n ty; } z| dt|v  W Y d }~d S d }~ww | 	d d S )Nzh        [program:foo]
        command = /bin/cat
        environment = KEY1=val1,KEY2=val2,KEY3
        r   r  r=  z^Unexpected end of key/value pairs in value 'KEY1=val1,KEY2=val2,KEY3' in section 'program:foo'z9instance.processes_from_section should raise a ValueError)
r   r   r   r  r  rF  r(   r   r  r   )r   r   r   r  r   r  r   r   r   =test_processes_from_section_unexpected_end_of_key_value_pairsC	  s    
zPServerOptionsTests.test_processes_from_section_unexpected_end_of_key_value_pairsc                 C   s   |   }td}tjddV}z!|| |  ddlm} | }||j	 |
|dd  W n tyN } z| |jd d|j	  W Y d }~nd }~ww | d W d    d S W d    d S 1 sgw   Y  d S )	Nz2        [program:foo]
        ;no command
        rz  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  r2  r5   rF  r(   rc   r   r   )r   r   r   r   r  r   r  r   r   r   =test_processes_from_section_shows_conf_filename_on_valueerrorX	  s,   
	"zPServerOptionsTests.test_processes_from_section_shows_conf_filename_on_valueerrorc                 C   sj   |   }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	   r  r  rF  rc   rr  r  r   r   r   4test_processes_from_section_autolog_without_rolloverm	  s   
zGServerOptionsTests.test_processes_from_section_autolog_without_rolloverc                 C   s   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_parserrc   rd   r5   rH  rI  r   r   r  r   r   gconfigsgconfigr   r   r   +test_homogeneous_process_groups_from_parser	  s   

z>ServerOptionsTests.test_homogeneous_process_groups_from_parserc                 C   s  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_handlerr(  bizr   r   rm  r  dog)r   r   r  supervisor.dispatchersr  r  r   r  rc   rd   r5   result_handlerrI  rH  )r   r   r  r  r   r   r  gconfig1r   r   r   %test_event_listener_pools_from_parser	  s,   

z8ServerOptionsTests.test_event_listener_pools_from_parserc                 C   sf  t d}ddlm} ddlm} |  }t 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  r  r   myeventlistenerz/bin/dogr  1)r   r   ENV_EL1_PROCNAMEENV_EL1_COMMANDENV_EL1_NUMPROCSENV_EL1_PRIORITYr   rm  r  r(  r   r  myeventlistener_dog_0myeventlistener_dog_1)r   r   r  r  r  r   r   r   r   rZ  r  r  rc   rd   r5   rH  r  rI  rJ  )r   r   r  r  r   r   r  gconfig0r  dog0dog1r   r   r   Atest_event_listener_pools_from_parser_with_environment_expansions	  sD   



zTServerOptionsTests.test_event_listener_pools_from_parser_with_environment_expansionsc              
   C      t d}ddlm} | }|| |  }z|| | d W d S  ty? } z| |j	d d W Y d }~d S d }~w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   r  r   r(   rc   r   r   r   r  r   r   r   r   r   r   3test_event_listener_pool_disallows_buffer_size_zero	     

 zFServerOptionsTests.test_event_listener_pool_disallows_buffer_size_zeroc              
   C   r  )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 protocolr  r  r   r   r   2test_event_listener_pool_disallows_redirect_stderr
  r  zEServerOptionsTests.test_event_listener_pool_disallows_redirect_stderrc                 C   sl   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.baser  r  r   r  rc   rd   r  )r   r   r  r  r   r   r  r  r   r   r   2test_event_listener_pool_with_event_result_handler
  s   

zEServerOptionsTests.test_event_listener_pool_with_event_result_handlerc              
   C   r  )Nz        [eventlistener:cat]
        events=PROCESS_COMMUNICATION
        command = /bin/cat
        result_handler = thisishopefullynotanimportablepackage:nonexistent
        r   r  r   z_thisishopefullynotanimportablepackage:nonexistent cannot be resolved within [eventlistener:cat]r  r  r   r   r   @test_event_listener_pool_result_handler_unimportable_ImportError1
     

zSServerOptionsTests.test_event_listener_pool_result_handler_unimportable_ImportErrorc              
   C   r  )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]r  r  r   r   r   Ctest_event_listener_pool_result_handler_unimportable_AttributeErrorD
  r  zVServerOptionsTests.test_event_listener_pool_result_handler_unimportable_AttributeErrorc                 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   rC   r(   r  r   r   r  r   r   r   r   r   %test_event_listener_pool_noeventslineW
     
z8ServerOptionsTests.test_event_listener_pool_noeventslinec                 C   r  )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  r  r  r   r   r   *test_event_listener_pool_unknown_eventtypee
     
z=ServerOptionsTests.test_event_listener_pool_unknown_eventtypec                 C   s`  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	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   
   |  |S r'   r  r   r   r   r   r   get_process_groups
     
zMServerOptionsTests.test_fcgi_programs_from_parser.<locals>.get_process_groupsr,  r   r   zunix:///tmp/foo.sock    r   r     zunix:///tmp/bar.sockr  r(  cubztcp://localhost:6000flubzunix:///tmp/flub.sock)r   r  r  r   r  r  r   r   r   rP  r`  return_valuer   rc   rd   	__class__r5   rH  socket_configurl	get_ownerget_modeget_backlogrI  )r   r  r  r   r  r   r   pwd_mockgrp_mockr  r  	exp_owner	gconf_foopconfig_foo	gconf_bar	gconf_cub
gconf_flubr   r   r   test_fcgi_programs_from_parsert
  sl   






z1ServerOptionsTests.test_fcgi_programs_from_parserc                 C   s  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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  r$  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  r  r   r   r   r  
  r  ziServerOptionsTests.test_fcgi_programs_from_parser_with_environment_expansions.<locals>.get_process_groupsr   r   zunix:///tmp/foo.usockr  r   r   z/bin/foo --arg1=bar)r   r  r  r   r  r   r   rZ  r  r   r   rP  r`  r  r   rc   rd   r  r5   rH  r  r  r  r	  r
  rI  rJ  )r   r  r  r   r  r   r   r  r  r  r  r  r  r  r   r   r   :test_fcgi_programs_from_parser_with_environment_expansions
  sX   



zMServerOptionsTests.test_fcgi_programs_from_parser_with_environment_expansionsc                 C   r  )Nz        [fcgi-program:foo]
        process_name = %(program_name)s_%(process_num)s
        command = /bin/foo
        numprocs = 2
        priority = 1
        r   r  r  r  r   r   r   test_fcgi_program_no_socket  r  z.ServerOptionsTests.test_fcgi_program_no_socketc                 C   r  )Nz        [fcgi-program:foo]
        socket=junk://blah
        process_name = %(program_name)s_%(process_num)s
        command = /bin/foo
        numprocs = 2
        priority = 1
        r   r  r  r  r   r   r   )test_fcgi_program_unknown_socket_protocol  r  z<ServerOptionsTests.test_fcgi_program_unknown_socket_protocolc                 C   r  )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  r  r  r   r   r   $test_fcgi_program_rel_unix_sock_path*  r  z7ServerOptionsTests.test_fcgi_program_rel_unix_sock_pathc                 C   r  )Nz        [fcgi-program:foo]
        socket=tcp://missingport
        process_name = %(program_name)s_%(process_num)s
        command = /bin/foo
        numprocs = 2
        priority = 1
        r   r  r  r  r   r   r   %test_fcgi_program_bad_tcp_sock_format9  r  z8ServerOptionsTests.test_fcgi_program_bad_tcp_sock_formatc                 C   r  )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  r  r  r   r   r   (test_fcgi_program_bad_expansion_proc_numH  r  z;ServerOptionsTests.test_fcgi_program_bad_expansion_proc_numc                 C   r  )Nz        [fcgi-program:foo]
        socket=tcp://localhost:8000
        socket_owner=nobody:nobody
        command = /bin/foo
        r   r  r  r  r   r   r   *test_fcgi_program_socket_owner_set_for_tcpW     
z=ServerOptionsTests.test_fcgi_program_socket_owner_set_for_tcpc                 C   r  )Nz        [fcgi-program:foo]
        socket = tcp://localhost:8000
        socket_mode = 0777
        command = /bin/foo
        r   r  r  r  r   r   r   )test_fcgi_program_socket_mode_set_for_tcpd  r&  z<ServerOptionsTests.test_fcgi_program_socket_mode_set_for_tcpc                 C   r  )Nz        [fcgi-program:foo]
        socket = unix:///tmp/foo.sock
        socket_owner = sometotaljunkuserthatshouldnobethere
        command = /bin/foo
        r   r  r  r  r   r   r   "test_fcgi_program_bad_socket_ownerq  r&  z5ServerOptionsTests.test_fcgi_program_bad_socket_ownerc                 C   r  )Nz        [fcgi-program:foo]
        socket = unix:///tmp/foo.sock
        socket_mode = junk
        command = /bin/foo
        r   r  r  r  r   r   r   !test_fcgi_program_bad_socket_mode~  r&  z4ServerOptionsTests.test_fcgi_program_bad_socket_modec                 C   r  )Nz        [fcgi-program:foo]
        socket = unix:///tmp/foo.sock
        socket_backlog = -1
        command = /bin/foo
        r   r  r  r  r   r   r   $test_fcgi_program_bad_socket_backlog  r&  z7ServerOptionsTests.test_fcgi_program_bad_socket_backlogc                 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   r  r  r   r   r   -test_heterogeneous_process_groups_from_parser  s   

z@ServerOptionsTests.test_heterogeneous_process_groups_from_parserc                 C   s   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   r  r   r,  r  r  )r   r   r  r   r   r  
manyconfigr  r   r   r   &test_mixed_process_groups_from_parser1  s   

z9ServerOptionsTests.test_mixed_process_groups_from_parser1c                 C   r+  )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  r,  r  r  r   r   r   &test_mixed_process_groups_from_parser2  s   

z9ServerOptionsTests.test_mixed_process_groups_from_parser2c                 C   r+  )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  r`   r  r  r   r   r   &test_mixed_process_groups_from_parser3  s   

z9ServerOptionsTests.test_mixed_process_groups_from_parser3c                 C   r  )Nz        [program:one]
        command = /bin/cat

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

        [group:thegroup]
        programs = oner   r  r  r  r   r   r   -test_ambiguous_process_in_heterogeneous_group  s   	

z@ServerOptionsTests.test_ambiguous_process_in_heterogeneous_groupc                 C   r  )Nzj        [program:one]
        command = /bin/cat

        [group:foo]
        programs = notthere
        r   r  r  r  r   r   r   +test_unknown_program_in_heterogeneous_group%  s   

z>ServerOptionsTests.test_unknown_program_in_heterogeneous_groupc                 C   s   t dt }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_pluginsrc   rd   sysmodules)r   r   r  r   r   	factoriesfactoryr   r   r   test_rpcinterfaces_from_parser4  s    
z1ServerOptionsTests.test_rpcinterfaces_from_parserc                 C   s   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  rm  )r<  petr4  r5  r   r6  r   r   )r   r   r  r   r   rZ  r  r8  rc   rd   r9  r:  )r   r   r  r   r   r;  r<  r   r   r   1test_rpcinterfaces_from_parser_factory_expansionsH  s   
zDServerOptionsTests.test_rpcinterfaces_from_parser_factory_expansionsc              
   C      t d}ddlm} | }|| |  }z||dd | d W d S  tyA } z| |j	d d W Y d }~d S d }~ww )Nz]        [rpcinterface:dummy]
        # note: no supervisor.rpcinterface_factory here
        r   r  r4  r5  r   zOsection [rpcinterface:dummy] does not specify a supervisor.rpcinterface_factory
r   r   r  r  r   r8  r   r(   rc   r   r  r   r   r   .test_rpcinterfaces_from_parser_factory_missing\     
 zAServerOptionsTests.test_rpcinterfaces_from_parser_factory_missingc              
   C   r@  )Nz[        [rpcinterface:dummy]
        supervisor.rpcinterface_factory = nonexistent
        r   r  r4  r5  r   z:nonexistent cannot be resolved within [rpcinterface:dummy]rA  r  r   r   r   5test_rpcinterfaces_from_parser_factory_not_importablen  rC  zHServerOptionsTests.test_rpcinterfaces_from_parser_factory_not_importablec           	   
   C   s   t  }zV|  }||_d}||_|d|d}|d }|d }t|d}t|d}|  | t	j
| | t	j
| | t	j
| |  |  W tj|dd d S tj|dd w )	Nr2  r   r   z.1z.2r   Tr   )r   r   r   r>  r=  get_autochildlog_namer   clear_autochildlogdirrt  rn   r   r  r  r   r   )	r   dnr   sidlogfnfirstsecondf1f2r   r   r   test_clear_autochildlogdir  s$   


"z-ServerOptionsTests.test_clear_autochildlogdirc                 C   s4   |   }d|_t |_|  | |jjdg d S )Nz!/tmp/this/cant/possibly/existjjjjzCould not clear childlog dir)r   r>  r	   r  rF  rc   r.  r   r   r   r   *test_clear_autochildlogdir_listdir_oserror  s
   z=ServerOptionsTests.test_clear_autochildlogdir_listdir_oserrorc                 C   s   t  }|  }||_|j}tj|d| }t|d}|	d W d    n1 s,w   Y  dd }||_
t |_|  | |jjd| g d S )Nzcat-stdout---%s-ayWAp9.logr   logc                  W   s
   t tjr'   )r  r   ENOENTr   r   r   r   raise_oserror  r   zSServerOptionsTests.test_clear_autochildlogdir_unlink_oserror.<locals>.raise_oserrorzFailed to clean up '%s')r   r   r   r>  r=  rn   r   r   r   r   remover	   r  rF  rc   r.  )r   r   r   identr  r   rR  r   r   r   )test_clear_autochildlogdir_unlink_oserror  s   
z<ServerOptionsTests.test_clear_autochildlogdir_unlink_oserrorc                    sh   t  }|  }dd }||_g   fdd}||_|| | t d d}|  d | d S )Nc                 S      t tjr'   )r@  rs   r   
EADDRINUSEr3  r   r   r   raise_eaddrinuse  r  zhServerOptionsTests.test_openhttpservers_reports_friendly_usage_when_eaddrinuse.<locals>.raise_eaddrinusec                    r  r'   rw   r  r  r   r   r    r  zdServerOptionsTests.test_openhttpservers_reports_friendly_usage_when_eaddrinuse.<locals>.record_usager   z$Another program is already listeningr   )	r   r   make_http_serversr  openhttpserversrc   rd   r   r   )r   r3  r   rY  r  rO  r   r  r   ;test_openhttpservers_reports_friendly_usage_when_eaddrinuse  s   
zNServerOptionsTests.test_openhttpservers_reports_friendly_usage_when_eaddrinusec                    sj   t  }|  }dd }||_g   fdd}||_|| | t d dtj }|  d | d S )Nc                 S   rV  r'   )r@  rs   r   EPERMrX  r   r   r   rZ    r  zbServerOptionsTests.test_openhttpservers_reports_socket_error_with_errno.<locals>.make_http_serversc                    r  r'   rw   r  r  r   r   r    r  z]ServerOptionsTests.test_openhttpservers_reports_socket_error_with_errno.<locals>.record_usager   zBCannot open an HTTP server: socket.error reported errno.EPERM (%d)r   )	r   r   rZ  r  r[  rc   rd   r   r]  r   r3  r   rZ  r  rO  r   r  r   4test_openhttpservers_reports_socket_error_with_errno  s   
zGServerOptionsTests.test_openhttpservers_reports_socket_error_with_errnoc                    d   t  }|  }dd }||_g   fdd}||_|| | t d d}|  d | d S )Nc                 S   s
   t d)Nzuh oh)r@  rs   rX  r   r   r   rZ    r   z^ServerOptionsTests.test_openhttpservers_reports_other_socket_errors.<locals>.make_http_serversc                    r  r'   rw   r  r  r   r   r    r  zYServerOptionsTests.test_openhttpservers_reports_other_socket_errors.<locals>.record_usager   z7Cannot open an HTTP server: socket.error reported uh ohr   r   r   rZ  r  r[  rc   rd   r^  r   r  r   0test_openhttpservers_reports_other_socket_errors  s   
zCServerOptionsTests.test_openhttpservers_reports_other_socket_errorsc                    r`  )Nc                 S   s   t d)Nnot prefixed with help)r(   rX  r   r   r   rZ    s   zWServerOptionsTests.test_openhttpservers_reports_value_errors.<locals>.make_http_serversc                    r  r'   rw   r  r  r   r   r    r  zRServerOptionsTests.test_openhttpservers_reports_value_errors.<locals>.record_usager   rc  r   ra  r^  r   r  r   )test_openhttpservers_reports_value_errors  s   
z<ServerOptionsTests.test_openhttpservers_reports_value_errorsc                 C   s0   t  }|  }dd }||_| t|j| d S )Nc                 S   s   t r'   )OverflowErrorrX  r   r   r   rZ    s   zgServerOptionsTests.test_openhttpservers_does_not_catch_other_exception_types.<locals>.make_http_servers)r   r   rZ  rC   re  r[  )r   r3  r   rZ  r   r   r   9test_openhttpservers_does_not_catch_other_exception_types  s   zLServerOptionsTests.test_openhttpservers_does_not_catch_other_exception_typesc                 C   s"   |   }|d }| |d d S )NzNo user specified to setuid to!r   drop_privilegesrc   r   r   r   r   r   r   test_drop_privileges_user_none  s   
z1ServerOptionsTests.test_drop_privileges_user_noner  )r   N   "   )r  z	os.getuidrk  c                 C   s&   |   }|t }| |d  d S r'   )r   rh  rn   getuidrc   ri  r   r   r   &test_drop_privileges_nonroot_same_user  s   z9ServerOptionsTests.test_drop_privileges_nonroot_same_user)r   N7   rl  c                 C   s"   |   }|d}| |d d S )Nri   z$Can't drop privilege as nonroot userrg  ri  r   r   r   +test_drop_privileges_nonroot_different_user  s   
z>ServerOptionsTests.test_drop_privileges_nonroot_different_userc                 C   s>   |   }dd |_t |_|  |jj  |jj  d S )Nc                   S   s   d S r'   r   r   r   r   r   r}     s    zYServerOptionsTests.test_daemonize_notifies_poller_before_and_after_fork.<locals>.<lambda>)r   
_daemonizer   r  	daemonizebefore_daemonizeassert_called_once_withafter_daemonizer   r   r   r   4test_daemonize_notifies_poller_before_and_after_fork  s   
zGServerOptionsTests.test_daemonize_notifies_poller_before_and_after_forkN)r   r    r!   r   r   r  r   r   r   r   ro  rv  ry  r   r   r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r  r  r  r%  r'  r)  r*  r/  r5  r6  r:  r  r<  rM  rP  rW  rX  r\  r^  r_  ra  rd  rg  rh  rj  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r!  r"  r#  r$  r%  r'  r(  r)  r*  r-  r/  r0  r1  r2  r3  r=  r?  rB  rD  rN  rO  rU  r\  r_  rb  rd  rf  rj  rn  rp  rv  r   r   r   r   r	    s$    D		##	


	

	


2'(%$.4Y@#$r	  c                   @   s\   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )ProcessConfigTestsc                 C   r   )Nr   )ProcessConfig)r   rx  )r   rx  r   r   r   r     r   z"ProcessConfigTests._getTargetClassc                 O   D   i }dD ]}|||< qdD ]}d||< q| | |  |i |S N)r5   rJ  r4  r5  rH  rK  rL  rN  rO  rP  rQ  rG  rH  rc  rT  stderr_capture_maxbytesstderr_events_enabledrf  rR  rU  rV  rW  r|   rI  rF  )rZ  rX  stderr_logfile_backupsstderr_logfile_maxbytesr!  r*   r   r   argkwdefaultsr5   r   r   r   r   #     



zProcessConfigTests._makeOnec                 C   s,   t  }| j|d d}| | |  d S )NrF  r
   r   rc   get_pathr   r?   r   r   r   r   .test_get_path_env_is_None_delegates_to_options6  s   zAProcessConfigTests.test_get_path_env_is_None_delegates_to_optionsc                 C   s0   t  }| j|ddid}| | |  d S )Nr  r  r  r  r  r   r   r   8test_get_path_env_dict_with_no_PATH_delegates_to_options;  s   zKProcessConfigTests.test_get_path_env_dict_with_no_PATH_delegates_to_optionsc                 C   sD   t  }| j|ddid}| | |  | | g d d S )Nr]  z/a:/b:/cr  )z/az/bz/c)r
   r   assertNotEqualr  rc   r  r   r   r   (test_get_path_env_dict_with_PATH_uses_it@  s   z;ProcessConfigTests.test_get_path_env_dict_with_PATH_uses_itc                 C   sT   t  }| |}ddlm} ||_||_|  | |j|j | |j|j d S )Nr   )r]  )	r
   r   r<   r]  rQ  rT  create_autochildlogsrc   tempfile_name)r   r?   r   r]  r   r   r   test_create_autochildlogsF  s   
z,ProcessConfigTests.test_create_autochildlogsc                 C   sD   t  }| |}| }ddlm} | |j| | |jd  d S )Nr   
Subprocessr
   r   make_processsupervisor.processr  rc   r  r  r   r?   r   processr  r   r   r   test_make_processP  s   
z$ProcessConfigTests.test_make_processc                 C   F   t  }| |}|d}ddlm} | |j| | |jd d S )NrQ   r   r  r  r  r   r   r   test_make_process_with_groupX     

z/ProcessConfigTests.test_make_process_with_groupc           
   	   C   s"  t  }| |}t {}t ^}|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 W d    n1 srw   Y  W d    d S W d    d S 1 sw   Y  d S )	NFr  r   r   ProcessCommunicationStdoutEvent   r   ProcessCommunicationStderrEvent)r
   r   r   r   r5   rQ  rT  rI  r   make_dispatchersrc   channelsupervisor.eventsr  
event_typer  
r   r?   r   rQ  rT  process1dispatchersr$  r  r  r   r   r   +test_make_dispatchers_stderr_not_redirected`  s2   


"z>ProcessConfigTests.test_make_dispatchers_stderr_not_redirectedc                 C   s   t  }| |}t 1}|j|_t|}||\}}| |d j	d | |d d | |d d  W d    d S 1 s@w   Y  d S )Nr  r   r   )
r
   r   r   r   r5   rQ  r   r  rc   r  )r   r?   r   rQ  r  r  r$  r   r   r   'test_make_dispatchers_stderr_redirectedu  s   

"z:ProcessConfigTests.test_make_dispatchers_stderr_redirectedN)r   r    r!   r   r   r  r  r  r  r  r  r  r  r   r   r   r   rw    s    
rw  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )EventListenerConfigTestsc                 C   r   )Nr   )EventListenerConfig)r   r  )r   r  r   r   r   r     r   z(EventListenerConfigTests._getTargetClassc                 O   ry  rz  r  r  r   r   r   r     r  z!EventListenerConfigTests._makeOnec           
   	   C   sJ  t  }| |}t }t r}|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 W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )NFr,  r  r  r   r   )EventListenerStatesr  r   r  )r
   r   r   r   r5   rQ  rT  rI  r   r  rc   r  r  supervisor.statesr  r  listener_stateACKNOWLEDGEDr  r  r  )
r   r?   r   rQ  rT  r  r  r$  r  r  r   r   r   test_make_dispatchers  s6   


"z.EventListenerConfigTests.test_make_dispatchersN)r   r    r!   r   r   r  r   r   r   r   r    s    r  c                   @   4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )FastCGIProcessConfigTestsc                 C   r   )Nr   r  )r   r  )r   r  r   r   r   r     r   z)FastCGIProcessConfigTests._getTargetClassc                 O   ry  rz  r  r  r   r   r   r     r  z"FastCGIProcessConfigTests._makeOnec                 C   s"   t  }| |}| t|j d S r'   )r
   r   rC   NotImplementedErrorr  r  r   r   r   r    s   
z+FastCGIProcessConfigTests.test_make_processc                 C   r  )NrQ   r   )FastCGISubprocess)r
   r   r  r  r  rc   r  r  )r   r?   r   r  r  r   r   r   r    r  z6FastCGIProcessConfigTests.test_make_process_with_groupc           
   	   C   sF  t  }| |}t }t p}|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	 W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )NFr,  r  Tr  r   r   r  r  r   r  )r
   r   r   r   r5   rQ  rT  rI  r   r  rc   r  r  r  r  r  r  r  r   r   r   r    s6   


"z/FastCGIProcessConfigTests.test_make_dispatchersN)r   r    r!   r   r   r  r  r  r   r   r   r   r    s    r  c                   @   r  )ProcessGroupConfigTestsc                 C   r   )Nr   )ProcessGroupConfig)r   r  )r   r  r   r   r   r     r   z'ProcessGroupConfigTests._getTargetClassc                 C   s   |   ||||S r'   r   )r   r?   r5   rH  rK  r   r   r   r        z ProcessGroupConfigTests._makeOnec                 C   sR   t  }| |ddg }| |j| | |jd | |jd | |jg  d S )Nwhateverr  )r
   r   rc   r?   r5   rH  rI  r  r   r   r   	test_ctor  s   z!ProcessGroupConfigTests.test_ctorc                 C   sB   t  }t|ddg}| |dd|}|  | |d jd d S )Nr  /bin/process1r  r  r   Tr
   r   r   after_setuidrc   autochildlogs_createdr   r?   rK  r   r   r   r   test_after_setuid  s
   z)ProcessGroupConfigTests.test_after_setuidc                 C   sJ   t  }t|ddg}| |dd|}| }ddlm} | |j| d S )Nr  r  r  r  r   )ProcessGroup)r
   r   r   
make_groupr  r  rc   r  )r   r?   rK  r   r  r  r   r   r   test_make_group  s   z'ProcessGroupConfigTests.test_make_groupN)r   r    r!   r   r   r  r  r  r   r   r   r   r    s    r  c                   @   ,   e Zd Zdd Zdd Zdd Zdd Zd	S )
EventListenerPoolConfigTestsc                 C   r   )Nr   )EventListenerPoolConfig)r   r  )r   r  r   r   r   r     r   z,EventListenerPoolConfigTests._getTargetClassc                 C   s   |   |||||||S r'   r   )r   r?   r5   rH  rI  buffer_sizepool_eventsr  r   r   r   r     s   z%EventListenerPoolConfigTests._makeOnec              	   C   sH   t  }t|ddg}| |dd|dg d }|  | |d jd d S )Nr  r  r5   r  r   r   Tr  r  r   r   r   r    s
   z.EventListenerPoolConfigTests.test_after_setuidc              	   C   sP   t  }t|ddg}| |dd|dg d }| }ddlm} | |j| d S )Nr  r  r5   r  r   r   )EventListenerPool)r
   r   r   r  r  r  rc   r  )r   r?   rK  r   r  r  r   r   r   r    s   z,EventListenerPoolConfigTests.test_make_groupN)r   r    r!   r   r   r  r  r   r   r   r   r    s
    r  c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )FastCGIGroupConfigTestsc                 C   r   )Nr   r  )r   r  )r   r  r   r   r   r   &  r   z'FastCGIGroupConfigTests._getTargetClassc                 O      |   |i |S r'   r   r   r   r  r   r   r   r   *  r  z FastCGIGroupConfigTests._makeOnec                 C   sj   t  }td}| |ddg |}| |j| | |jd | |jd | |jg  | |j| d S Nr`   r  r  )	r
   r   r   rc   r?   r5   rH  rI  r  )r   r?   sock_configr   r   r   r   r  -  s   z!FastCGIGroupConfigTests.test_ctorc                 C   sZ   t  }td}| |ddg |}td}| |ddg |}| ||k | ||k d S r  r
   r   r   r   rt  r   r?   sock_config1	instance1sock_config2	instance2r   r   r   test_same_sockets_are_equal7     z3FastCGIGroupConfigTests.test_same_sockets_are_equalc                 C   sZ   t  }td}| |ddg |}td}| |ddg |}| ||k | ||k d S )Nr`   r  r  r  r  r  r   r   r   test_diff_sockets_are_not_equalB  r  z7FastCGIGroupConfigTests.test_diff_sockets_are_not_equalc                 C   sF   t  }td}| |ddg |}| }ddlm} | |j| d S )Nr`   r5   r  r   )FastCGIProcessGroup)r
   r   r   r  r  r  rc   r  )r   r?   r  r   r  r  r   r   r   r  M  s   z'FastCGIGroupConfigTests.test_make_groupN)	r   r    r!   r   r   r  r  r  r  r   r   r   r   r  %  s    
r  c                   @   r  )
SignalReceiverTestsc                 C   s&   ddl m} | }| | d  d S )Nr   SignalReceiver)r   r  rc   r  r   r  srr   r   r   test_returns_None_initiallyV  s   z/SignalReceiverTests.test_returns_None_initiallyc                 C   sf   ddl m} | }|tjd |tjd | | tj | | tj | | d  d S Nr   r  frame)r   r  r  rS  r[  r  rc   r  r  r   r   r   &test_returns_signals_in_order_received[  s   z:SignalReceiverTests.test_returns_signals_in_order_receivedc                 C   sT   ddl m} | }|tjd |tjd | | tj | | d  d S r  )r   r  r  rS  r[  rc   r  r  r   r   r   %test_does_not_queue_duplicate_signalsd  s   z9SignalReceiverTests.test_does_not_queue_duplicate_signalsc                 C   sv   ddl m} | }|tjd | | tj | | d  |tjd | | tj | | d  d S r  )r   r  r  rS  r[  rc   r  r  r  r   r   r   %test_queues_again_after_being_emptiedl  s   z9SignalReceiverTests.test_queues_again_after_being_emptiedN)r   r    r!   r  r  r  r  r   r   r   r   r  U  s
    	r  c                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!S )"UnhosedConfigParserTestsc                 C   r   )Nr   r  )r   r  )r   r  r   r   r   r   w  r   z(UnhosedConfigParserTests._getTargetClassc                 O   r  r'   r   r  r   r   r   r   {  r  z!UnhosedConfigParserTests._makeOnec                 C   s6   |   }|d ddlm} | |j|jdd d S )N[supervisord]
r   )ConfigParserr3  missing)r   r  r  r  rC   NoOptionErrorsaneget)r   r  r  r   r   r   test_saneget_no_default~  s   
z0UnhosedConfigParserTests.test_saneget_no_defaultc                 C   s2   |   }|d |jdddd}| |d d S )Nr  r3  r  rQ   r4   r   r  r  rc   r   r  resultr   r   r   test_saneget_with_default     
z2UnhosedConfigParserTests.test_saneget_with_defaultc                 C   s<   |   }ddi|_|d |jdddd}| |d d S )Nr>  r  r  r3  r   %(pet)sr  r   rZ  r  r  rc   r  r   r   r   $test_saneget_with_default_and_expand  s
   

z=UnhosedConfigParserTests.test_saneget_with_default_and_expandc                 C   s>   |   }ddi|_|d |jddddd}| |d d S )	Nr>  r  r  r3  r   r  F)r4   	do_expandr  r  r   r   r   #test_saneget_with_default_no_expand  s   

z<UnhosedConfigParserTests.test_saneget_with_default_no_expandc                 C   s2   |   }|d |jdddd}| |d d S )N[supervisord]
foo=%(pet)s
r3  r   F)r  r  r  r  r   r   r   !test_saneget_no_default_no_expand  r  z:UnhosedConfigParserTests.test_saneget_no_default_no_expandc                 C   s8   |   }ddi|_|d |dd}| |d d S )Nr>  r  r  r3  r   r  r  r   r   r   (test_saneget_expands_instance_expansions  s
   

zAUnhosedConfigParserTests.test_saneget_expands_instance_expansionsc                 C   s@   |   }ddi|_|d |jddddid}| |d d S )Nr>  r  r  r3  r   rm  )rZ  r  r  r   r   r   #test_saneget_expands_arg_expansions  s   

z<UnhosedConfigParserTests.test_saneget_expands_arg_expansionsc                 C   s.   |   }|d|j  | |dd d S )Nz[%s]
foo=bar
r   r   )r   r  	mysectionrc   
getdefaultr   r  r   r   r   +test_getdefault_does_saneget_with_mysection  s   zDUnhosedConfigParserTests.test_getdefault_does_saneget_with_mysectionc                 C   sf   |   }tjdd}|d |  ||j}W d    n1 s$w   Y  | ||jg d S Nrz  r{  [foo]
r   r   r   r   r}  r2  r5   rc   r   r  r   ok_filenamesr   r   r   test_read_filenames_as_string  s   
z6UnhosedConfigParserTests.test_read_filenames_as_stringc                 C   sh   |   }tjdd}|d |  ||jg}W d    n1 s%w   Y  | ||jg d S r  r  r  r   r   r   test_read_filenames_as_list  s   
z4UnhosedConfigParserTests.test_read_filenames_as_listc                 C   s   t jt jtd}|  }tjdd}|d |	  |
||jg}W d    n1 s1w   Y  | ||jg d S )Nr   rz  r{  r  )rn   r   r   r   r   r   r   r   r   r}  r2  r5   rc   )r   r   r  r   r   r   r   r   3test_read_returns_ok_filenames_like_rawconfigparser  s   
zLUnhosedConfigParserTests.test_read_returns_ok_filenames_like_rawconfigparserc                 C   s   |   }| |ji  d S r'   )r   rc   section_to_filer  r   r   r   )test_read_section_to_file_initially_empty  s   zBUnhosedConfigParserTests.test_read_section_to_file_initially_emptyc                 C   sl   |   }tjdd}|d |  ||jg W d    n1 s%w   Y  | |jd |j d S )Nrz  r{  r  r   	r   r   r   r   r}  r2  r5   rc   r  )r   r  r   r   r   r   'test_read_section_to_file_read_one_file  s   
z@UnhosedConfigParserTests.test_read_section_to_file_read_one_filec              	   C   s   |   }tjdd9}tjdd#}|d |  |d |  ||j|jg W d    n1 s7w   Y  W d    n1 sFw   Y  | |jd |j | |jd |j d S )Nrz  r{  r  z[bar]
r   r   r  )r   r  rL  rM  r   r   r   -test_read_section_to_file_read_multiple_files  s   

zFUnhosedConfigParserTests.test_read_section_to_file_read_multiple_filesN)r   r    r!   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r  v  s"    	r  c                   @   s   e Zd Zdd Zdd ZdS )UtilFunctionsTestsc                 C   s4   ddl m} | |ddd | |ddd d S )Nr   )make_namespecr  r  zgroup:process)r   r
  rc   )r   r
  r   r   r   test_make_namespec  s   z%UtilFunctionsTests.test_make_namespecc                 C   sT   ddl m} |}| |dd | |dd | |dd | |d	d d S )
Nr   )split_namespeczprocess:group)r  r  r  )r  r  zgroup:)r  Nzgroup:*)r   r  rc   )r   r  r   r   r   r   test_split_namespec  s   z&UtilFunctionsTests.test_split_namespecN)r   r    r!   r  r  r   r   r   r   r	    s    r	  )(__doc__rn   r9  r   r@  unittestrS  r   r   r  r  r   r   r  r   r   r   supervisor.loggersr   r   r	   r
   r   r   r   r   r   TestCaser   r   r	  rw  r  r  r  r  r  r  r  r	  r   r   r   r   <module>   st     h 7                      zb0<0!o