o
    ð›hc(  ã                   @   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© úIc:\Users\shubh\Videos\agent\nova\Lib\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  qŽq†d 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,    	/&