o
    ZhA                     @   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   l   d} t | ddg}|sJ ddkgd} t | ddg}|s&J ddkgt | dg}|dgks4J d S )	Nz/foo/bar.pya.txtb.txtz
/foo/a.txtz
/foo/b.txtz/fooz/a.txtz/b.txttt	full_pathZspathresult r   W/var/www/html/lang_env/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   Zparse_test_output)errZfailZbothtxtZnerrZnfailZnerr1Z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   Ztemp_pyfileospathisfileopenread)srcfnameZfh2Z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   ZAssertPrintsprintselfr   r   r   test_passingF   
   
"zTestAssertPrints.test_passingc                 C   s   dd }|  t| d S )Nc                   S   r   )Nr    Zacdr"   r#   r$   r   r   r   r   funcM   r)   z+TestAssertPrints.test_failing.<locals>.func)assertRaisesAssertionError)r'   r*   r   r   r   test_failingL   s   zTestAssertPrints.test_failingN)__name__
__module____qualname__r(   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Zmktmpr   Zipexec_validater   r'   outr   r   r   test_main_pathW      
z#Test_ipexec_validate.test_main_pathc                 C   r2   )zGTest with only stdout results, expecting windows line endings.
        r3   A
BNr5   r6   r   r   r   test_main_path2`   r9   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)
r4   zC
DZexpected_outZexpected_errNr5   r6   r   r   r   test_exception_pathi      
z(Test_ipexec_validate.test_exception_pathc                 C   r<   )zSTest exception path in exception_validate, expecting windows line endings.
        r=   r:   zC
Dr>   Nr5   r6   r   r   r   test_exception_path2u   r@   z)Test_ipexec_validate.test_exception_path2c                 C   s   t j|  d S )N)r   TempFileMixintearDownr&   r   r   r   rC      s   zTest_ipexec_validate.tearDownN)r.   r/   r0   r8   r;   r?   rA   rC   r   r   r   r   r1   V   s    		r1   )__doc__r   ZunittestZIPython.testingr   decr   r   Z
skip_win32r   Zskip_if_not_win32r   r   r   ZTestCaser   rB   r1   r   r   r   r   <module>   s   


