U
    n5{i‘  ã                   @   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                   @   sV   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„Zddœdd„ZdS )Ú	ExitTestsz
    Tests for L{exit}.
    N©Úreturnc                 C   s   t ƒ | _|  td| j¡ d S )NZsysexit)Ú	DummyExitr	   Úpatchr   ©Úself© r   úM/tmp/pip-unpacked-wheel-mnhg7r0q/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   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_exitMessageNonZero7   s
    
z!ExitTests.test_exitMessageNonZero)	Ú__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d„Zd	eeeef  d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.
    Nr   c                 C   s
   d| _ d S )NF)Úexitedr   r   r   r   Ú__init__K   s    zDummyExit.__init__)r   r   c                 C   s   | j r
t‚|| _d| _ d S )NT)r,   ÚAssertionErrorr   )r   r   r   r   r   Ú__call__N   s    
zDummyExit.__call__)N)
r(   r)   r*   r+   r-   r   r   ÚintÚstrr/   r   r   r   r   r   E   s   r   )r+   Úior   Útypingr   r   Ztwisted.trial.unittestZtwistedÚrunnerr   r   r	   ZtrialZunittestZTestCaser
   r   r   r   r   r   Ú<module>   s   5