o
    ˷e2                     @   s   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	 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e dddZG dd de	ZdS )    )Path)search_ancestor)inference_state_method_cache)load_module_from_path)ParserTreeFilter)	NO_VALUESValueSet)infer_call_of_leaf))_pytestmonkeypatch)r
   capture)r
   logging)r
   tmpdir)r
   pytesterc                        fdd}|S )Nc                    s(   |   dkr| j  dkrtS  | |S )Nfixturez_pytest.fixtures)
py__name__parent_contextr   )value	argumentscallback J/var/www/ideatree/venv/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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)py__getattribute__execute_annotationr"   r   r   r   r%   &   s
    
)
	tree_node
annotationexecute_with_valuesanyr   	from_sets
as_contextis_generatormerge_yield_valuesget_return_values)r   result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   )r4   r   r   r%   E   s    z9infer_anonymous_param.<locals>.wrapper.<locals>.<genexpr>)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funcr4   r   r   r   5   s    z&infer_anonymous_param.<locals>.wrapperr   rD   r   r   rC   r   infer_anonymous_param   s   rF   c                    r   )Nc                    s4   t | \}}|rt|  | j|d}|r|S  | S Nr5   )r:   r<   r;   r=   )r>   r?   r@   namesrD   r   r   r   O   s   z%goto_anonymous_param.<locals>.wrapperr   rE   r   rI   r   goto_anonymous_paramN   s   rJ   c                    r   )Nc                    sH   |   }t||rg }t|D ]
}|t| 7 }q|r|S  | ||S r7   )r;   _is_pytest_func_iter_pytest_modulesFixtureFiltervalues)context	func_namedecorator_nodesmodule_contextrH   rI   r   r   r   _   s   
z%complete_param_names.<locals>.wrapperr   rE   r   rI   r   complete_param_names^   s   	rS   c                 C   s0   t | |dD ]} t| |}|r|  S qd S rG   )rL   rM   get)rR   r    r6   rH   r   r   r   r<   k   s   r<   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_nameget_decoratorsrK   r    r   r=   )r>   rU   
decoratorsr   r   r   r:   r   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,   )rP   rQ   r   r   r   rK      s   
rK   Fc                 #   s    |s| V  |   j}|d urf|  | j }d }t fdd|D rf d}t|j| 	 krJzt
| j|}| V  W n	 tyI   Y nw    |d urY j|jkrYn }t fdd|D s%tD ]}| j|D ]}| V  qpqhd S )Nc                 3   s    | ]	} j |V  qd S r7   )pathr]   )r#   pfolderr   r   r%      r\   z'_iter_pytest_modules.<locals>.<genexpr>zconftest.py)	get_valuefile_ioget_parent_folderinference_stateget_sys_pathr,   get_file_ior   r^   
py__file__r   r.   FileNotFoundError_PYTEST_FIXTURE_MODULESimport_module)rR   r6   rc   sys_pathlast_foldermrH   module_valuer   r`   r   rL      s6   


rL   c                       s$   e Zd Z fddZdd Z  ZS )rM   c                 #   sH    t  |D ]}|j}|jdkr!|j}|jdkr!| |r!|V  qd S )NrU   	decorated)super_filterparenttype_is_fixture)selfrH   r    rU   rp   	__class__r   r   rr      s   
zFixtureFilter._filterc           	      C   s   |j d }|jdkr|j }n|g}|D ]G}|j d }d| v rZ|jdkrB|j d }| }|dkr;t| j|dd	}n| j|}n| j|}|D ]}|jjdd
dkrY  dS qJqdS )Nr   rX      r   	atom_expr)T)cut_own_trailerr   )r
   rB   r   F)	childrenrt   rZ   get_last_leafr	   r   
infer_noder    r!   )	rv   rp   rX   	decoratordotted_namelast_trailer	last_leafrN   r   r   r   r   ru      s0   




zFixtureFilter._is_fixture)__name__
__module____qualname__rr   ru   __classcell__r   r   rw   r   rM      s    	rM   N)F)pathlibr   
parso.treer   jedi.inference.cacher   jedi.inference.importsr   jedi.inference.filtersr   jedi.inference.base_valuer   r   jedi.inference.helpersr	   rj   r   rF   rJ   rS   r<   r:   rK   rL   rM   r   r   r   r   <module>   s$    	/ 