U
    ÝÁ]ï
  ã                   @   sJ   d Z ddlZddlZddlZddlZG dd„ dejƒZedkrFe ¡  dS )zTests for certbot.reporter.é    Nc                   @   sp   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d„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚReporterTestz$Tests for certbot.reporter.Reporter.c                 C   s6   ddl m} | tjdd¡| _tj| _t 	¡ t_d S )Nr   )ÚreporterF)Úquiet)
Zcertbotr   ZReporterÚmockZ	MagicMockÚsysÚstdoutÚ
old_stdoutÚsixÚStringIO)Úselfr   © r   ú=/usr/lib/python3/dist-packages/certbot/tests/reporter_test.pyÚsetUp   s    zReporterTest.setUpc                 C   s   | j t_d S ©N)r   r   r   ©r   r   r   r   ÚtearDown   s    zReporterTest.tearDownc                 C   sF   | j  d| j j¡ | j  ¡  tj ¡ }|  d|k¡ |  d|k¡ d S )NzLine 1
Line 2zLine 1
zLine 2)r   Úadd_messageÚLOW_PRIORITYÚprint_messagesr   r   ÚgetvalueÚ
assertTrue©r   Úoutputr   r   r   Útest_multiline_message   s
    

z#ReporterTest.test_multiline_messagec                 C   s   dd„ t j_|  ¡  d S )Nc                   S   s   dS ©NTr   r   r   r   r   Ú<lambda>   ó    z3ReporterTest.test_tty_print_empty.<locals>.<lambda>)r   r   ÚisattyÚtest_no_tty_print_emptyr   r   r   r   Útest_tty_print_empty   s    z!ReporterTest.test_tty_print_emptyc                 C   sZ   | j  ¡  |  tj ¡ d¡ zt‚W n tk
rB   | j  ¡  Y nX |  tj ¡ d¡ d S )NÚ )r   r   ZassertEqualr   r   r   Ú
ValueErrorr   r   r   r   r       s    
z$ReporterTest.test_no_tty_print_emptyc                 C   s   dd„ t j_|  ¡  d S )Nc                   S   s   dS r   r   r   r   r   r   r   *   r   z7ReporterTest.test_tty_successful_exit.<locals>.<lambda>)r   r   r   Ú_successful_exit_commonr   r   r   r   Útest_tty_successful_exit)   s    z%ReporterTest.test_tty_successful_exitc                 C   s   |   ¡  d S r   )r"   r   r   r   r   Útest_no_tty_successful_exit-   s    z(ReporterTest.test_no_tty_successful_exitc                 C   s   dd„ t j_|  ¡  d S )Nc                   S   s   dS r   r   r   r   r   r   r   1   r   z9ReporterTest.test_tty_unsuccessful_exit.<locals>.<lambda>)r   r   r   Ú_unsuccessful_exit_commonr   r   r   r   Útest_tty_unsuccessful_exit0   s    z'ReporterTest.test_tty_unsuccessful_exitc                 C   s   |   ¡  d S r   )r%   r   r   r   r   Útest_no_tty_unsuccessful_exit4   s    z*ReporterTest.test_no_tty_unsuccessful_exitc                 C   sX   |   ¡  | j ¡  tj ¡ }|  d|k¡ |  d|k¡ |  d|k¡ |  d|k¡ d S ©NzIMPORTANT NOTES:ÚHighÚMedÚLow)Ú_add_messagesr   r   r   r   r   r   r   r   r   r   r"   7   s    

z$ReporterTest._successful_exit_commonc                 C   sv   |   ¡  zt‚W n tk
r.   | j ¡  Y nX tj ¡ }|  d|k¡ |  d|k¡ |  d|k¡ |  d|k¡ d S r(   )r,   r!   r   r   r   r   r   r   r   r   r   r   r%   @   s    
z&ReporterTest._unsuccessful_exit_commonc                 C   sB   | j  d| j j¡ | j jd| j jdd | j jd| j jdd d S )Nr)   r*   F)Zon_crashr+   )r   r   ZHIGH_PRIORITYZMEDIUM_PRIORITYr   r   r   r   r   r,   L   s      ÿ  ÿzReporterTest._add_messagesN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r#   r$   r&   r'   r"   r%   r,   r   r   r   r   r   	   s   		r   Ú__main__)	r0   r   Zunittestr   r	   ZTestCaser   r-   Úmainr   r   r   r   Ú<module>   s   K