o
    iS                     @  sj  U d dl mZ d dlZd dlmZ d dlZd dlad dlZd dlZd dl	Z	d dl
mZ d dlmZ 	 dZtdZdadadadadadadadZdadadadadae Ze Zda de!d	< d
d Z"dd Z#dd Z$dd Z%dd Z&dd Z'dd Z(dd Z)dd Z*dd Z+dd Z,d d! Z-d"d# Z.d$d% Z/d&d' Z0g Z1g Z2d(d) Z3d*d+ Z4e3d,d- Z5e3d.d/ Z6e4d0d1 Z7e4d2d3 Z8e3d4d5 Z9e4d6d7 Z:e4d8d9 Z;d:d; Z<e4d<d= Z=e4d>d? Z>e4d@dA Z?dBdC Z@dDdE ZAdFdG ZBdHdI ZCdJdK ZDdLdM ZEdNdO ZFdPdQ ZGdRdS ZHdTdU ZIdVdW ZJdXdY ZKdddZd[ZLd\d] ZMd^d_ ZNG d`da daejOZPdaQdbdc ZRdS )e    )annotationsN)	Namespace)Any)asyncioFzsqlalchemy.testing.plugin_baser   optionsc                 C  s  | ddt tdd | ddt tdd | ddt d	d
d | ddtdd | ddt ddd | ddt ddd | ddddd | dddd | ddtddd | d dtd!d"d | d#dtd$d%d | d&dtd'd(d | d)t d*d+d,d- | d.t d/d0d1 | d2dd3d4d | d5t d6d7d1 | d8dt td9d | d:dtt d;d< | d=dtt d>d< | d?dd@dAdBdC | dDddEdAdFdC | dGt dHdId1 | dJt dg dKdLdM | dNt dOdP | dQddRd d S )SNz
--log-infocallbackz,turn on info logging for <LOG> (multiple OK))actiontyper   helpz--log-debugz-turn on debug logging for <LOG> (multiple OK)z--dbappenddbzBUse prefab database uri. Multiple OK, first one is run by default.)r   r	   destr
   z--dbszList available prefab dbs)r   zeroarg_callbackr
   z--dburidburiz8Database uri.  Multiple OK, first one is run by default.z
--dbdriverdbdriverz|Additional database drivers to include in tests.  These are linked to the existing database URLs by the provisioning system.z--dropfirst
store_true	dropfirstz,Drop all tables in the target database first)r   r   r
   z--disable-asyncioz8disable test / fixtures / provisoning running in asyncio)r   r
   z--backend-onlybackendz}Run only tests marked with __backend__ or __sparse_backend__; this is now equivalent to the pytest -m backend mark expressionz
--nomemorymemory_intensivezpDon't run memory profiling tests; this is now equivalent to the pytest -m 'not memory_intensive' mark expressionz--notimingintensivetiming_intensivezpDon't run timing intensive tests; this is now equivalent to the pytest -m 'not timing_intensive' mark expressionz--nomypymypyz_Don't run mypy typing tests; this is now equivalent to the pytest -m 'not mypy' mark expressionz--profile-sort
cumulativeprofilesortz*Type of sort for profiling standard output)r	   defaultr   r
   z--profile-dumpprofiledumpz2Filename where a single profile run will be dumped)r	   r   r
   z--low-connectionslow_connectionsz>Use a low number of distinct connections - i.e. for Oracle TNSz--write-identswrite_identszCwrite out generated follower idents to <file>, when -n<num> is usedz--requirementsz3requirements class for testing, overrides setup.cfgz--include-tagzAInclude tests with tag <tag>; legacy, use pytest -m 'tag' instead)r   r   r	   r
   z--exclude-tagzEExclude tests with tag <tag>; legacy, use pytest -m 'not tag' insteadz--write-profileswrite_profilesFz$Write/update failing profiling data.)r   r   r   r
   z--force-write-profilesforce_write_profilesz,Unconditionally write/update profiling data.z--dump-pyannotatedump_pyannotatez/Run pyannotate and dump json info to given filez--mypy-extra-test-pathmypy_extra_test_pathszlAdditional test directories to add to the mypy tests. This is used only when running mypy tests. Multiple OK)r	   r   r   r   r
   z--postgresql-templatedbz^name of template database to use for PostgreSQL CREATE DATABASE (defaults to current database))r	   r
   z--oracledb-thick-modez:enables the 'thick mode' when testing with oracle+oracledb)str_log	_list_dbs_set_tag_include_set_tag_exclude_requirements_opt_include_tag_exclude_tag)make_option r*   e/var/www/html/LicenciasMIG/venv/lib/python3.10/site-packages/sqlalchemy/testing/plugin/plugin_base.pysetup_options:   s@  		

r,   c                 C  s   ddl m} | |_dS )zConfigure required state for a follower.

    This invokes in the parent process and typically includes
    database creation.

    r   	provisionN)sqlalchemy.testingr.   FOLLOWER_IDENT)follower_identr.   r*   r*   r+   configure_follower   s   
r2   c                 C     dS )zStore important configuration we will need to send to a follower.

    This invokes in the parent process after normal config is set up.

    Hook is currently not used.

    Nr*   dict_r*   r*   r+   !memoize_important_follower_config       r6   c                 C  r3   )zRestore important configuration needed by a follower.

    This invokes in the follower process.

    Hook is currently not used.

    Nr*   r4   r*   r*   r+   !restore_important_follower_config  r7   r8   c                 C  s*   t  att| d t| d g d S )Nz	setup.cfgztest.cfg)configparserConfigParserfile_configreadr!   )	root_pathr*   r*   r+   read_config  s   r>   c                 C  s   | a tD ]}|t t qdS )z7things to set up early, before coverage might be setup.N)r   pre_configurer;   )optfnr*   r*   r+   	pre_begin  s   rB   c                 C  s
   | t _d S N)r   has_coverage)valuer*   r*   r+   set_coverage_flag  s   
rF   c                  C  sp   t D ]} | tt qddlma ddlmamama ddlm	a	m
a
ma ddlmama ddlma t
  dS )z9things to set up later, once we know coverage is running.r   testing)fixturesengines
exclusions)
assertionswarnings	profiling)configr.   )utilN)post_configurer   r;   
sqlalchemyrH   r/   rI   rJ   rK   rL   rM   rN   rO   r.   rP   setup_filtersrA   r*   r*   r+   
post_begin#  s   rU   c                 C  sX   t s
dd l a t   | drt |t j d S | dr*t |t j d S d S )Nr   z-infoz-debug)loggingbasicConfigendswith	getLoggersetLevelINFODEBUGopt_strrE   parserr*   r*   r+   r"   5  s   

r"   c                  G  sB   t d ttdD ]}t d|td|f  qtd d S )Nz0Available --db options (use --dburi to override)r   z%20s	%sr   )printsortedr;   r   getsysexit)argsmacror*   r*   r+   r#   B  s   r#   c                 C  s   t | d S rC   )_setup_requirementsr]   r*   r*   r+   r&   I  s   r&   c                       fdd}|S )Nc                      t |  | d S rC   )r'   r]   tagr*   r+   _do_include_tagN     z)_set_tag_include.<locals>._do_include_tagr*   )rk   rl   r*   rj   r+   r$   M     r$   c                   rh   )Nc                   ri   rC   )r(   r]   rj   r*   r+   _do_exclude_tagU  rm   z)_set_tag_exclude.<locals>._do_exclude_tagr*   )rk   ro   r*   rj   r+   r%   T  rn   r%   c                 C     t |dd d S N-_)exclude_tagsaddreplacer]   r*   r*   r+   r(   [     r(   c                 C  rp   rq   )include_tagsru   rv   r]   r*   r*   r+   r'   _  rw   r'   c                 C     t |  | S rC   )r?   r   rT   r*   r*   r+   preg     
rz   c                 C  ry   rC   )rQ   r   rT   r*   r*   r+   postl  r{   r|   c                 C     | a d S rC   r   r@   r;   r*   r*   r+   _setup_optionsq  s   r   c                 C  s,   ddl m} |ddd |ddd d S )Nr   )registryzsqlite.pysqlite_numericz#sqlalchemy.dialects.sqlite.pysqlite_SQLiteDialect_pysqlite_numericzsqlite.pysqlite_dollar_SQLiteDialect_pysqlite_dollar)sqlalchemy.dialectsr   register)r@   r;   r   r*   r*   r+    _register_sqlite_numeric_dialectw  s   r   c              
   C  sV   t jdddkr)ddlm} z|dd W d S  ty( } ztd|d }~ww d S )	NREQUIRE_SQLALCHEMY_CEXT01r   )has_compiled_extT)raise_zEREQUIRE_SQLALCHEMY_CEXT is set but can't import the cython extensions)osenvironrb   sqlalchemy.utilr   ImportErrorAssertionError)r@   r;   r   errr*   r*   r+   __ensure_cext  s   r   c                 C  s   ddl m} t |_d S Nr   rO   )r/   rO   _fixture_fn_class_fixture_functions)r   r;   rO   r*   r*   r+   _init_symbols  s   r   c                 C  s   | j rdt_d S d S NF)disable_asyncior   ENABLE_ASYNCIOr   r*   r*   r+   _set_disable_asyncio  s   
r   c              	   C  sV  ddl m} ddlm} ddlm} | jrt| j}ng }| jp!g }| jrJ| jD ]!}t	
d|D ]}||dvr?td| ||d| q0q(|sU||dd d |_t|||}	|	D ]F}
td	|
 | jr|jrt| jd
}||j d|
jdd d W d    n1 sw   Y  ||
| ||j}|js||| qbd S )Nr   rG   r   r-   z[,\s]+r   z:Unknown URI specifier '%s'.  Specify --dbs for known uris.r   zAdding database URL: %sa F)hide_password
)rR   rH   r/   rO   r.   r   listr   r   resplitr   RuntimeErrorr   rb   _currentgenerate_db_urlsloginfor   r0   openwriterender_as_stringsetup_configset_as_current)r   r;   rH   rO   r.   db_urlsextra_driversdb_tokenr   expanded_urlsdb_urlfile_cfgr*   r*   r+   _engine_uri  sN   

	

r   c                 C  s   | dd}t| d S )Nsqla_testingrequirement_cls)rb   rg   )r   r;   r   r*   r*   r+   _requirements  s   r   c                 C  sr   ddl m} ddlm} | d\}}t|}|ddd  D ]}t||}q t||}|  |_|_t	|_	d S )Nr   r   rG   :.   )
r/   rO   rR   rH   r   
__import__getattrrequirementsrequiresbootstrapped_as_sqlalchemy)argumentrO   rH   modnameclsnamemod	componentreq_clsr*   r*   r+   rg     s   

rg   c                 C  sD   ddl m} | jrddl m} |j D ]}|||j qd S d S )Nr   r   r-   )r/   rO   r   r.   Configall_configsdrop_all_schema_objectsr   )r   r;   rO   r.   r   r*   r*   r+   _prep_testing_database  s   r   c                 C  s   ddl m} t|_||_d S r   )r/   rO   r   r;   )r@   r;   rO   r*   r*   r+   _post_setup_options  s   
r   c                 C  s.   ddl m} |j|dd| j| jd|_d S )Nr   )rN   r   profile_file)sortdump)r/   rN   ProfileStatsFilerb   r   r   _profile_stats)r   r;   rN   r*   r*   r+   _setup_profiling  s   
r   c                 C  s"   t |tjsdS | drdS dS )NFrs   T)
issubclassrI   TestBase
startswith)nameclsr*   r*   r+   
want_class  
   
r   c                 C  s"   |j dsdS |jd u rdS dS )Ntest_FT)__name__r   
__module__)r   rA   r*   r*   r+   want_method  r   r   c           	      c  s    d|v s	d|v rDd|v }t | |dD ].}| j}tdd|j}tdd|}d| j|f }t|| f||d	}t||| |V  qd S | V  d S )
Nr   sparse_backend)sparsez
[_\[\]\.]+rs   z_+$ z%s_%s)_sa_orig_cls_name__only_on_config__)_possible_configs_for_clsr   r   subr   r	   setattr)	r   modulemarkersr   r   	orig_name
alpha_namer   subclsr*   r*   r+   generate_sub_tests  s"   
r   c                 C  s   t |  t|  d S rC   )	_do_skips_setup_enginer   r*   r*   r+   !start_test_class_outside_fixtures2  s   r   c                 C  s   t |  tj  d S rC   )rI   stop_test_class_inside_fixturesrJ   testing_reaperr   r*   r*   r+   stop_test_class7  s   
r   c                 C  sJ   t j  tttj|  ztjst	  W t
  d S W t
  d S t
  w rC   )rJ   r    stop_test_class_outside_fixturesr.   rO   r   r   r   rL   global_cleanup_assertions_restore_enginer   r*   r*   r+   r   @  s   


r   c                   C  s   t jrt jt d S d S rC   )rO   r   resetrH   r*   r*   r*   r+   r   J  s   r   c                   C  s   t j  t  t  d S rC   )rJ   r   final_cleanuprL   r   r   r*   r*   r*   r+   final_process_cleanupO  s   

r   c                 C  s@   t | dd rt| j}d|d< tj|d}tj|t d S d S )N__engine_options__classscoper~   )	r   dictr   rJ   testing_enginerO   r   push_enginerH   )r   optsengr*   r*   r+   r   U  s   
r   c                 C  s*   t |d|j}d|||f }t| d S )Nr   z%s.%s.%s)r   r   rN   _start_current_test)testtest_module_name
test_class	test_namer   id_r*   r*   r+   before_test]  s   r  c                 C  s   t   tj  d S rC   )rI   
after_testrJ   r   r   r*   r*   r+   r  h  s   r  c                 C  s   t j|  d S rC   )rJ   r   after_test_outside_fixturesr  r*   r*   r+   after_test_fixturesm  rm   r	  c                 C  s  t tj }| jr tj| j }t|D ]}||r|| qt	| dd r?tjt
| j }t|D ]}||s>|| q3t	| dd rL|| jg t| dr}tj}t|D ]$}| jD ]}t	||}||}	|	r{|| |d ury||	  nq]qXt| drt  }
tj}t|D ]}| jD ]}t	||}||s|
| qq||
r||
 |ri }tt|dd dD ]}|jj}||vr|||< q| S |S )N__only_on__r   __requires____prefer_requires__c                 S  s   | j j| j j| j jjfS rC   )r   r   driverdialectserver_version_info)r   r*   r*   r+   <lambda>  s   z+_possible_configs_for_cls.<locals>.<lambda>)key)setrO   r   r   __unsupported_on__rK   db_specr   remover   rP   to_listr
  intersection_updater   hasattrr   r  matching_config_reasonsextendr  enabled_for_configru   
differencedifference_updatereversedra   r   r   values)r   reasonsr   r   spec
config_objr   requirementcheckskip_reasonsnon_preferredper_dialectr   r   r*   r*   r+   r   q  sl   















r   c                 C  s   g }t | |}t| ddr#t| dD ]}| r"td| j|jf  q|sCd| j| jddd tj D d|f }t| n)t	| drlt
 }tjt| j }|D ]}||sa|| qV||rl|| tj|vrzt| |  d S d S )	N__skip_if__Fz'%s' skipped by %sz1'%s.%s' unsupported on any DB implementation %s%sz, c              	   s  s>    | ]}d |j jddd t|j D |j jf V  qdS )z'%s(%s)+%s'r   c                 s  s    | ]}t |V  qd S rC   )r!   ).0digr*   r*   r+   	<genexpr>  s
    
z&_do_skips.<locals>.<genexpr>.<genexpr>N)r   r   joinrK   _server_versionr  )r)  r"  r*   r*   r+   r+    s    



z_do_skips.<locals>.<genexpr>__prefer_backends__)r   r   rO   	skip_testr   r   r,  r   r   r  r  rK   r  rP   r  r.  ru   r  r  r   _setup_configpop)r   r   r   cmsgr&  r!  r"  r*   r*   r+   r     s>   







r   c                 C  s   t j| t d S rC   )rO   r   pushrH   )r"  ctxr*   r*   r+   r0    s   r0  c                   @  sj   e Zd Zejdd Zejdd Zejdd Zejdd Zd	d
 Z	ejdddZ
ejdd ZdS )FixtureFunctionsc                 O     t  rC   NotImplementedErrorselfargkwr*   r*   r+   skip_test_exception     z$FixtureFunctions.skip_test_exceptionc                 O  r7  rC   r8  r;  re   r=  r*   r*   r+   combinations  r?  zFixtureFunctions.combinationsc                 O  r7  rC   r8  r@  r*   r*   r+   param_ident  r?  zFixtureFunctions.param_identc                 O  r7  rC   r8  r:  r*   r*   r+   fixture  r?  zFixtureFunctions.fixturec                 C  r7  rC   r8  r;  r*   r*   r+   get_current_test_name  s   z&FixtureFunctions.get_current_test_namereturnr   c                 C  r7  rC   r8  rD  r*   r*   r+   mark_base_test_class  r?  z%FixtureFunctions.mark_base_test_classc                 C  r7  rC   r8  rD  r*   r*   r+   add_to_marker  r?  zFixtureFunctions.add_to_markerN)rF  r   )r   r   __qualname__abcabstractmethodr>  rA  rB  rC  rE  rG  abstractpropertyrH  r*   r*   r*   r+   r6    s    



r6  c                 C  r}   rC   )r   )fixture_fn_classr*   r*   r+   set_fixture_functions  s   rN  r   )S
__future__r   rJ  argparser   r9   rV   r   r   rc   typingr   r/   r   r   rY   r   rI   rJ   rK   rM   rN   r.   rL   r   rO   rH   rP   r;   r  rx   rt   r   __annotations__r,   r2   r6   r8   r>   rB   rF   rU   r"   r#   r&   r$   r%   r(   r'   r?   rQ   rz   r|   r   r   r   r   r   r   r   rg   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r   r   r0  ABCr6  r   rN  r*   r*   r*   r+   <module>   s   	
 6







/





			

B+