o
    E6d^V                     @  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   Z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
--nomemoryZmemory_intensivezpDon't run memory profiling tests; this is now equivalent to the pytest -m 'not memory_intensive' mark expressionz--notimingintensiveZtiming_intensivezpDon't run timing intensive tests; this is now equivalent to the pytest -m 'not timing_intensive' mark expressionz--nomypyZmypyz_Don't run mypy typing tests; this is now equivalent to the pytest -m 'not mypy' mark expressionz--profile-sortZ
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-profilesZwrite_profilesFz$Write/update failing profiling data.)r   r   r   r
   z--force-write-profilesZforce_write_profilesz,Unconditionally write/update profiling data.z--dump-pyannotateZdump_pyannotatez/Run pyannotate and dump json info to given filez--mypy-extra-test-pathZ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!   |C:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\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)Zfollower_identr%   r!   r!   r"   configure_follower   s   
r(   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!   Zdict_r!   r!   r"   !memoize_important_follower_config       r+   c                 C  r)   )zRestore important configuration needed by a follower.

    This invokes in the follower process.

    Hook is currently not used.

    Nr!   r*   r!   r!   r"   !restore_important_follower_config  r,   r-   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   r3   c                 C  s   | a tD ]}|t t qdS )z7things to set up early, before coverage might be setup.N)r   pre_configurer0   )optfnr!   r!   r"   	pre_begin  s   r7   c                 C  s
   | t _d S N)r   Zhas_coverage)valuer!   r!   r"   set_coverage_flag  s   
r:   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   r0   
sqlalchemyr<   r&   r=   r>   r?   r@   rA   rB   rC   r%   rD   Zsetup_filtersr6   r!   r!   r"   
post_begin#  s   rH   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_strr9   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sortedr0   r   getsysexit)argsmacror!   r!   r"   r   B  s   r   c                 C  s   t | d S r8   )_setup_requirementsrP   r!   r!   r"   r   I  s   r   c                       fdd}|S )Nc                      t |  | d S r8   )r   rP   tagr!   r"   _do_include_tagN     z)_set_tag_include.<locals>._do_include_tagr!   )r^   r_   r!   r]   r"   r   M     r   c                   r[   )Nc                   r\   r8   )r   rP   r]   r!   r"   _do_exclude_tagU  r`   z)_set_tag_exclude.<locals>._do_exclude_tagr!   )r^   rb   r!   r]   r"   r   T  ra   r   c                 C     t |dd d S N-_)exclude_tagsaddreplacerP   r!   r!   r"   r   [     r   c                 C  rc   rd   )include_tagsrh   ri   rP   r!   r!   r"   r   _  rj   r   c                 C     t |  | S r8   )r4   r   rG   r!   r!   r"   preg     
rm   c                 C  rl   r8   )rE   r   rG   r!   r!   r"   postl  rn   ro   c                 C     | a d S r8   r   r5   r0   r!   r!   r"   _setup_optionsq  s   rs   c                 C  s,   ddl m} |ddd |ddd d S )Nr   )registryzsqlite.pysqlite_numericz#sqlalchemy.dialects.sqlite.pysqliteZ_SQLiteDialect_pysqlite_numericzsqlite.pysqlite_dollarZ_SQLiteDialect_pysqlite_dollar)Zsqlalchemy.dialectsrt   register)r5   r0   rt   r!   r!   r"    _register_sqlite_numeric_dialectw  s   rv   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 )	NZREQUIRE_SQLALCHEMY_CEXT01r   )has_compiled_extT)Zraise_zEREQUIRE_SQLALCHEMY_CEXT is set but can't import the cython extensions)osenvironrU   Zsqlalchemy.utilry   ImportErrorAssertionError)r5   r0   ry   errr!   r!   r"   __ensure_cext  s   r   c                 C  s   ddl m} t |_d S Nr   rC   )r&   rC   _fixture_fn_classZ_fixture_functions)r   r0   rC   r!   r!   r"   _init_symbols  s   r   c                 C  s   | j rdt_d S d S NF)Zdisable_asyncior   ZENABLE_ASYNCIOrr   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   r;   r   r$   z[,\s]+r   z:Unknown URI specifier '%s'.  Specify --dbs for known uris.r   zAdding database URL: %sa F)Zhide_password
)rF   r<   r&   rC   r%   r   listr   r   resplitr   RuntimeErrorr   rU   _currentZgenerate_db_urlsloginfor   r'   openwriteZrender_as_stringZsetup_configZset_as_current)r   r0   r<   rC   r%   Zdb_urlsZextra_driversZdb_tokenr   Zexpanded_urlsZdb_urlfile_cfgr!   r!   r"   _engine_uri  sN   

	

r   c                 C  s   | dd}t| d S )Nsqla_testingrequirement_cls)rU   rZ   )r   r0   r   r!   r!   r"   _requirements  s   r   c                 C  s   ddl m} ddlm} |jd urd S | d\}}t|}|ddd  D ]}t||}q't||}|  |_|_t	|_	d S )Nr   r   r;   :.   )
r&   rC   rF   r<   requirementsr   
__import__getattrrequiresbootstrapped_as_sqlalchemy)ZargumentrC   r<   modnameclsnamemod	componentZreq_clsr!   r!   r"   rZ     s   


rZ   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&   rC   r   r%   Configall_configsZdrop_all_schema_objectsr   )r   r0   rC   r%   r   r!   r!   r"   _prep_testing_database  s   r   c                 C  s   ddl m} t|_||_d S r   )r&   rC   r   r0   )r5   r0   rC   r!   r!   r"   _post_setup_options  s   
r   c                 C  s.   ddl m} |j|dd| j| jd|_d S )Nr   )rB   r   Zprofile_file)sortdump)r&   rB   ZProfileStatsFilerU   r   r   Z_profile_stats)r   r0   rB   r!   r!   r"   _setup_profiling   s   
r   c                 C  s"   t |tjsdS | drdS dS )NFrf   T)
issubclassr=   Z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 )NZtest_FT)__name__r   
__module__)r   r6   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   Zsparse_backend)sparsez
[_\[\]\.]+rf   z_+$ z%s_%s)_sa_orig_cls_name__only_on_config__)_possible_configs_for_clsr   r   subr   r	   setattr)	r   modulemarkersr   r   Z	orig_nameZ
alpha_namer   subclsr!   r!   r"   generate_sub_tests  s"   
r   c                 C  s   t |  t|  d S r8   )	_do_skips_setup_enginer   r!   r!   r"   !start_test_class_outside_fixtures5  s   r   c                 C  s   t |  tj  d S r8   )r=   Zstop_test_class_inside_fixturesr>   testing_reaperr   r!   r!   r"   stop_test_class:  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 r8   )r>   r    stop_test_class_outside_fixturesr%   rC   r   r   r   r@   global_cleanup_assertions_restore_enginer   r!   r!   r"   r   C  s   


r   c                   C  s   t jrt jt d S d S r8   )rC   r   resetr<   r!   r!   r!   r"   r   M  s   r   c                   C  s   t j  t  t  d S r8   )r>   r   Zfinal_cleanupr@   r   r   r!   r!   r!   r"   final_process_cleanupR  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scoperq   )	r   dictr   r>   Ztesting_enginerC   r   Zpush_enginer<   )r   optsZengr!   r!   r"   r   X  s   
r   c                 C  s*   t |d|j}d|||f }t| d S )Nr   z%s.%s.%s)r   r   rB   Z_start_current_test)testZtest_module_nameZ
test_classZ	test_namer   Zid_r!   r!   r"   before_test`  s   r   c                 C  s   t   tj  d S r8   )r=   
after_testr>   r   r   r!   r!   r"   r   k  s   r   c                 C  s   t j|  d S r8   )r>   r   Zafter_test_outside_fixturesr   r!   r!   r"   after_test_fixturesp  r`   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 r8   )r   r   driverdialectZserver_version_info)r   r!   r!   r"   <lambda>  s   z+_possible_configs_for_cls.<locals>.<lambda>)key)setrC   r   r   Z__unsupported_on__r?   db_specr   remover   rD   to_listr   intersection_updater   hasattrr   r   Zmatching_config_reasonsextendr   Zenabled_for_configrh   
differencedifference_updatereversedrT   r   r   values)r   reasonsr   r   spec
config_objr   requirementcheckZskip_reasonsnon_preferredZper_dialectr   r   r!   r!   r"   r   t  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 )	NZ__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 r8   )r   ).0digr!   r!   r"   	<genexpr>  s
    
z&_do_skips.<locals>.<genexpr>.<genexpr>N)r   r   joinr?   Z_server_versionr   )r   r   r!   r!   r"   r     s    



z_do_skips.<locals>.<genexpr>__prefer_backends__)r   r   rC   Z	skip_testr   r   r   r   r   r   r   r?   r   rD   r   r   rh   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 r8   )rC   r   pushr<   )r   ctxr!   r!   r"   r     s   r   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  r8   NotImplementedErrorselfargkwr!   r!   r"   skip_test_exception     z$FixtureFunctions.skip_test_exceptionc                 O  r   r8   r   r   rX   r   r!   r!   r"   combinations  r   zFixtureFunctions.combinationsc                 O  r   r8   r   r  r!   r!   r"   param_ident  r   zFixtureFunctions.param_identc                 O  r   r8   r   r   r!   r!   r"   fixture  r   zFixtureFunctions.fixturec                 C  r   r8   r   r   r!   r!   r"   get_current_test_name  s   z&FixtureFunctions.get_current_test_namereturnr   c                 C  r   r8   r   r  r!   r!   r"   mark_base_test_class  r   z%FixtureFunctions.mark_base_test_classc                 C  r   r8   r   r  r!   r!   r"   add_to_marker  r   zFixtureFunctions.add_to_markerN)r  r   )r   r   __qualname__abcabstractmethodr   r  r  r  r  r  abstractpropertyr	  r!   r!   r!   r"   r     s    



r   c                 C  rp   r8   )r   )Zfixture_fn_classr!   r!   r"   set_fixture_functions  s   r  r   )S
__future__r   r  argparser   r.   rI   rz   r   rV   typingr   r&   r   r   rL   r   r=   r>   r?   rA   rB   r%   r@   r   rC   r<   rD   r0   r   rk   rg   r   __annotations__r#   r(   r+   r-   r3   r7   r:   rH   r   r   r   r   r   r   r   r4   rE   rm   ro   rs   rv   r   r   r   r   r   rZ   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ABCr   r   r  r!   r!   r!   r"   <module>   s   	
 6







/



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