o
    ˷e=                     @   s   d Z ddlZddlZddlmZ ddlmZ ejdd Z	ej
dd Zd	d
 Zdd ZG dd dejZG dd dejZdS )z
Tests for testing.tools
    N)
decorators)toolsc                  C   j   d} t | ddg}|sJ ddkgd} t | ddg}|s&J ddkgt | d}|dgks3J d S )	Nz/foo/bar.pya.txtb.txtz
/foo/a.txtz
/foo/b.txtz/fooz/a.txtz/b.txttt	full_pathspathresult r   W/var/www/ideatree/venv/lib/python3.10/site-packages/IPython/testing/tests/test_tools.pytest_full_path_posix      r   c                  C   r   )	Nzc:\foo\bar.pyr   r   zc:\foo\a.txtzc:\foo\b.txtzc:\foozc:\a.txtzc:\b.txtr   r
   r   r   r   test_full_path_win32'   r   r   c                  C   sL   d} d}d}| ||fD ]\}}}t |\}}||ksJ ||ks#J qd S )N)zFAILED (errors=1)   r   )zFAILED (failures=1)r   r   )zFAILED (errors=1, failures=1)r   r   )r   parse_test_output)errfailbothtxtnerrnfailnerr1nfail1r   r   r   test_parser3   s   r   c                  C   sb   d} t | }tj|sJ t|dd}| }W d    n1 s$w   Y  || ks/J d S )Nzpass
zutf-8)encoding)r   temp_pyfileospathisfileopenread)srcfnamefh2src2r   r   r   test_temp_pyfile=   s   

r(   c                   @   s   e Zd Zdd Zdd ZdS )TestAssertPrintsc                 C   H   t d td td td W d    d S 1 sw   Y  d S )Nabcabcddef   ghir   AssertPrintsprintselfr   r   r   test_passingF   
   
"zTestAssertPrints.test_passingc                 C   s   dd }|  t| d S )Nc                   S   r*   )Nr+   acdr-   r.   r/   r   r   r   r   funcM   r5   z+TestAssertPrints.test_failing.<locals>.func)assertRaisesAssertionError)r3   r7   r   r   r   test_failingL   s   zTestAssertPrints.test_failingN)__name__
__module____qualname__r4   r:   r   r   r   r   r)   E   s    r)   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )Test_ipexec_validatec                 C       |  d d}t| j| dS )z'Test with only stdout results.
        print('A')
print('B')
A
BNmktmpr   ipexec_validater%   r3   outr   r   r   test_main_pathW      
z#Test_ipexec_validate.test_main_pathc                 C   r?   )zGTest with only stdout results, expecting windows line endings.
        r@   A
BNrB   rE   r   r   r   test_main_path2`   rH   z$Test_ipexec_validate.test_main_path2c                 C   $   |  d d}tj| j|dd dS )z3Test exception path in exception_validate.
        Yimport sys
print('A')
print('B')
print('C', file=sys.stderr)
print('D', file=sys.stderr)
rA   zC
Dexpected_outexpected_errNrB   rE   r   r   r   test_exception_pathi      
z(Test_ipexec_validate.test_exception_pathc                 C   rK   )zSTest exception path in exception_validate, expecting windows line endings.
        rL   rI   zC
DrM   NrB   rE   r   r   r   test_exception_path2u   rQ   z)Test_ipexec_validate.test_exception_path2c                 C   s   t j|  d S )N)r   TempFileMixintearDownr2   r   r   r   rT      s   zTest_ipexec_validate.tearDownN)r;   r<   r=   rG   rJ   rP   rR   rT   r   r   r   r   r>   V   s    		r>   )__doc__r   unittestIPython.testingr   decr   r   
skip_win32r   skip_if_not_win32r   r   r(   TestCaser)   rS   r>   r   r   r   r   <module>   s   


