U
    
W[¹	  ã                   @   s^   d Z ddlmZ ddlmZ ddlmZmZ ddlZG dd	„ d	ej	j
jƒZG d
d„ deƒZdS )z0
Tests for L{twisted.application.runner._exit}.
é    )ÚNativeStringIOé   )Ú_exité   )ÚexitÚ
ExitStatusNc                   @   sH   e Zd 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S )Ú	ExitTestsz
    Tests for L{exit}.
    c                 C   s   t ƒ | _|  td| j¡ d S )NZ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}.
        éÒ  N©r   ÚassertEqualÚarg©r   Zstatusr   r   r   Útest_exitStatusInt   s    zExitTests.test_exitStatusIntc                 C   s   |   ttd¡ dS )zn
        L{exit} given a L{str} status code that isn't a string integer raises
        L{ValueError}.
        ZfooN)ZassertRaisesÚ
ValueErrorr   r   r   r   r   Útest_exitStatusStringNotInt#   s    z%ExitTests.test_exitStatusStringNotIntc                 C   s   t dƒ |  | j jd¡ dS )z…
        L{exit} given a L{str} status code that is a string integer passes the
        corresponding L{int} to L{sys.exit}.
        Z1234r   Nr   r   r   r   r   Útest_exitStatusStringInt+   s    z"ExitTests.test_exitStatusStringIntc                 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_exitConstant4   s    zExitTests.test_exitConstantc                 C   s:   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>   s
    
zExitTests.test_exitMessageZeroc                 C   s:   t ƒ }|  td|¡ d}td|ƒ |  | ¡ |d ¡ dS )zj
        L{exit} given a non-zero status code writes the given message to
        standard error.
        Ústderrr   é@   r   Nr   r!   r   r   r   Útest_exitMessageNonZeroL   s
    
z!ExitTests.test_exitMessageNonZeroN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r$   r'   r   r   r   r   r      s   		
r   c                   @   s"   e Zd ZdZdd„ Zd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.
    c                 C   s
   d| _ d S )NF)Úexitedr   r   r   r   Ú__init__`   s    zDummyExit.__init__Nc                 C   s   | j r
t‚|| _d| _ d S )NT)r,   ÚAssertionErrorr   )r   r   r   r   r   Ú__call__d   s    
zDummyExit.__call__)N)r(   r)   r*   r+   r-   r/   r   r   r   r   r	   [   s   r	   )r+   Ztwisted.python.compatr   Zrunnerr   r   r   Ztwisted.trial.unittestZtwistedZtrialZunittestZTestCaser   Úobjectr	   r   r   r   r   Ú<module>   s   K