3
h                 @   sR   d dl Zd dlZd dlZd dlZd dlZddlmZmZm	Z	 G dd dej
ZdS )    N   )
write_filewrite_newer_file_parse_patternc                   sp   e Zd Z fddZ f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  ZS )TestTestUtilsc                s   t t| j  tj | _d S )N)superr   setUptempfilemkdtemptemp_dir)self)	__class__ l/var/www/html/CrowdFlow/Picklecon/ble_analysis_env/lib/python3.6/site-packages/Cython/Tests/TestTestUtils.pyr      s    zTestTestUtils.setUpc                s2   | j r tjj| j r tj| j  tt| j  d S )N)	r   ospathisdirshutilrmtreer   r   tearDown)r   )r   r   r   r      s    zTestTestUtils.tearDownc             C   s   t jj| j|S )N)r   r   joinr   )r   filenamer   r   r   
_test_path   s    zTestTestUtils._test_pathc             K   sf   | j d}t||f| tjj|s(tt|d}|j }W d Q R X ||ksbtt|t|fd S )NZabcfilerb)	r   r   r   r   isfileAssertionErroropenreadrepr)r   contentexpectedkwargs	file_pathffoundr   r   r   _test_write_file   s    
zTestTestUtils._test_write_filec             C   s   d}| j ||jd d S )Nu	   abcüöäutf8)r%   encode)r   textr   r   r   test_write_file_text"   s    z"TestTestUtils.test_write_file_textc             C   s$   d}| j |tj|jddd d S )Nz|
        A horse is a horse,
        of course, of course,
        And no one can talk to a horse
        of course
        r&   T)dedent)r%   textwrapr*   r'   )r   r(   r   r   r   test_write_file_dedent&   s    z$TestTestUtils.test_write_file_dedentc             C   s   | j dd d S )Ns   ab c)r%   )r   r   r   r   test_write_file_bytes/   s    z#TestTestUtils.test_write_file_bytesc             C   sj   | j d}| j d}t|d tjj|s.tt||d tjj|sJttjj|tjj|ksftd S )Nzabcfile1.txtzabcfile2.txtabcxyz)r   r   r   r   r   r   r   getmtime)r   Zfile_path_1Zfile_path_2r   r   r   test_write_newer_file2   s    


z#TestTestUtils.test_write_newer_filec             C   sD   | j d}t|d tjj|}t||d tjj||ks@td S )Nzabcfile.txtr.   r/   )r   r   r   r   r0   r   r   )r   r"   mtimer   r   r   test_write_newer_file_same;   s
    

z(TestTestUtils.test_write_newer_file_samec             C   s<   | j d}tjj| stt||d tjj|s8td S )Nzabcfile.txtr/   )r   r   r   existsr   r   r   )r   r"   r   r   r   test_write_newer_file_freshB   s    
z)TestTestUtils.test_write_newer_file_freshc             C   sT   | j tdd | j tdd	 | j tdd
 | j tdd | j tdd d S )Npatternz/start/:patternstartz:/end/  patternendz/start/:/end/  patternz/start/:/end/pattern)NNr6   )r7   Nr6   )Nr8   r6   )r7   r8   r6   )r7   r8   r6   )assertEqualr   )r   r   r   r   test_parse_patternH   s    z TestTestUtils.test_parse_pattern)__name__
__module____qualname__r   r   r   r%   r)   r,   r-   r1   r3   r5   r:   __classcell__r   r   )r   r   r      s   			r   )os.pathr   Zunittestr	   r+   r   Z	TestUtilsr   r   r   ZTestCaser   r   r   r   r   <module>   s   