o
    Zhc(                     @   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 g d
Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdeee  fddZe d#ddZ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                        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 J/var/www/html/lang_env/lib/python3.10/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   s^   | j jd ur|  }tdd |D rtdd |D S |S |  }| r+| S |	 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
    
)
	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| \}}|r)|  }t|| j|d}|r)tfdd|D S  | S )Nskip_own_modulec                 3   s&    | ]}|  D ]} |V  qqd S N)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   r9   r   r   r8   r   infer_anonymous_param!   s   r;   c                    r   )Nc                    s4   t | \}}|rt|  | j|d}|r|S  | S Nr+   )r/   r1   r0   r2   )r3   r4   r5   namesr9   r   r   r   Q   s   z%goto_anonymous_param.<locals>.wrapperr   r:   r   r>   r   goto_anonymous_paramP   s   r?   c                    r   )Nc                    sH   |   }t||rg }t|D ]
}|t| 7 }q|r|S  | ||S r-   )r0   _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   r:   r   r>   r   complete_param_names`   s   	rH   c                 C   s0   t | |dD ]} t| |}|r|  S qd S r<   )rA   rB   get)rG   r   r,   r=   r   r   r   r1   m   s   r1   c                 C   s<   t | jd}|du 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   r2   )r3   rJ   
decoratorsr   r   r   r/   t   s   r/   c                 C   s   |  dptdd |D S )Ntestc                 s   s    | ]	}d |  v V  qdS )r   N)get_code)r    nr   r   r   r"          z"_is_pytest_func.<locals>.<genexpr>)
startswithr&   )rE   rF   r   r   r   r@      s   
r@   returnc                  C   s   t jdkr7ddlm}  t jdkr| dd}n|  dd}t jdkr)d	d
 |D S dd
 |D }dd
 |D S ddlm} dd
 |dd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)rS   
   Zpytest11)groupr   )rS   	   c                 S      g | ]}|j d qS .)r6   splitr    epr   r   r   
<listcomp>       z/_find_pytest_plugin_modules.<locals>.<listcomp>c                 S   s   g | ]	}|j |jqS r   )patternmatchr   r]   r   r   r   r_      s    c                 S   s    g | ]}|r| d dqS )r6   r[   )rW   r\   )r    xr   r   r   r_      s     )iter_entry_pointsc                 S   rY   rZ   )module_namer\   r]   r   r   r   r_      r`   )sysversion_infoimportlib.metadatarU   rI   pkg_resourcesrd   )rU   Zpytest_entry_pointsmatchesrd   r   r   r   _find_pytest_plugin_modules   s   


rk   Fc                 #   s2   |s| V  |   j}|d ur|  | j }d }t fdd|D r d}t|j| 	 krez(t
| j|}| }|V  |j d}|rZ||d }t| |E d H  W n	 tyd   Y nw    |d urt j|jkrtn }t fdd|D s%tt  D ]}	| j|	D ]}
|
 V  qqd S )Nc                 3   s    | ]	} j |V  qd S r-   )pathrQ   )r    pfolderr   r   r"      rP   z'_iter_pytest_modules.<locals>.<genexpr>zconftest.pyZpytest_pluginsr   )	get_valuefile_ioZget_parent_folderinference_stateZget_sys_pathr&   Zget_file_ior   rl   Z
py__file__r   r(   r$   Zget_used_namesrI   Zcreate_name_load_pytest_pluginsFileNotFoundError_PYTEST_FIXTURE_MODULESrk   import_module)rG   r,   rq   sys_pathZlast_foldermZconftest_moduleZplugins_listr   r=   module_valuer   rn   r   rA      sB   


rA   c           	      c   sn    ddl m} | D ])}| D ]"}| D ]}||}|r2|d}| j|D ]}| V  q*qqqd S )Nr   )get_str_or_noner[   )jedi.inference.helpersrz   r.   Z
py__iter__r\   rr   rv   r(   )	rG   r   rz   inferredZ	seq_valuer   Zfq_namer=   ry   r   r   r   rs      s   
rs   c                       s$   e Zd Z fddZdd Z  ZS )rB   c                 #   sb    t  |D ]'}|jjdkr$t j|}t fdd|D r#|V  q  j|r.|V  qd S )NZimport_fromc                 3   s&    | ]}|j r |j|j V  qd S r-   )rK   _is_fixturer   )r    Zinameselfr   r   r"      s    
z(FixtureFilter._filter.<locals>.<genexpr>)super_filterparenttyper   r   r&   r}   )r   r=   r   Zimported_names	__class__r~   r   r      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r"|j}n|g}|D ]D}|jd }d| v rk|jdkrT|jd	 }| }	|	d
krNt||	dd}
n||}
n||}
|
D ]}|jjdddkrj  dS q[q'dS )NrJ   F	decoratedr   rL      r   Z	atom_expr)T)Zcut_own_trailerr   )r   r7   r   )	r   r   childrenrN   Zget_last_leafr   Z
infer_noder   r   )r   rD   r   rJ   r   rL   	decoratorZdotted_nameZlast_trailerZ	last_leafrC   r   r   r   r   r}      s<   







zFixtureFilter._is_fixture)__name__
__module____qualname__r   r}   __classcell__r   r   r   r   rB      s    rB   )F) rf   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
   r{   r   ru   r   r;   r?   rH   r1   r/   r@   strrk   rA   rs   rB   r   r   r   r   <module>   s,    	/&