HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/supervisor/tests/__pycache__/test_dispatchers.cpython-36.pyc
3

�k�`���@s�ddlZddlZddlZddlmZddlmZddlmZddlmZddlm	Z	ddlm
Z
Gdd	�d	ej�ZGd
d�dej�Z
Gdd
�d
ej�ZGdd�dej�ZGdd�dej�Zdd�Zedkr�ejdd�dS)�N)�as_bytes)�DummyOptions)�DummyProcess)�DummyPConfig)�DummyLogger)�
DummyEventc@sFeZdZdd�Zdd�Zdd�Zdd
d�Zdd
�Zdd�Zdd�Z	dS)�PDispatcherTestscCsddlm}|�dS)Nr)�clear)�supervisor.eventsr	)�selfr	�r�&/usr/lib/python3.6/test_dispatchers.py�setUpszPDispatcherTests.setUpcCsddlm}|�dS)Nr)r	)r
r	)rr	rrr
�tearDownszPDispatcherTests.tearDowncCsddlm}|S)Nr)�PDispatcher)�supervisor.dispatchersr)rrrrr
�_getTargetClasssz PDispatcherTests._getTargetClassN�stdoutrcCs|j�|||�S)N)r)r�process�channel�fdrrr
�_makeOneszPDispatcherTests._makeOnecCs|j�}|jt|j�dS)N)r�assertRaises�NotImplementedError�readable)r�instrrr
�
test_readableszPDispatcherTests.test_readablecCs|j�}|jt|j�dS)N)rrr�writable)rrrrr
�
test_writable!szPDispatcherTests.test_writablecCs|j�}|j|j�d�dS)N)r�assertEqual�flush)rrrrr
�
test_flush%szPDispatcherTests.test_flush)Nrr)
�__name__�
__module__�__qualname__rrrrrrr!rrrr
r
s
rc@seZdZdd�Zdd�Zdd�ZdGdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFS)H�POutputDispatcherTestscCsddlm}|�dS)Nr)r	)r
r	)rr	rrr
r*szPOutputDispatcherTests.setUpcCsddlm}|�dS)Nr)r	)r
r	)rr	rrr
r.szPOutputDispatcherTests.tearDowncCsddlm}|S)Nr)�POutputDispatcher)rr&)rr&rrr
r2sz&POutputDispatcherTests._getTargetClassrcCs.ddlm}|j|jd�}|j�|||d�S)Nr)�events)r�stderr)�
supervisorr'�ProcessCommunicationStdoutEventZProcessCommunicationStderrEventr)rrrr'rrr
r6s
zPOutputDispatcherTests._makeOnecCs8t�}t|dd�}t|�}|j|�}|j|j�d�dS)N�process1z
/bin/process1F)rrrrrr)r�options�configr�
dispatcherrrr
r=s

z$POutputDispatcherTests.test_writablecCs>t�}t|dd�}t|�}|j|�}d|_|j|j�d�dS)Nr+z
/bin/process1FT)rrrr�closedrr)rr,r-rr.rrr
�test_readable_openDs
z)POutputDispatcherTests.test_readable_opencCs>t�}t|dd�}t|�}|j|�}d|_|j|j�d�dS)Nr+z
/bin/process1TF)rrrrr/rr)rr,r-rr.rrr
�test_readable_closedLs
z+POutputDispatcherTests.test_readable_closedcCs6t�}t|dd�}t|�}|j|�}|jt|j�dS)Nr+z
/bin/process1)rrrrrr�handle_write_event)rr,r-rr.rrr
�test_handle_write_eventTs

z.POutputDispatcherTests.test_handle_write_eventcCsPt�}d|_t|dddd�}t|�}|j|�}|j|j�d�|j|jd�dS)Nsabcr+z
/bin/process1�d)�stdout_capture_maxbytes)r�
readfd_resultrrrr�handle_read_event�
output_buffer)rr,r-rr.rrr
�test_handle_read_event[s
z-POutputDispatcherTests.test_handle_read_eventcCsht�}d|_t|dddd�}t|�}|j|�}|j|j�|j|j�d�|j|j	d�|j
|j�dS)N�r+z
/bin/process1r4)r5)rr6rrrZassertFalser/rr7r8�
assertTrue)rr,r-rr.rrr
�%test_handle_read_event_no_data_closeses
z<POutputDispatcherTests.test_handle_read_event_no_data_closesc	Csht�}t|dd�}t|�}|j|�}ytd��Wn|j�YnX|jjd}|j|j	d�|�dS)N�testz/test�foorz,uncaptured python exception, closing channel)
rrrr�
ValueError�handle_error�logger�datar;�
startswith)rr,r-rr.�resultrrr
�test_handle_errorqs
z(POutputDispatcherTests.test_handle_errorcs�t�}t|ddddd�}t|�}d|_|j|�}d|_dd	�|j_g��fd
d�}dd
lm	}|j
|jj|�|j
�|jt��d��d}|j|j|�|j|jd�|j|jd�dS)Nr+z
/bin/process1z/tmp/fooi�)�stdout_logfiler5i�TcSsdS)N�hallooorrrrr
�<lambda>�szLPOutputDispatcherTests.test_toggle_capturemode_sends_event.<locals>.<lambda>cs�j|�dS)N)�append)�event)�Lrr
�doit�szHPOutputDispatcherTests.test_toggle_capturemode_sends_event.<locals>.doitr)r'�rG)rrr�pidrZcapturemode�
capturelog�getvaluer)r'�	subscribe�
EventTypesZPROCESS_COMMUNICATIONZtoggle_capturemoder�lenrrB)rr,r-rr.rLr'rJr)rKr
�#test_toggle_capturemode_sends_event~s&
z:POutputDispatcherTests.test_toggle_capturemode_sends_eventcCs�t�}t|dddd�}t|�}|j|�}|j�|j|jjdjd�|j|jjdj	d�|j|j
jdjd�|j|j
jdj	d�dS)Nr+z
/bin/process1z/tmp/foo)rFrT)rrrr�
removelogsr�	normallog�handlers�reopened�removed�childlog)rr,r-rr.rrr
�test_removelogs�s
z&POutputDispatcherTests.test_removelogscCs`t�}t|dddd�}t|�}|j|�}|j�|j|jjdjd�|j|j	jdjd�dS)Nr+z
/bin/process1z/tmp/foo)rFrT)
rrrr�
reopenlogsrrZrWrXrV)rr,r-rr.rrr
�test_reopenlogs�s
z&POutputDispatcherTests.test_reopenlogscCs�t�}ddlm}|jj|_t|dddd�}t|�}|j|�}d|_	|j
�|j|jj
dg�|j|jj
dd�|j|j	d	�dS)
Nr)�loggersr+z
/bin/process1z/tmp/foo)rF�az'process1' stdout output:
ar:)rr)r^�LevelsByName�TRAC�loglevelrrrr8�
record_outputrrZrBrA)rr,r^r-rr.rrr
�&test_record_output_log_non_capturemode�s

z=POutputDispatcherTests.test_record_output_log_non_capturemodecs�t�}t|dddd�}t|�}|j|d�}d|_g��fdd�}d	d
lm}|j|jj	|�|j
�|jt��d��d	}|j|j
|�|j|jd�dS)Nr+z
/bin/process1T)�stdout_events_enabledrshello from stdoutcs�j|�dS)N)rI)rJ)rKrr
rL�szWPOutputDispatcherTests.test_record_output_emits_stdout_event_when_enabled.<locals>.doitr)r'rM)rrrrr8r)r'rQrR�PROCESS_LOG_STDOUTrcrrSrrB)rr,r-rr.rLr'rJr)rKr
�2test_record_output_emits_stdout_event_when_enabled�szIPOutputDispatcherTests.test_record_output_emits_stdout_event_when_enabledcsxt�}t|dddd�}t|�}|j|d�}d|_g��fdd�}d	d
lm}|j|jj	|�|j
�|jt��d	�dS)Nr+z
/bin/process1F)rershello from stdoutcs�j|�dS)N)rI)rJ)rKrr
rL�sz`POutputDispatcherTests.test_record_output_does_not_emit_stdout_event_when_disabled.<locals>.doitr)r')
rrrrr8r)r'rQrRrfrcrrS)rr,r-rr.rLr'r)rKr
�;test_record_output_does_not_emit_stdout_event_when_disabled�szRPOutputDispatcherTests.test_record_output_does_not_emit_stdout_event_when_disabledcs�t�}t|dddd�}t|�}|j|d�}d|_g��fdd�}d	d
lm}|j|jj	|�|j
�|jt��d��d	}|j|j
|�|j|jd�dS)Nr+z
/bin/process1T)�stderr_events_enabledr(shello from stderrcs�j|�dS)N)rI)rJ)rKrr
rL�szWPOutputDispatcherTests.test_record_output_emits_stderr_event_when_enabled.<locals>.doitr)r'rM)rrrrr8r)r'rQrR�PROCESS_LOG_STDERRrcrrSrrB)rr,r-rr.rLr'rJr)rKr
�2test_record_output_emits_stderr_event_when_enabled�szIPOutputDispatcherTests.test_record_output_emits_stderr_event_when_enabledcsxt�}t|dddd�}t|�}|j|d�}d|_g��fdd�}d	d
lm}|j|jj	|�|j
�|jt��d	�dS)Nr+z
/bin/process1F)rir(shello from stderrcs�j|�dS)N)rI)rJ)rKrr
rL�sz`POutputDispatcherTests.test_record_output_does_not_emit_stderr_event_when_disabled.<locals>.doitr)r')
rrrrr8r)r'rQrRrjrcrrS)rr,r-rr.rLr'r)rKr
�;test_record_output_does_not_emit_stderr_event_when_disabled�szRPOutputDispatcherTests.test_record_output_does_not_emit_stderr_event_when_disabledcCsxt�}ddlm}|jj|_t|ddddd�}t|�}|j|�}d|_	|j
�|j|jj
dg�|j|jj
dd	�dS)
Nr)r^r+z
/bin/process1z/tmp/foor4)rFr5s!stdout string longer than a tokenz;'process1' stdout output:
stdout string longer than a token)rr)r^r`rarbrrrr8rcrrZrBrA)rr,r^r-rr.rrr
�7test_record_output_capturemode_string_longer_than_tokens


zNPOutputDispatcherTests.test_record_output_capturemode_string_longer_than_tokencCsZt�}t|ddddd�}t|�}|j|�}d|_|j�|j|jjg�|j|jd�dS)Nr+z
/bin/process1z/tmp/foor4)rFr5r_)	rrrrr8rcrrZrB)rr,r-rr.rrr
�;test_record_output_capturemode_string_not_longer_than_tokens
zRPOutputDispatcherTests.test_record_output_capturemode_string_not_longer_than_tokencsdddlm}ddlm}g��fdd�}|||�|j}|j}|d|}t�}ddlm}||_d}	t|d	d
|	dd�}
t	|
�}|j
|�}z�||_|j�|j
tjj|	�d�|j
t|j�d�|j
t��d
��d}
ddlm}|j
|
j|�|j
|
j|�|j
|
jd�|j
|
jd�Wdy"|jj�|jj�tj|	�Wnttfk
�r\YnXXdS)Nr)�ProcessCommunicationEvent)rQcs�j|�dS)N)rI)rJ)r'rr
rL-szJPOutputDispatcherTests.test_stdout_capturemode_single_buffer.<locals>.doitshello)�	getLoggerz/tmp/logr+z
/bin/process1i�)rFr5rM)r*r)r
rorQ�BEGIN_TOKEN�	END_TOKENr�supervisor.loggersrprrrr8rcr�os�path�getsizerSr*�	__class__rrrBrO�closerZ�remove�OSError�IOError)rrorQrLrqrrrBr,rp�logfiler-rr.rJr*r)r'r
�%test_stdout_capturemode_single_buffer'sF



z<POutputDispatcherTests.test_stdout_capturemode_single_bufferc(s�ddlm}ddlm}g��fdd�}|||�ddl}tt|d|j��}t|j�d}|j}|j	}|||||}	d}
|	j
|
�}|d|
}|d	|
}
|d
}t�}ddlm
}||_
d}t|d
d|dd�}t|�}|j|�}�z�||_|j�dd�|jjD�t|d��}|j|j�|�WdQRX|j|j|t|�d��|jt��d�|j|
7_|j�|jt��d�dd�|jjD�t|d��}|j|j�|�WdQRX|j|j|t|�d��|jt��d�|j|7_|j�dd�|jjD�t|d��}|j|j�|d
�WdQRX|jt��d	��d}ddlm}|j|j|�|j|j|�|j|jd�|j|j|�Wdy"|jj�|jj�t j!|�Wnt"t#fk
�r�YnXXdS)Nr)ro)rQcs�j|�dS)N)rI)rJ)r'rr
rLWszMPOutputDispatcherTests.test_stdout_capturemode_multiple_buffers.<locals>.doit�letters��:rM�)rpz/tmp/logr+z
/bin/process1i')rFr5cSsg|]}|j��qSr)r )�.0�xrrr
�
<listcomp>uszSPOutputDispatcherTests.test_stdout_capturemode_multiple_buffers.<locals>.<listcomp>�rbcSsg|]}|j��qSr)r )r�r�rrr
r�~scSsg|]}|j��qSr)r )r�r�rrr
r��s)r*r)$r
rorQ�stringr�getattrZ
ascii_letters�digitsrqrr�splitrrsrprrrr8rcrZrW�openr�readrSr*rwrrrBrOrxrtryrzr{)rrorQrLr�r~r�rqrrrBZcolonZbroken�first�secondZthirdr,rpr|r-rr.�frJr*r)r'r
�(test_stdout_capturemode_multiple_buffersSsv




z?POutputDispatcherTests.test_stdout_capturemode_multiple_bufferscCs�t�}d|_t|dddd�}t|�}|j|�}d}d}||_|j�|jt|j	j
�d�|j|j	j
d	|�d
|_||_|j�|jt|j	j
�d�|j|j	j
d|�dS)NTr+z
/bin/process1z/tmp/foo)rFs4Hello world... this is longer than a token!s+Hello world... this is longer than a token!rMrFr�)r�
strip_ansirrrr8rcrrSrZrB)rr,r-rr.�ansi�noansirrr
�test_strip_ansi�s"
z&POutputDispatcherTests.test_strip_ansicCs|t�}t|dd�}t|�}|j|�}|j|j|�|j|jd�|j|jd�|j|jd�|j|j	d�|j|j
d�dS)Nr+z
/bin/process1rr)rrrrrrrrrOrVrZ)rr,r-rr.rrr
�test_ctor_no_logfiles�s
z,POutputDispatcherTests.test_ctor_no_logfilescCs�t�}t|dddd�}t|�}|j|�}|j|j|�|j|jd�|j|jd�|j|jd�|j|j	j
t�|j|j|j	�dS)Nr+z
/bin/process1z/tmp/foo)rFrr)
rrrrrrrrrOrVrwrrZ)rr,r-rr.rrr
�test_ctor_logfile_only�s
z-POutputDispatcherTests.test_ctor_logfile_onlycCs�t�}t|dddd�}t|�}|j|�}|j|j|�|j|jd�|j|jd�|j|jj	t
�|j|jd�|j|jd�dS)Nr+z
/bin/process1i,)r5rr)
rrrrrrrrrOrwrrVrZ)rr,r-rr.rrr
�test_ctor_capturelog_only�s
z0POutputDispatcherTests.test_ctor_capturelog_onlycCstddlm}t�}t|dd|d�d�}t|�}|j|�}|j|j|�|j|jd�|j|j	d�|j|j
d�dS)Nr)�logfile_namer+z
/bin/process1�)rFr)�supervisor.datatypesr�rrrrrrrrrV)rr�r,r-rr.rrr
�(test_ctor_stdout_logfile_is_empty_string�s
z?POutputDispatcherTests.test_ctor_stdout_logfile_is_empty_stringcCs~ddlm}m}t�}t|dd|d�|d�d�}t|�}|j|�}|j|j|�|j|j	d�|j|j
d�|j|jd�dS)	Nr)�booleanr�r+z
/bin/process1�NONE�false)rF�
stdout_syslogr)r�r�r�rrrrrrrrrV)rr�r�r,r-rr.rrr
�5test_ctor_stdout_logfile_none_and_stdout_syslog_false�s
zLPOutputDispatcherTests.test_ctor_stdout_logfile_none_and_stdout_syslog_falsec
Cs�ddlm}m}ddlm}m}ddlm}|�}|j|_	t
|dd|d�|d�d	�}t|�}|j|�}	|j
|	j|�|j
|	jd
�|j
|	jd�|j
t|	jj�d�|j
|	jjdj|�dS)Nr)r�r�)r`�
SyslogHandler)�
ServerOptionsr+z
/bin/process1r��true)rFr�rrM)r�r�r�rsr`r��supervisor.optionsr�rarbrrrrrrrrSrVrWrw)
rr�r�r`r�r�r,r-rr.rrr
�4test_ctor_stdout_logfile_none_and_stdout_syslog_true�s 
zKPOutputDispatcherTests.test_ctor_stdout_logfile_none_and_stdout_syslog_truec
Cs�ddlm}m}ddlm}m}ddlm}|�}|j|_	t
|dd|d�|d�d	�}t|�}|j|�}	|j
|	j|�|j
|	jd
�|j
|	jd�|j
t|	jj�d�|j
|	jjdj|�|	jj�dS)Nr)r�r�)�FileHandlerr`)r�r+z
/bin/process1z/tmp/foor�)rFr�rrM)r�r�r�rsr�r`r�r�rarbrrrrrrrrSrVrWrwrx)
rr�r�r�r`r�r,r-rr.rrr
�4test_ctor_stdout_logfile_str_and_stdout_syslog_falses 
zKPOutputDispatcherTests.test_ctor_stdout_logfile_str_and_stdout_syslog_falsec	s�ddlm}m}ddlm�m}m�ddlm}|�}|j	|_
t|dd|d�|d�d	�}t|�}|j
|�}|j|j|�|j|jd
�|j|jd�|jt|jj�d�|jt�fdd
�|jjD���|jt�fdd
�|jjD���|jj�dS)Nr)r�r�)r�r`r�)r�r+z
/bin/process1z/tmp/foor�)rFr�rr�c3s|]}t|��VqdS)N)�
isinstance)r��h)r�rr
�	<genexpr>!sz]POutputDispatcherTests.test_ctor_stdout_logfile_str_and_stdout_syslog_true.<locals>.<genexpr>c3s|]}t|��VqdS)N)r�)r�r�)r�rr
r�#s)r�r�r�rsr�r`r�r�r�rarbrrrrrrrrSrVrWr;�anyrx)	rr�r�r`r�r,r-rr.r)r�r�r
�3test_ctor_stdout_logfile_str_and_stdout_syslog_trues&
zJPOutputDispatcherTests.test_ctor_stdout_logfile_str_and_stdout_syslog_truecCsbt�}t|dd�}t|�}|j|�}t|�}|jd|k�|j|jd�d�|j|jd�|�dS)Nr+z
/bin/process1r&z"supervisor.tests.base.DummyProcessrMz	(stdout)>���)	rrrr�reprr;�assertNotEqual�find�endswith)rr,r-rr.�dreprrrr
�	test_repr's
z POutputDispatcherTests.test_reprcCsTt�}t|dd�}t|�}|j|�}|j�|j|jd�|j�|j|jd�dS)Nr+z
/bin/process1T)rrrrrxrr/)rr,r-rr.rrr
�
test_close3s
z!POutputDispatcherTests.test_closeN)r)%r"r#r$rrrrrr0r1r3r9r<rErTr[r]rdrgrhrkrlrmrnr}r�r�r�r�r�r�r�r�r�r�r�r�rrrr
r%)sD



,F


r%c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!S)"�PInputDispatcherTestscCsddlm}|S)Nr)�PInputDispatcher)rr�)rr�rrr
r?sz%PInputDispatcherTests._getTargetClasscCsd}|j�||d�S)N�stdinr)r)rrrrrr
rCszPInputDispatcherTests._makeOnecCs2td�}|j|�}d|_d|_|j|j�d�dS)Nr_FT)rr�input_bufferr/rr)rrr.rrr
�test_writable_open_nodataGs

z/PInputDispatcherTests.test_writable_open_nodatacCs2td�}|j|�}d|_d|_|j|j�d�dS)Nr�F)rrr�r/rr)rrr.rrr
�test_writable_open_withdataNs

z1PInputDispatcherTests.test_writable_open_withdatacCs2td�}|j|�}d|_d|_|j|j�d�dS)Nr_TF)rrr�r/rr)rrr.rrr
�test_writable_closed_nodataUs

z1PInputDispatcherTests.test_writable_closed_nodatacCs2td�}|j|�}d|_d|_|j|j�d�dS)Nr�TF)rrr�r/rr)rrr.rrr
�test_writable_closed_withdata\s

z3PInputDispatcherTests.test_writable_closed_withdatacCs&td�}|j|�}|j|j�d�dS)NF)rrrr)rrr.rrr
rcs
z#PInputDispatcherTests.test_readablecCsPt�}t|dd�}t|�}|j|�}d|_|j|j�d�|j|jdd�dS)Nr+z
/bin/process1�halloooor)rrrrr�rr2�written)rr,r-rr.rrr
r3hs
z-PInputDispatcherTests.test_handle_write_eventcCsZt�}t|dd�}t|�}|j|�}|j|jd�|j�|j|jd�|j|ji�dS)Nr=z/testr:)rrrrrr�r2r�)rr,r-rr.rrr
�test_handle_write_event_nodataqs
z4PInputDispatcherTests.test_handle_write_event_nodatacCs�t�}t|dd�}t|�}|j|�}d|_ddl}t|jtj	|j��|_
|j�|j|jd�|j
|jjdjd��|j
|jjdjd��dS)Nr=z/testr�rr:zfd 0 closed, stopped monitoringz(stdin)>)rrrrr��errnorzZEPIPErt�strerror�write_exceptionr2rr;rArBrCr�)rr,r-rr.r�rrr
�$test_handle_write_event_epipe_raised{s
z:PInputDispatcherTests.test_handle_write_event_epipe_raisedcCsZt�}t|dd�}t|�}|j|�}d|_ddl}t|jtj	|j��|_
|jt|j�dS)Nr=z/testr�r)
rrrrr�r�rzZEBADFrtr�r�rr2)rr,r-rr.r�rrr
�'test_handle_write_event_uncaught_raised�s
z=PInputDispatcherTests.test_handle_write_event_uncaught_raisedcCsdt�}t|dd�}t|�}|j|�}d|_dd|_|j�|jt|j�d�|j|j	dd�dS)Nr=z/testrMr_�2�1r)
rrrrZwrite_acceptr�r2rrSr�)rr,r-rr.rrr
�%test_handle_write_event_over_os_limit�s

z;PInputDispatcherTests.test_handle_write_event_over_os_limitcCs$td�}|j|�}|jt|j�dS)N)rrrrr7)rrr.rrr
r9�s
z,PInputDispatcherTests.test_handle_read_eventc	Csht�}t|dd�}t|�}|j|�}ytd��Wn|j�YnX|jjd}|j|j	d�|�dS)Nr=z/testr>rz,uncaptured python exception, closing channel)
rrrrr?r@rArBr;rC)rr,r-rr.rDrrr
rE�s
z'PInputDispatcherTests.test_handle_errorcCsbt�}t|dd�}t|�}|j|�}t|�}|jd|k�|j|jd�d�|j|jd�|�dS)Nr+z
/bin/process1r�z"supervisor.tests.base.DummyProcessrMz(stdin)>r�)	rrrrr�r;r�r�r�)rr,r-rr.r�rrr
r��s
zPInputDispatcherTests.test_reprcCsTt�}t|dd�}t|�}|j|�}|j�|j|jd�|j�|j|jd�dS)Nr+z
/bin/process1T)rrrrrxrr/)rr,r-rr.rrr
r��s
z PInputDispatcherTests.test_closeN)r"r#r$rrr�r�r�r�rr3r�r�r�r�r9rEr�r�rrrr
r�>s 	

r�c@seZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dES)F�PEventListenerDispatcherTestscCsddlm}|�dS)Nr)r	)r
r	)rr	rrr
r�sz#PEventListenerDispatcherTests.setUpcCsddlm}|�dS)Nr)r	)r
r	)rr	rrr
r�sz&PEventListenerDispatcherTests.tearDowncCsddlm}|S)Nr)�PEventListenerDispatcher)rr�)rr�rrr
r�sz-PEventListenerDispatcherTests._getTargetClasscCsd}|j�||d�S)Nrr)r)rrrrrr
r�sz&PEventListenerDispatcherTests._makeOnecCs8t�}t|dd�}t|�}|j|�}|j|j�d�dS)Nr+z
/bin/process1F)rrrrrr)rr,r-rr.rrr
r�s

z+PEventListenerDispatcherTests.test_writablecCs>t�}t|dd�}t|�}|j|�}d|_|j|j�d�dS)Nr+z
/bin/process1FT)rrrrr/rr)rr,r-rr.rrr
r0�s
z0PEventListenerDispatcherTests.test_readable_opencCs>t�}t|dd�}t|�}|j|�}d|_|j|j�d�dS)Nr+z
/bin/process1TF)rrrrr/rr)rr,r-rr.rrr
r1�s
z2PEventListenerDispatcherTests.test_readable_closedcCs6t�}t|dd�}t|�}|j|�}|jt|j�dS)Nr+z
/bin/process1)rrrrrrr2)rr,r-rr.rrr
r3�s

z5PEventListenerDispatcherTests.test_handle_write_eventcCs�t�}t|dddd�}t|�}ddlm}|j|_|j|�}|j|_	|j
|j�d�|j
|j|j�|j
|j
d�|j
t|jj�d�|j
|jjd|j�dS)	Nr+z
/bin/process1z/tmp/foo)rFr)�EventListenerStatesr:rM)rrrrr��ACKNOWLEDGED�listener_staterZREADY_FOR_EVENTS_TOKENr6rr7�READY�state_bufferrSrZrB)rr,r-rr�r.rrr
�9test_handle_read_event_calls_handle_listener_state_change�s
zWPEventListenerDispatcherTests.test_handle_read_event_calls_handle_listener_state_changecCsjt�}d|_t|dd�}t|�}|j|�}|j|j�d�|j|jd�ddlm	}|j|j
j|j�dS)Nr�r+z
/bin/process1r:r)r�)
rr6rrrrr7r�rr�rr�r�)rr,r-rr.r�rrr
�test_handle_read_event_nodatas

z;PEventListenerDispatcherTests.test_handle_read_event_nodatacCsLt�}d|_t|dd�}t|�}|j|�}|j|j�d�|j|jd�dS)Ns"supercalifragilisticexpialidociousr+z
/bin/process1)rr6rrrrr7rZ)rr,r-rr.rrr
�%test_handle_read_event_logging_nologss
zCPEventListenerDispatcherTests.test_handle_read_event_logging_nologscCsjt�}d|_t|dddd�}t|�}|j|�}|j|j�d�|jt|jj	�d�|j|jj	dd�dS)Ns"supercalifragilisticexpialidociousr+z
/bin/process1z/tmp/foo)rFrMr)
rr6rrrrr7rSrZrB)rr,r-rr.rrr
�'test_handle_read_event_logging_childlogs
zEPEventListenerDispatcherTests.test_handle_read_event_logging_childlogcCs�t�}t|dd�}t|�}ddlm}|j|�}|j|_d|_|j	|j
�d�|j	|jd�|j	|jjg�|j	|j|j�dS)Nr+z
/bin/process1r)r�swhateverr:)
rrrrr�r�UNKNOWNr�r�r�handle_listener_state_changerArB)rr,r-rr�r.rrr
�.test_handle_listener_state_change_from_unknown*s
zLPEventListenerDispatcherTests.test_handle_listener_state_change_from_unknowncCs�t�}t|dd�}t|�}ddlm}|j|�}|j|_d|_|j	|j
�d�|j	|jd�|j	|jjdd�|j	|j|j
�dS)Nr+z
/bin/process1r)r�sREADY
r:zprocess1: ACKNOWLEDGED -> READY)rrrrr�rr�r�r�rr�rArBr�)rr,r-rr�r.rrr
�7test_handle_listener_state_change_acknowledged_to_ready7s
zUPEventListenerDispatcherTests.test_handle_listener_state_change_acknowledged_to_readycCs�t�}t|dd�}t|�}ddlm}|j|�}|j|_d|_|j	|j
�d�|j	|jd�|j	|jjdd�|j	|jjdd	�|j	|j|j
�dS)
Nr+z
/bin/process1r)r�sREADY
garbage
r:zprocess1: ACKNOWLEDGED -> READYrMzprocess1: READY -> UNKNOWN)rrrrr�rr�r�r�rr�rArBr�)rr,r-rr�r.rrr
�6test_handle_listener_state_change_acknowledged_gobblesEs
zTPEventListenerDispatcherTests.test_handle_listener_state_change_acknowledged_gobblescCs�t�}t|dd�}t|�}ddlm}|j|�}|j|_d|_|j	|j
�d�|j	|jd�|j	|jjg�|j	|j|j�dS)Nr+z
/bin/process1r)r�sRE)
rrrrr�rr�r�r�rr�rArB)rr,r-rr�r.rrr
�>test_handle_listener_state_change_acknowledged_to_insufficientUs
z\PEventListenerDispatcherTests.test_handle_listener_state_change_acknowledged_to_insufficientcCs�t�}t|dd�}t|�}ddlm}|j|�}|j|_d|_|j	|j
�d�|j	|jd�|j	|jjdd�|j	|jjdd	�|j	|j|j
�dS)
Nr+z
/bin/process1r)r�s
bogus data yor:z!process1: ACKNOWLEDGED -> UNKNOWNrMz�process1: has entered the UNKNOWN state and will no longer receive events, this usually indicates the process violated the eventlistener protocol)rrrrr�rr�r�r�rr�rArBr�)rr,r-rr�r.rrr
�9test_handle_listener_state_change_acknowledged_to_unknowncs
zWPEventListenerDispatcherTests.test_handle_listener_state_change_acknowledged_to_unknowncCs�t�}t|dd�}t|�}ddlm}|j|�}|j|_d|_|j	|j
�d�|j	|jd�|j	|jjdd�|j	|jjdd	�|j	|j|j
�dS)
Nr+z
/bin/process1r)r�s
bogus data yor:zprocess1: READY -> UNKNOWNrMz�process1: has entered the UNKNOWN state and will no longer receive events, this usually indicates the process violated the eventlistener protocol)rrrrr�rr�r�r�rr�rArBr�)rr,r-rr�r.rrr
�2test_handle_listener_state_change_ready_to_unknownus
zPPEventListenerDispatcherTests.test_handle_listener_state_change_ready_to_unknowncCspt�}t|dd�}t|�}ddlm}|j|�}|j|_d|_|j	|j
�d�|j	|jd�|j	|j|j�dS)Nr+z
/bin/process1r)r�s
bogus data yo)rrrrr�r�BUSYr�r�rr�)rr,r-rr�r.rrr
�6test_handle_listener_state_change_busy_to_insufficient�s
zTPEventListenerDispatcherTests.test_handle_listener_state_change_busy_to_insufficientcCs�t�}t|dd�}t|�}ddlm}|j|�}|j|_Gdd�d�}|�|_|�|j_	ddlm
}||jj	_d|_|j
|j�d�|j
|jd	�|j
|jjdd
�|j
|jjdd�|j
|j|j�dS)
Nr+z
/bin/process1r)r�c@seZdZdS)ziPEventListenerDispatcherTests.test_handle_listener_state_change_busy_to_acknowledged_procd.<locals>.DummyN)r"r#r$rrrr
�Dummy�sr�)�default_handlersRESULT 2
OKabcsabczprocess1: event was processedrMzprocess1: BUSY -> ACKNOWLEDGED)rrrrr�rr�r��groupr-r��result_handlerr�rr�rArBr�)rr,r-rr�r.r�r�rrr
�<test_handle_listener_state_change_busy_to_acknowledged_procd�s(


zZPEventListenerDispatcherTests.test_handle_listener_state_change_busy_to_acknowledged_procdcCs�t�}t|dd�}t|�}ddlm}|j|�}|j|_Gdd�d�}|�|_|�|j_	ddlm
}||jj	_d|_|j
|j�d�|j
|jd	�|j
|jjdd
�|j
|jjdd�|j
|j|j�dS)
Nr+z
/bin/process1r)r�c@seZdZdS)zlPEventListenerDispatcherTests.test_handle_listener_state_change_busy_to_acknowledged_rejected.<locals>.DummyN)r"r#r$rrrr
r��sr�)r�sRESULT 4
FAILabcsabczprocess1: event was rejectedrMzprocess1: BUSY -> ACKNOWLEDGED)rrrrr�rr�r�r�r-r�r�r�rr�rArBr�)rr,r-rr�r.r�r�rrr
�?test_handle_listener_state_change_busy_to_acknowledged_rejected�s(


z]PEventListenerDispatcherTests.test_handle_listener_state_change_busy_to_acknowledged_rejectedc
sddlm}ddlm}g��fdd�}|||�t�}t|dd�}t|�}ddlm}|j|�}|j	|_
t�}	|	|_d	|_
|j|j�d�|j|j
d
�|j|jjdd�|j|jjdd
�|j|jjdd�|j|j
|j�|j�dj|�|j�dj|	�dS)Nr)�EventRejectedEvent)rQcs�j|�dS)N)rI)rJ)r'rr
rL�sz]PEventListenerDispatcherTests.test_handle_listener_state_change_busy_to_unknown.<locals>.doitr+z
/bin/process1)r�sbogus data
r:z'process1: bad result line: 'bogus data'rMzprocess1: BUSY -> UNKNOWNr�z�process1: has entered the UNKNOWN state and will no longer receive events, this usually indicates the process violated the eventlistener protocol)r
r�rQrrrrr�rr�r�rrJr�rr�rArBr�r)
rr�rQrLr,r-rr�r.Z
current_eventr)r'r
�1test_handle_listener_state_change_busy_to_unknown�s4

zOPEventListenerDispatcherTests.test_handle_listener_state_change_busy_to_unknowncCs�t�}t|dd�}t|�}ddlm}|j|�}|j|_Gdd�d�}|�|_|�|j_	ddlm
}||jj	_d|_|j
|j�d�|j
|jd	�|j
|jjdd
�|j
|jjdd�|j
|jjd
d�|j
|jjdd�|j
|j|j�dS)Nr+z
/bin/process1r)r�c@seZdZdS)zTPEventListenerDispatcherTests.test_handle_listener_state_busy_gobbles.<locals>.DummyN)r"r#r$rrrr
r��sr�)r�sRESULT 2
OKbogus data
r:zprocess1: event was processedrMzprocess1: BUSY -> ACKNOWLEDGEDr�z!process1: ACKNOWLEDGED -> UNKNOWN�z�process1: has entered the UNKNOWN state and will no longer receive events, this usually indicates the process violated the eventlistener protocol)rrrrr�rr�r�r�r-r�r�r�rr�rArBr�)rr,r-rr�r.r�r�rrr
�'test_handle_listener_state_busy_gobbles�s0


zEPEventListenerDispatcherTests.test_handle_listener_state_busy_gobblescs�ddlm}t�}t|dd�}t|�}g��fdd�}ddlm}||j|�ddlm	}|j
|�}d	d
�}	Gdd�d�}
|
�|_|
�|j_|	|jj_
|j|_|jd
�|jt��d�|j|j|j�|j|jjdd�|j|jjdd�dS)Nr)rQr+z
/bin/process1cs�j|�dS)N)rI)rJ)rKrr
rLszEPEventListenerDispatcherTests.test_handle_result_accept.<locals>.doit)r')r�cSsdS)Nr)rJrDrrr
�handle	szGPEventListenerDispatcherTests.test_handle_result_accept.<locals>.handlec@seZdZdS)zFPEventListenerDispatcherTests.test_handle_result_accept.<locals>.DummyN)r"r#r$rrrr
r�sr�r>zprocess1: event was processedrMzprocess1: BUSY -> ACKNOWLEDGED)r
rQrrrr)r'r�rr�rr�r-r�r�r��
handle_resultrrSr�rArB)rrQr,r-rrLr'r�r.r�r�r)rKr
�test_handle_result_accept�s0



z7PEventListenerDispatcherTests.test_handle_result_acceptcsddlm}t�}t|dd�}t|�}g��fdd�}ddlm}||j|�ddlm	}|j
|�}d	d
�}	Gdd�d�}
|
�|_|
�|j_|	|jj_
|j|_|jd
�|jt��d�|j�dj|j�|j|j|j�|j|jjdd�|j|jjdd�dS)Nr)rQr+z
/bin/process1cs�j|�dS)N)rI)rJ)rKrr
rL szJPEventListenerDispatcherTests.test_handle_result_rejectevent.<locals>.doit)r')r�cSsddlm}||��dS)Nr)�RejectEvent)rr�)rJrDr�rrr
�rejected&szNPEventListenerDispatcherTests.test_handle_result_rejectevent.<locals>.rejectedc@seZdZdS)zKPEventListenerDispatcherTests.test_handle_result_rejectevent.<locals>.DummyN)r"r#r$rrrr
r�)sr�r>rMzprocess1: event was rejectedzprocess1: BUSY -> ACKNOWLEDGED)r
rQrrrr)r'r�rr�rr�r-r�r�r�r�rrSrwr�rArB)rrQr,r-rrLr'r�r.r�r�r)rKr
�test_handle_result_rejectevents2



z<PEventListenerDispatcherTests.test_handle_result_rejecteventcs$ddlm}t�}t|dd�}t|�}g��fdd�}ddlm}||j|�ddlm	}|j
|�}d	d
�}	Gdd�d�}
|
�|_|
�|j_|	|jj_
|	|j_
|j|_|jd
�|jt��d�|j�dj|j�|j|j|j�|j|jjdd�|j|jjdd�|j|jjdd�dS)Nr)rQr+z
/bin/process1cs�j|�dS)N)rI)rJ)rKrr
rL?szHPEventListenerDispatcherTests.test_handle_result_exception.<locals>.doit)r')r�cSst�dS)N)r?)rJrDrrr
�	exceptionEszMPEventListenerDispatcherTests.test_handle_result_exception.<locals>.exceptionc@seZdZdS)zIPEventListenerDispatcherTests.test_handle_result_exception.<locals>.DummyN)r"r#r$rrrr
r�Gsr�r>rMzprocess1: event caused an errorzprocess1: BUSY -> UNKNOWNr�z�process1: has entered the UNKNOWN state and will no longer receive events, this usually indicates the process violated the eventlistener protocol)r
rQrrrr)r'r�rr�rr�r-r�r�r�r�rrSrwr�rArB)rrQr,r-rrLr'r�r.r�r�r)rKr
�test_handle_result_exception9s8



z:PEventListenerDispatcherTests.test_handle_result_exceptionc	Csht�}t|dd�}t|�}|j|�}ytd��Wn|j�YnX|jjd}|j|j	d�|�dS)Nr=z/testr>rz,uncaptured python exception, closing channel)
rrrrr?r@rArBr;rC)rr,r-rr.rDrrr
rE\s
z/PEventListenerDispatcherTests.test_handle_errorcCs`t�}t|dddd�}t|�}|j|�}|j�|j|jjdjd�|j|jjdj	d�dS)Nr+z
/bin/process1z/tmp/foo)rFrT)
rrrrrUrrZrWrXrY)rr,r-rr.rrr
r[is
z-PEventListenerDispatcherTests.test_removelogscCsJt�}t|dddd�}t|�}|j|�}|j�|j|jjdjd�dS)Nr+z
/bin/process1z/tmp/foo)rFrT)	rrrrr\rrZrWrX)rr,r-rr.rrr
r]ss
z-PEventListenerDispatcherTests.test_reopenlogscCs�t�}d|_t|dddd�}t|�}|j|�}d}d}||_|j�|jt|j	j
�d�|j|j	j
d	|�d
|_||_|j�|jt|j	j
�d�|j|j	j
d|�dS)NTr+z
/bin/process1z/tmp/foo)rFs4Hello world... this is longer than a token!s+Hello world... this is longer than a token!rMrFr�)rr�rrrr6r7rrSrZrB)rr,r-rr.r�r�rrr
r�|s"
z-PEventListenerDispatcherTests.test_strip_ansicCs`t�}t|dd�}t|�}|j|�}|j|j|�|j|jd�|j|jd�|j|jd�dS)Nr+z
/bin/process1rr)	rrrrrrrrrZ)rr,r-rr.rrr
�test_ctor_nologfiles�s
z2PEventListenerDispatcherTests.test_ctor_nologfilescCsft�}t|dddd�}t|�}|j|�}|j|j|�|j|jd�|j|jd�|j|jj	t
�dS)Nr+z
/bin/process1z/tmp/foo)rFrr)rrrrrrrrrZrwr)rr,r-rr.rrr
r��s
z4PEventListenerDispatcherTests.test_ctor_logfile_onlycCsbt�}t|dd�}t|�}|j|�}t|�}|jd|k�|j|jd�d�|j|jd�|�dS)Nr+z
/bin/process1r�z"supervisor.tests.base.DummyProcessrMz	(stdout)>r�)	rrrrr�r;r�r�r�)rr,r-rr.r�rrr
r��s
z'PEventListenerDispatcherTests.test_reprcCsTt�}t|dd�}t|�}|j|�}|j�|j|jd�|j�|j|jd�dS)Nr+z
/bin/process1T)rrrrrxrr/)rr,r-rr.rrr
r��s
z(PEventListenerDispatcherTests.test_closeN)%r"r#r$rrrrrr0r1r3r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rEr[r]r�r�r�r�r�rrrr
r��sD
#

	
r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�stripEscapeTestscCsddlm}||�S)Nr)�stripEscapes)rr�)r�sr�rrr
�_callFUT�szstripEscapeTests._callFUTcCs|j|jd�d�dS)Nr:)rr�)rrrr
�test_zero_length_string�sz(stripEscapeTests.test_zero_length_stringcCsd}d}|j|j|�|�dS)Ns4Hello world... this is longer than a token!s+Hello world... this is longer than a token!)rr�)rr�r�rrr
�	test_ansi�szstripEscapeTests.test_ansicCsd}|j|j|�|�dS)Ns+Hello world... this is longer than a token!)rr�)rr�rrr
�test_noansi�szstripEscapeTests.test_noansiN)r"r#r$r�r�r�r�rrrr
r��sr�cCstjtjt�S)N)�unittestZ
findTestCases�sys�modulesr"rrrr
�
test_suite�sr��__main__)ZdefaultTest)r�rtr�Zsupervisor.compatrZsupervisor.tests.baserrrrrZTestCaserr%r�r�r�r�r"�mainrrrr
�<module>s0y