a
    ñ»j½  ã                   @   sn   d Z ddlZddl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 e e¡ZG dd„ deƒZdS )	a¶  This plugin captures stdout during test execution. If a test fails
or raises an error, the captured output will be appended to the error
or failure output. It is disabled by default, but can be enabled with
the options: ``--capture-output`` or ``--capture_output``.
Or enable it by setting os.environ["NOSE_CAPTURE"] to "1".

:Options:
  ``--capture-output`` or ``--capture_output``
    Capture stdout (stdout output will not be printed) é    N)ÚPlugin)Úexc_to_unicodeÚforce_unicode)Úln)ÚStringIOc                   @   s’   e Zd ZdZd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d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zeeddd ƒZdS )!ÚCapturezºOutput-capturing plugin. Now disabled by default.
    Can be enabled with ``--capture-output`` or ``--capture_output``.
    Or enable it with os.environ["NOSE_CAPTURE"]="1" before tests.TÚcapturei@  c                 C   s   g | _ d | _d S ©N)ÚstdoutÚ_buf©Úself© r   ú:E:\soccer\ml_env\Lib\site-packages\nose/plugins/capture.pyÚ__init__   s    zCapture.__init__c                 C   s0   |j ddddddd� |j dd	d
dddd� dS )zRegister commandline optionsz-sz--nocaptureÚstore_falseFr   zUDon't capture stdout (any stdout output will be printed immediately) [NOSE_NOCAPTURE])ÚactionÚdefaultÚdestÚhelpz--capture-outputz--capture_outputÚ
store_trueÚcapture_outputzACapture stdout (stdout output will not be printed) [NOSE_CAPTURE]N)Ú
add_option)r   ÚparserÚenvr   r   r   Úoptions!   s    ýýzCapture.optionsc                 C   s<   || _ dtjv rtjd dks$|jr,d| _n|js8d| _dS )z/Configure plugin. Plugin is enabled by default.ZNOSE_CAPTUREÚ1TFN)ÚconfÚosÚenvironr   Úenabledr   )r   r   r   r   r   r   Ú	configure0   s    ÿþýzCapture.configurec                 C   s   |   ¡  d| _dS )zClear capture buffer.N)Úendr   ©r   Útestr   r   r   Ú	afterTest;   s    zCapture.afterTestc                 C   s   |   ¡  dS )z'Replace sys.stdout with capture buffer.N©Ústartr   r   r   r   Úbegin@   s    zCapture.beginc                 C   s   |   ¡  dS )zFlush capture buffer.Nr&   r#   r   r   r   Ú
beforeTestD   s    zCapture.beforeTestc                 C   s6   | j  |_}d| _|s|S |\}}}||  ||¡|fS )z$Add captured output to error report.N)ÚbufferZcapturedOutputr   ÚaddCaptureToErr)r   r$   ÚerrÚoutputÚecÚevÚtbr   r   r   ÚformatErrorH   s    
zCapture.formatErrorc                 C   s   |   ||¡S )z&Add captured output to failure report.)r1   )r   r$   r,   r   r   r   ÚformatFailureT   s    zCapture.formatFailurec                 C   s*   t |ƒ}t|ƒ}d |tdƒ|tdƒg¡S )NÚ
z>> begin captured stdout <<z>> end captured stdout <<)r   r   Újoinr   )r   r/   r-   r   r   r   r+   X   s    üÿzCapture.addCaptureToErrc                 C   s"   | j  tj ¡ tƒ | _| jt_ d S r	   )r
   ÚappendÚsysr   r   r   r   r   r   r'   d   s    zCapture.startc                 C   s   | j r| j  ¡ t_ d S r	   )r
   Úpopr6   r   r   r   r   r"   i   s    zCapture.endc                 C   s   | j r|  ¡  q dS )zRestore stdout.N)r
   r"   )r   Úresultr   r   r   Úfinalizem   s    zCapture.finalizec                 C   s   | j d ur| j  ¡ S d S r	   )r   Úgetvaluer   r   r   r   Ú_get_bufferr   s    

zCapture._get_bufferNzCaptured stdout output.)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r    ÚnameZscorer   r   r!   r%   r(   r)   r1   r2   r+   r'   r"   r9   r;   Úpropertyr*   r   r   r   r   r      s$   r   )r?   Úloggingr   r6   Znose.plugins.baser   Znose.pyversionr   r   Z	nose.utilr   Úior   Ú	getLoggerr<   Úlogr   r   r   r   r   Ú<module>   s   	
