o
    ¯b‘  ã                   @   sl   d Z ddlmZ ddlmZmZ ddlZddlm	Z	 ddl	m
Z
mZ G d	d
„ d
ejjjƒZG dd„ dƒZdS )z0
Tests for L{twisted.application.runner._exit}.
é    )ÚStringIO)ÚOptionalÚUnionNé   )Ú_exité   )Ú
ExitStatusÚexitc                   @   sB   e Zd ZdZddd„Zddd„Zddd	„Zdd
d„Zddd„ZdS )Ú	ExitTestsz
    Tests for L{exit}.
    ÚreturnNc                 C   s   t ƒ | _|  td| j¡ d S )NÚsysexit)Ú	DummyExitr	   Úpatchr   ©Úself© r   úK/usr/lib/python3/dist-packages/twisted/application/runner/test/test_exit.pyÚsetUp   s   zExitTests.setUpc                 C   s    d}t |ƒ |  | j j|¡ dS )zR
        L{exit} given an L{int} status code will pass it to L{sys.exit}.
        iÒ  N)r	   ÚassertEqualÚarg©r   Ústatusr   r   r   Útest_exitStatusInt   s   zExitTests.test_exitStatusIntc                 C   s$   t j}t|ƒ |  | jj|j¡ dS )zu
        L{exit} given a L{ValueConstant} status code passes the corresponding
        value to L{sys.exit}.
        N)r   Ú	EX_CONFIGr	   r   r   Úvaluer   r   r   r   Útest_exitConstant!   s   zExitTests.test_exitConstantc                 C   ó:   t ƒ }|  td|¡ d}td|ƒ |  | ¡ |d ¡ dS )zq
        L{exit} given a status code of zero (C{0}) writes the given message to
        standard output.
        ÚstdoutúHello, world.r   Ú
N©r   r   r   r	   r   Úgetvalue©r   ÚoutÚmessager   r   r   Útest_exitMessageZero*   ó
   
zExitTests.test_exitMessageZeroc                 C   r   )zj
        L{exit} given a non-zero status code writes the given message to
        standard error.
        Ústderrr   é@   r   Nr    r"   r   r   r   Útest_exitMessageNonZero7   r&   z!ExitTests.test_exitMessageNonZero©r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r%   r)   r   r   r   r   r
      s    



	r
   c                   @   s:   e Zd ZdZd	dd„Zd
deeeef  ddfdd„Z	dS )r   zv
    Stub for L{sys.exit} that remembers whether it's been called and, if it
    has, what argument it was given.
    r   Nc                 C   s
   d| _ d S )NF)Úexitedr   r   r   r   Ú__init__K   s   
zDummyExit.__init__r   c                 C   s   | j rJ ‚|| _d| _ d S )NT)r/   r   )r   r   r   r   r   Ú__call__N   s   

zDummyExit.__call__r*   )N)
r+   r,   r-   r.   r0   r   r   ÚintÚstrr1   r   r   r   r   r   E   s    
$r   )r.   Úior   Útypingr   r   Útwisted.trial.unittestÚtwistedÚrunnerr   r   r	   ÚtrialÚunittestÚTestCaser
   r   r   r   r   r   Ú<module>   s   5