a
    lc2                     @   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))_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 O/var/www/html/django/DPS/env/lib/python3.9/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 u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   E   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   5   s     z&infer_anonymous_param.<locals>.wrapperr   r4   r   r   r3   r   infer_anonymous_param   s    r6   c                    s    fdd}|S )Nc                    s4   t | \}}|r,t|  | j|d}|r,|S  | S Nr'   )r*   r,   r+   r-   )r.   r/   r0   namesr4   r   r   r   O   s    z%goto_anonymous_param.<locals>.wrapperr   r5   r   r9   r   goto_anonymous_paramN   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_contextr8   r9   r   r   r   _   s    
z%complete_param_names.<locals>.wrapperr   r5   r   r9   r   complete_param_names^   s    	rC   c                 C   s0   t | |dD ]} t| |}|r|  S qd S r7   )r<   r=   get)rB   r   r(   r8   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   Z	tree_nameZget_decoratorsr;   r   r   r-   )r.   rE   
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"   )r@   rA   r   r   r   r;      s    
r;   Fc                 #   s   |s
| V  |   j}|d ur|  | j }d }t fdd|D r d}t|j| 	 krzt
| j|}| V  W n ty   Y n0    |d ur j|jkrq }q2tD ] }| j|D ]}| V  qqd S )Nc                 3   s   | ]} j |V  qd S r)   )pathrK   )r   pfolderr   r   r      rJ   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   rL   Z
py__file__r   r$   FileNotFoundError_PYTEST_FIXTURE_MODULESimport_module)rB   r(   rQ   sys_pathZlast_foldermr8   Zmodule_valuer   rN   r   r<      s,    


r<   c                       s$   e Zd Z fddZdd Z  ZS )r=   c                 #   sF   t  |D ]4}|j}|jdkr|j}|jdkr| |r|V  qd S )NrE   	decorated)super_filterparenttype_is_fixture)selfr8   r   rE   rW   	__class__r   r   rY      s    
zFixtureFilter._filterc           	      C   s   |j d }|jdkr|j }n|g}|D ]}|j d }d| v r&|jdkr|j d }| }|dkrvt| j|dd	}q| j|}n| j|}|D ]}|jjdd
dkr  dS qq&dS )Nr   rF      r   Z	atom_expr)T)Zcut_own_trailerr   )r
   r2   r   F)	childrenr[   rH   Zget_last_leafr	   r   Z
infer_noder   r   )	r]   rW   rF   	decoratorZdotted_nameZlast_trailerZ	last_leafr>   r   r   r   r   r\      s,    




zFixtureFilter._is_fixture)__name__
__module____qualname__rY   r\   __classcell__r   r   r^   r   r=      s   	r=   N)F)pathlibr   Z
parso.treer   Zjedi.inference.cacher   Zjedi.inference.importsr   Zjedi.inference.filtersr   Zjedi.inference.base_valuer   r   Zjedi.inference.helpersr	   rS   r   r6   r:   rC   r,   r*   r;   r<   r=   r   r   r   r   <module>   s"   	/ 