o
    V\i                    @   s  d dl Z d dlZd dlZd dlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z! ddl"m#Z# ddl"m$Z$ ddl"m%Z% dd l&m'Z' dd!l&m(Z( dd"lm)Z) dd#lm*Z* dd$l+m,Z, dd%l-m.Z. dd&lm/Z/ dd'lm0Z0 dd(lm1Z1 dd)lm2Z2 dd*lm3Z3 dd+lm4Z4 d,\Z5Z6G d-d. d.ej7Z8G d/d0 d0e8Z9G d1d2 d2ej7Z:G d3d4 d4ej;Z<G d5d6 d6ej;Z=G d7d8 d8ej7Z>d9d: Z?G d;d< d<e0e8Z@G d=d> d>ej;ZAG d?d@ d@e/ej;ZBG dAdB dBej7ZCG dCdD dDejDZEG dEdF dFej7ZFG dGdH dHej7ZGdIZHdS )J    N   )config)engines)eq_)eq_regex)expect_raises)expect_raises_message)expect_warnings)fixtures)is_)get_temp_table_name)temp_table_keyword_argsColumn)Table   )Boolean)DateTime)event)
ForeignKey)func)Identity)inspect)Integer)MetaData)String)testing)types)	Inspector)
ObjectKind)ObjectScope)NoSuchTableError)UnreflectableTableError)DDL)Index)quoted_name)BLANK_SCHEMA)ComparesIndexes)ComparesTables)is_false)is_none)is_true)mockNNc                   @   s   e Zd Zedd ZdS )OneConnectionTablesTestc                 C   s2   t jjjrddlm} tjt|j	dddS t j
S )Nr   )poolclass)	poolclassscope)options)r   requirementsindependent_connectionsenabled
sqlalchemyr/   r   testing_enginedict
StaticPooldb)clsr/    r=   /var/www/www-root/data/www/176.119.141.140/sports-predictor/venv/lib/python3.10/site-packages/sqlalchemy/testing/suite/test_reflection.py
setup_bind<   s   
z"OneConnectionTablesTest.setup_bindN)__name__
__module____qualname__classmethodr?   r=   r=   r=   r>   r.   ;   s    r.   c                   @   s   e Zd ZdZdZedd Zedd Zedd Zed	d
 Z	dd Z
dd Zejjdd Zejjdd Zejjdd Zejjdd Zejjejjejjdd Zejjejjdd ZdS )HasTableTestTNc                 C   s   t d|tdtddtdtd tjjjr*t d|tdtddtdtdtj	d tjj
r3| | tjjjr?| | d S d S )	N
test_tableidTprimary_keydata2   test_table_sschema)r   r   r   r   r   requiresschemasr6   r   test_schemaview_reflectiondefine_viewshas_temp_tabledefine_temp_tablesr<   metadatar=   r=   r>   define_tablesP   s&   


zHasTableTest.define_tablesc                 C   st   d}t |dt| t |dtd tjjjr8dtjtjf }t |dt| t |dtdtj  d S d S )Nz1CREATE VIEW vv AS SELECT id, data FROM test_tableafter_createbefore_dropzDROP VIEW vvz9CREATE VIEW %s.vv AS SELECT id, data FROM %s.test_table_szDROP VIEW %s.vv)	r   listenr#   r   rN   rO   r6   r   rP   )r<   rV   queryr=   r=   r>   rR   f   s"   
zHasTableTest.define_viewsc                 C      t ttjdtj S N	user_tmp_r   r   r;   identr<   r=   r=   r>   temp_table_name|      zHasTableTest.temp_table_namec              	   C   s   t ttj}|  }t||tdtjddtdtdfi |}t	j
jjrBt	j
jjrDt|dtdtj  t|dtd	 d S d S d S )
NrF   TrG   namerJ   rX   =create temporary view user_tmp_v as select * from user_tmp_%srY   drop view user_tmp_v)r   r   r;   rb   r   r   saINTVARCHARr   rN   rQ   r6   temporary_viewsr   rZ   r#   r`   r<   rV   kw
table_nameuser_tmpr=   r=   r>   rT      s2   zHasTableTest.define_temp_tablesc                 C   sl   t j '}tt jj|d tt jj|d tt jj|d W d    d S 1 s/w   Y  d S )NrE   rK   nonexistent_table)r   r;   beginr+   dialect	has_tabler)   selfconnr=   r=   r>   test_has_table   s
   "zHasTableTest.test_has_tablec              	   C   s   t tj}t|d td|tdt}t|d |	tj zt|d |
  t|d W |tj d S |tj w )NrE   	new_tablecol)r   r   r;   r+   rr   r   r   r   r)   createclear_cachedrop)rt   rV   inspntr=   r=   r>   test_has_table_cache   s   
z!HasTableTest.test_has_table_cachec                 C   s~   t j 0}tt jjj|dt jd tt jjj|dt jd tt jjj|dt jd W d    d S 1 s8w   Y  d S )NrE   rL   rK   ro   )r   r;   rp   r)   rq   rr   rP   r+   rs   r=   r=   r>   test_has_table_schema   s"   "z"HasTableTest.test_has_table_schemac                 C   sH   t j }tt jjj|ddd W d    d S 1 sw   Y  d S )NrE   nonexistent_schemarL   )r   r;   rp   r)   rq   rr   rs   r=   r=   r>   !test_has_table_nonexistent_schema   s   "z.HasTableTest.test_has_table_nonexistent_schemac                 C      t |}t|d d S Nvvr   r+   rr   rt   
connectionr|   r=   r=   r>   test_has_table_view   s   z HasTableTest.test_has_table_viewc                 C   s"   t |}|  }t|| d S N)r   rb   r+   rr   )rt   r   r|   rb   r=   r=   r>   test_has_table_temp_table   s   z&HasTableTest.test_has_table_temp_tablec                 C   r   N
user_tmp_vr   r   r=   r=   r>   test_has_table_temp_view   s   z%HasTableTest.test_has_table_temp_viewc                 C   s   t |}t|dtj d S r   )r   r+   rr   r   rP   r   r=   r=   r>   test_has_table_view_schema   s   z'HasTableTest.test_has_table_view_schema)r@   rA   rB   __sparse_driver_backend__run_deletesrC   rW   rR   rb   rT   rv   r~   r   rN   rO   r   r   viewsr   rS   r   rQ   rj   r   r   r=   r=   r=   r>   rD   K   s8    







rD   c                   @   sX   e Zd ZdZdZedd ZejddddZ	d	d
 Z
e	dd Zejje	dd ZdS )HasIndexTestT)index_reflectionc              	   C   s   t d|tdtddtdtdtdtd}td|jj tjj	j
r@t d|tdtddtdtdtjd	}td
|jj d S d S )NrE   rF   TrG   rI   rJ   data2my_idxrL   my_idx_s)r   r   r   r   r$   crI   r   rN   rO   r6   r   rP   )r<   rV   ttr=   r=   r>   rW      s$   
zHasIndexTest.define_tablesrq   	inspectorkindargnamesc                    s   |dkr
 fddS t  jS )Nrq   c                     s   t jjj g| R i |S r   )r   r;   rq   	has_index)akru   r=   r>   <lambda>       z)HasIndexTest._has_index.<locals>.<lambda>)r   r   )rt   r   ru   r=   r   r>   
_has_index   s   
zHasIndexTest._has_indexc              	   C   s$  |  ||}|ddsJ |ddrJ |ddrJ |ddr"J |ddr)J |ddr0J td| jjjj}td|td	ttdd	}|	| |	| z6|d
krh|ddr\J |ddrcJ |j
  |dddu sqJ |dddu szJ W || || d S || || w )NrE   r   r   ro   nonexistent_idxmy_idx_2test_table_2my_idx_3foor   T)r   r$   tablesrE   r   r   r   r   r   ry   __self__rz   r{   )rt   r   r   rV   methidxtblr=   r=   r>   test_has_index  s6   




zHasIndexTest.test_has_indexc                 C   s`   |  ||}|ddtjdsJ |ddtjdrJ |ddtjdr$J |ddtjdr.J d S )NrE   r   rL   r   ro   nonexistent_idx_s)r   r   rP   )rt   r   r   r   r=   r=   r>   test_has_index_schema"  s   
z"HasIndexTest.test_has_index_schemaN)r@   rA   rB   r   __requires__rC   rW   r   combinationsr   r   r   rN   rO   r   r=   r=   r=   r>   r      s    

r   c                   @   s   e Zd ZdZdd Zdd Zedddge e ejj	dd	 Z
e e ejjd
d Ze e ejjdd ZdS )BizarroCharacterTestTc                   C      t jddddddS )N)	plainname)z(3))zcol%p)z[brack]
columnnamer   r   r   r=   r=   r=   r>   column_names4     z!BizarroCharacterTest.column_namesc                   C   r   )N)plain)z(2))z
per % cent)z
[brackets]	tablenamer   r   r=   r=   r=   r>   table_names=  r   z BizarroCharacterTest.table_namesuse_compositeFc           
      C   s  t ||t|tddddd}|r|tdtdd |r?t d|tdtddtdttd	ttdd	g|jj|jjgdd nt d|tdtddtdt	|jjdd |
| t }t d||d
}|j| }	|jj|	jd stJ |r|jj|	jd sJ dS dS )ztests for #10275rF   T)keyrH   test_needs_fkid2rG   otherrefref2autoload_withr      N)r   r   r   append_columnrg   ForeignKeyConstraintr   rF   r   r   
create_allr   r   r   
referencesr   )
rt   r   rV   r   r   r   r   m2o2t1r=   r=   r>   test_fk_refF  sD   


z BizarroCharacterTest.test_fk_refc              	   C   sL   t ||t|tt dd || t|}t||d d d d d S )NTrG   r   identitystartr   r   r   r   r   r   r   r   get_columnsrt   r   r   r   rV   r|   r=   r=   r>   test_reflect_identityu  s   
 z*BizarroCharacterTest.test_reflect_identityc              	   C   sP   t ||tdtddt|tdd || t|}t||d d d d S )NrF   TrG   some commentcommentr   r   r   r   r   r   r   r   r   r   r=   r=   r>   test_reflect_comments  s   
z*BizarroCharacterTest.test_reflect_commentsN)r@   rA   rB   r   r   r   r   	variationrN   !foreign_key_constraint_reflectionr   identity_columnsr   comment_reflectionr   r=   r=   r=   r>   r   0  s"    		+r   c                   @   sB   e Zd ZdZdZejdd Zejj	dd Z
ejjdd Zd	S )
TempTableElementsTestT)temp_table_reflectionc                 C   r\   )N
ident_tmp_r_   rt   r=   r=   r>   r     rc   zTempTableElementsTest.tablenamec              	   C   sL   t ||tdtt dd || t|}t||d d d d d S )NrF   TrG   r   r   r   r   r   rt   r   r   rV   r|   r=   r=   r>   r     s   
 z+TempTableElementsTest.test_reflect_identityc              	   C   sP   t ||tdtddtdtdd || t|}t||d d d d S )	NrF   TrG   foobarr   r   r   r   r   r   r=   r=   r>   r     s   
z+TempTableElementsTest.test_reflect_commentsN)r@   rA   rB   r   r   r   fixturer   rN   r   r   temp_table_comment_reflectionr   r=   r=   r=   r>   r     s    

r   c                   @   s   e Zd ZdZdZedd Zdd Zedd Zee	j
jd	d
 Zedd Zedd Zee	j
jdd Zee	j
jdd Zee	j
jdd Zee	j
jdd Zee	j
jdd ZdS )QuotedNameArgumentTestonceTc                 C   s  t d|tdttdtdtdtdtdttjdddtd	dtjdd
dtjdgdgddtj	dddddd t
jjjr}t d|tdttdtdtdtdtdttjdddtddtjdddtjdgdgddtj	dddddd t d|tdtddtdtdd t
jjjrt
jjjrddg}ndg}|D ]4}dtjjjd| tjjj|f }t|dt| t|dtd tjjjd|   qd S d S )!Nquote ' onerF   rd   rJ   rI   
related_idzpk quote ' onerd   zix quote ' onezuq quote' onez
related.idzfk quote ' onezname != 'foo'zck quote ' onezquote ' one commentT)r   r   quote " twozpk quote " twozix quote " twozuq quote" twozfk quote " twozck quote " two zquote " two commentrelatedrG   r   z"CREATE VIEW %s AS SELECT * FROM %sview %srX   rY   zDROP VIEW %s)r   r   r   r   rg   PrimaryKeyConstraintr$   UniqueConstraintr   CheckConstraintr   rN   symbol_names_w_double_quoter6   view_column_reflectionr   r;   rq   identifier_preparerquoter   rZ   r#   )r<   rV   namesrd   r[   r=   r=   r>   rW     s   









z$QuotedNameArgumentTest.define_tablesc                 C   s   t ddt jjf| S )N)r   r   )r   r   rN   r   )fnr=   r=   r>   quote_fixtures  s   
z%QuotedNameArgumentTest.quote_fixturesc                 C   sh   t tj}tjjjr||}tt	|t
 d S tt || W d    d S 1 s-w   Y  d S r   )r   r   r;   r   rN   reflect_table_optionsr6   get_table_optionsr+   
isinstancer9   r   NotImplementedError)rt   rd   r|   resr=   r=   r>   test_get_table_options  s   



"z-QuotedNameArgumentTest.test_get_table_optionsc                 C   s    t tj}|d| sJ d S )Nr   )r   r   r;   get_view_definitionrt   rd   r|   r=   r=   r>   test_get_view_definition%  s   
z/QuotedNameArgumentTest.test_get_view_definitionc                 C      t tj}||sJ d S r   )r   r   r;   r   r   r=   r=   r>   test_get_columns+     
z'QuotedNameArgumentTest.test_get_columnsc                 C   r  r   )r   r   r;   get_pk_constraintr   r=   r=   r>   test_get_pk_constraint0  r  z-QuotedNameArgumentTest.test_get_pk_constraintc                 C   r  r   )r   r   r;   get_foreign_keysr   r=   r=   r>   test_get_foreign_keys5     
z,QuotedNameArgumentTest.test_get_foreign_keysc                 C   r  r   )r   r   r;   get_indexesr   r=   r=   r>   test_get_indexes;  r	  z'QuotedNameArgumentTest.test_get_indexesc                 C   r  r   )r   r   r;   get_unique_constraintsr   r=   r=   r>   test_get_unique_constraintsA  r	  z2QuotedNameArgumentTest.test_get_unique_constraintsc                 C   r  r   )r   r   r;   get_table_commentr   r=   r=   r>   test_get_table_commentG  r	  z-QuotedNameArgumentTest.test_get_table_commentc                 C   r  r   )r   r   r;   get_check_constraintsr   r=   r=   r>   test_get_check_constraintsM  r	  z1QuotedNameArgumentTest.test_get_check_constraintsN)r@   rA   rB   run_create_tablesr   rC   rW   r   r   r   rN   r   r  r  r  r   r  r   r  unique_constraint_reflectionr  r   r  check_constraint_reflectionr  r=   r=   r=   r>   r     s<    
R



r   c              
   C   s   t jd dd t jjfdd}t jtjtjtjdd}t jtj	tj
tjtjtjtj	tj
B tj	tjB dd}t jddd	d}||||| S )
Nc                   S   s   t jS r   )r   rP   r=   r=   r=   r>   r   X  s    z$_multi_combination.<locals>.<lambda>rM   r   r2   r   TF
use_filter)r   r   rN   rO   r    DEFAULT	TEMPORARYANYr   TABLEVIEWMATERIALIZED_VIEWANY_VIEW)r   rM   r2   r   filter_namesr=   r=   r>   _multi_combinationT  s2   


r  c                   @   s  e Zd Zd ZZdZedd Zedd Zedd Z	ed	d
 Z
edd Zdd Zdd Zdd ZdejejdfddZdejejdfddZdejejdfddZedd ZdejejdfddZedd Zdejejdfdd Zed!d" Zdejejdfd#d$Zed%d& Zdejejdd'fd(d)Zed*d+ Zdejejdfd,d-Zed.d/ Z e!j"j#d0d1 Z$e!j"j#d2d3 Z%e!j"j#d4d5 Z&e!j"j#d6d7 Z'e!j"j#e!j"j(d8d9 Z)e!j"j#d:d; Z*e!j"j#d<d= Z+e!j,dd>e!j"j-fd?d@e!j,de!j"j.fd'dAd@dBdC Z/e!j,de!j"j.fd'dAd@dDdE Z0e!j"j1dFdG Z2e!j"j3e!j"j4dHdI Z5e!j"j6dJdK Z7e!j"j6e!j"j.dLdM Z8ddNdOZ9e!j,dPd'de!j"j.fdd'e!j"j3fdde!j"j.e!j"j3 fdQd@dRdS Z:e!j"j;dTdU Z<e!j"j;dVdW Z=e!j"j;e!j"j>e!j"j4dXdY Z?e!j,dZde!j"j.fdAd@e!j"j@d[d\ ZAe!j,d]d^d_d`dad@e!j"j@e!j"jBdbdc ZCe!j,dZde!j"j.fdAd@e!j"j-ddde ZDe!j,dfdgdhdidjd@e!j"j-dkdl ZEe!j"jFe!j"j.dmdn ZGe!j,dZde!j"j.fdAd@e!j"jHdodp ZIe!j,dqdrdsd@e!j"jHe!j"jJe!j"jKdtdu ZLe!j,dvdwdxdydzd@e!j"jHd{d| ZMe!j"j;e!j"jNd}d~ ZOe!j"jPdd ZQe!j,de!j"j.fdZdAd@e!j"jNdd ZRe!j,dddddd@e!j"jNdd ZSe!j"j3e!j,dZde!j"j.fdAd@dd ZTe!j"j3dd ZUe!j"jVdd ZWe!j,de!j"j.fdZdAd@dd ZXe!,de!j"j.fd'dd ZYe!jZdd Z[e!j"j\e]dd Z^e!j"j6e]dd Z_dd Z`dddZadddZbe]dd Zce!j"j@e]dd Zddd Zee!j"j-e]dd Zfe!j"jHe]dd Zge!j"jNe]dd Zhe!j"jie]dd Zje!j,de!j"j\fdde!j"j@fde!j"j-fde!j"jHfde!j"jNfde!j"jifde!j"j6fdd@	dd Zkdd Zle!j,dd'dAd@e!j,de!j"jmfd'dd@dd Zne!j"j6dd Zoe!j"jpdd Zqe!j"jre!j"jsddÄ ZtdS )ComponentReflectionTestNTc                 C   s.   |  |d  tjjjr|  |tjj d S d S r   )define_reflected_tablesr   rN   rO   r6   r   rP   rU   r=   r=   r>   rW   w  s   
z%ComponentReflectionTest.define_tablesc                 C   s  |r|d }nd}t jjjrtd| ddf}nd}td|tdtjd	d
tdt	dddtdt
 ddtdtjg|R  tjddddtd|d	d
}td|tdtjd	d
tdtjtd| dddtdtjtd| tdtdd	d tjd!d"dtjddd#d$d|d	d
 td%|tdtjtd&tjt|jjtd'td(d	d)tjdd*d+d|d	d td,|td-tjd	d.d/tdtd(d0d1td2td(d3d1td4td5d6d1|d7d8 td9|tdtd(|d:d8 t jjjrR|d u rtd;|td-tjd	d
tdtd(td<td=t jj d	tjjjd> n7td?|td-tjd	d
td@tdAtjjj tdtd(|d	d tdB|td-tjd	d
tdtd(|d	d t jjjrtdC|jj|jjd	d  tdD|jj|jj|jj |stdE|tdFtdd	dG}tdH|td-tjd	d
tdFtdd	dG}t jjjrt jjjrtdI|jj  tdJ|jj  t jj jr| !|| |st jj"jr| #| d S d S d S )KN. z%susers.user_id
user_id_fkr   r=   usersuser_idTrG   test1   Fnullabletest2parent_user_id	test2 > 0zz_test2_gt_zerousers check constraintrd   r   test2 <= 1000rM   r   
dingalingsdingaling_id
address_idz%semail_addresses.address_idzz_email_add_id_fgdi fk commentid_userrI      )uniquez$address_id > 0 AND address_id < 1000address_id_gt_zerozz_dingalings_multipledi unique commentemail_addressesremote_user_idemail_address   )indexemail_ad_pkea pk commentcomment_testrF   
id comment)rH   r   data % commentr   d2)Comment types type speedily ' " \ '' Fun!d3*   Comment
withescapesthe test % ' " \ table comment)rM   r   no_constraints"no
constraintshasescapedcommentlocal_table	remote_idz%s.remote_table_2.id)r   rM   remote_tablelocal_idz%s.local_table.idremote_table_2users_t_idxusers_all_idxnoncol_idx_test_nopkqr   noncol_idx_test_pknoncol_idx_nopknoncol_idx_pk)$r   rN   self_referential_foreign_keysr6   r   r   r   rg   rh   CHARFloatr   r   r   r   r   r%  r   cross_schema_fk_reflectionr   rP   r;   rq   default_schema_namer   r$   r&  r*  indexes_with_ascdescreflect_indexes_with_ascdescrW  descr   rR   r   rT   )r<   rV   rM   schema_prefixparent_id_argsr$  rV  rX  r=   r=   r>   r   }  s@  

	
 


		z/ComponentReflectionTest.define_reflected_tablesc                 C   r\   r]   r_   ra   r=   r=   r>   rb   +  rc   z'ComponentReflectionTest.temp_table_namec                 C   s   t ttj}|  }t||tdtjddtdtdtdtjtj	ddtj
 dtd	dfi |}tjjjrVtjjjrXt|d
tdtj
  t|dtd d S d S d S )NrF   TrG   rd   rJ   r   user_tmp_uq_r   user_tmp_ixrX   re   rY   rf   )r   r   r;   rb   r   r   rg   rh   ri   r   r`   r$   r   rN   rQ   r6   rj   r   rZ   r#   rk   r=   r=   r>   rT   1  s8   

z*ComponentReflectionTest.define_temp_tablesc              
   C   s   t jjjr	dh}nt }dD ]b}|}|r| d| }|d }||v r%dnd}d| d| d	| }t|d
t| ||v rad}	|rOt drO| d|	 }	d|	 d| d}
t|d
t|
 t|dtd| d|  qd S )Nr2  r$  r=  r2  r!  _vzMATERIALIZED r"  zCREATE zVIEW z AS SELECT * FROM rX   	mat_indexoraclezCREATE INDEX z ON z(data)rY   zDROP )	r   rN   materialized_viewsr6   setr   rZ   r#   against)r<   rV   rM   materializedrm   fullname	view_nameprefixr[   
index_namer   r=   r=   r>   rR   S  s,   
z$ComponentReflectionTest.define_viewsc                 C   sD   i }t j|v r|| t j|v r|| t j|v r || |S r   )r   r  updater  r  )rt   r   r   r   rn  r   r=   r=   r>   _resolve_kindn  s   





z%ComponentReflectionTest._resolve_kindc                 C   sB   t jjjs|  |  d S t jjjs|| |  d S d S r   )r   rN   r   r6   clearrk  rs  )rt   r   rn  r=   r=   r>   _resolve_viewsx  s   


z&ComponentReflectionTest._resolve_viewsc              	      s   dd |t ju rdd |t ju rdd d ddhtjjddd	d
|  hitjjj	s>d  
d tjj ddg tjjj	sLd  dd	g tjjj	rVtjjj	sad  d
|  g tjjj	snd  d
g  fdd| D }|S )Nc                 S   s   dS )NTr=   )_r=   r=   r>   r     s    z8ComponentReflectionTest._resolve_names.<locals>.<lambda>c                 S   s   d| d vS Ntmpr   r=   r   r=   r=   r>   r         c                 S   s   d| d v S rx  r=   rz  r=   r=   r>   r     r{  rQ  rS  rO  rV  rX  r   c                    s>   i | ]\}}|r|d   vr r|d   v r||qS )r   r=   ).0r   vr  removedrM   scope_filterr=   r>   
<dictcomp>  s    z:ComponentReflectionTest._resolve_names.<locals>.<dictcomp>)r    r  r  r   r   rP   rb   rN   r^  r6   addrs  r   r   temp_table_namesrj   items)rt   rM   r2   r  valuesr   r=   r~  r>   _resolve_names  sD   





z&ComponentReflectionTest._resolve_namesc           	      C   s   |dft ji}|dft j|dft j|dft ji}| || |dft j|dft j|dft j|dft j|d	ft j|d
ft j|dft j|dft j|dft j|dft j||  ft ji}| ||||}| ||||}|S )Ndingalings_vemail_addresses_vusers_vr   r$  r2  r=  rD  rM  rO  rQ  rS  rV  rX  r,   r  rv  rb   rt  r  )	rt   rM   r2   r   r  rn  r   r   r   r=   r=   r>   exp_options  s*   












z#ComponentReflectionTest.exp_optionsc           
      C   s   dd i}|df|i}|df||df||df|i}|  || |df||df||df||d	fdd
i|dfddi|df||df||df||df||df|||  f|i}| ||||}	| ||||	}	|	S )Ntextr  r  r  r   r$  r2  r=  rD  rL  rM  rN  rO  rQ  rS  rV  rX  )rv  rb   rt  r  )
rt   rM   r2   r   r  emptyrn  r   r   r   r=   r=   r>   exp_comments  s4   z$ComponentReflectionTest.exp_commentsc           
         s$  dt jd dfdd  fdd}|df dd	t jd
 d d dgi}|df dd	t jd
 d dg|df dd	t jd
 dt jd dt jd dg|df dd	t jd
 d dgi}| || |df|d ddd ddd dg|df|d d d dg|df|d d dg|df|ddd  dd!d  d"d#d  d$d%d g|d&f dg|d'f|d d d(g|d)f|d d* dg|d+f|d dg|d,f d-g|d.f|d d-g||  f|d d dgi}| ||||}	| ||||	}	|	S )/NFTc                 S   s*   | |t j|||d}|dkr|d |S )N)rd   autoincrementtypedefaultr   r)  omitr  )r,   r  pop)rd   autor  r   r)  r   r=   r=   r>   rx     s   
z0ComponentReflectionTest.exp_columns.<locals>.colc                    s"   dt jdd|} | fi |S )NTF)r  r  r)  r,   r  )rd   rl   rx   r=   r>   pk  s   z/ComponentReflectionTest.exp_columns.<locals>.pkr  r3  r  )r  r)  r4  r7  rI   r  r>  r?  r  r%  r&  r(  r*  r+  r   rF   rd   r   r$  r2  r=  rD  rE  r   rF  rG  rH  rI  rK  rM  rO  rP  rQ  rR  rS  rV  rW  rX  r  )
rt   rM   r2   r   r  r  rn  r   r   r   r=   r  r>   exp_columns  s   

	




	
'z#ComponentReflectionTest.exp_columnsc                 C      h dS )N>   rd   r  r  r)  r=   r   r=   r=   r>   _required_column_keysN     z-ComponentReflectionTest._required_column_keysc                 C   sH  t jd ddd}|d d}tjjjr|df|di}n|df|i}|df||df||d	f|i}| || |d
f|d|df|d|df|dddd|df|d|df||df|d|df|d|df|d|df||df|d||  f|di}	tjjjs|		 D ]}
|
d d urt j|
d< q| 
||	||}| ||||}|S )Nr/  c                 W   s   t || |dS )N)constrained_columnsrd   r   )list)rd   r   colsr=   r=   r>   r  Y  s   z+ComponentReflectionTest.exp_pks.<locals>.pkr   r  r3  r  r  r   r$  r%  r2  r=  r4  rB  rC  rD  rF   rM  rO  rQ  rS  rV  rX  rd   )r,   r  r   rN   materialized_views_reflect_pkr6   rv  rb   reflects_pk_namesr  rt  r  )rt   rM   r2   r   r  r  r  rn  r   r   valr   r=   r=   r>   exp_pksR  s@   



zComponentReflectionTest.exp_pksc                 C      ddhS )Nrd   r  r=   r   r=   r=   r>   _required_pk_keys  r  z)ComponentReflectionTest._required_pk_keysc                    s  G dd d |t jd f fdd	}|dfg i}|dfg |dfg |dfg i}| || |d	f|d
gdgd	ddg|df|dgdgd	|dgdgddddg|df|dgdgd	g|dfg |dfg |df|dgdgdtjdg|df|dgdgdd dg|dfg |dfg |d fg ||  fg i}tjjj	s||d	f 
  tjjj	s| D ]}	|	D ]}
|
d! t jurt j|
d!< qq| ||||}| ||||}|S )"Nc                   @      e Zd Zdd ZdS )z+ComponentReflectionTest.exp_fks.<locals>.ttc                 S   s   |d u p
t jjj|kS r   )r   r;   rq   r_  rt   r   r=   r=   r>   __eq__  s   z2ComponentReflectionTest.exp_fks.<locals>.tt.__eq__Nr@   rA   rB   r  r=   r=   r=   r>   r         r   c                    s$   | ||t j|d ur|n  ||dS )N)r  referred_columnsrd   r3   referred_schemareferred_tabler   r  )r  ref_col	ref_table
ref_schemard   r   r   r=   r>   fk  s   	z+ComponentReflectionTest.exp_fks.<locals>.fkr  r  r  r   r$  r+  r%  r#  r   r2  r7  r4  r=  r5  r6  r/  r>  rD  rM  rO  rP  rF   rS  )r  rQ  rR  rV  rX  rd   )r,   r  rv  r   rP   rb   r   rN   r[  r6   ru  named_constraintsr  rt  r  )rt   rM   r2   r   r  r  rn  r   r   valsr  r   r=   r  r>   exp_fks  sr   

#

zComponentReflectionTest.exp_fksc                 C   r  )N>   rd   r  r  r  r  r=   r   r=   r=   r>   _required_fk_keys  r  z)ComponentReflectionTest._required_fk_keysc           
      C   s  dd ddddd}|dfg i}|dfg |dfg |dfg i}|  || |r3||df |d	d
d |dfg |dddd|ddddd|ddddd|dfg |d	tjddd|dtjdd|dddddd|dfg |dtjd|dtjdd|d fg |d!fg |d"fg |d#tjdd|d$fg |d%tjdd|d&fg |d'fg |d(d)d(d*id+|d,fg |d(d-d(d*id+||  fg |d.d/d|d0d1tj ddd2i}tjj	j
rtjjj
s||d'f   ||d,f   | ||||}	| ||||	}	|	S )3NF)r9  column_sorting
duplicatesr  c                    s   t jj}t jj}t jj}|r|jr|r|jsdS |t|| tjg d}	 r? |	d< |jr?|	d  |	d< }
 fdd|
D |	d< |rE| |	d< |	gS )	Nr=   )r9  r   rd   dialect_optionsinclude_columnsr  r   expressionsc                    s   g | ]
}| v r
d n|qS r   r=   r|  r   r  r=   r>   
<listcomp>  s    zDComponentReflectionTest.exp_indexes.<locals>.idx.<locals>.<listcomp>duplicates_constraint)	r   rN   foreign_keys_reflect_as_index#unique_constraints_reflect_as_index*reflect_indexes_with_ascdesc_as_expressionr6   r  r,   r  )rd   r9  r  r  r  r  fk_reqdup_reqsorting_expressionr   origr=   r  r>   r     s4   


z0ComponentReflectionTest.exp_indexes.<locals>.idxr  r  r  r   rI   ri  r   r$  r+  r#  T)rd   r  r%  r*  r&  rU  rT  )rd   r9  r2  )rd   r9  r  r7  r4  r3  r;  r=  r?  r>  rD  rM  rO  rP  rQ  rR  rS  rV  rW  rY  )rb  )rd   r  rX  rZ  r   rf  rd   re  )rd   r  r9  )rv  extendr,   r  rb   r   r`   r   rN   r`  r6   ra  ru  rt  r  )
rt   rM   r2   r   r  r   rn  r   r   r   r=   r=   r>   exp_indexes  s   
%



5z#ComponentReflectionTest.exp_indexesc                 C   r  )N>   rd   r9  r   r=   r   r=   r=   r>   _required_index_keys]  r  z,ComponentReflectionTest._required_index_keysFc                 C   s(  d dd ddd}|dfg i}|dfg |dfg |dfg i}|  || |d	fg |d
ddddd|dfg |dtjtjd|dddddd|dfg |dfg |dfg |dfg |dfg |dfg |dfg |dfg ||  fg |dd tj d!i}	|ri |||	S | ||	||}
| ||||
}
|
S )"NF)duplicates_indexis_indexr   c                 W   s8   t jj}|r|jsdS t|| |d}|r||d< |gS )Nr=   )r   rd   r   r  )r   rN   *unique_index_reflect_as_unique_constraintsr6   r  )rd   r  r  r   r  reqr   r=   r=   r>   uci  s   
z+ComponentReflectionTest.exp_ucs.<locals>.ucr  r  r  r   r$  r&  r*  rT  T)rd   r  r  r2  rI   )rd   r  r4  r3  r;  r<  )rd   r  r   r=  rD  rM  rO  rQ  rS  rV  rX  rd   re  r   )rv  r,   r  rb   r   r`   rt  r  )rt   rM   r2   r   r  all_r  rn  r   r   r   r=   r=   r>   exp_ucsa  sZ   		
 zComponentReflectionTest.exp_ucsc                 C   r  )Nrd   r   r=   r   r=   r=   r>   _required_unique_cst_keys  r  z1ComponentReflectionTest._required_unique_cst_keysc           
         s   G dd dt  d fdd	}|dfg i}|dfg |dfg |dfg i}| || |d	f|d
tj|ddddg|df|dddg|dfg |dfg |dfg |dfg |dfg |dfg |dfg |dfg ||  fg i}| ||||}	| ||||	}	|	S )Nc                   @   r  )z+ComponentReflectionTest.exp_ccs.<locals>.ttc                 S   s(   |  dddddd}| |v S )N(r"  )`)lowerreplace)rt   r   r   r=   r=   r>   r    s   z2ComponentReflectionTest.exp_ccs.<locals>.tt.__eq__Nr  r=   r=   r=   r>   r     r  r   c                    s    | ||dS )N)sqltextrd   r   r=   )r  rd   r   r  r=   r>   cc  s   z+ComponentReflectionTest.exp_ccs.<locals>.ccr  r  r  r   r$  r0  r,  r-  r.  r   r2  z$address_id > 0 and address_id < 1000r:  r   r=  rD  rM  rO  rQ  rS  rV  rX  r   )strrv  r,   r  rb   rt  r  )
rt   rM   r2   r   r  r  rn  r   r   r   r=   r  r>   exp_ccs  sF   

zComponentReflectionTest.exp_ccsc                 C   r  )Nrd   r  r=   r   r=   r=   r>   _required_cc_keys  r  z)ComponentReflectionTest._required_cc_keysc                 C   s    t |}ttjj| v  d S r   )r   r+   r   r   rP   get_schema_namesr   r=   r=   r>   test_get_schema_names  s   z-ComponentReflectionTest.test_get_schema_namesc                 C   s,   t |}t|tjj t|d d S )Nsa_fake_schema_foo)r   r+   
has_schemar   r   rP   r)   r   r=   r=   r>   test_has_schema  s   z'ComponentReflectionTest.test_has_schemac                 C   s8   |j ddttjjid}t|}ttjj| v  dS )z
test #7300r   barschema_translate_mapN)execution_optionsr&   r   r   rP   r   r+   r  r   r=   r=   r>   %test_get_schema_names_w_translate_map  s   z=ComponentReflectionTest.test_get_schema_names_w_translate_mapc                 C   sD   |j ddttjjid}t|}t|tjj t|d d S )Nr   r  r  r  )	r  r&   r   r   rP   r   r+   r  r)   r   r=   r=   r>   test_has_schema_w_translate_map  s   z7ComponentReflectionTest.test_has_schema_w_translate_mapc              
   C   s   t |}td| v  t|d |td z,td| v  t|d |  td| v  t|d W |td d S |td w )Nfoo_barzCREATE SCHEMA foo_barzDROP SCHEMA foo_bar)r   r)   r  r  executer#   rz   r+   r   r=   r=   r>   test_schema_cache  s   "z)ComponentReflectionTest.test_schema_cachec                 C   s$   t  }t| t|jdsJ d S )Nr_  )r   r8   r   hasattrrq   )rt   enginer=   r=   r>   test_dialect_initialize!  s   z/ComponentReflectionTest.test_dialect_initializec                 C   s   t |}t|j|jj d S r   )r   r   r_  rq   r   r=   r=   r>   test_get_default_schema_name'  s   z4ComponentReflectionTest.test_get_default_schema_nameforeign_keyorder_byr   
use_schemac           	         s   |rt j}nd }h d t|}|rdd ||D }n||} fdd|D }|dkr:g d}t|| d S g d}tt|| d S )N>   rO  rD  rQ  rM  rS  rX  rV  c                 S   s   g | ]
}|d  r|d  qS )r   r=   )r|  recr=   r=   r>   r  G  s    z@ComponentReflectionTest.test_get_table_names.<locals>.<listcomp>c                    s   g | ]}| vr|qS r=   r=   r|  t_ignore_tablesr=   r>   r  N  s    r  rg  )r2  r=  r$  )r   rP   r   get_sorted_table_and_fkc_namesget_table_namesr   sorted)	rt   r   r  r  rM   r|   r   r   answerr=   r  r>   test_get_table_names,  s    	

z,ComponentReflectionTest.test_get_table_namesc                 C   sn   t |}|r
tj}nd }||}tjjjr*tt	|ddg t|
|dg d S g d}tt	|| d S )Nr  r  r  )r  r  r  )r   r   rP   get_view_namesr   rN   rk  r6   r   r  get_materialized_view_names)rt   r   r  r|   rM   r   r  r=   r=   r>   test_get_view_namesW  s   

z+ComponentReflectionTest.test_get_view_namesc                 C   s,   t |}| }tt|dtj g d S r]   )r   get_temp_table_namesr   r  r   r`   rt   r   r|   r  r=   r=   r>   test_get_temp_table_namesh  s   z1ComponentReflectionTest.test_get_temp_table_namesc                 C   s$   t |}| }tt|dg d S r   )r   get_temp_view_namesr   r  r  r=   r=   r>   test_get_temp_view_namesn  s   z0ComponentReflectionTest.test_get_temp_view_namesc                 C   s   |  | d S r   )_test_get_commentsrt   r   r=   r=   r>   test_get_commentsu  s   z)ComponentReflectionTest.test_get_commentsc                 C   s   |  |tjj d S r   )r  r   r   rP   r  r=   r=   r>   test_get_comments_with_schemay  s   z5ComponentReflectionTest.test_get_comments_with_schemac                 C   s   t |}| j|d}t|jd|d||df  t|jd|d||df  t|jd|d||df  | jjj}t|j||d|||f  d S )NrL   rD  r$  )r   r  r   r  r   rM  rd   )rt   r   rM   r|   expno_cstr=   r=   r>   r  ~  s&   




z*ComponentReflectionTest._test_get_comments)FFzuse_views,use_schemac                 C   sh  |rt j}nd }| jj| jj}}|rg d}nddg}t|}t|||fD ]\}	}
|}|j|	|d}tt	|dkt	| t
|
jD ]l\}}t|j|| d  || d j}|j}t|tjjrf|j}tdrv|tjtjfv rvtj}tt	t|j|jtjtjtjtjtjtjtj gdkd	|j|j|| d |f  |j!s|| d
 d u sJ qDq'd S )Nr  r  r  r$  r=  rL   r   rd   r  rj  z%s(%s), %s(%s)r  )"r   rP   r   r$  r=  r   zipr   r+   len	enumeratecolumnsr   rd   	__class__r  r   rg   r   
TypeEnginer   rm  	sql_typesDater   rl  __mro__intersectionr   NumericTimer   _BinaryrH   )rt   r   	use_viewsr  rM   r$  	addressesr   r|   rm   tableschema_namer  irx   ctype	ctype_defr=   r=   r>   r    sb   
z(ComponentReflectionTest.test_get_columnsc                 C   s6   |   }| j| }t|t |d}| j||dd d S )Nr   F)strict_constraints)rb   r   r   r   assert_tables_equal)rt   r   rm   rn   reflected_user_tmpr=   r=   r>   test_reflect_table_temp_table  s   

z5ComponentReflectionTest.test_reflect_table_temp_tablec                 C   sf   |   }| j| }t|}||}tt|dkt| t|jD ]\}}t|j	|| d  q"d S )Nr   rd   )
rb   r   r   r   r+   r
  r  r  r   rd   )rt   r   rm   rn   r|   r  r  rx   r=   r=   r>   test_get_temp_table_columns  s   

z3ComponentReflectionTest.test_get_temp_table_columnsc                 C   s.   t |}|d}tdd |D g d d S )Nr   c                 S      g | ]}|d  qS r   r=   r|  rx   r=   r=   r>   r        zFComponentReflectionTest.test_get_temp_view_columns.<locals>.<listcomp>)rF   rd   r   )r   r   r   )rt   r   r|   r  r=   r=   r>   test_get_temp_view_columns  s   
z2ComponentReflectionTest.test_get_temp_view_columns)Fc                 C   s  |rt jj}nd }| jj| jj}}t|}| j|d}|j|j	|d}| 
|g|||j	f g| j |j|j	|d}	|||j	f d }
t|	d |
 t jj  t|	d d W d    n1 scw   Y  | jjj	}| 
|j||dg|||f g| j d S )NrL   r  rd   rB  )r   r   rP   r   r$  r=  r   r  r  rd   _check_listr  r   rN   r  fail_ifrM  )rt   r   r  rM   r$  r  r|   r  
users_cons	addr_consexp_colsr  r=   r=   r>   r    s,   

z.ComponentReflectionTest.test_get_pk_constraintPK_test_tablepk_test_tablemixedCasePKzpk.with.dotspk_namec              	   C   sh   t d|tdttdtdtjd|d || t|}|d}t	|d | t	|d dg dS )	zZTest that primary key constraint names with various casing are
        properly reflected.rE   rF   rI   rJ   r   rd   r  N)
r   r   r   r   rg   r   r   r   r  r   )rt   r   rV   r.  r|   pk_consr=   r=   r>   "test_get_pk_constraint_quoted_name"  s   

z:ComponentReflectionTest.test_get_pk_constraint_quoted_namec                 C   s|  |rt j}nd }| jj| jj}}t|}|}tjjj	rd|j
|j|d}|d }	tjj  t|	d d W d    n1 s@w   Y  t|	d | t|	d |j t|	d dg t|	d	 d
g |j
|j|d}
|
d }	tjj  t|	d d u W d    n1 sw   Y  t|	d | t|	d |j t|	d dg t|	d	 dg | jjj}t|j
||dg  d S )NrL   r   rd   r#  r  r  r  r%  r  r+  r>  )r   rP   r   r$  r=  r   r   rN   r[  r6   r  rd   r  r'  r   implicitly_named_constraintsr+   rM  )rt   r   r  rM   r$  r  r|   expected_schemausers_fkeysfkey1
addr_fkeysr  r=   r=   r>   r  A  s6   

z-ComponentReflectionTest.test_get_foreign_keysFK_users_idfk_users_idmixedCaseNamezfk.with.dotsfk_namec              
   C   s   t d|tdtdddd t d|tdtddtdttjdgdg|d	dd || t|}|d}tt	|d
 |d }t
jj  t|d | W d   n1 sXw   Y  t|d d t|d dg t|d dg dS )zZTest that foreign key constraint names with various casing are
        properly reflected.	users_refr%  TrG   r   user_ordersorder_idzusers_ref.user_idr   r   r   rd   Nr  r  r  )r   r   r   rg   r   r   r   r  r   r
  r   rN   r  r'  )rt   r   rV   r9  r|   fkeysfkeyr=   r=   r>   !test_get_foreign_keys_quoted_namek  s:   

z9ComponentReflectionTest.test_get_foreign_keys_quoted_namec           
      C   s  |  d|jj dtjj dtjj \}}}t|}||j}t	t
|d |d }t	|d tjj t	|d |j t	|d d	g t	|d
 dg |j|jtjjd}t	t
|d |d }	t|	d d |jjfv  t	|	d |j t	|	d d	g t	|	d
 dg d S )Nz%s.local_tablez%s.remote_tablez%s.remote_table_2r   r   r  r  r  rF   r  rP  rL   rR  )r   rq   r_  r   r   rP   r   r  rd   r   r
  r+   )
rt   r   rO  rQ  rS  r|   local_fkeysr4  remote_fkeysfkey2r=   r=   r>   "test_get_inter_schema_foreign_keys  s8   




z:ComponentReflectionTest.test_get_inter_schema_foreign_keysc                 C   sz   |rt j}nd }t|}|jd|d}| j|d}| |||df | j | jjj	}| |j||d|||f | j d S )Nr$  rL   )
r   rP   r   r
  r  r&  r  r   rM  rd   )rt   r   r  rM   r|   indexesr  r  r=   r=   r>   r    s   

z(ComponentReflectionTest.test_get_indexes)rV  rY  )rX  rZ  ztname,ixnamec                 C   s   t |}||}|  d |f }| ||| j t|t |d}tt|j	d t
t|j	d j| tt|j	d j| d S )Nr   r   r   )r   r
  r  r&  r  r   r   r   r
  rD  r   r  r  rd   )rt   r   tnameixnamer|   rD  expected_indexesr  r=   r=   r>   test_get_noncol_index  s   	
z-ComponentReflectionTest.test_get_noncol_indexIX_test_dataix_test_datamixedCaseIndexzix.with.dotsidx_namec           	         s   t d|tdtddtdtd}t |jj || t|}|	d}dd |D } |v s;J d	  d
|  fdd|D }t
t|d t
|d d dg dS )zATest that index names with various casing are properly reflected.rE   rF   TrG   rI   rJ   c                 S   r"  r   r=   r|  r   r=   r=   r>   r    r$  zHComponentReflectionTest.test_get_indexes_quoted_name.<locals>.<listcomp>z	Expected z in c                    s   g | ]
}|d   kr|qS r   r=   rM  rL  r=   r>   r    r   r   r   r   N)r   r   r   r   r$   r   rI   r   r   r
  r   r
  )	rt   r   rV   rL  r  r|   rD  index_namesmatching_idxr=   rN  r>   test_get_indexes_quoted_name  s   

z4ComponentReflectionTest.test_get_indexes_quoted_namec                 C   sB   t |}|  }||}| jddd |f }| ||| j d S )NT)r  )r   rb   r  r  r&  r  )rt   r   r|   rd   	reflectedr  r=   r=   r>   &test_get_temp_table_unique_constraints  s
   
z>ComponentReflectionTest.test_get_temp_table_unique_constraintsc                 C   sn   t |}|  }||}|D ]}|dd  qddgddg}tjjjr+g |d d< tdd	 |D | d S )
Nr  Fr   rf  )r9  r   rd   r   r  c                 S   s   g | ]
}|d  dkr|qS )rd   rf  r=   rM  r=   r=   r>   r  &  r   zGComponentReflectionTest.test_get_temp_table_indexes.<locals>.<listcomp>)	r   rb   r
  r  r   rN   index_reflects_included_columnsr6   r   )rt   r   r|   rm   rD  indexpectedr=   r=   r>   test_get_temp_table_indexes  s   

z3ComponentReflectionTest.test_get_temp_table_indexesc                 C   s   |rt j}nd }tddgddg dddg dddd	d
gdddgdddgdgtdd}td|tdtdtdtdtdtj	td	tdtd
td|d}|D ]}|
tj|d d|d i q\|| t|}t|jd|dtdd}	t }
tt|t|	 t||	D ]%\}}|dd }|r|
| t|dd d  |dd  t|| qt }td|||d}	dd |	jD }dd |	jD dg}||rJ |
rt|
| t|t  | jjj}t|j||dg  d S )Nunique_ar   )rd   r   unique_a_b_c)r   br   unique_c_a_b)r   r   rZ  unique_asc_keyascr   zi.have.dotsrZ  zi have spacesr   rd   r   testtblr@  r8  rL   r   r  r   r  )r   rM   c                 S   s   h | ]}|j qS r=   r   rM  r=   r=   r>   	<setcomp>w  s    zFComponentReflectionTest.test_get_unique_constraints.<locals>.<setcomp>c                 S   s   h | ]}t |tjr|jqS r=   )r   rg   r   rd   )r|  uqr=   r=   r>   r`  x  s    
)r   rP   r  operator
itemgetterr   r   rg   r   r   append_constraintr   ry   r   r  rl  r   r
  r	  r  r  r   rD  constraints
differencer  r   rM  rd   )rt   rV   r   r  rM   uniquesr  r  r|   rR  names_that_duplicate_indexr  refldupereflected_metadata	idx_namesuq_namesr  r=   r=   r>   r  *  sz   







z3ComponentReflectionTest.test_get_unique_constraintsUQ_emailuq_emailmixedCaseUQzuq.with.dotsuq_namec              	   C   s   t d|tdtddtdtdtjd|d || t|}|d}t	t
|d t	|d	 d
 | t	|d	 d dg dS )zUTest that unique constraint names with various casing are
        properly reflected.rE   rF   TrG   emailrJ   r   r   r   rd   r   N)r   r   r   r   rg   r   r   r   r  r   r
  )rt   r   rV   rq  r|   uq_consr=   r=   r>   'test_get_unique_constraints_quoted_name  s   

z?ComponentReflectionTest.test_get_unique_constraints_quoted_namec                 C   s@   |rt j}nd }t|}dD ]}|j||d}tt| qd S )Nr  rL   )r   rP   r   r   r+   bool)rt   r   r  rM   r|   viewr}  r=   r=   r>   r    s   z0ComponentReflectionTest.test_get_view_definitionc                 C   sr   t |}tt |d W d    n1 sw   Y  tt |d W d    d S 1 s2w   Y  d S )Nview_does_not_existr$  )r   r   r!   r   r   r=   r=   r>   'test_get_view_definition_does_not_exist  s   

"z?ComponentReflectionTest.test_get_view_definition_does_not_existc                 C   sF   t |}dD ]\}}||}dd |D | }|dds J qdS )a  test that 'autoincrement' is reflected according to sqla's policy.

        Don't mark this test as unsupported for any backend !

        (technically it fails with MySQL InnoDB since "id" comes before "id2")

        A backend is better off not returning "autoincrement" at all,
        instead of potentially returning "False" for an auto-incrementing
        primary key column.

        ))r$  r%  )r=  r4  )r2  r3  c                 S      i | ]}|d  |qS r   r=   r  r=   r=   r>   r        zBComponentReflectionTest.test_autoincrement_col.<locals>.<dictcomp>r  TN)r   r   get)rt   r   r|   rE  cnamer  id_r=   r=   r>   test_autoincrement_col  s   
z.ComponentReflectionTest.test_autoincrement_colc                 C   s   t tj}|r
tjnd }tjjjr/|jd|d}t	t
|t |jd|d}t	t
|t d S tt |jd|d W d    d S 1 sFw   Y  d S )Nr$  rL   rM  )r   r   r;   rP   r   rN   r   r6   r   r+   r   r9   r   r   )rt   r  r|   rM   r   r=   r=   r>   r     s   


"z.ComponentReflectionTest.test_get_table_optionsc                    s   t tj tjjjr,|rtjnd  jd} fdd j	dD }t
|| d S tt    W d    d S 1 s@w   Y  d S )NrL   c                    s    i | ]}|f j |d qS )rL   )r   )r|  r  r|   rM   r=   r>   r    s    zHComponentReflectionTest.test_multi_get_table_options.<locals>.<dictcomp>)r   r   r;   r   rN   r   r6   rP   get_multi_table_optionsr  r   r   r   )rt   r  r   r  r=   r  r>   test_multi_get_table_options  s   




"z4ComponentReflectionTest.test_multi_get_table_optionsc                    s    fdd}|S )Nc                    s   t  }||d ||d}| r|  } g }tj|v r!|g d tj|v r-|ddg tj|v r9|ddg | r?| |d< |rE||d< || |||dd	}	|g}
|tjkrf|	 }|
d
 |
| |tjkry|	 }|
d |
| t  |
|	fS )Nr=  )r2   r   )rD  r$  does-not-existr  r  r  rM   r  )rM   r2   r   r  r2   r   )r   r   r  r  r  r  r{  r    r  copyr  append)rM   r2   r   r  single_reflect_fn
exp_methodr|   rl   r  r  kwsnkwr   r=   r>   provide_fixture  sD   










z>ComponentReflectionTest.get_multi_exp.<locals>.provide_fixturer=   )rt   r   r  r=   r  r>   get_multi_exp  s   .z%ComponentReflectionTest.get_multi_expc                 C   sL   |||||t j| j\}}}|D ]}	|  |jdi |	}
t|
| qd S Nr=   )r   r   r  rz   r  r   rt   r  rM   r2   r   r  r|   r  r  rl   resultr=   r=   r>   #test_multi_get_table_options_tables'	  s   
z;ComponentReflectionTest.test_multi_get_table_options_tablesc           
      C   sH   |||||t j| j\}}}|D ]}	|  t|jdi |	| qd S r  )r   r  r  rz   r   get_multi_table_comment)
rt   r  rM   r2   r   r  r|   r  r  rl   r=   r=   r>   test_get_multi_table_comment9	  s   
z4ComponentReflectionTest.test_get_multi_table_commentc                    sX   dt fdd t|trt fdd| D || d S t fdd|D || d S )Nr  c                 S   s   t dd|  S )Nz['\" ]r"  )resubr  )r  r=   r=   r>   _cleanK	  s   z:ComponentReflectionTest._check_expressions.<locals>._cleanc                    s   i | ]	\}} ||qS r=   r=   )r|  er}  r  r=   r>   r  O	      z>ComponentReflectionTest._check_expressions.<locals>.<dictcomp>c                    s   g | ]} |qS r=   r=   )r|  r  r  r=   r>   r  Q	  r$  z>ComponentReflectionTest._check_expressions.<locals>.<listcomp>)r  r   r9   r   r  )rt   r  r  err_msgr=   r  r>   _check_expressionsJ	  s   
"z*ComponentReflectionTest._check_expressionsc           	      C   s   |d u rt ||| d S t t|t|| t||D ]?\}}t|t|B D ]2}||v s5||v rY||v rY| d| d| }|dv rO| || || | q't || || | q'qd S )Nz - )r  r  )r   r
  r	  rl  r  )	rt   r  r  req_keysmsgrr  r   r  r=   r=   r>   r&  S	  s   z#ComponentReflectionTest._check_listc                 C   s\   t t| t|  |D ]}|| || }}|r#|g|g}}| |||| qd S r   )r   rl  keysr&  )rt   r  r  r  
make_listsr   r  r  r=   r=   r>   _check_table_dicta	  s   z)ComponentReflectionTest._check_table_dictc                 C   R   |||||t j| j\}}}|D ]}	|  |jdi |	}
| |
|| j qd S r  )r   r   r  rz   get_multi_columnsr  r  r  r=   r=   r>   test_get_multi_columnsi	  s   
	z.ComponentReflectionTest.test_get_multi_columnsc                 C   sV   |||||t j| j\}}}|D ]}	|  |jdi |	}
| j|
|| jdd qd S )NT)r  r=   )r   r  r  rz   get_multi_pk_constraintr  r  r  r=   r=   r>   test_get_multi_pk_constraint{	  s   

z4ComponentReflectionTest.test_get_multi_pk_constraintc                 C   sX   t jjjs(||fD ] }| D ]}t|dkr&tdd |D r&|j|d qq	d S d S )Nr   c                 s   s$    | ]}| d dtjfv V  qdS )rd   N)r{  r,   r  )r|  r}  r=   r=   r>   	<genexpr>	  s    
z7ComponentReflectionTest._adjust_sort.<locals>.<genexpr>r^  )r   rN   r1  r6   r  r
  anysort)rt   r  rV  r   objr  r=   r=   r>   _adjust_sort	  s   
z$ComponentReflectionTest._adjust_sortc                 C   d   |||||t j| j\}}}|D ]}	|  |jdi |	}
| |
|dd  | |
|| j qd S )Nc                 S      t | d S )Nr  tupledr=   r=   r>   r   	  r{  zEComponentReflectionTest.test_get_multi_foreign_keys.<locals>.<lambda>r=   )r   r  r  rz   get_multi_foreign_keysr  r  r  r  r=   r=   r>   test_get_multi_foreign_keys	  s    

z3ComponentReflectionTest.test_get_multi_foreign_keysc                 C   r  r  )r   r
  r  rz   get_multi_indexesr  r  r  r=   r=   r>   test_get_multi_indexes	  s   
z.ComponentReflectionTest.test_get_multi_indexesc                 C   r  )Nc                 S   r  )Nr   r  r  r=   r=   r>   r   	  r{  zKComponentReflectionTest.test_get_multi_unique_constraints.<locals>.<lambda>r=   )r   r  r  rz   get_multi_unique_constraintsr  r  r  r  r=   r=   r>   !test_get_multi_unique_constraints	     
z9ComponentReflectionTest.test_get_multi_unique_constraintsc                 C   r  )Nc                 S   r  Nr  r  r  r=   r=   r>   r   	  r{  zJComponentReflectionTest.test_get_multi_check_constraints.<locals>.<lambda>r=   )r   r  r  rz   get_multi_check_constraintsr  r  r  r  r=   r=   r>    test_get_multi_check_constraints	  r  z8ComponentReflectionTest.test_get_multi_check_constraintsr   r   r  r  r
  r  r  r  methodc                 C   sH   t |}t||}tt |d W d    d S 1 sw   Y  d S )Ntable_does_not_exists)r   getattrr   r!   )rt   r  r   r|   r   r=   r=   r>   test_not_existing_table	  s
   


"z/ComponentReflectionTest.test_not_existing_tablec              	      s   t j  fdd}tjt d|2 ttd t|t	dt
 d  W d    n1 s.w   Y  W d    d S W d    d S 1 sFw   Y  d S )Nc                     s&   | di }td|d<  | i |S )Nunreflectableerr)N
some_table)
setdefaultr"   )r   r   urmcr=   r>   patched
  s   z;ComponentReflectionTest.test_unreflectable.<locals>.patchedr  r  r  )r   r  r,   patchobjectr   r"   r   reflect_tabler   r   )rt   r   r  r=   r  r>   test_unreflectable
  s   "z*ComponentReflectionTest.test_unreflectabler   c                    s   t  }|rtjnd  |j| |dd t|}| }|r8|| 7 }z	|| 7 }W n	 ty7   Y nw  rC fdd|D }t	t
|jt
| d S )NF)rM   r   resolve_fksc                    s   g | ]	}  d | qS )r!  r=   r  rL   r=   r>   r  "
  r  z9ComponentReflectionTest.test_metadata.<locals>.<listcomp>)r   r   rP   reflectr   r  r  r  r   r   r  r   )rt   r   r  r   mr|   r   r=   rL   r>   test_metadata
  s   
z%ComponentReflectionTest.test_metadatac              	   C   s   t d|tdtddtdtdddd || t|}|d}t|ddi |d}d	d
 |D }ddd}t|| d S )Nunicode_commentsunicodeu   é試蛇ẟΩr   emojiu	   ☁️✨u   試蛇ẟΩ✨r  c                 S      i | ]	}|d  |d qS r/  r=   r  r=   r=   r>   r  6
  r  zAComponentReflectionTest.test_comments_unicode.<locals>.<dictcomp>)r  r  r   r   r   r   r   r  r   r   )rt   r   rV   r|   tcr  valuer  r=   r=   r>   test_comments_unicode%
  s   



z-ComponentReflectionTest.test_comments_unicodec                 C   sp   t d|tdtdddd || t|}|d}t|ddi |dd }t|d |d	 iddi d S )
Nr  r  u&   🐍🧙🝝🧙‍♂️🧙‍♀️r   u&   🎩🁰🝑🤷‍♀️🤷‍♂️r  r   rd   r   r  )rt   r   rV   r|   r  r   r=   r=   r>   test_comments_unicode_full:
  s   

z2ComponentReflectionTest.test_comments_unicode_fullc           	      C   s   t jt}td|tdtj|dtdt  || t	 }td||d}t
|jjjj| t|jjjj t|}|d\}}t
|d j| t|d j d S )Nr  collated)	collationnot_collatedr   r  )r   rN   get_order_by_collationr   r   r   rg   r   r   r   r   r   r  r  r  r*   r  r   r   )	rt   r   rV   r  r   t2r|   r  r  r=   r=   r>    test_column_collation_reflectionK
  s    
z8ComponentReflectionTest.test_column_collation_reflectionr   r-   )NF)ur@   rA   rB   run_insertsr   r   rC   rW   r   rb   rT   rR   rt  rv  r  r    r  r   r  r  r  propertyr  r  r  r  r  r  r  r  r  r  r  r   rN   schema_reflectionr  r  r  r  schema_create_deleter  r  r  r   r   rO   r  r  r  r  rQ   rj   r  r   r  r  r  r  r   r   r!  r   r%  !primary_key_constraint_reflectionr  r  r0  r  r?  r^  rC  r   r  r`  ra  rH  rQ  r  rS  temp_table_reflect_indexesrW  r  rt  r  rx  table_reflectionr~  r   r  r   r  r   r  r  r  r  r&  r  r  r  r  r  r  r  r  r  r  r  r   r  r  comment_reflection_full_unicoder  column_collation_reflectionorder_by_collationr  r=   r=   r=   r>   r  r  s.   

 .

!

-
!
&
`

0

X

u

E

:







#




A


&'$
X





1
	

	





r  c                   @   sh   e Zd ZdZdZejdd Zejdd Zdd Z	d	d
 Z
dd Zejjdd Zejjdd ZdS )TableNoColumnsTest)reflect_tables_no_columnsTc                 C   s   t d| || d S Nr  )r   r   rt   r   rV   r=   r=   r>   table_no_columnsg
  s   
z#TableNoColumnsTest.table_no_columnsc                 C   s<   t d| t|dtd t|dtd || d S )Nr  rX   z*CREATE VIEW empty_v AS SELECT * FROM emptyrY   zDROP VIEW IF EXISTS empty_v)r   r   rZ   r#   r   r  r=   r=   r>   view_no_columnsl
  s   

z"TableNoColumnsTest.view_no_columnsc                 C   $   t dt |d}tt|jg  d S )Nr  r   r   r   r   r  r   )rt   r   r  r  r=   r=   r>   test_reflect_table_no_columns|
  s   z0TableNoColumnsTest.test_reflect_table_no_columnsc                 C   s2   t |}t|dg  | }t|dg i d S )Nr  r  )r   r   r   r  )rt   r   r  r|   multir=   r=   r>   !test_get_columns_table_no_columns
  s   z4TableNoColumnsTest.test_get_columns_table_no_columnsc                 C   s*   t  }|| t|jdgsJ d S r  )r   r  rl  r   r  )rt   r   r  r  r=   r=   r>   "test_reflect_incl_table_no_columns
  s   
z5TableNoColumnsTest.test_reflect_incl_table_no_columnsc                 C   r  )Nempty_vr   r  )rt   r   r  r  r=   r=   r>   test_reflect_view_no_columns
  s   z/TableNoColumnsTest.test_reflect_view_no_columnsc                 C   s8   t |}t|dg  |jtjd}t|dg i d S )Nr  )r   )Nr  )r   r   r   r  r   r  )rt   r   r  r|   r  r=   r=   r>    test_get_columns_view_no_columns
  s   z3TableNoColumnsTest.test_get_columns_view_no_columnsN)r@   rA   rB   r   r   r   r   r  r  r  r  r  rN   r   r  r  r=   r=   r=   r>   r  c
  s    


r  c                   @   s4  e Zd ZdZejddgddd Ze dd Zdd	 Zej	j
d
d Zej	jejddddddd Zej	j
ejddddddd Zej	jdd Zej	jdd Zej	jdd Zej	jdd Zdd  Zej	jd!d" Zej	jejejejejejej	jfej ej	jfd#dd$d% Z!ej	jd&d' Z"ejdd(dej	j#fddd)ej	j$fi dd*ej	j$fi d*dej	j%fddd+ej	j&fdd+dej	j'fd,dd-d. Z(eje)e*+d/d0fe)d/d0fe,e*- d1fe)e*+d2d3ej	j.fe)e*+d4d5ej	j.fe/e01 d6fe)e*2d7e*2d8 d3ej	j.fd9dej	j3d:d; Z4dS )<ComponentReflectionTestExtraTF)paramsc                 C   s   |j rtjS d S r   )paramr   rP   )rt   requestr=   r=   r>   use_schema_fixture
  s   z/ComponentReflectionTestExtra.use_schema_fixturec                    s   t j fdd}|S )Nc                 3   s    t  fV    d S r   )r   r   )r   r   rV   r  r=   r>   go
  s   z:ComponentReflectionTestExtra.inspect_for_table.<locals>.go)
contextlibcontextmanager)rt   rV   r   r  r  r=   r  r>   inspect_for_table
  s   z.ComponentReflectionTestExtra.inspect_for_tablec                    sD   dd  t  fdd|D dd d}t |dd d}t|| d S )	Nc                 S   s   d td|  tjS )N zand|\d|=|a|b|c|or|<|>)joinr  findallr  I)r  r=   r=   r>   	normalize
  s   z5ComponentReflectionTestExtra.ck_eq.<locals>.normalizec                    s"   g | ]}|d   |d dqS )rd   r  rd   r  r=   )r|  itemr  r=   r>   r  
  s    z6ComponentReflectionTestExtra.ck_eq.<locals>.<listcomp>c                 S      | d S r  r=   r  r=   r=   r>   r   
      z4ComponentReflectionTestExtra.ck_eq.<locals>.<lambda>r^  c                 S   r  r  r=   r	  r=   r=   r>   r   
  r
  )r  r   )rt   rR  rV  r=   r  r>   ck_eq
  s   
z"ComponentReflectionTestExtra.ck_eqc              	   C   sb   |d\}}t d|tdtd|d W d    n1 sw   Y  | |jd|dg  d S )NrM  rI   r@  rL   )r   r   rg   r   r  r  )rt   rV   r  rM   r   r=   r=   r>   #test_check_constraint_no_constraint
  s   z@ComponentReflectionTestExtra.test_check_constraint_no_constraint	my_inlineMyInlineNconstraint_namer   c                 C   s   |d)\}}t d|tdt ddtdt tjd|dtdtd	|d
 W d    n1 s0w   Y  |jd|d
}| ||pCtj	ddg d S )Nsa_ccrF   TrG   r   a > 1 AND a < 5r   rI   rJ   rL   a > 1 and a < 5r  )
r   r   r   rg   r   r   r  r  r,   r  rt   rV   r  r  rM   r   rR  r=   r=   r>   test_check_constraint_inline
  s0   z9ComponentReflectionTestExtra.test_check_constraint_inlinemy_ck_const	MyCkConstc              	   C   s|   |d\}}t d|tdt tjd|d|d W d    n1 s#w   Y  |jd|d}| ||p6tjddg d S )Nr  r   za = 1 OR (a > 2 AND a < 5)r   rL   za = 1 or a > 2 and a < 5r  )	r   r   r   rg   r   r  r  r,   r  r  r=   r=   r>    test_check_constraint_standalone
  s&   
z=ComponentReflectionTestExtra.test_check_constraint_standalonec                 C   s   |dI\}}t d|tdt ddtdt tdtdt tjdd	d
tdt tdtdtjddd
tjddd
tjddd
|d W d    n1 sPw   Y  |jd|d}| |dddd	ddt	j
ddg d S )Nr  rF   TrG   r   r  rZ  zb > 1 AND b < 5r  r   r   rI   rJ   some_uqzc > 1 AND c < 5cc1	some_c_uqrL   zc > 1 and c < 5r  zb > 1 and b < 5r  )r   r   r   rg   r   r   r   r  r  r,   r  )rt   rV   r  rM   r   rR  r=   r=   r>   test_check_constraint_mixed  s6   

z8ComponentReflectionTestExtra.test_check_constraint_mixedc              	   C   s   |d*\}}t d|tdtddtdttdt}td|jj|jj|jj W d   n1 s1w   Y  |d}t	|d	 d
 g d dS )ztest for #12894sa_multi_indexColumn1TrG   Column2Column3Index_ExampleNr   r   )r  r  r  )
r   r   r   r$   r   r  r  r  r
  r   )rt   rV   r  rM   r   rE   rD  r=   r=   r>   test_index_column_order4  s"   
z4ComponentReflectionTestExtra.test_index_column_orderc              	      s  t d|tdtdtdtdtdtd}tdt|jj|jjt|jj	 dtdt
|jj td	|jj |  t }d	dgd
i dg} fdd}||d  G dd dt}G fdddt}tjjjrdg d|dd|dgd
d}	||	 |d|	 dd g|d dgd
d}
||
 ||
 t|d| t }t d| d}n&td t|d| t }t d| d}W d    n1 sw   Y  | || jj d S )Nr  xr8  yzt_idxa  long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string 
t_idx_longt_idx_2F)rd   r   r9  r  c                    s<   t jjjrg | d<  jj dg i| d< d S | di  d S )Nr  _includer  )r   rN   rT  r6   r  rd   r  )entryr  r=   r>   completeIndexd  s
   
zYComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.completeIndexr   c                   @   r  )z[ComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.lower_index_strc                 S   s    |  }d|v od|v pd|v S )Nr  r"  r#  r  )rt   r   olr=   r=   r>   r  p  s   zbComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.lower_index_str.__eq__Nr  r=   r=   r=   r>   lower_index_stro  r  r-  c                       s   e Zd Z fddZdS )z^ComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.coalesce_index_strc                    s   d|  v o	 |v S )Ncoalescer+  r  long_strr=   r>   r  v  s   zeComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.coalesce_index_str.__eq__Nr  r=   r/  r=   r>   coalesce_index_stru  s    r1  )Nr$  Nzlower(x)zlower(y))rd   r   r  r9  zcoalesce(x, 'z')r   z>Skipped unsupported reflection of expression-based index t_idx)r   r   r   r$   r   r  r   r"  r$  r#  r.  r   r   r  r   rN    reflect_indexes_with_expressionsr6   insertr  r   r
  r   r	   !compare_table_index_with_expectedr  rd   )rt   rV   r   r  r|   rV  r*  r-  r1  
expr_indexexpr_index_longr   r  r=   )r   r0  r>   %test_reflect_expression_based_indexesH  sn   &
		



zBComponentReflectionTestExtra.test_reflect_expression_based_indexesc                 C   s   t d|tdtdtdtd}td|jj}dg|j|jj d< |	| t
|}|d}t|ddgdgdtjdg t|d	 d
 d|jj  dg t dt |d}tt|jd	 j|jj d dg d S )Nr  r"  r8  r#  r%  includeF)rd   r   r  r9  r  r   r  z
%s_includer   )r   r   r   r$   r   r"  r  r  rd   r   r   r
  r   r,   r  r   r  rD  )rt   rV   r   r  r   r|   r
  r  r=   r=   r>   test_reflect_covering_index  sD   



z8ComponentReflectionTestExtra.test_reflect_covering_indexc                 G   sB   t d|gdd t|D R  }|| dd t|dD S )Nr  c                 S   s   g | ]\}}t d | |qS )zt%dr   )r|  r  type_r=   r=   r>   r        zAComponentReflectionTestExtra._type_round_trip.<locals>.<listcomp>c                 S   r"  )r  r=   r  r=   r=   r>   r    r$  )r   r  ry   r   r   )rt   r   rV   r   r  r=   r=   r>   _type_round_trip  s   
z-ComponentReflectionTestExtra._type_round_tripc                 C   sH   |  ||tddD ]}t|tjsJ t|jd t|jd qd S )N   r'  )r<  r  r  r   r   	precisionscale)rt   r   rV   typr=   r=   r>   test_numeric_reflection  s   z4ComponentReflectionTestExtra.test_numeric_reflectionr:  c                 C   s   |  |||dd }t|tjrt|tjsJ nt|tjr)t|tjs(J nt|tjs1J t|jd t|jt	s?J d S )N4   r   )
r<  
issubclassr  ri   r   r\  r   r   lengthint)rt   r   rV   r:  r@  r=   r=   r>   test_string_length_reflection  s   
z:ComponentReflectionTestExtra.test_string_length_reflectionc              	   C   sT   t d|tdtddtdtdd}|| tdd t|dD ddd	 d S )
Nr  r   Tr(  rZ  Fc                 S   r  )rd   r)  r=   r#  r=   r=   r>   r     s    zIComponentReflectionTestExtra.test_nullable_reflection.<locals>.<dictcomp>)r   rZ  )r   r   r   ry   r   r   r   )rt   r   rV   r  r=   r=   r>   test_nullable_reflection  s   
z5ComponentReflectionTestExtra.test_nullable_reflectionCASCADEzSET NULLz	NO ACTIONRESTRICTzexpected,ondelete,onupdatec                    s"  i }|r||d< |r||d< |d u r|}t d|tdtdddd t d|tdtddtd	ttd
ddtdtddd t d|tdtddtdtdddtdttjdgdgfddi|dd || t|}|	dd d  t
 fdd D i  |	dd d  t
 | d S )Nondeleteonupdater"  rF   TrG   r   r  x_idzx.idxidr   test
   userrd   rJ   Fr(  tidztable.idmyfkr   r3   c                    s   i | ]} | r| | qS r=   r=   )r|  r   optsr=   r>   r  ^  r;  zMComponentReflectionTestExtra.test_get_foreign_key_options.<locals>.<dictcomp>)r   r   r   r   r   rg   r   r   r   r  r   )rt   r   rV   rV  rJ  rK  r3   r|   r=   rS  r>   test_get_foreign_key_options  sT   *	
z9ComponentReflectionTestExtra.test_get_foreign_key_options10z'?10'?z1|truez3 + 5z3\+5z(3 * 5)z3\*5zcurrent_timestamp|now|getdate35zdatatype, default, expected_regc           	   	   C   sd   t d|tdtddtd||d}|| t|dd d }td	d
|}t||tj	d d S )Nr  rF   TrG   thecol)server_defaultr   r  z	[\(\) \']r"  )flags)
r   r   r   ry   r   r   r  r  r   
IGNORECASE)	rt   rV   r   datatyper  expected_regr  rR  reflected_sanitizedr=   r=   r>   test_server_defaultsd  s   
z1ComponentReflectionTestExtra.test_server_defaults)5r@   rA   rB   r   r   r   r  r  r  rN   r  r  "inline_check_constraint_reflectionr   r  r  r  indexes_check_column_orderr!  indexes_with_expressionsr7  rT  r9  r<  r  rA  r  r   ri   r\  NVARCHARnvarchar_typesNCHARrF  rG  1foreign_key_constraint_option_reflection_ondelete1foreign_key_constraint_option_reflection_onupdate1fk_constraint_option_reflection_ondelete_noaction1fk_constraint_option_reflection_onupdate_restrict1fk_constraint_option_reflection_ondelete_restrictrU  r   rg   r  r   trueexpression_server_defaultsr   r   nowliteral_columnserver_defaultsr`  r=   r=   r=   r>   r  
  s    

	
 


Z
*



'6r  c                   @   s0   e Zd ZdZdZedd Zdd Zdd Zd	S )
NormalizedNameTest)denormalized_namesTc                 C   sL   t tddd|tdtdd t tddd|tdtddtdtd d S )	Nr   Tr   rF   rG   r  t1idzt1.id)r   r%   r   r   r   rU   r=   r=   r>   rW     s   

z NormalizedNameTest.define_tablesc                 C   s~   t  }ttddd|tjd}|jd }|jj|jj	sJ t  }|j
tjdd d |jd jj|jd jj	s=J d S )	Nr  Trs  r   r   c                 S   s   |   dv S )Nr   r  r+  )rd   r  r=   r=   r>   r     r{  zINormalizedNameTest.test_reflect_lowercase_forced_tables.<locals>.<lambda>)only)r   r   r%   r   r;   r   r   rt  r   rF   r  )rt   r   t2_reft1_refm3r=   r=   r>   $test_reflect_lowercase_forced_tables  s   

&z7NormalizedNameTest.test_reflect_lowercase_forced_tablesc                 C   sP   dd t tj D }t|d  |d   t|d  |d   d S )Nc                 S   s   g | ]
}|  d v r|qS )ru  r+  r  r=   r=   r>   r    s
    z;NormalizedNameTest.test_get_table_names.<locals>.<listcomp>r   r   )r   r   r;   r  r   upperr  )rt   
tablenamesr=   r=   r>   r    s
   z'NormalizedNameTest.test_get_table_namesN)	r@   rA   rB   r   r   rC   rW   rz  r  r=   r=   r=   r>   rq    s    
rq  c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zejj	d	d
 Z
dS )ComputedReflectionTestc                 C   s^   t tj}|d}dd |D }td|d d v  t|d d d  t|d d d  d S )	Ncomputed_default_tablec                 S   ry  r   r=   r  r=   r=   r>   r    rz  zLComputedReflectionTest.test_computed_col_default_not_set.<locals>.<dictcomp>42with_defaultr  normalcomputed_col)r   r   r;   r   r+   r   )rt   r|   r  col_datar=   r=   r>   !test_computed_col_default_not_set  s   

z8ComputedReflectionTest.test_computed_col_default_not_setc                 C   s   t tj}|d}dd |D }dD ]
}td|| v q|d }td|v  td|d v  t| |d d d td	|d v tjj	j
 tjj	j
r[t|d d	 tjjj
 d S d S )
Nr~  c                 S   ry  r   r=   r  r=   r=   r>   r    rz  zKComputedReflectionTest.test_get_column_returns_computed.<locals>.<dictcomp>)rF   r  r  computedr  r  	normal+42	persisted)r   r   r;   r   r+   r   r  r   rN   "computed_columns_reflect_persistedr6   "computed_columns_default_persisted)rt   r|   r  rI   r   compDatar=   r=   r>    test_get_column_returns_computed  s&   




z7ComputedReflectionTest.test_get_column_returns_computedc                 C   s\   t d|| v  || d }t| |d | tjjjr,t d|v  t|d | d S d S )Nr  r  r  )r+   r   r  r   rN   r  r6   r   )rt   rI   columnr  r  r  r=   r=   r>   check_column  s   
z#ComputedReflectionTest.check_columnc                 C   st   t tj}|d}dd |D }| |ddtjjj tjj	jr)| |ddd tjj
jr8| |d	d
d d S d S )Ncomputed_column_tablec                 S   ry  r   r=   r  r=   r=   r>   r    rz  zLComputedReflectionTest.test_get_column_returns_persisted.<locals>.<dictcomp>computed_no_flagr  computed_virtualznormal+2Fcomputed_storedz	normal-42T)r   r   r;   r   r  r   rN   r  r6   computed_columns_virtualcomputed_columns_storedrt   r|   r  rI   r=   r=   r>   !test_get_column_returns_persisted  s0   



z8ComputedReflectionTest.test_get_column_returns_persistedc                 C   sz   t tj}|jdtjd}dd |D }| |ddtjjj	 tjj
j	r,| |ddd	 tjjj	r;| |d
dd d S d S )Nr  rL   c                 S   ry  r   r=   r  r=   r=   r>   r    rz  zXComputedReflectionTest.test_get_column_returns_persisted_with_schema.<locals>.<dictcomp>r  z	normal/42r  znormal/2Fr  z	normal*42T)r   r   r;   r   rP   r  r   rN   r  r6   r  r  r  r=   r=   r>   -test_get_column_returns_persisted_with_schema  s4   


zDComputedReflectionTest.test_get_column_returns_persisted_with_schemaN)r@   rA   rB   r  r  r  r  r   rN   rO   r  r=   r=   r=   r>   r}    s    	r}  c                   @   sH   e Zd Zd ZZdZdZedd Zdd Z	dd	 Z
ejjd
d ZdS )IdentityReflectionTestNT)r   r  c                 C   s   t d|tdttdtt  t d|tdttdddd	d
ddd tjjjr>t d|tdttdttdddtj	d d S d S )Nr   r  id1r  r   Tr   r   rJ     alwaysr   	incrementminvaluemaxvaluecyclecacher@  )r  r   rL   )
r   r   r   r   r   rN   rO   r6   r   rP   rU   r=   r=   r>   rW      s@   

z$IdentityReflectionTest.define_tablesc                 C   s   t jjjrXd}t|D ]}||vr|| q|rQtt|t| |D ]*}|dkr5t|| || k q$|dv rDt|| || k q$t|| || | q$d S t|| d S t|d |d  t|d |d  d S )Nr  r  >   r  r  r   r  )	r   rN   identity_columns_standardr6   r  r  r   r
  r+   )rt   r  r  approxcommon_keysr   r=   r=   r>   checkB  s$   
	
zIdentityReflectionTest.checkc                 C   s  t tj}|d|d }|D ]p}|d dkr td|v  q|d dkrQd|v r0t|d  t|d d  td|v  | j|d td	d
d
d
dd	d
ddd q|d dkrd|v rat|d  t|d d  td|v  | j|d tddddddddd	d qd S )Nr   r  rd   r  r   r  r  r  Fr   r  Tr  r   r   r   r  rJ  r  )	r   r   r;   r   r)   r+   r   r  r9   rt   r|   r  rx   r=   r=   r>   r   _  sV   
		z,IdentityReflectionTest.test_reflect_identityc                 C   s   t tj}|jdtjd}|D ]?}|d dkrtd|v  q|d dkrNd|v r.t|d  t|d d  td|v  | j|d t	d	d
ddddddd	d qd S )Nr   rL   rd   r  r   r  r  r  Tr@  r   r  Fr  r  )
r   r   r;   r   rP   r)   r+   r   r  r9   r  r=   r=   r>   test_reflect_identity_schema  s2   
	z3IdentityReflectionTest.test_reflect_identity_schema)r@   rA   rB   r  r   r   r   rC   rW   r  r   r   rN   rO   r  r=   r=   r=   r>   r    s    
!,r  c                   @   s<   e Zd ZdZedd Zejjdd Z	ejj
dd ZdS )	CompositeKeyReflectionTestTc                 C   s   t d|tdttdttdtdtjdddddd dd	}t d
|tdtddtdttdttdtdtjg d|jj	|jj
|jjgddd dd		 d S )Ntb1rF   attrrd   r@  pk_tb1r   Tr1  tb2rG   pidpattrpnamer  r  r  fk_tb1_name_id_attr)r   r   r   r  ri   rg   r   r   r   rd   rF   r  )r<   rV   r  r=   r=   r>   rW     s2   

z(CompositeKeyReflectionTest.define_tablesc                 C   s0   t |}|| jjj}t|dg d d S )Nr  rd   rF   r  )r   r  r   r  rd   r   r{  )rt   r   r|   rH   r=   r=   r>   test_pk_column_order  s   z/CompositeKeyReflectionTest.test_pk_column_orderc                 C   sZ   t |}|| jjj}tt|d |d }t|dg d t|dg d d S )Nr   r   r  r  r  r  )r   r  r   r  rd   r   r
  r{  )rt   r   r|   foreign_keysr4  r=   r=   r>   test_fk_column_order  s   z/CompositeKeyReflectionTest.test_fk_column_orderN)r@   rA   rB   r   rC   rW   r   rN   r  r  r   r  r=   r=   r=   r>   r    s    

r  )r  r  r  r   r   rD   r   rq  r}  r  r  r   )Ir  rb  r  r7   rg   r"  r   r   r   r   r   r   r	   r
   r   	provisionr   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r   r    excr!   r"   r#   r$   sql.elementsr%   
sql.schemar&   r'   r(   r)   r*   r+   r,   rV   r$  
TablesTestr.   rD   r   TestBaser   r   r   r  r  r  r  rq  ComputedReflectionFixtureTestr}  r  r  __all__r=   r=   r=   r>   <module>   s    Mg&                 5   y+a 1