o
    DDi!                     @   sx   d dl mZ d dlmZ d dlmZ d dlZd dlmZ d dl	m
Z
 d dlmZmZmZ d dlmZ G d	d
 d
eZdS )    Path)TemporaryDirectory)SetN)
CSTVisitor)chdir)FilePathProviderFullRepoManagerMetadataWrapper)UnitTestc                   @   s*   e Zd Zd	ddZd	ddZd	ddZdS )
FilePathProviderTestreturnNc                 C   s,   t  | _t| jj | _| | jj d S N)r   tdr   nameresolvetdp
addCleanupcleanupself r   f/var/www/Datamplify/venv/lib/python3.10/site-packages/libcst/metadata/tests/test_file_path_provider.pysetUp   s   zFilePathProviderTest.setUpc              	      s  j d      fdddD }dd |D  d) tj dd |D th}|  tdd	 |D i}||j W d    n1 sJw   Y  d
- tj fdd|D th}|  tfdd	|D i}||j W d    n1 sw   Y  dJ tj , tdfdd|D th}|  tfdd	|D i}||j W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Npkgc                       g | ]}t  | qS r   r   .0r   r   r   r   
<listcomp>       z<FilePathProviderTest.test_provider_cache.<locals>.<listcomp>zfile1.pyzfile2.pyzfile3.pyc                 S      g | ]}| d qS zprint('hello')

write_textr   filer   r   r   r          absolute pathsc                 S      g | ]}|  qS r   as_posixr   fr   r   r   r          c                 S   s   i | ]}|  |qS r   r+   r-   r   r   r   
<dictcomp>$   r(   z<FilePathProviderTest.test_provider_cache.<locals>.<dictcomp>repo relative pathsc                       g | ]
}|  j qS r   relative_tor   r,   r-   r   r   r   r   +       c                       i | ]}|  j |qS r   r3   r-   r   r   r   r0   1       dot relative paths.c                    r2   r   r3   r-   r   r   r   r   ;   r5   c                    r6   r   r3   r-   r   r   r   r0   A   r7   )	r   mkdirsubTestr	   r   resolve_cacheassertDictEqualcacher   )r   filesrepo_managerexpectedr   )r   r   r   test_provider_cache   sV   
"z(FilePathProviderTest.test_provider_cachec              
      s  j d      fdddD }dd |D  t G fdddt}dD   tj d	d |D th}|  |D ]}t	
| }t||| d
}||  qCt|}| W d    n1 srw   Y  dJ   tj fdd|D th}|  |D ]}t	
| }t|||j  d
}||  qt|}| W d    n1 sw   Y  dh tj I   tdfdd|D th}|  |D ]}t	
| }t|||j  d
}||  qt|}| W d    n1 s&w   Y  W d    d S W d    d S 1 s?w   Y  d S )Nr   c                    r   r   r   r   r   r   r   r   J   r    z5FilePathProviderTest.test_visitor.<locals>.<listcomp>r!   c                 S   r"   r#   r$   r&   r   r   r   r   K   r(   c                       s*   e Zd ZegZdejddf fddZdS )z6FilePathProviderTest.test_visitor.<locals>.FakeVisitornoder   Nc                    s     | t| d S r   )addget_metadatar   )r   rC   seenr   r   visit_ModuleR   s   zCFilePathProviderTest.test_visitor.<locals>.FakeVisitor.visit_Module)__name__
__module____qualname__r   METADATA_DEPENDENCIESlibcstModulerH   r   rF   r   r   FakeVisitorO   s    rO   r)   c                 S   r*   r   r+   r-   r   r   r   r   X   r/   )r>   r1   c                    r2   r   r3   r-   r   r   r   r   j   r5   r8   r9   c                    r2   r   r3   r-   r   r   r   r      r5   )r   r:   setr   r;   clearr	   r   r<   rM   parse_module
read_bytesr
   get_cache_for_pathr,   visitassertSetEqualr4   r   )r   r?   rO   r@   r'   modulewrapperrA   r   )r   rG   r   r   test_visitorG   s   
 $z!FilePathProviderTest.test_visitor)r   N)rI   rJ   rK   r   rB   rY   r   r   r   r   r      s    

0r   )pathlibr   tempfiler   typingr   rM   libcst._visitorsr   libcst.helpers.pathsr   libcst.metadatar   r	   r
   libcst.testing.utilsr   r   r   r   r   r   <module>   s   