
    ^j%                         d dl 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
 Zd Zd Zd Zd Zd Zd Zdeee      fdZ e       dd       Zd Z G d de      Zy)    N)List)Path)inference_state_method_cache)goto_importload_module_from_path)ParserTreeFilter)	NO_VALUESValueSet)infer_call_of_leaf))_pytestmonkeypatch)r   capture)r   logging)r   tmpdir)r   pytesterc                       fd}|S )Nc                     | j                         dk(  r#| j                  j                         dk(  rt        S  | |      S )Nfixturez_pytest.fixtures)
py__name__parent_contextr	   )value	argumentscallbacks     L/opt/ringagent/.cad-venv/lib/python3.12/site-packages/jedi/plugins/pytest.pywrapperzexecute.<locals>.wrapper   sA     *((3359KKy))     )r   r   s   ` r   executer      s    * Nr   c                      d  fd}|S )Nc                 .   | j                   j                  @| j                         }t        d |D              rt	        j
                  d |D              S |S | j                         }|j                         r|j                         S |j                         S )Nc              3   Z   K   | ]#  }|j                   j                  d       dk(   % yw)Tinclude_module_names)typing	GeneratorN)nameget_qualified_names.0vs     r   	<genexpr>z=infer_anonymous_param.<locals>.get_returns.<locals>.<genexpr>$   s2      $ 66--4-H-. $s   )+c              3   \   K   | ]$  }|j                  d       j                  d       & yw)__next__N)py__getattribute__execute_annotationr(   s     r   r+   z=infer_anonymous_param.<locals>.get_returns.<locals>.<genexpr>'   s.      * ((4GGM*s   *,)
	tree_node
annotationexecute_with_valuesanyr
   	from_sets
as_contextis_generatormerge_yield_valuesget_return_values)r   resultfunction_contexts      r   get_returnsz*infer_anonymous_param.<locals>.get_returns!   s    ??%%1..0F $"$ $  )) *#*   M
 !++-((*#6688#5577r   c                     | j                   r |       S t        |       \  }}|rH| j                         }t        || j                  |      }|rt        j                  fd|D              S  |       S )Nskip_own_modulec              3   X   K   | ]!  }|j                         D ]  } |        # y wN)infer)r)   r   r   r;   s      r   r+   z9infer_anonymous_param.<locals>.wrapper.<locals>.<genexpr>F   s9      *!(*   &*&*s   '*)annotation_node _is_a_pytest_param_and_inheritedget_root_context_goto_pytest_fixturestring_namer
   r4   )
param_nameis_pytest_paramparam_name_is_function_namemodulefixturesfuncr;   s        r   r   z&infer_anonymous_param.<locals>.wrapper6   s    %%
##,Z8 	54002F+&& !<H )) *#+*  
 Jr   r   )rL   r   r;   s   ` @r   infer_anonymous_paramrM       s    8* , Nr   c                       fd}|S )Nc                     t        |       \  }}|r*t        | j                         | j                  |      }|r|S  |       S Nr=   )rC   rE   rD   rF   )rG   rH   rI   namesrL   s       r   r   z%goto_anonymous_param.<locals>.wrapperP   sO    ,Z8 	54(++-&& ;E
 Jr   r   rL   r   s   ` r   goto_anonymous_paramrS   O   s      Nr   c                       fd}|S )Nc                     | j                         }t        ||      r2g }t        |      D ]  }|t        |      j	                         z  }  |r|S  | ||      S r@   )rD   _is_pytest_func_iter_pytest_modulesFixtureFiltervalues)context	func_namedecorator_nodesmodule_contextrQ   rL   s        r   r   z%complete_param_names.<locals>.wrapper`   se     1139o6E"6~"F @~6==??@GY88r   r   rR   s   ` r   complete_param_namesr^   _   s    9 Nr   c                 h    t        | |      D ]"  } t        |       j                  |      }|s |c S  y rP   )rW   rX   get)r]   r&   r>   rQ   s       r   rE   rE   l   s5    .~_ n-11$7Lr   c                     | j                   j                  d      }|y|j                         }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.
    funcdef)FF)	tree_namesearch_ancestorget_decoratorsrV   r&   r   rF   )rG   rb   
decoratorss      r   rC   rC   s   sf     ""229=G'')J7<<--z:j4445 5r   c                 L    | j                  d      xs t        d |D              S )Ntestc              3   @   K   | ]  }d |j                         v   yw)r   N)get_code)r)   ns     r   r+   z"_is_pytest_func.<locals>.<genexpr>   s     BQyAJJL(Bs   )
startswithr3   )r[   r\   s     r   rV   rV      s*    ' CB/BBCr   returnc                      ddl m}  t        j                  dk\  r
 | d      }n |        j	                  dd      }|D cg c]  }|j
                  j                  d       c}S c c}w )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)   
   pytest11)groupr   .)importlib.metadataro   sysversion_infor`   rJ   split)ro   pytest_entry_pointseps      r   _find_pytest_plugin_modulesr{      sV     0
7"*<*n00R@+>?RBIIOOC ???s   "A$c              #   v  K   |s|  | j                         j                  }|8|j                         | j                  j	                         }d }t        fd|D              rj                  d      }t        |j                        | j                         k7  r~	 t        | j                  |      }|j                         }| |j                  j                         j                  d      }|r(|j                  |d         }t!        | |      E d {    j                         |j                  |j                  k(  rn}t        fd|D              rt$        t'               z   D ]4  }	| j                  j)                  |	      D ]  }
|
j                           6 y 7 # t"        $ r Y w xY ww)Nc              3   T   K   | ]  }j                   j                  |       ! y wr@   )pathrl   )r)   pfolders     r   r+   z'_iter_pytest_modules.<locals>.<genexpr>   s      >&++((+>s   %(zconftest.pypytest_pluginsr   )	get_valuefile_ioget_parent_folderinference_stateget_sys_pathr3   get_file_ior   r~   
py__file__r   r5   r0   get_used_namesr`   create_name_load_pytest_pluginsFileNotFoundError_PYTEST_FIXTURE_MODULESr{   import_module)r]   r>   r   sys_pathlast_foldermconftest_moduleplugins_listr&   rQ   module_valuer   s              @r   rW   rW      s    &&(00G**,!11>>@ >X>>((7GGLL!^%>%>%@@
-n.L.LgVA&'llnO))#$;;#=#=#?#C#CDT#UL#.::<?K#7#MMM --/F &6;;+:J:J+J K' >X>>* )+F+HH ,*::HHO 	,L))++	,, N( sE   BF9A8F* F(F* AF9A	F9(F* *	F63F95F66F9c              #   2  K   ddl m} |j                         D ]z  }|j                         D ]e  }|j                         D ]P  } ||      }|s|j	                  d      }| j
                  j                  |      D ]  }|j                           R g | y w)Nr   )get_str_or_nonert   )jedi.inference.helpersr   rA   
py__iter__rx   r   r   r5   )	r]   r&   r   inferred	seq_valuer   fq_namerQ   r   s	            r   r   r      s     6JJL 8!,,. 	8I"* 8)%0#MM#.E(6(F(F(T(TUZ([ 8*55778	8	88s   A
BA
Bc                   $     e Zd Z fdZd Z xZS )rX   c              #      K   t            |      D ]l  }|j                  j                  dk(  r0t	         j
                  |      }t         fd|D              sG| L j                   j
                  |      si| n y w)Nimport_fromc              3      K   | ]6  }|j                   r(j                  |j                  |j                          8 y wr@   )rc   _is_fixturer   )r)   inameselfs     r   r+   z(FixtureFilter._filter.<locals>.<genexpr>   s7       $$U%9%95??Ks   <?)super_filterparenttyper   r   r3   r   )r   rQ   r&   imported_names	__class__s   `   r   r   zFixtureFilter._filter   sz     GOE* 	D{{=0!,T-@-@$!G !/  J!!$"5"5t<
	s   AB!B=Bc                 >   |j                   }|j                  dk7  ry|j                   }|j                  dk7  ry|j                  d   }|j                  dk(  r|j                  }n|g}|D ]  }|j                  d   }d|j                         v s%|j                  dk(  rE|j                  d	   }|j	                         }	|	d
k(  rt        ||	d      }
n#|j                  |      }
n|j                  |      }
|
D ]$  }|j                  j                  d      dk(  s#  y  y)Nrb   F	decoratedr   rf      r   	atom_expr)T)cut_own_trailerr"   )r   rK   r   )	r   r   childrenrj   get_last_leafr   
infer_noder&   r'   )r   rZ   r&   rb   r   rf   	decoratordotted_namelast_trailer	last_leafrY   r   s               r   r   zFixtureFilter._is_fixture   s.   ++<<9$NN	>>[(''*
??l*#,,J$J# 	$I#,,Q/KK0022##{2 $/#7#7#;L , : : <I C'!3#Y" ")!3!3K!@$//<F# $Ezz5545PAB#$#	$* r   )__name__
__module____qualname__r   r   __classcell__)r   s   @r   rX   rX      s     "r   rX   )F)rv   r$   r   pathlibr   jedi.inference.cacher   jedi.inference.importsr   r   jedi.inference.filtersr   jedi.inference.base_valuer	   r
   r   r   r   r   rM   rS   r^   rE   rC   rV   strr{   rW   r   rX   r   r   r   <module>r      s    
   = E 3 9 5 	,^ 
5C
@T$s)_ @  #,  #,L
83$ 3r   