
    BTh^                        d dl Z d dlmZmZmZmZmZmZ d dlZd dl	m
Z
mZ d dlmZ d dlmZ d dlmZ erd dlmZ dd	lmZmZ dd
lmZ ddlmZ dZde
ddfdZd-dZdeddfdZdeddfdZ ej@                  d      dede!fd       Z" ej@                  d      dede#fd       Z$ej@                  defd       Z%ej@                  dedee!   fd       Z&ej@                  dedee   fd       Z' ej@                  d      dede!d ee   ded   fd!       Z( ej@                  d      ded ee   d"e!de!d#e#d$e
deed%      fd&       Z) ej@                  d'      dede!fd(       Z*ej@                  dede!fd)       Z+d*ed+e!de!fd,Z,y).    N)TYPE_CHECKINGAnyDictIteratorListOptional)ConfigPytestPluginManager)Parser)
SubRequest)Mark)Cassette   )hooksnetwork)merge_kwargs)validate_block_network_mark)oncenew_episodesnoneallrewriteconfigreturnc                    | j                   j                  d      rt        d      | j                  dd       | j                  dd       | j                  dd       | j                  dd       t	        j
                          y )Nvcrzx`pytest-recording` is incompatible with `pytest-vcr`. Please, uninstall `pytest-vcr` in order to use `pytest-recording`.markersz#vcr: Mark the test as using VCR.py.z=block_network: Block network access except for VCR recording.z5default_cassette: Override the default cassette name.zRallowed_hosts: List of regexes to match hosts to where connection must be allowed.)pluginmanager
has_pluginRuntimeErroraddinivalue_liner   install_pycurl_wrapper)r   s    i/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/pytest_recording/plugin.pypytest_configurer$      s    &&u-Q
 	
 I'LM
I'fg
I'^_
\ ""$    c                  ,    t        j                          y N)r   uninstall_pycurl_wrapper r%   r#   pytest_unconfigurer*   $   s    $$&r%   parserc                     | j                  d      }|j                  ddd t        d       |j                  dddd	
       |j                  ddd d
       |j                  dddd
       y )N	recording--record-modestorez&VCR.py record mode. Default to "none".)actiondefaultchoiceshelp--block-network
store_trueFz.Block network access except for VCR recording.)r0   r1   r3   --allowed-hostszXList of regexes, separated by comma, to match hosts to where connection must be allowed.--disable-recordingDisable VCR.py integration.)getgroup	addoptionRECORD_MODES)r+   groups     r#   pytest_addoptionr=   (   s    OOK(E	OO5   
OO=	   
OOg	   
OO*	  r%   r   c                 .    | j                  t               y r'   )add_hookspecsr   )r   s    r#   pytest_addhooksr@   E   s    &r%   session)scoperequestc                 @    | j                   j                  d      xs dS )z]When recording is disabled the VCR recording mode should be "none" to prevent network access.r.   r   r   	getoptionrC   s    r#   record_moderH   I   s     >>##O4>>r%   c                 8    | j                   j                  d      S )r8   r7   rE   rG   s    r#   disable_recordingrJ   O   s     >>##$9::r%   c                      i S )z4A shareable configuration for VCR.use_cassette call.r)   r)   r%   r#   
vcr_configrL   U   s	     Ir%   c                 :   | j                   j                  d      }| j                  d      }t        |di       j	                  d      xs. | j
                  j                  d      xs |j	                  d      }t        |t              r|j                  d      }|S )zCList of regexes to match hosts to where connection must be allowed.block_networknamerL   kwargsallowed_hostsr6   ,)
nodeget_closest_markergetfixturevaluegetattrgetr   rF   
isinstancestrsplit)rC   rN   r   rR   s       r#   rR   rR   [   s     LL333IM$$\2F 	x,00A 	'>>##$56	'::o& 
 -%%++C0r%   c                 L    t        | j                  j                  d            S )zaAll markers applied to the certain test together with cassette names associated with each marker.r   rO   )listrT   iter_markersrG   s    r#   vcr_markersr_   n   s!     ))u)566r%   T)autouserH   r_   c              #     K   | j                   j                  d      }|t        |       |rJ| j                  d      }t	        ||      }| j
                  j                  d      |j                  dd      }|s| j
                  j                  d      r<|r|dk(  r5| j                  d	      }t        j                  |
      5  d ddd       yd y# 1 sw Y   yxY ww)zCBlock network access in tests except for "none" VCR recording mode.rN   rO   NrL   r.   rH   r   r4   rR   )rR   )
rT   rU   r   rV   r   r   rF   rX   r   blocking_context)rC   rH   r_   rN   r   merged_configrR   s          r#   rN   rN   t   s      LL333IM #M2
 ((6$V[9>>##O4<'++M6BK112CD{^ims^s//@%%MB 		 	 		 	s   CC"CC"CC"vcr_cassette_dirrJ   pytestconfigr   c              #      K   |rd y|rCddl m} | j                  d      }| j                  d      } |||||||      5 }	|	 ddd       yd y# 1 sw Y   yxY ww)z>Install a cassette if a test is marked with `pytest.mark.vcr`.Nr   )use_cassetterL   default_cassette_name)_vcrrg   rV   )
rC   r_   rd   rH   rJ   re   rg   r   default_cassettecassettes
             r#   r   r      s|      
	&((6"223JK
 	 N	 	 
	 	s   ?A AA AA modulec                     | j                   j                  }t        j                  j	                  |j
                  d|j                        S )zEach test module has its own cassettes directory to avoid name collisions.

    For example each test module could have test function with the same names:
      - test_users.py:test_create
      - test_profiles.py:test_create
    	cassettes)rT   fspathospathjoindirnamepurebasename)rC   rl   s     r#   rd   rd      s4     \\  F77<<V5H5HIIr%   c                     | j                   j                  d      }|"|j                  sJ d       |j                  d   S t        | j                  | j                   j
                        S )Nrj   z]You should pass the cassette name as an argument to the `pytest.mark.default_cassette` markerr   )rT   rU   argsget_default_cassette_nameclsrP   )rC   markers     r#   rh   rh      s^    \\,,-?@F{{ 	
k	
{ {{1~$W[[',,2C2CDDr%   
test_class	test_namec                 z    | rdj                  | j                  |      }n|}dD ]  }|j                  |d      } |S )Nz{}.{}z<>?%*:|\"'/\\-)format__name__replace)rz   r{   cassette_namechs       r#   rw   rw      sI    z':':IF!
  7%--b#67r%   )r   N)-rp   typingr   r   r   r   r   r   pytest_pytest.configr	   r
   _pytest.config.argparsingr   _pytest.fixturesr   _pytest.mark.structuresr   vcr.cassetter    r   r   utilsr   
validationr   r;   r$   r*   r=   r@   fixturerZ   rH   boolrJ   rL   rR   r_   rN   r   rd   rh   rw   r)   r%   r#   <module>r      sg   	 E E  6 , ' (%   3A%V % % 'V  :'#6 '4 ' i ? ? ? !?
 i ;z ;d ; !;
 D  
 : $s)  $ 7 7T
 7 7
 : C d4j U]^bUc  0 d  	
   hz"# : hJj JS J  J E: E# E E# # # r%   