o
    ¯bv  ã                   @   sT   d Z ddlZddlmZ ddlmZ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.
é    N)ÚStringIO)ÚdeferÚreactor)Ú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                    óv   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                    ó"   ˆ j }| ¡ }ˆ d|v |¡ d S )Ns,   -m twisted [options] plugin [plugin_options]©ÚoutFÚgetvalueÚ
assertTrue©ÚignÚfÚoutput©Ú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                    r   )z6Invoking python -m twisted.trial should execute trial.r	   ztwisted.trialr   Nr   r   r   r   c                    r   )Ns   -j, --jobs= r   r   r   r   r   r   8   s   z*MainTests.test_trial.<locals>.processEnded)r    r!   r   r   r"   r#   r   r$   r%   r&   Útwisted.trialr   r'   r(   r)   r*   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Ú )	r   r'   r    Útwisted.__main__r   r   ÚrestoreÚassertEqualr   )r   r   Úmonkeyr
   r   r   r   Útest_twisted_import@   s   zMainTests.test_twisted_importN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r-   r/   r6   r   r   r   r   r      s
    r   )r:   r    Úior   Útwisted.internetr   r   Útwisted.test.test_processr   Útwisted.trial.unittestr   r   r   r   r   r   Ú<module>   s   