o
     ZhJT                     @  sv  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m	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$ Z0d%d& Z1d'd( Z2g Z3g Z4d)d* Z5d+d, Z6e5d-d. Z7e5d/d0 Z8e6d1d2 Z9e6d3d4 Z:e5d5d6 Z;e6d7d8 Z<e6d9d: Z=d;d< Z>e6d=d> Z?e6d?d@ Z@e6dAdB ZAdCdD ZBdEdF ZCdGdH ZDdIdJ ZEdKdL ZFdMdN ZGdOdP ZHdQdR ZIdSdT ZJdUdV ZKdWdX ZLdYdZ ZMded[d\ZNd]d^ ZOd_d` ZPG dadb dbejQZRdaSdcdd ZTdS )f    )annotationsN)	Namespace)Path)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"   \/var/www/html/lang_env/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)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   r4   c                 C  s   | a tD ]}|t t qdS )z7things to set up early, before coverage might be setup.N)r   pre_configurer1   )optfnr"   r"   r#   	pre_begin  s   r8   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   r1   
sqlalchemyr=   r'   r>   r?   r@   rA   rB   rC   rD   r&   rE   Zsetup_filtersr7   r"   r"   r#   
post_begin$  s   rI   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_strr:   parserr"   r"   r#   r   6  s   

r   c                  G  sV   t d u r
tt  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   )
r1   r4   r   cwdprintsortedr   getsysexit)argsmacror"   r"   r#   r   C  s   r   c                 C  s   t | d S r9   )_setup_requirementsrQ   r"   r"   r#   r   N  s   r   c                       fdd}|S )Nc                      t |  | d S r9   )r   rQ   tagr"   r#   _do_include_tagS     z)_set_tag_include.<locals>._do_include_tagr"   )r`   ra   r"   r_   r#   r   R     r   c                   r]   )Nc                   r^   r9   )r    rQ   r_   r"   r#   _do_exclude_tagZ  rb   z)_set_tag_exclude.<locals>._do_exclude_tagr"   )r`   rd   r"   r_   r#   r   Y  rc   r   c                 C     t |dd d S N-_)exclude_tagsaddreplacerQ   r"   r"   r#   r    `     r    c                 C  re   rf   )include_tagsrj   rk   rQ   r"   r"   r#   r   d  rl   r   c                 C     t |  | S r9   )r5   r   rH   r"   r"   r#   prel     
ro   c                 C  rn   r9   )rF   r   rH   r"   r"   r#   postq  rp   rq   c                 C     | a d S r9   r   r6   r1   r"   r"   r#   _setup_optionsv  s   ru   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.dialectsrv   register)r6   r1   rv   r"   r"   r#    _register_sqlite_numeric_dialect|  s   rx   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environrW   Zsqlalchemy.utilr{   ImportErrorAssertionError)r6   r1   r{   errr"   r"   r#   __ensure_cext  s   r   c                 C  s   ddl m} t |_d S Nr   rD   )r'   rD   _fixture_fn_classZ_fixture_functions)r   r1   rD   r"   r"   r#   _init_symbols  s   r   c                 C  s   | j rdt_d S d S NF)Zdisable_asyncior   ZENABLE_ASYNCIOrt   r"   r"   r#   _set_disable_asyncio  s   
r   c              	     sz  ddl m} ddlm} ddlm} ddlm  | jr!t| j}ng }| j	p'g }| j
rP| j
D ]!}td|D ]}||dvrEtd| ||d| q6q.|s[||dd	 d |_| jr|jr fd
d|D D ](}	t| jd}
|
|j d|	jdd d W d    n1 sw   Y  qmt|||}|D ]}	td|	 ||	| ||j}|js||| qd S )Nr   r<   r   r%   )urlz[,\s]+r   z:Unknown URI specifier '%s'.  Specify --dbs for known uris.r   c                   s   g | ]}  |qS r"   )Zmake_url).0db_urlZsa_urlr"   r#   
<listcomp>  s    z_engine_uri.<locals>.<listcomp>a F)Zhide_password
zAdding database URL: %s)rG   r=   r'   rD   r&   Zsqlalchemy.enginer   r   listr   r   resplitr   RuntimeErrorr   rW   _currentr   r(   openwriteZrender_as_stringZgenerate_db_urlsloginfoZsetup_configZset_as_current)r   r1   r=   rD   r&   Zdb_urlsZextra_driversZdb_tokenr   r   file_Zexpanded_urlscfgr"   r   r#   _engine_uri  sT   

	

r   c                 C  s   | dd}t| d S )Nsqla_testingrequirement_cls)rW   r\   )r   r1   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   r<   :.   )
r'   rD   rG   r=   r   
__import__getattrrequirementsrequiresbootstrapped_as_sqlalchemy)argumentrD   r=   modnameZclsnamemod	componentZreq_clsr"   r"   r#   r\     s   

r\   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'   rD   r   r&   Configall_configsZdrop_all_schema_objectsr   )r   r1   rD   r&   r   r"   r"   r#   _prep_testing_database  s   r   c                 C  s   ddl m} t|_||_d S r   )r'   rD   r   r1   )r6   r1   rD   r"   r"   r#   _post_setup_options  s   
r   c                 C  s.   ddl m} |j|dd| j| jd|_d S )Nr   )rC   r   Zprofile_file)sortdump)r'   rC   ZProfileStatsFilerW   r   r   Z_profile_stats)r   r1   rC   r"   r"   r#   _setup_profiling  s   
r   c                 C  s"   t |tjsdS | drdS dS )NFrh   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   r7   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
[_\[\]\.]+rh   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 r9   )	_do_skips_setup_enginer   r"   r"   r#   !start_test_class_outside_fixtures9  s   r   c                 C  s   t |  tj  d S r9   )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 r9   )r?   r    stop_test_class_outside_fixturesr&   rD   r   r   r   rA   global_cleanup_assertions_restore_enginer   r"   r"   r#   r   G  s   


r   c                   C  s   t jrt jt d S d S r9   )rD   r   resetr=   r"   r"   r"   r#   r   Q  s   r   c                   C  s   t j  t  t  d S r9   )r?   r   Zfinal_cleanuprA   r   r   r"   r"   r"   r#   final_process_cleanupV  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scopers   )	r   dictr   r?   Ztesting_enginerD   r   Zpush_enginer=   )r   optsZengr"   r"   r#   r   \  s   
r   c                 C  s*   t |d|j}d|||f }t| d S )Nr   z%s.%s.%s)r   r   rC   Z_start_current_test)testZtest_module_nameZ
test_classZ	test_namer   Zid_r"   r"   r#   before_testd  s   r   c                 C  s   t   tj  d S r9   )r>   
after_testr?   r   r   r"   r"   r#   r   o  s   r   c                 C  s   t j|  d S r9   )r?   r   Zafter_test_outside_fixturesr   r"   r"   r#   after_test_fixturest  rb   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 r9   )r   r   driverdialectZserver_version_info)r   r"   r"   r#   <lambda>  s   z+_possible_configs_for_cls.<locals>.<lambda>)key)setrD   r   r   Z__unsupported_on__r@   db_specr   remover   rE   to_listr   intersection_updater   hasattrr   r   Zmatching_config_reasonsextendr   Zenabled_for_configrj   
differencedifference_updatereversedrV   r   r   values)r   reasonsr   r   spec
config_objr   requirementcheckZskip_reasonsnon_preferredZper_dialectr   r   r"   r"   r#   r   x  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 r9   )r   )r   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   rD   Z	skip_testr   r   r   r   r   r   r   r@   r   rE   r   r   rj   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 r9   )rD   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  r9   NotImplementedErrorselfargkwr"   r"   r#   skip_test_exception     z$FixtureFunctions.skip_test_exceptionc                 O  r   r9   r   r  rZ   r  r"   r"   r#   combinations  r  zFixtureFunctions.combinationsc                 O  r   r9   r   r  r"   r"   r#   param_ident  r  zFixtureFunctions.param_identc                 O  r   r9   r   r  r"   r"   r#   fixture  r  zFixtureFunctions.fixturec                 C  r   r9   r   r  r"   r"   r#   get_current_test_name  s   z&FixtureFunctions.get_current_test_namereturnr   c                 C  r   r9   r   r  r"   r"   r#   mark_base_test_class  r  z%FixtureFunctions.mark_base_test_classc                 C  r   r9   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  rr   r9   )r   )Zfixture_fn_classr"   r"   r#   set_fixture_functions	  s   r  r   )U
__future__r   r  argparser   r/   rJ   r|   pathlibr   r   rX   typingr   r'   r   r   rM   r   r>   r?   r@   rB   rC   r&   rA   r   rD   r=   rE   r1   r   rm   ri   r   __annotations__r$   r)   r,   r.   r4   r8   r;   rI   r   r   r   r   r   r    r   r5   rF   ro   rq   ru   rx   r   r   r   r   r   r\   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







1



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