U
    -e%                     @   s   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
mZ d dlmZ d dlmZmZ d d	lmZ d
ddddgZdd Zdd Zdd Zdd Zdd Zdd Zdd Zeee  dddZe d%d!d"ZG d#d$ d$eZdS )&    N)List)Path)search_ancestor)inference_state_method_cache)goto_importload_module_from_path)ParserTreeFilter)	NO_VALUESValueSet)infer_call_of_leaf)_pytestZmonkeypatch)r   capture)r   logging)r   Ztmpdir)r   Zpytesterc                    s    fdd}|S )Nc                    s(   |   dkr| j  dkrtS  | |S )Nfixturez_pytest.fixtures)Z
py__name__parent_contextr	   )value	argumentscallback T/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/jedi/plugins/pytest.pywrapper   s
    zexecute.<locals>.wrapperr   )r   r   r   r   r   execute   s    r   c                    s   dd  fdd}|S )Nc                 S   sb   | j jd k	r>|  }tdd |D r:tdd |D S |S |  }| rV| S |	 S d S )Nc                 s   s    | ]}|j jd ddkV  qdS )TZinclude_module_names)typing	GeneratorN)nameget_qualified_names.0vr   r   r   	<genexpr>%   s   z=infer_anonymous_param.<locals>.get_returns.<locals>.<genexpr>c                 s   s   | ]}| d  V  qdS )__next__N)Zpy__getattribute__Zexecute_annotationr   r   r   r   r!   (   s   )
Z	tree_node
annotationZexecute_with_valuesanyr
   	from_sets
as_contextZis_generatorZmerge_yield_valuesZget_return_values)r   resultZfunction_contextr   r   r   get_returns"   s    
z*infer_anonymous_param.<locals>.get_returnsc                    sZ   | j r | S t| \}}|rR|  }t|| j|d}|rRtfdd|D S  | S )Nskip_own_modulec                 3   s$   | ]}|  D ]} |V  qqd S N)Zinfer)r   r   r   )r(   r   r   r!   G   s   
 z9infer_anonymous_param.<locals>.wrapper.<locals>.<genexpr>)Zannotation_node _is_a_pytest_param_and_inheritedget_root_context_goto_pytest_fixturestring_namer
   r%   )
param_nameis_pytest_paramparam_name_is_function_namemodulefixturesfuncr(   r   r   r   7   s     z&infer_anonymous_param.<locals>.wrapperr   r6   r   r   r5   r   infer_anonymous_param!   s    r8   c                    s    fdd}|S )Nc                    s4   t | \}}|r,t|  | j|d}|r,|S  | S Nr)   )r,   r.   r-   r/   )r0   r1   r2   namesr6   r   r   r   Q   s    z%goto_anonymous_param.<locals>.wrapperr   r7   r   r;   r   goto_anonymous_paramP   s    r<   c                    s    fdd}|S )Nc                    sH   |   }t||r<g }t|D ]}|t| 7 }q|r<|S  | ||S r+   )r-   _is_pytest_func_iter_pytest_modulesFixtureFiltervalues)context	func_namedecorator_nodesmodule_contextr:   r;   r   r   r   a   s    
z%complete_param_names.<locals>.wrapperr   r7   r   r;   r   complete_param_names`   s    	rE   c                 C   s0   t | |dD ]} t| |}|r|  S qd S r9   )r>   r?   get)rD   r   r*   r:   r   r   r   r.   m   s    r.   c                 C   s<   t | jd}|dkrdS | }t|jj||jj| jkfS )z
    Pytest params are either in a `test_*` function or have a pytest fixture
    with the decorator @pytest.fixture.

    This is a heuristic and will work in most cases.
    funcdefN)FF)r   	tree_nameZget_decoratorsr=   r   r   r/   )r0   rG   
decoratorsr   r   r   r,   t   s    r,   c                 C   s   |  dptdd |D S )Ntestc                 s   s   | ]}d |  kV  qdS )r   N)get_code)r   nr   r   r   r!      s     z"_is_pytest_func.<locals>.<genexpr>)
startswithr$   )rB   rC   r   r   r   r=      s    
r=   )returnc                  C   s   t jdkrpddlm}  t jdkr,| dd}n|  dd}t jdkrRd	d
 |D S dd
 |D }dd
 |D S n ddlm} dd
 |ddD S dS )z
    Finds pytest plugin modules hooked by setuptools entry points

    See https://docs.pytest.org/en/stable/how-to/writing_plugins.html#setuptools-entry-points
    )      r   )entry_points)rO   
   Zpytest11)groupr   )rO   	   c                 S   s   g | ]}|j d qS .)r3   splitr   epr   r   r   
<listcomp>   s     z/_find_pytest_plugin_modules.<locals>.<listcomp>c                 S   s   g | ]}|j |jqS r   )patternmatchr   rX   r   r   r   rZ      s   c                 S   s    g | ]}|r| d dqS )r3   rV   )rS   rW   )r   xr   r   r   rZ      s      )iter_entry_pointsc                 S   s   g | ]}|j d qS rU   )module_namerW   rX   r   r   r   rZ      s     N)sysversion_infoimportlib.metadatarQ   rF   pkg_resourcesr^   )rQ   Zpytest_entry_pointsmatchesr^   r   r   r   _find_pytest_plugin_modules   s    


re   Fc                 #   s   |s
| V  |   j}|d k	r|  | j }d }t fdd|D r d}t|j| 	 krzt
| j|}| V  W n tk
r   Y nX    |d k	r j|jkrq }q2tt  D ] }| j|D ]}| V  qqd S )Nc                 3   s   | ]} j |V  qd S r+   )pathrM   )r   pfolderr   r   r!      s     z'_iter_pytest_modules.<locals>.<genexpr>zconftest.py)	get_valuefile_ioZget_parent_folderZinference_stateZget_sys_pathr$   Zget_file_ior   rf   Z
py__file__r   r&   FileNotFoundError_PYTEST_FIXTURE_MODULESre   import_module)rD   r*   rk   sys_pathZlast_foldermr:   Zmodule_valuer   rh   r   r>      s,    


r>   c                       s$   e Zd Z fddZdd Z  ZS )r?   c                 #   s`   t  |D ]N}|jjdkrFt j|}t fdd|D rZ|V  q  j|r|V  qd S )NZimport_fromc                 3   s$   | ]}|j r |j|j V  qd S r+   )rH   _is_fixturer   )r   Zinameselfr   r   r!      s   z(FixtureFilter._filter.<locals>.<genexpr>)super_filterparenttyper   r   r$   rq   )rs   r:   r   Zimported_names	__class__rr   r   ru      s    zFixtureFilter._filterc                 C   s   |j }|jdkrdS |j }|jdkr(dS |jd }|jdkrD|j}n|g}|D ]}|jd }d| krN|jdkr|jd	 }| }	|	d
krt||	dd}
q||}
n
||}
|
D ]}|jjdddkr  dS qqNdS )NrG   F	decoratedr   rI      r   Z	atom_expr)T)Zcut_own_trailerr   )r   r4   r   )	rv   rw   childrenrK   Zget_last_leafr   Z
infer_noder   r   )rs   rA   r   rG   rz   rI   	decoratorZdotted_nameZlast_trailerZ	last_leafr@   r   r   r   r   rq      s<    






  
zFixtureFilter._is_fixture)__name__
__module____qualname__ru   rq   __classcell__r   r   rx   r   r?      s   r?   )F)r`   r   r   pathlibr   Z
parso.treer   Zjedi.inference.cacher   Zjedi.inference.importsr   r   Zjedi.inference.filtersr   Zjedi.inference.base_valuer	   r
   Zjedi.inference.helpersr   rm   r   r8   r<   rE   r.   r,   r=   strre   r>   r?   r   r   r   r   <module>   s2   	/ 