U
    
W[	                     @   s|   d Z ddlmZmZ ddlZddlmZ ddlmZ ddl	m
Z
mZ ddlmZ ddlmZ dd	lmZ G d
d deZdS )z6
Test that twisted scripts can be invoked as modules.
    )divisionabsolute_importN)TwistOptions)trial)deferreactor)NativeStringIO)Accumulator)TestCasec                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )		MainTestsz4Test that twisted scripts can be invoked as modules.c                    sv   t j}t  t  } _tj ||dddgdd  j	  ddl
m} t d|jdg  fd	d
}||S )z0Invoking python -m twisted should execute twist.-mtwisted--helpNenvr   __main__argvc                    s<    j }| dd}t }d|d}|| d S Ns   
   
z{}
zutf-8)outFgetvaluereplacer   formatencodeassertEqualZignfoutputZoptionsmessagepself 8/usr/lib/python3/dist-packages/twisted/test/test_main.pyprocessEnded"   s
    z,MainTests.test_twisted.<locals>.processEnded)sys
executabler	   r   DeferredendedDeferredr   spawnProcess	transport
closeStdinr   r   patch__file__addCallbackr"   cmddr   r%   r#   r    r$   test_twisted   s    
zMainTests.test_twistedc                    sv   t j}t  t  } _tj ||dddgdd  j	  ddl
m} t d|jdg  fd	d
}||S )z6Invoking python -m twisted.trial should execute trial.r   ztwisted.trialr   Nr   r   r   r   c                    s>    j }| dd}t }d|d}|| d S r   )r   r   r   r   ZOptionsr   r   r   r   r    r#   r$   r%   7   s
    z*MainTests.test_trial.<locals>.processEnded)r&   r'   r	   r   r(   r)   r   r*   r+   r,   Ztwisted.trialr   r-   r.   r/   r0   r#   r    r$   
test_trial+   s    
zMainTests.test_trialc                 C   sD   t  }| td|}ddl}| |j |  | | d dS )z2Importing twisted.__main__ does not execute twist.stdoutr   N )	StringIOr-   r&   Ztwisted.__main__Z
assertTruer   Zrestorer   r   )r"   r   Zmonkeyr   r#   r#   r$   test_twisted_import@   s    zMainTests.test_twisted_importN)__name__
__module____qualname____doc__r3   r4   r8   r#   r#   r#   r$   r      s   r   )r<   Z
__future__r   r   r&   Z"twisted.application.twist._optionsr   Ztwisted.scriptsr   Ztwisted.internetr   r   Ztwisted.python.compatr   r7   Ztwisted.test.test_processr	   Ztwisted.trial.unittestr
   r   r#   r#   r#   r$   <module>   s   