o
    wi                     @   sF   d dl Z d dlZd dlZddlmZ ddlmZ G dd dejZdS )    N   )open_source_file   )strip_string_literalsc                   @   s<   e Zd ZdZedd Zdd Zdd Zdd	 Zd
d Z	dS )TestStripLiteralsNc                    s    fdd}t d|| S )Nc                    s    |    S N)group)matchliterals a/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/Cython/Build/Tests/TestStripLiterals.pylookup   s   z1TestStripLiterals._rebuild_string.<locals>.lookupz__Pyx_L[0-9]+_)resub)strippedr   r   r   r
   r   _rebuild_string   s   z!TestStripLiterals._rebuild_stringc                     sV   fdd}g d}dd |D dddd	d
ddddddddddddddddddddd d d td!d"D  d# fg }|D ]e\}} j|d$ ||| W d    n1 sXw   Y  | }| } j|d$ ||| W d    n1 s{w   Y  |d%7 }|d%7 } j|d$ ||| W d    n1 sw   Y  q>|d&d' d S )(Nc                    s4   t | \}} ||  ||} | | d S r   )r   assertEqualr   )sexpectedr   r   	recoveredselfr   r   strip_equals   s   zBTestStripLiterals.test_strip_string_literals.<locals>.strip_equals) abc123z	func(123)z '' z '''''''''''' z '''''''''''''' c                 S   s   g | ]}||fqS r   r   ).0coder   r   r   
<listcomp>%   s    z@TestStripLiterals.test_strip_string_literals.<locals>.<listcomp>)z"x"z"__Pyx_L1_")z'x''__Pyx_L1_')z	 '"' "'" z '__Pyx_L1_' "__Pyx_L2_" )z
 '''' '''  '''__Pyx_L1_''' )z
 """" """ z """__Pyx_L1_""" )z
 '''a
''' r!   )z'a\'b'r    )z'a\\'r    )z'a\\\'b'r    )zu'abc'zu'__Pyx_L1_')zr'abc\\'zr'__Pyx_L1_')z	ru'abc\\'zru'__Pyx_L1_')z	abc # fooabc #__Pyx_L1_)z	abc # 'x'r"   )z'abc#'r    )z include 'a.pxi' # something herezinclude '__Pyx_L1_' #__Pyx_L2_)z!cdef extern from 'a.h': # commentz(cdef extern from '__Pyx_L1_': #__Pyx_L2_)z4 func('xyz') + " " + "" '' # '' | "" "123" 'xyz' "' z3 func('__Pyx_L1_') + "__Pyx_L2_" + "" '' #__Pyx_L3_)z f'f' z f'__Pyx_L1_' )z f'a{123}b' z f'__Pyx_L1_{123}__Pyx_L2_' )z f'{1}{f'xyz'}' z f'{1}{f'__Pyx_L1_'}' )z f'{f'''xyz{f"""abc"""}'''}' z) f'{f'''__Pyx_L1_{f"""__Pyx_L2_"""}'''}' )z* f'{{{{{"abc"}}}}}{{}}{{' == '{{abc}}{}{' z3 f'__Pyx_L1_{"__Pyx_L2_"}__Pyx_L3_' == '__Pyx_L4_' a  f'{x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x} {x:{width}} 'zf'r   c                 S   s   g | ]}d | dqS )z
{x}__Pyx_L_r   )r   nr   r   r   r   f   s          z{x:{width}}__Pyx_L251_')r   
z( print("Say something: %s' % something) z print("__Pyx_L1_)joinrangesubTeststrip)r   r   	unchangedtestsr   r   r   r   r   test_strip_string_literals   sb   
 Dz,TestStripLiterals.test_strip_string_literalsc              
   C   s   t dj}t|D ]n}| jt||dY tt|}| }W d    n1 s-w   Y  t	|\}}||}	|	r]t
|	ddkr]|	 d }
| d||
d |
d   | ||}| || W d    n1 ssw   Y  q
d S )Nz[^_'"}](['"]+)[^_'"{])filer%   r   zLeftover string found:    )r   compilesearchsortedr*   strrelative_tor   readr   lenr   startfailr   r   )r   base_dir
file_paths_find_leftover_string	file_pathfr   r   r   r	   	match_posr   r   r   r   _test_all_files{   s    
 z!TestStripLiterals._test_all_filesc                 C   s>   t t jd }|jdksJ |j}| ||d d S )Nr   Cython*.py)	pathlibPath__file__absoluteparentsnameparentr@   rglob)r   package_dirr:   r   r   r   #test_strip_string_literals_py_files   s   z5TestStripLiterals.test_strip_string_literals_py_filesc                 C   sp   t t jd }|d }g }| D ]}| r/|jdkr/||	d ||	d q| 
|| d S )Nr   r-   errorsrB   z*.pyx)rC   rD   rE   rF   rG   iterdiris_dirrH   extendrJ   r@   )r   r:   	tests_dir
test_filestest_subdirr   r   r   %test_strip_string_literals_test_files   s   z7TestStripLiterals.test_strip_string_literals_test_files)
__name__
__module____qualname__maxDiffstaticmethodr   r.   r@   rL   rT   r   r   r   r   r   	   s    
hr   )	rC   r   unittestUtilsr   Dependenciesr   TestCaser   r   r   r   r   <module>   s    