a
    [gP                    @   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(\Z1Z2G d)d* d*ej3Z4G d+d, d,e4Z5G d-d. d.ej3Z6G d/d0 d0ej7Z8G d1d2 d2ej3Z9d3d4 Z:G d5d6 d6e-e4Z;G d7d8 d8ej7Z<G d9d: d:e,ej7Z=G d;d< d<ej3Z>G d=d> d>ej?Z@G d?d@ d@ej3ZAG dAdB dBej3ZBdCZCdS )D    N   )config)engines)eq_)expect_raises)expect_raises_message)expect_warnings)fixtures)is_)get_temp_table_name)temp_table_keyword_argsColumn)Table   )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_true)mock)NNc                   @   s   e Zd Zedd ZdS )OneConnectionTablesTestc                 C   s6   t jjjr,ddlm} tjt|j	dddS t j
S d S )Nr   )poolclass)Z	poolclassscope)options)r   requirementsZindependent_connectionsenabled
sqlalchemyr*   r   testing_enginedictZ
StaticPooldb)clsr*    r5   v/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/sqlalchemy/testing/suite/test_reflection.py
setup_bind8   s    
z"OneConnectionTablesTest.setup_bindN)__name__
__module____qualname__classmethodr7   r5   r5   r5   r6   r)   7   s   r)   c                   @   s   e 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 )HasTableTestTc                 C   s~   t d|tdtddtdtd tjjjrTt d|tdtddtdtdtj	d tjj
rf| | tjjjrz| | d S )	N
test_tableidTprimary_keydata2   test_table_sschema)r   r   r   r   r   requiresschemasr/   r   test_schemaview_reflectiondefine_viewshas_temp_tabledefine_temp_tablesr4   metadatar5   r5   r6   define_tablesJ   s$    


zHasTableTest.define_tablesc                 C   sp   d}t |dt| t |dtd tjjjrldtjtjf }t |dt| t |dtdtj  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   rF   rG   r/   r   rH   )r4   rN   queryr5   r5   r6   rJ   `   s     
zHasTableTest.define_viewsc                 C   s   t ttjdtj S NZ	user_tmp_r   r   r3   identr4   r5   r5   r6   temp_table_namev   s    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rt	j
jjrt|dtdtj  t|dtd	 d S )
Nr>   Tr?   namerB   rP   =create temporary view user_tmp_v as select * from user_tmp_%srQ   drop view user_tmp_v)r   r   r3   rX   r   r   saINTVARCHARr   rF   rI   r/   temporary_viewsr   rR   r    rV   r4   rN   kw
table_nameuser_tmpr5   r5   r6   rL   |   s0    zHasTableTest.define_temp_tablesc                 C   sj   t j L}tt jj|d tt jj|d tt jj|d W d    n1 s\0    Y  d S )Nr=   rC   nonexistent_table)r   r3   beginr'   dialect	has_tabler&   selfconnr5   r5   r6   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 z4t|d |
  t|d W |tj n|tj 0 d S )Nr=   Z	new_tablecol)r   r   r3   r'   rg   r   r   r   r&   createclear_cachedrop)ri   rN   inspntr5   r5   r6   test_has_table_cache   s    
z!HasTableTest.test_has_table_cachec                 C   s|   t j ^}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    n1 sn0    Y  d S )Nr=   rD   rC   rd   )r   r3   re   r&   rf   rg   rH   r'   rh   r5   r5   r6   test_has_table_schema   s     z"HasTableTest.test_has_table_schemac                 C   sF   t j (}tt jjj|ddd W d    n1 s80    Y  d S )Nr=   Znonexistent_schemarD   )r   r3   re   r&   rf   rg   rh   r5   r5   r6   !test_has_table_nonexistent_schema   s    z.HasTableTest.test_has_table_nonexistent_schemac                 C   s   t |}t|d d S Nvvr   r'   rg   ri   
connectionrp   r5   r5   r6   test_has_table_view   s    z HasTableTest.test_has_table_viewc                 C   s"   t |}|  }t|| d S N)r   rX   r'   rg   )ri   ry   rp   rX   r5   r5   r6   test_has_table_temp_table   s    z&HasTableTest.test_has_table_temp_tablec                 C   s   t |}t|d d S N
user_tmp_vrw   rx   r5   r5   r6   test_has_table_temp_view   s    z%HasTableTest.test_has_table_temp_viewc                 C   s   t |}t|dtj d S ru   )r   r'   rg   r   rH   rx   r5   r5   r6   test_has_table_view_schema   s    z'HasTableTest.test_has_table_view_schemaN)r8   r9   r:   __backend__r;   rO   rJ   rX   rL   rk   rr   r   rF   rG   rs   rt   viewsrz   rK   r|   rI   r_   r   r   r5   r5   r5   r6   r<   G   s4   







r<   c                   @   sT   e 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 )HasIndexTestTc              	   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 )Nr=   r>   Tr?   rA   rB   data2my_idxrD   my_idx_s)r   r   r   r   r!   crA   r   rF   rG   r/   r   rH   )r4   rN   ttr5   r5   r6   rO      s"    
zHasIndexTest.define_tablesrf   	inspectorkindargnamesc                    s"   |dkr fddS t  jS d S )Nrf   c                     s   t jjj g| R i |S r{   )r   r3   rf   	has_index)akrj   r5   r6   <lambda>       z)HasIndexTest._has_index.<locals>.<lambda>)r   r   )ri   r   rj   r5   r   r6   
_has_index   s    zHasIndexTest._has_indexc              	   C   s&  |  ||}|ddsJ |ddr(J |ddr6J |ddrDJ |ddrRJ |ddr`J td| jjjj}td|td	ttdd	}|	| |	| zj|d
kr|ddrJ |ddrJ |j
  |dddu sJ |dddu sJ W || || n|| || 0 d S )Nr=   r   r   rd   Znonexistent_idxZmy_idx_2Ztest_table_2Zmy_idx_3foor   T)r   r!   tablesr=   r   r   r   r   r   rm   __self__rn   ro   )ri   r   ry   rN   methidxtblr5   r5   r6   test_has_index   s6    




zHasIndexTest.test_has_indexc                 C   s`   |  ||}|ddtjds J |ddtjdr4J |ddtjdrHJ |ddtjdr\J d S )Nr=   r   rD   r   rd   Znonexistent_idx_s)r   r   rH   )ri   r   ry   r   r5   r5   r6   test_has_index_schema  s    
z"HasIndexTest.test_has_index_schemaN)r8   r9   r:   r   r;   rO   r   combinationsr   r   r   rF   rG   r   r5   r5   r5   r6   r      s   

r   c                	   @   sT   e Zd ZdZdZejdddddded	dd
gejdddddddd ZdS ) BizarroCharacterFKResolutionTestztests for #10275T)r>   )z(3))zcol%p)z[brack]
columnnamer   use_compositeF)plain)z(2))z
per % cent)z
[brackets]	tablenamec           
      C   s  t ||t|tddddd}|r4|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 sJ |r|jj|	jd sJ d S )Nr>   T)keyr@   test_needs_fkid2r?   otherrefref2autoload_withr      )r   r   r   append_columnr\   ForeignKeyConstraintr   r>   r   r   
create_allr   r   r   
referencesr   )
ri   ry   rN   r   r   r   r   m2o2t1r5   r5   r6   test_fk_ref.  s@    


z,BizarroCharacterFKResolutionTest.test_fk_refN)	r8   r9   r:   __doc__r   r   r   Z	variationr   r5   r5   r5   r6   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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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rt 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r>ddg}ndg}|D ]f}dtjjjd| tjjj|f }t|dt| t|dtd tjjjd|   qHd S )!Nquote ' oner>   rY   rB   rA   Z
related_idzpk quote ' onerY   zix quote ' onezuq quote' onez
related.idzfk quote ' onezname != 'foo'zck quote ' onezquote ' one commentT)commentr   quote " twozpk quote " twozix quote " twozuq quote" twozfk quote " twozck quote " two zquote " two commentrelatedr?   r   z"CREATE VIEW %s AS SELECT * FROM %sview %srP   rQ   zDROP VIEW %s)r   r   r   r   r\   PrimaryKeyConstraintr!   UniqueConstraintr   CheckConstraintr   rF   symbol_names_w_double_quoter/   view_column_reflectionr   r3   rf   Zidentifier_preparerquoter   rR   r    )r4   rN   namesrY   rS   r5   r5   r6   rO   h  s    






z$QuotedNameArgumentTest.define_tablesc                 C   s   t ddt jjf| S )N)r   r   )r   r   rF   r   )fnr5   r5   r6   quote_fixtures  s    
z%QuotedNameArgumentTest.quote_fixturesc                 C   sd   t tj}tjjjr.||}tt	|t
 n2tt ||}W d    n1 sV0    Y  d S r{   )r   r   r3   r   rF   reflect_table_optionsr/   get_table_optionsr'   
isinstancer2   r   NotImplementedError)ri   rY   rp   resr5   r5   r6   test_get_table_options  s    



z-QuotedNameArgumentTest.test_get_table_optionsc                 C   s    t tj}|d| sJ d S )Nr   )r   r   r3   get_view_definitionri   rY   rp   r5   r5   r6   test_get_view_definition  s    
z/QuotedNameArgumentTest.test_get_view_definitionc                 C   s   t tj}||sJ d S r{   )r   r   r3   get_columnsr   r5   r5   r6   test_get_columns  s    
z'QuotedNameArgumentTest.test_get_columnsc                 C   s   t tj}||sJ d S r{   )r   r   r3   get_pk_constraintr   r5   r5   r6   test_get_pk_constraint  s    
z-QuotedNameArgumentTest.test_get_pk_constraintc                 C   s   t tj}||sJ d S r{   )r   r   r3   get_foreign_keysr   r5   r5   r6   test_get_foreign_keys  s    
z,QuotedNameArgumentTest.test_get_foreign_keysc                 C   s   t tj}||sJ d S r{   )r   r   r3   get_indexesr   r5   r5   r6   test_get_indexes  s    
z'QuotedNameArgumentTest.test_get_indexesc                 C   s   t tj}||sJ d S r{   )r   r   r3   get_unique_constraintsr   r5   r5   r6   test_get_unique_constraints  s    
z2QuotedNameArgumentTest.test_get_unique_constraintsc                 C   s   t tj}||sJ d S r{   )r   r   r3   get_table_commentr   r5   r5   r6   test_get_table_comment  s    
z-QuotedNameArgumentTest.test_get_table_commentc                 C   s   t tj}||sJ d S r{   )r   r   r3   get_check_constraintsr   r5   r5   r6   test_get_check_constraints  s    
z1QuotedNameArgumentTest.test_get_check_constraintsN)r8   r9   r:   Zrun_create_tablesr   r;   rO   r   r   r   rF   r   r   r   r   r   r   unique_constraint_reflectionr   comment_reflectionr   check_constraint_reflectionr   r5   r5   r5   r6   r   d  s6   
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   rH   r5   r5   r5   r6   r     r   z$_multi_combination.<locals>.<lambda>rE   r   r,   r   TF
use_filter)r   r   rF   rG   r   DEFAULT	TEMPORARYANYr   TABLEVIEWMATERIALIZED_VIEWZANY_VIEW)r   rE   r,   r   filter_namesr5   r5   r6   _multi_combination  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,dZde!j"j.fdAd@e!j"j-d]d^ ZBe!j"jCe!j"j.d_d` ZDe!j,dZde!j"j.fdAd@e!j"jEdadb ZFe!j,dcddded@e!j"jEe!j"jGe!j"jHdfdg ZIe!j"j;e!j"jJdhdi ZKe!j"jLdjdk ZMe!j,de!j"j.fdZdAd@e!j"jJdldm ZNe!j"j3e!j,dZde!j"j.fdAd@dndo ZOe!j"j3dpdq ZPe!j"jQdrds ZRe!j,de!j"j.fdZdAd@dtdu ZSe!,de!j"j.fd'dvdw ZTe!jUdxdy ZVe!j"jWeXdzd{ ZYe!j"j6eXd|d} ZZd~d Z[dddZ\dddZ]eXdd Z^e!j"j@eXdd Z_dd Z`e!j"j-eXdd Zae!j"jEeXdd Zbe!j"jJeXdd Zce!j"jdeXdd Zee!j,de!j"jWfdde!j"j@fde!j"j-fde!j"jEfde!j"jJfde!j"jdfde!j"j6fdd@	dd Zfdd Zge!j,dd'dAd@e!j,de!j"jhfd'dd@dd Zie!j"j6dd Zje!j"jkdd ZldS )ComponentReflectionTestNTc                 C   s*   |  |d  tjjjr&|  |tjj d S r{   )define_reflected_tablesr   rF   rG   r/   r   rH   rM   r5   r5   r6   rO     s    
z%ComponentReflectionTest.define_tablesc                 C   s  |r|d }nd}t jjjr0t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r|d u r6td;|td-tjd	d
tdtd(td<td=t jj d	tjjjd> nnt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rjtdC|jj|jjd	d  tdD|jj|jj|jj |sjtdE|tdFtdd	dG}tdH|td-tjd	d
tdFtdd	dG}t jjjrjt jjjrjtdI|jj  tdJ|jj  t jj jr| !|| |st jj"jr| #| d S )KN. z%susers.user_id
user_id_fkr   r5   usersuser_idTr?   test1   Fnullabletest2parent_user_id	test2 > 0zz_test2_gt_zerousers check constraintrY   r   test2 <= 1000rE   r   
dingalingsdingaling_id
address_idz%semail_addresses.address_idzz_email_add_id_fgdi fk commentid_userrA      )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_testr>   
id comment)r@   r   data % commentr   d2)Comment types type speedily ' " \ '' Fun!d3*   Comment
withescapesthe test % ' " \ table comment)rE   r   no_constraints"no
constraintshasescapedcommentlocal_table	remote_idz%s.remote_table_2.id)r   rE   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   rF   self_referential_foreign_keysr/   r   r   r   r\   r]   ZCHARFloatr   r   r   r   r   r   r   cross_schema_fk_reflectionr   rH   r3   rf   default_schema_nameindex_reflectionr!   r   r   indexes_with_ascdescreflect_indexes_with_ascdescr"  descr   rJ   temp_table_reflectionrL   )r4   rN   rE   Zschema_prefixZparent_id_argsr   r!  r#  r5   r5   r6   r   "  s>   

	
 


		z/ComponentReflectionTest.define_reflected_tablesc                 C   s   t ttjdtj S rT   rU   rW   r5   r5   r6   rX     s    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rtjjjrt|d
tdtj
  t|dtd d S )Nr>   Tr?   rY   rB   r   user_tmp_uq_r   user_tmp_ixrP   rZ   rQ   r[   )r   r   r3   rX   r   r   r\   r]   r^   r   rV   r!   r   rF   rI   r/   r_   r   rR   r    r`   r5   r5   r6   rL     s6    

z*ComponentReflectionTest.define_temp_tablesc              
   C   s   t jjjrdh}nt }dD ]}|}|r6| d| }|d }||v rJdnd}d| d| d	| }t|d
t| ||v rd}	|rt dr| d|	 }	d|	 d| d}
t|d
t|
 t|dtd| d|  qd S )Nr   r   r  r   r   _vzMATERIALIZED r   zCREATE zVIEW z AS SELECT * FROM rP   	mat_indexoraclezCREATE INDEX z ON z(data)rQ   zDROP )	r   rF   materialized_viewsr/   setr   rR   r    against)r4   rN   rE   materializedrb   fullnameZ	view_nameprefixrS   Z
index_namer   r5   r5   r6   rJ     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   )ri   r   r   r   r8  r   r5   r5   r6   _resolve_kind  s    





z%ComponentReflectionTest._resolve_kindc                 C   s<   t jjjs|  |  nt jjjs8|| |  d S r{   )r   rF   r   r/   clearr5  r;  )ri   r   r8  r5   r5   r6   _resolve_views  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	sd  dd	g tjjj	rtjjj	sd  d
|  g tjjj	s܈d  d
g  fdd| D }|S )Nc                 S   s   dS )NTr5   )_r5   r5   r6   r   &  r   z8ComponentReflectionTest._resolve_names.<locals>.<lambda>c                 S   s   d| d vS Ntmpr   r5   r   r5   r5   r6   r   (  r   c                 S   s   d| d v S r@  r5   rB  r5   r5   r6   r   *  r   r  r  r  r!  r#  r~   c                    s>   i | ]6\}}|r|d   vr r4|d   v r||qS )r   r5   ).0r   vr   removedrE   Zscope_filterr5   r6   
<dictcomp>G  s
   z:ComponentReflectionTest._resolve_names.<locals>.<dictcomp>)r   r   r   r   r   rH   rX   rF   r(  r/   addr;  r*  r.  temp_table_namesr_   items)ri   rE   r,   r   valuesr   r5   rE  r6   _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   r   r  r  r  r  r  r  r!  r#  r(   r   r>  rX   r<  rL  )	ri   rE   r,   r   r   r8  r   r   r   r5   r5   r6   exp_optionsP  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textrM  rN  rO  r~   r   r   r  r  r  r  r  r  r  r  r!  r#  )r>  rX   r<  rL  )
ri   rE   r,   r   r   emptyr8  r   r   r   r5   r5   r6   exp_commentso  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)rY   autoincrementtypedefaultr   r   omitrU  )r(   r   pop)rY   autorW  r   r   r   r5   r5   r6   rl     s    
z0ComponentReflectionTest.exp_columns.<locals>.colc                    s"   dt jdd|} | fi |S )NTF)rZ  rW  r   r(   r   )rY   ra   rl   r5   r6   pk  s    z/ComponentReflectionTest.exp_columns.<locals>.pkrM  r   rX  )rZ  r   r   r  rA   rN  r  r	  rO  r   r   r   r   r   r~   r>   rY   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r"  r#  rP  )
ri   rE   r,   r   r   r]  r8  r   r   r   r5   r\  r6   exp_columns  s    

	




	
'z#ComponentReflectionTest.exp_columnsc                 C   s   h dS )N>   rY   r   rV  rW  r5   ri   r5   r5   r6   _required_column_keys  s    z-ComponentReflectionTest._required_column_keysc                 C   sN  t jd ddd}|d d}tjjjr8|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r
t j|
d< q
| 
||	||}| ||||}|S )Nr   c                 W   s   t || |dS )N)constrained_columnsrY   r   )list)rY   r   colsr5   r5   r6   r]    s    z+ComponentReflectionTest.exp_pks.<locals>.pkr   rM  r   rN  rO  r~   r   r   r   r  r   r  r  r  r>   r  r  r  r  r!  r#  rY   )r(   r   r   rF   Zmaterialized_views_reflect_pkr/   r>  rX   reflects_pk_namesrK  r<  rL  )ri   rE   r,   r   r   r]  rS  r8  r   r   valr   r5   r5   r6   exp_pks  s>    

zComponentReflectionTest.exp_pksc                 C   s   ddhS )NrY   ra  r5   r_  r5   r5   r6   _required_pk_keys'  s    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rXt j|
d!< qXqP| ||||}| ||||}|S )"Nc                   @   s   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   r3   rf   r)  ri   r   r5   r5   r6   __eq__3  s    z2ComponentReflectionTest.exp_fks.<locals>.tt.__eq__Nr8   r9   r:   ri  r5   r5   r5   r6   r   2  s   r   c                    s$   | ||t j|d ur|n  ||dS )N)ra  referred_columnsrY   r-   referred_schemareferred_tabler   r[  )rc  ref_colZ	ref_table
ref_schemarY   r   r   r5   r6   fk9  s    	z+ComponentReflectionTest.exp_fks.<locals>.fkrM  rN  rO  r~   r   r   r   r   r   r   r  r   r  r   r   r   r  r  r  r  r  r>   r  )ro  r  r  r!  r#  rY   )r(   r   r>  r   rH   rX   r   rF   r&  r/   r=  named_constraintsrK  r<  rL  )ri   rE   r,   r   r   rq  r8  r   r   valsre  r   r5   rp  r6   exp_fks+  sn    
#zComponentReflectionTest.exp_fksc                 C   s   h dS )N>   rY   rk  ra  rm  rl  r5   r_  r5   r5   r6   _required_fk_keys  s    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}|  || |rf||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)r  column_sorting
duplicatesrq  c                    s   t jj}t jj}t jj}|r"|jr,|r0|js0dS |t|| tjg d}	 r~ |	d< |jr~|	d  |	d< }
 fdd|
D |	d< |r| |	d< |	gS )	Nr5   )r  column_namesrY   dialect_optionsinclude_columnsrv  rx  expressionsc                    s   g | ]}| v rd n|qS r{   r5   rC  r   rv  r5   r6   
<listcomp>  s   zDComponentReflectionTest.exp_indexes.<locals>.idx.<locals>.<listcomp>Zduplicates_constraint)	r   rF   Zforeign_keys_reflect_as_indexZ#unique_constraints_reflect_as_indexZ*reflect_indexes_with_ascdesc_as_expressionr/   rb  r(   r   )rY   r  rv  rw  rq  rc  Zfk_reqZdup_reqZsorting_expressionr   origr5   r}  r6   r     s4    


z0ComponentReflectionTest.exp_indexes.<locals>.idxrM  rN  rO  r~   rA   r3  r   r   r   r   T)rY   rq  r   r   r   r   r  )rY   r  r   )rY   r  rw  r  r   r   r  r  r	  r  r  r  r  r  r  r  r  r!  r"  r$  )r-  )rY   rv  r#  r%  r   r0  rY   r/  )rY   rw  r  )r>  extendr(   r   rX   r   rV   r   rF   r+  r/   r,  r=  r<  rL  )
ri   rE   r,   r   r   r   r8  r   r   r   r5   r5   r6   exp_indexes  s    
%



5z#ComponentReflectionTest.exp_indexesc                 C   s   h dS )N>   rY   r  rx  r5   r_  r5   r5   r6   _required_index_keys  s    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}	|ri |||	S | ||	||}
| ||||
}
|
S d S )"NF)duplicates_indexis_indexr   c                 W   s8   t jj}|r|jsdS t|| |d}|r2||d< |gS )Nr5   )rx  rY   r   r  )r   rF   Z*unique_index_reflect_as_unique_constraintsr/   rb  )rY   r  r  r   rc  reqr   r5   r5   r6   uc  s    
z+ComponentReflectionTest.exp_ucs.<locals>.ucrM  rN  rO  r~   r   r   r   r  T)rY   r  r  r   rA   )rY   r  r   r   r  r  )rY   r  r   r  r  r  r  r  r  r!  r#  rY   r/  r   )r>  r(   r   rX   r   rV   r<  rL  )ri   rE   r,   r   r   all_r  r8  r   r   r   r5   r5   r6   exp_ucs  sZ    		
 zComponentReflectionTest.exp_ucsc                 C   s   ddhS )NrY   rx  r5   r_  r5   r5   r6   _required_unique_cst_keysK  s    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                   @   s   e Zd Zdd ZdS )z+ComponentReflectionTest.exp_ccs.<locals>.ttc                 S   s(   |  dddddd}| |v S )N(r   )`)lowerreplace)ri   r   r   r5   r5   r6   ri  W  s    z2ComponentReflectionTest.exp_ccs.<locals>.tt.__eq__Nrj  r5   r5   r5   r6   r   V  s   r   c                    s    | ||dS )N)sqltextrY   r   r5   )rR  rY   r   rp  r5   r6   cc`  s    z+ComponentReflectionTest.exp_ccs.<locals>.ccrM  rN  rO  r~   r   r   r   r   r   r  r   z$address_id > 0 and address_id < 1000r  r   r  r  r  r  r  r  r!  r#  )N)strr>  r(   r   rX   r<  rL  )
ri   rE   r,   r   r   r  r8  r   r   r   r5   rp  r6   exp_ccsO  sF    

zComponentReflectionTest.exp_ccsc                 C   s   ddhS )NrY   r  r5   r_  r5   r5   r6   _required_cc_keys  s    z)ComponentReflectionTest._required_cc_keysc                 C   s    t |}ttjj| v  d S r{   )r   r'   r   r   rH   get_schema_namesrx   r5   r5   r6   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   rH   r&   rx   r5   r5   r6   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Zschema_translate_mapN)execution_optionsr#   r   r   rH   r   r'   r  rx   r5   r5   r6   %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   rH   r   r'   r  r&   rx   r5   r5   r6   test_has_schema_w_translate_map  s    z7ComponentReflectionTest.test_has_schema_w_translate_mapc              
   C   s   t |}td| v  t|d |td zVtd| v  t|d |  td| v  t|d W |td n|td 0 d S )NZfoo_barzCREATE SCHEMA foo_barzDROP SCHEMA foo_bar)r   r&   r  r  executer    rn   r'   rx   r5   r5   r6   test_schema_cache  s    z)ComponentReflectionTest.test_schema_cachec                 C   s$   t  }t| t|jds J d S )Nr)  )r   r1   r   hasattrrf   )ri   enginer5   r5   r6   test_dialect_initialize  s    z/ComponentReflectionTest.test_dialect_initializec                 C   s   t |}t|j|jj d S r{   )r   r   r)  rf   rx   r5   r5   r6   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rrg d}t|| ng d}tt|| d S )N>   r  r  r  r  r#  r  r!  c                 S   s   g | ]}|d  r|d  qS )r   r5   )rC  Zrecr5   r5   r6   r~    s   z@ComponentReflectionTest.test_get_table_names.<locals>.<listcomp>c                    s   g | ]}| vr|qS r5   r5   rC  tZ_ignore_tablesr5   r6   r~    r   r  r1  )r   r  r   )r   rH   r   Zget_sorted_table_and_fkc_namesget_table_namesr   sorted)	ri   ry   r  r  rE   rp   r   table_namesanswerr5   r  r6   test_get_table_names  s     	

z,ComponentReflectionTest.test_get_table_namesc                 C   sl   t |}|rtj}nd }||}tjjjrRtt	|ddg t|
|dg ng d}tt	|| d S )NrN  rO  rM  )rM  rN  rO  )r   r   rH   get_view_namesr   rF   r5  r/   r   r  get_materialized_view_names)ri   ry   r  rp   rE   r  r  r5   r5   r6   test_get_view_names  s    

z+ComponentReflectionTest.test_get_view_namesc                 C   s,   t |}| }tt|dtj g d S rT   )r   Zget_temp_table_namesr   r  r   rV   ri   ry   rp   rI  r5   r5   r6   test_get_temp_table_names  s    z1ComponentReflectionTest.test_get_temp_table_namesc                 C   s$   t |}| }tt|dg d S r}   )r   Zget_temp_view_namesr   r  r  r5   r5   r6   test_get_temp_view_names  s    z0ComponentReflectionTest.test_get_temp_view_namesc                 C   s   |  | d S r{   )_test_get_commentsri   ry   r5   r5   r6   test_get_comments  s    z)ComponentReflectionTest.test_get_commentsc                 C   s   |  |tjj d S r{   )r  r   r   rH   r  r5   r5   r6   test_get_comments_with_schema  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 )NrD   r  r   )r   rT  r   r   r   r  rY   )ri   ry   rE   rp   expno_cstr5   r5   r6   r  #  s&    




z*ComponentReflectionTest._test_get_comments)FFzuse_views,use_schemac                 C   sj  |rt j}nd }| jj| jj }}|r0g d}nddg}t|}t|||fD ]\}	}
|}|j|	|d}tt	|dkt	| t
|
jD ]\}}t|j|| d  || d j}|j}t|tjjr|j}tdr|tjtjfv rt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 qqNd S )NrO  rN  rM  r   r  rD   r   rY   rV  r4  z%s(%s), %s(%s)rW  )"r   rH   r   r   r  r   zipr   r'   len	enumeratecolumnsr   rY   	__class__rV  r   r\   r   Z
TypeEnginer   r7  	sql_typesDateDateTimer6  __mro__intersectionr   NumericZTimer   Z_Binaryr@   )ri   ry   Z	use_viewsr  rE   r   	addressesr  rp   rb   tableZschema_namerc  irl   ctypeZ	ctype_defr5   r5   r6   r   ;  s\    

z(ComponentReflectionTest.test_get_columnsc                 C   s6   |   }| j| }t|t |d}| j||dd d S )Nr   F)Zstrict_constraints)rX   r   r   r   Zassert_tables_equal)ri   ry   rb   rc   Zreflected_user_tmpr5   r5   r6   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  qDd S )Nr   rY   )
rX   r   r   r   r'   r  r  r  r   rY   )ri   ry   rb   rc   rp   rc  r  rl   r5   r5   r6   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   s   g | ]}|d  qS r   r5   rC  rl   r5   r5   r6   r~    r   zFComponentReflectionTest.test_get_temp_view_columns.<locals>.<listcomp>)r>   rY   r   )r   r   r   )ri   ry   rp   rc  r5   r5   r6   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 s0    Y  | jjj	}| 
|j||dg|||f g| j d S )NrD   ra  rY   r  )r   r   rH   r   r   r  r   rf  r   rY   _check_listrg  r   rF   rd  fail_ifr  )ri   ry   r  rE   r   r  rp   r  Z
users_consZ	addr_consZexp_colsr  r5   r5   r6   r     s*    
,
z.ComponentReflectionTest.test_get_pk_constraintc                 C   s~  |rt j}nd }| jj| jj }}t|}|}tjjj	r|j
|j|d}|d }	tjj  t|	d d W d    n1 s0    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 s0    Y  t|	d | t|	d |j t|	d dg t|	d	 dg | jjj}t|j
||dg  d S )NrD   r   rY   r   rl  rm  rk  r   ra  r   r  )r   rH   r   r   r  r   r   rF   r&  r/   r   rY   rr  r  r   implicitly_named_constraintsr'   r  )ri   ry   r  rE   r   r  rp   Zexpected_schemaZusers_fkeysfkey1Z
addr_fkeysr  r5   r5   r6   r     s2    
,0
z-ComponentReflectionTest.test_get_foreign_keysc           
      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   rl  rm  rk  r>   ra  r  rD   r  )r   rf   r)  r   r   rH   r   r   rY   r   r  r'   )
ri   ry   r  r  r  rp   Zlocal_fkeysr  Zremote_fkeysZfkey2r5   r5   r6   "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   rD   )
r   rH   r   r   r  r  r  r   r  rY   )ri   ry   r  rE   rp   indexesr  r  r5   r5   r6   r     s    

z(ComponentReflectionTest.test_get_indexes)r!  r$  )r#  r%  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  r  r
   rb  r  rY   )ri   ry   tnameZixnamerp   r  Zexpected_indexesr  r5   r5   r6   test_get_noncol_index1  s    	
z-ComponentReflectionTest.test_get_noncol_indexc                 C   sB   t |}|  }||}| jddd |f }| ||| j d S )NT)r  )r   rX   r   r  r  r  )ri   ry   rp   rY   	reflectedr  r5   r5   r6   &test_get_temp_table_unique_constraintsG  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rVg |d d< tdd	 |D | d S )
Nry  Fr   r0  )r  rx  rY   r   rz  c                 S   s   g | ]}|d  dkr|qS )rY   r0  r5   rC  r   r5   r5   r6   r~  ]  r   zGComponentReflectionTest.test_get_temp_table_indexes.<locals>.<listcomp>)	r   rX   r   rY  r   rF   index_reflects_included_columnsr/   r   )ri   ry   rp   rb   r  indexpectedr5   r5   r6   test_get_temp_table_indexesP  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 ]B\}}|dd }|rP|
| t|dd d  t|| q,t }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 )NZunique_ar   )rY   rx  Zunique_a_b_c)r   br   Zunique_c_a_b)r   r   r  Zunique_asc_keyascr   zi.have.dotsr  zi have spacesr   rY   r   Ztesttblr
  r  rD   rx  r  r   )r   rE   c                 S   s   h | ]
}|j qS r5   r   r  r5   r5   r6   	<setcomp>  r   zFComponentReflectionTest.test_get_unique_constraints.<locals>.<setcomp>c                 S   s   h | ]}t |tjr|jqS r5   )r   r\   r   rY   )rC  Zuqr5   r5   r6   r    s   )r   rH   r  operator
itemgetterr   r   r\   r   r   Zappend_constraintr   rm   r   r   r6  r   r  r  rY  rH  r   r  constraints
differencer  r   r  rY   )ri   rN   ry   r  rE   Zuniquesr  r  rp   r  Znames_that_duplicate_indexr  ZreflZdupeZreflected_metadataZ	idx_namesZuq_namesr  r5   r5   r6   r   a  sx    







z3ComponentReflectionTest.test_get_unique_constraintsc                 C   s@   |rt j}nd }t|}dD ]}|j||d}tt| qd S )Nr  rD   )r   rH   r   r   r'   bool)ri   ry   r  rE   rp   viewrD  r5   r5   r6   r     s    z0ComponentReflectionTest.test_get_view_definitionc                 C   sp   t |}tt |d W d    n1 s00    Y  tt |d W d    n1 sb0    Y  d S )NZview_does_not_existr   )r   r   r   r   rx   r5   r5   r6   'test_get_view_definition_does_not_exist  s
    
(
z?ComponentReflectionTest.test_get_view_definition_does_not_existc                 C   sF   t |}dD ]4\}}||}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  r   )r   r   c                 S   s   i | ]}|d  |qS r   r5   r|  r5   r5   r6   rG    r   zBComponentReflectionTest.test_autoincrement_col.<locals>.<dictcomp>rU  TN)r   r   get)ri   ry   rp   r  cnamerc  Zid_r5   r5   r6   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 n6tt |jd|d}W d    n1 s0    Y  d S )Nr   rD   r  )r   r   r3   rH   r   rF   r   r/   r   r'   r   r2   r   r   )ri   r  rp   rE   r   r5   r5   r6   r     s    


z.ComponentReflectionTest.test_get_table_optionsc                    s   t tj tjjjrV|rtjnd  jd} fdd j	dD }t
|| n0tt   }W d    n1 s|0    Y  d S )NrD   c                    s    i | ]}|f j |d qS )rD   )r   )rC  r  rp   rE   r5   r6   rG    s   zHComponentReflectionTest.test_multi_get_table_options.<locals>.<dictcomp>)r   r   r3   r   rF   r   r/   rH   get_multi_table_optionsr  r   r   r   )ri   r  r   r  r5   r  r6   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 rB|g d tj|v rZ|ddg tj|v rr|ddg | r~| |d< |r||d< || |||dd	}	|g}
|tjkr|	 }|
d
 |
| |tjkr|	 }|
d |
| t  |
|	fS )Nr  )r,   r   )r  r   does-not-existrN  r  rM  rE   r   )rE   r,   r   r   r,   r   )r   r   r   r  r   r   r  r   r   copyrY  append)rE   r,   r   r   Zsingle_reflect_fnZ
exp_methodrp   ra   r   r  kwsZnkwry   r5   r6   provide_fixture  sD    










z>ComponentReflectionTest.get_multi_exp.<locals>.provide_fixturer5   )ri   ry   r  r5   r  r6   get_multi_exp  s    .z%ComponentReflectionTest.get_multi_expc                 C   sL   |||||t j| j\}}}|D ]&}	|  |jf i |	}
t|
| q d S r{   )r   r   rQ  rn   r  r   ri   r  rE   r,   r   r   rp   r  r  ra   resultr5   r5   r6   #test_multi_get_table_options_tables=  s    
z;ComponentReflectionTest.test_multi_get_table_options_tablesc           
      C   sH   |||||t j| j\}}}|D ]"}	|  t|jf i |	| q d S r{   )r   r   rT  rn   r   Zget_multi_table_comment)
ri   r  rE   r,   r   r   rp   r  r  ra   r5   r5   r6   test_get_multi_table_commentO  s    
z4ComponentReflectionTest.test_get_multi_table_commentc                    sV   t ddd t|tr8t fdd| D || nt fdd|D || d S )NrR  c                 S   s   t dd|  S )Nz['\" ]r   )resubr  r  r5   r5   r6   _cleana  s    z:ComponentReflectionTest._check_expressions.<locals>._cleanc                    s   i | ]\}} ||qS r5   r5   )rC  erD  r  r5   r6   rG  e  r   z>ComponentReflectionTest._check_expressions.<locals>.<dictcomp>c                    s   g | ]} |qS r5   r5   )rC  r  r  r5   r6   r~  g  r   z>ComponentReflectionTest._check_expressions.<locals>.<listcomp>)r  r   r2   r   rJ  )ri   r  r  err_msgr5   r  r6   _check_expressions`  s    
 z*ComponentReflectionTest._check_expressionsc           	      C   s   |d u rt ||| nt t|t|| t||D ]~\}}t|t|B D ]d}||v sh||v rL||v rL| d| d| }|dv r| || || | qLt || || | qLq4d S )Nz - )r{  rv  )r   r  r  r6  r  )	ri   r  r  req_keysmsgrr  r   r   r5   r5   r6   r  i  s    z#ComponentReflectionTest._check_listc                 C   s\   t t| t|  |D ]8}|| ||  }}|rF|g|g }}| |||| qd S r{   )r   r6  keysr  )ri   r  r  r  
make_listsr   r  r  r5   r5   r6   _check_table_dictw  s    z)ComponentReflectionTest._check_table_dictc                 C   sR   |||||t j| j\}}}|D ],}	|  |jf i |	}
| |
|| j q d S r{   )r   r   r^  rn   get_multi_columnsr  r`  r  r5   r5   r6   test_get_multi_columns  s    
	z.ComponentReflectionTest.test_get_multi_columnsc                 C   sV   |||||t j| j\}}}|D ]0}	|  |jf i |	}
| j|
|| jdd q d S )NT)r  )r   r   rf  rn   Zget_multi_pk_constraintr  rg  r  r5   r5   r6   test_get_multi_pk_constraint  s    

z4ComponentReflectionTest.test_get_multi_pk_constraintc                 C   sT   t jjjsP||fD ]<}| D ].}t|dkrtdd |D r|j|d qqd S )Nr   c                 s   s"   | ]}| d dtjfv V  qdS )rY   N)r  r(   r   )rC  rD  r5   r5   r6   	<genexpr>  s   z7ComponentReflectionTest._adjust_sort.<locals>.<genexpr>r  )r   rF   r  r/   rK  r  anysort)ri   r  r  r   objre  r5   r5   r6   _adjust_sort  s    
z$ComponentReflectionTest._adjust_sortc                 C   sd   |||||t j| j\}}}|D ]>}	|  |jf i |	}
| |
|dd  | |
|| j q d S )Nc                 S   s   t | d S )Nra  tupledr5   r5   r6   r     r   zEComponentReflectionTest.test_get_multi_foreign_keys.<locals>.<lambda>)r   r   rt  rn   Zget_multi_foreign_keysr  r  ru  r  r5   r5   r6   test_get_multi_foreign_keys  s    

z3ComponentReflectionTest.test_get_multi_foreign_keysc                 C   sR   |||||t j| j\}}}|D ],}	|  |jf i |	}
| |
|| j q d S r{   )r   r   r  rn   Zget_multi_indexesr  r  r  r5   r5   r6   test_get_multi_indexes  s    
z.ComponentReflectionTest.test_get_multi_indexesc                 C   sd   |||||t j| j\}}}|D ]>}	|  |jf i |	}
| |
|dd  | |
|| j q d S )Nc                 S   s   t | d S )Nrx  r  r  r5   r5   r6   r     r   zKComponentReflectionTest.test_get_multi_unique_constraints.<locals>.<lambda>)r   r   r  rn   Zget_multi_unique_constraintsr  r  r  r  r5   r5   r6   !test_get_multi_unique_constraints  s    
z9ComponentReflectionTest.test_get_multi_unique_constraintsc                 C   sd   |||||t j| j\}}}|D ]>}	|  |jf i |	}
| |
|dd  | |
|| j q d S )Nc                 S   s   t | d S Nr  r  r  r5   r5   r6   r     r   zJComponentReflectionTest.test_get_multi_check_constraints.<locals>.<lambda>)r   r   r  rn   Zget_multi_check_constraintsr  r  r  r  r5   r5   r6    test_get_multi_check_constraints  s    
z8ComponentReflectionTest.test_get_multi_check_constraintsr   r   r   r   r   r   r   r   methodc                 C   sF   t |}t||}tt |d W d    n1 s80    Y  d S )NZtable_does_not_exists)r   getattrr   r   )ri   r  ry   rp   r   r5   r5   r6   test_not_existing_table  s    

z/ComponentReflectionTest.test_not_existing_tablec              	      s   t j  fdd}tjt d|R ttd( t|t	dt
 d  W d    n1 s\0    Y  W d    n1 sz0    Y  d S )Nc                     s&   | di }td|d<  | i |S )NZunreflectableerr)N
some_table)
setdefaultr   )r   r   urZmcr5   r6   patched	  s    z;ComponentReflectionTest.test_unreflectable.<locals>.patchedr  r  r  )r   r  r(   patchobjectr   r   r   Zreflect_tabler   r   )ri   ry   r!  r5   r   r6   test_unreflectable	  s    z*ComponentReflectionTest.test_unreflectabler   c                    s   t  }|rtjnd  |j| |dd t|}| }|rp|| 7 }z|| 7 }W n tyn   Y n0  r fdd|D }t	t
|jt
| d S )NF)rE   r   Zresolve_fksc                    s   g | ]}  d | qS )r   r5   r  rD   r5   r6   r~  8	  r   z9ComponentReflectionTest.test_metadata.<locals>.<listcomp>)r   r   rH   reflectr   r  r  r  r   r   r  r   )ri   ry   r  r   mrp   r   r5   rD   r6   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   試蛇ẟΩ✨rR  c                 S   s   i | ]}|d  |d qS r   r5   r|  r5   r5   r6   rG  L	  r   zAComponentReflectionTest.test_comments_unicode.<locals>.<dictcomp>)r)  r*  r   r   r   r   r   r   r   r   )ri   ry   rN   rp   tcrc  valuer  r5   r5   r6   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&   🎩🁰🝑🤷‍♀️🤷‍♂️rR  r   rY   r   r+  )ri   ry   rN   rp   r,  r   r5   r5   r6   test_comments_unicode_fullP	  s    

z2ComponentReflectionTest.test_comments_unicode_full)N)NN)NF)mr8   r9   r:   run_insertsrun_deletesr   r;   rO   r   rX   rL   rJ   r<  r>  rL  r   r   r   rQ  rT  r^  propertyr`  rf  rg  rt  ru  r  r  r  r  r  r  r   rF   Zschema_reflectionr  r  r  r  Zschema_create_deleter  r  r  r   !foreign_key_constraint_reflectionrG   r  r  rI  r  rI   r_   r  r   r  r  r  r   r.  r  r  r   r  !primary_key_constraint_reflectionr   r   r(  r  r*  r   r+  r,  r  r   r  Ztemp_table_reflect_indexesr  r   r   r  table_reflectionr  r   r  fixturer  r   r   r  r  r  r  r  r	  r
  r  r  r  r  r   r  r  r$  r   r'  r.  Zcomment_reflection_full_unicoder/  r5   r5   r5   r6   r     s  

 .

!

-
!
&
`

0

X

u

E

:







#




A


&$
V





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)Zreflect_tables_no_columnsTc                 C   s   t d| || d S NrS  )r   r   ri   ry   rN   r5   r5   r6   table_no_columnsf	  s    
z#TableNoColumnsTest.table_no_columnsc                 C   s<   t d| t|dtd t|dtd || d S )NrS  rP   z*CREATE VIEW empty_v AS SELECT * FROM emptyrQ   zDROP VIEW IF EXISTS empty_v)r   r   rR   r    r   r9  r5   r5   r6   view_no_columnsk	  s    

z"TableNoColumnsTest.view_no_columnsc                 C   s$   t dt |d}tt|jg  d S )NrS  r   r   r   r   rb  r   )ri   ry   r:  t2r5   r5   r6   test_reflect_table_no_columns{	  s    z0TableNoColumnsTest.test_reflect_table_no_columnsc                 C   s2   t |}t|dg  | }t|dg i d S )NrS  r8  )r   r   r   r  )ri   ry   r:  rp   multir5   r5   r6   !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 r8  )r   r%  r6  r   r  )ri   ry   r:  r&  r5   r5   r6   "test_reflect_incl_table_no_columns	  s    
z5TableNoColumnsTest.test_reflect_incl_table_no_columnsc                 C   s$   t dt |d}tt|jg  d S )Nempty_vr   r<  )ri   ry   r;  r=  r5   r5   r6   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 )NrB  )r   )NrB  )r   r   r   r  r   r   )ri   ry   r;  rp   r?  r5   r5   r6    test_get_columns_view_no_columns	  s    z3TableNoColumnsTest.test_get_columns_view_no_columnsN)r8   r9   r:   __requires__r   r   r6  r:  r;  r>  r@  rA  rF   r   rC  rD  r5   r5   r5   r6   r7  b	  s   


r7  c                
   @   sd  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dd Zej	jdd  Zej	j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dS ),ComponentReflectionTestExtraTF)paramsc                 C   s   |j rtjS d S d S r{   )paramr   rH   )ri   requestr5   r5   r6   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   ry   rN   rJ  r5   r6   go	  s    z:ComponentReflectionTestExtra.inspect_for_table.<locals>.go)
contextlibcontextmanager)ri   rN   ry   rJ  rL  r5   rK  r6   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  r5   r5   r6   	normalize	  s    z5ComponentReflectionTestExtra.ck_eq.<locals>.normalizec                    s"   g | ]}|d   |d dqS )rY   r  rY   r  r5   )rC  itemrT  r5   r6   r~  	  s   z6ComponentReflectionTestExtra.ck_eq.<locals>.<listcomp>c                 S   s   | d S r  r5   rV  r5   r5   r6   r   	  r   z4ComponentReflectionTestExtra.ck_eq.<locals>.<lambda>r  c                 S   s   | d S r  r5   rX  r5   r5   r6   r   	  r   )r  r   )ri   r  r  r5   rW  r6   ck_eq	  s    
z"ComponentReflectionTestExtra.ck_eqc              	   C   sb   |d0\}}t d|tdtd|d W d    n1 s>0    Y  | |jd|dg  d S )Nr  rA   r
  rD   )r   r   r\   r   rY  r   )ri   rN   rO  rE   r   r5   r5   r6   #test_check_constraint_no_constraint	  s    $z@ComponentReflectionTestExtra.test_check_constraint_no_constraint	my_inlineZMyInlineNconstraint_namer   c                 C   s   |dR\}}t d|tdt ddtdt tjd|dtdtd	|d
 W d    n1 s`0    Y  |jd|d
}| ||ptj	ddg d S )Nsa_ccr>   Tr?   r   a > 1 AND a < 5r   rA   rB   rD   a > 1 and a < 5rU  )
r   r   r   r\   r   r   r   rY  r(   r   ri   rN   rO  r\  rE   r   r  r5   r5   r6   test_check_constraint_inline	  s.    $z9ComponentReflectionTestExtra.test_check_constraint_inlineZmy_ck_constZ	MyCkConstc              	   C   s|   |d8\}}t d|tdt tjd|d|d W d    n1 sF0    Y  |jd|d}| ||pltjddg d S )Nr]  r   za = 1 OR (a > 2 AND a < 5)r   rD   za = 1 or a > 2 and a < 5rU  )	r   r   r   r\   r   r   rY  r(   r   r`  r5   r5   r6    test_check_constraint_standalone	  s$    
$
z=ComponentReflectionTestExtra.test_check_constraint_standalonec                 C   s   |d\}}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 s0    Y  |jd|d}| |dddd	ddt	j
ddg d S )Nr]  r>   Tr?   r   r^  r  zb > 1 AND b < 5r[  r   r   rA   rB   Zsome_uqzc > 1 AND c < 5Zcc1Z	some_c_uqrD   zc > 1 and c < 5rU  zb > 1 and b < 5r_  )r   r   r   r\   r   r   r   r   rY  r(   r   )ri   rN   rO  rE   r   r  r5   r5   r6   test_check_constraint_mixed
  s4    
$
z8ComponentReflectionTestExtra.test_check_constraint_mixedc              	      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rrdg d|dd|dgd
d}	||	 |d|	 dd g|d dgd
d}
||
 ||
 t|d| t }t d| d}nNtd4 t|d| t }t d| d}W d    n1 s0    Y  | || jj d S )Nr  xr  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 Z
t_idx_longZt_idx_2F)rY   rx  r  ry  c                    s:   t jjjr*g | d<  jj dg i| d< n| di  d S )Nrz  Z_includery  )r   rF   r  r/   r  rY   r  )entryr  r5   r6   completeIndexO
  s
    

zYComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.completeIndexr   c                   @   s   e Zd Zdd ZdS )z[ComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.lower_index_strc                 S   s    |  }d|v od|v pd|v S )Nr  rd  re  r  )ri   r   olr5   r5   r6   ri  [
  s    zbComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.lower_index_str.__eq__Nrj  r5   r5   r5   r6   lower_index_strZ
  s   rl  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coalescerj  rh  long_strr5   r6   ri  a
  s    zeComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.coalesce_index_str.__eq__Nrj  r5   rn  r5   r6   coalesce_index_str`
  s   rp  )Nrf  Nzlower(x)zlower(y))rY   rx  r{  r  zcoalesce(x, 'z')r   z>Skipped unsupported reflection of expression-based index t_idx)r   r   r   r!   r   r  r   rd  rf  re  rm  r   r   r  r   rF   Z reflect_indexes_with_expressionsr/   insertr  r   r   r   r   Z!compare_table_index_with_expectedr  rY   )ri   rN   ry   r  rp   r  ri  rl  rp  Z
expr_indexZexpr_index_longr   r=  r5   )ry   ro  r6   %test_reflect_expression_based_indexes3
  sl    &
		

.
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  rd  r  re  rg  includeF)rY   rx  rz  r  ry  r   ry  z
%s_includer   )r   r   r   r!   r   rd  ry  r  rY   r   r   r   r   r(   r   r   rb  r  )ri   rN   ry   r  r   rp   r   r=  r5   r5   r6   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   )rC  r  type_r5   r5   r6   r~  
  r   zAComponentReflectionTestExtra._type_round_trip.<locals>.<listcomp>c                 S   s   g | ]}|d  qS )rV  r5   r|  r5   r5   r6   r~  
  r   )r   r  rm   r   r   )ri   ry   rN   r   r  r5   r5   r6   _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   )rv  r  r  r   r   	precisionscaleri   ry   rN   typr5   r5   r6   test_numeric_reflection
  s    z4ComponentReflectionTestExtra.test_numeric_reflectionc                 C   s8   |  ||tdd }t|tjs(J t|jd d S )N4   r   )rv  r  r   r   r   lengthrz  r5   r5   r6   test_varchar_reflection
  s    z4ComponentReflectionTestExtra.test_varchar_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   r  Fc                 S   s   i | ]}|d  |d qS )rY   r   r5   r  r5   r5   r6   rG  
  s   zIComponentReflectionTestExtra.test_nullable_reflection.<locals>.<dictcomp>)r   r  )r   r   r   rm   r   r   r   )ri   ry   rN   r  r5   r5   r6   test_nullable_reflection
  s    
z5ComponentReflectionTestExtra.test_nullable_reflectionZCASCADEzSET NULLz	NO ACTIONZ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onupdaterd  r>   Tr?   r   r  Zx_idzx.idxidr   test
   userrY   rB   Fr   tidztable.idZmyfkr   r-   c                    s   i | ]} | r| | qS r5   r5   )rC  r   optsr5   r6   rG  <  r   zMComponentReflectionTestExtra.test_get_foreign_key_options.<locals>.<dictcomp>)r   r   r   r   r   r\   r   r   r   r   r   )ri   ry   rN   r  r  r  r-   rp   r5   r  r6   test_get_foreign_key_options
  sT    *	
z9ComponentReflectionTestExtra.test_get_foreign_key_options) r8   r9   r:   r   r   r6  rJ  rO  rY  rF   r   rZ  Z"inline_check_constraint_reflectionr   ra  rb  rc  Zindexes_with_expressionsrr  r  rt  rv  r5  r|  r  r  Z1foreign_key_constraint_option_reflection_ondeleteZ1foreign_key_constraint_option_reflection_onupdateZ1fk_constraint_option_reflection_ondelete_noactionZ1fk_constraint_option_reflection_onupdate_restrictZ1fk_constraint_option_reflection_ondelete_restrictr  r5   r5   r5   r6   rF  	  s   

	
 

Z
*



'rF  c                   @   s0   e Zd ZdZdZedd Zdd Zdd Zd	S )
NormalizedNameTest)Z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   r>   r?   r=  t1idzt1.id)r   r"   r   r   r   rM   r5   r5   r6   rO   G  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	szJ d S )	Nr=  Tr  r   r   c                 S   s   |   dv S )Nr   r=  rj  )rY   r&  r5   r5   r6   r   _  r   zINormalizedNameTest.test_reflect_lowercase_forced_tables.<locals>.<lambda>)only)r   r   r"   r   r3   r   r   r  r   r>   r%  )ri   r   Zt2_refZt1_refZm3r5   r5   r6   $test_reflect_lowercase_forced_tablesU  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 )r  rj  r  r5   r5   r6   r~  d  s   z;NormalizedNameTest.test_get_table_names.<locals>.<listcomp>r   r   )r   r   r3   r  r   upperr  )ri   Z
tablenamesr5   r5   r6   r  c  s
    z'NormalizedNameTest.test_get_table_namesN)	r8   r9   r:   rE  r   r;   rO   r  r  r5   r5   r5   r6   r  C  s   
r  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   s   i | ]}|d  |qS r   r5   r|  r5   r5   r6   rG  s  r   zLComputedReflectionTest.test_computed_col_default_not_set.<locals>.<dictcomp>Z42with_defaultrW  normalcomputed_col)r   r   r3   r   r'   r
   )ri   rp   rc  Zcol_datar5   r5   r6   !test_computed_col_default_not_seto  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
rt|d d	 tjjj
 d S )
Nr  c                 S   s   i | ]}|d  |qS r   r5   r|  r5   r5   r6   rG  |  r   zKComputedReflectionTest.test_get_column_returns_computed.<locals>.<dictcomp>)r>   r  r  computedr  r  	normal+42	persisted)r   r   r3   r   r'   r   rT  r   rF   "computed_columns_reflect_persistedr/   "computed_columns_default_persisted)ri   rp   rc  rA   r   compDatar5   r5   r6    test_get_column_returns_computedx  s$    




z7ComputedReflectionTest.test_get_column_returns_computedc                 C   sX   t d|| v  || d }t| |d | tjjjrTt d|v  t|d | d S )Nr  r  r  )r'   r   rT  r   rF   r  r/   r
   )ri   rA   columnr  r  r  r5   r5   r6   check_column  s    
z#ComputedReflectionTest.check_columnc                 C   sp   t tj}|d}dd |D }| |ddtjjj tjj	jrR| |ddd tjj
jrl| |d	d
d d S )Ncomputed_column_tablec                 S   s   i | ]}|d  |qS r   r5   r|  r5   r5   r6   rG    r   zLComputedReflectionTest.test_get_column_returns_persisted.<locals>.<dictcomp>computed_no_flagr  computed_virtualznormal+2Fcomputed_storedz	normal-42T)r   r   r3   r   r  r   rF   r  r/   computed_columns_virtualcomputed_columns_storedri   rp   rc  rA   r5   r5   r6   !test_get_column_returns_persisted  s.    



z8ComputedReflectionTest.test_get_column_returns_persistedc                 C   sv   t tj}|jdtjd}dd |D }| |ddtjjj	 tjj
j	rX| |ddd	 tjjj	rr| |d
dd d S )Nr  rD   c                 S   s   i | ]}|d  |qS r   r5   r|  r5   r5   r6   rG    r   zXComputedReflectionTest.test_get_column_returns_persisted_with_schema.<locals>.<dictcomp>r  z	normal/42r  znormal/2Fr  z	normal*42T)r   r   r3   r   rH   r  r   rF   r  r/   r  r  r  r5   r5   r6   -test_get_column_returns_persisted_with_schema  s2    


zDComputedReflectionTest.test_get_column_returns_persisted_with_schemaN)r8   r9   r:   r  r  r  r  r   rF   rG   r  r5   r5   r5   r6   r  n  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)Zidentity_columnsr5  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rxt d|tdttdttdddtj	d d S )Nr   r  id1r=  r   Tr   r   r     alwaysstart	incrementminvaluemaxvaluecyclecacher
  )r  r  rD   )
r   r   r   r   r   rF   rG   r/   r   rH   rM   r5   r5   r6   rO     s>    
z$IdentityReflectionTest.define_tablesc                 C   s   t jjjrd}t|D ]}||vr|| q|rtt|t| |D ]T}|dkrjt|| || k qH|dv rt|| || k qHt|| || | qHqt|| n$t|d |d  t|d |d  d S )Nr  r  >   r  r  r  r  )	r   rF   Zidentity_columns_standardr/   rb  rY  r   r  r'   )ri   r-  r  approxZcommon_keysr   r5   r5   r6   check  s     
	zIdentityReflectionTest.checkc                 C   s  t tj}|d|d }|D ]}|d dkr@td|v  q"|d dkrd|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 dkr"d|v rt|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=  rY   r  identityr  rU  rW  Fr   r  Tr  r   r   r   r  r  r  )	r   r   r3   r   r&   r'   r   r  r2   ri   rp   rc  rl   r5   r5   r6   test_reflect_identity  sR    
		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rd|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   rD   rY   r  r  r  rU  rW  Tr
  r   r  Fr  r  )
r   r   r3   r   rH   r&   r'   r   r  r2   r  r5   r5   r6   test_reflect_identity_schema@  s.    
	z3IdentityReflectionTest.test_reflect_identity_schema)r8   r9   r:   r0  r1  r   rE  r;   rO   r  r  r   rF   rG   r  r5   r5   r5   r6   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tb1r>   attrrY   r
  Zpk_tb1r   Tr   tb2r?   pidpattrpnamer  r  r  Zfk_tb1_name_id_attr)r   r   r   r  r^   r\   r   r   r   rY   r>   r  )r4   rN   r  r5   r5   r6   rO   _  s2    
z(CompositeKeyReflectionTest.define_tablesc                 C   s0   t |}|| jjj}t|dg d d S )Nra  rY   r>   r  )r   r   r   r  rY   r   r  )ri   ry   rp   r@   r5   r5   r6   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   rk  r  ra  r  )r   r   r   r  rY   r   r  r  )ri   ry   rp   Zforeign_keysr  r5   r5   r6   test_fk_column_order  s    z/CompositeKeyReflectionTest.test_fk_column_orderN)r8   r9   r:   r   r;   rO   r   rF   r4  r  r3  r  r5   r5   r5   r6   r  \  s   

r  )r   rF  r7  r   r   r<   r   r  r  r  r  )DrM  r  r  r0   r\   r   r   r   r   r   r   r   r	   r
   Z	provisionr   r   rE   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r   r   excr   r   r    r!   Zsql.elementsr"   Z
sql.schemar#   r$   r%   r&   r'   r(   rN   r   Z
TablesTestr)   r<   r   ZTestBaser   r   r   r   r7  rF  r  ZComputedReflectionFixtureTestr  r  r  __all__r5   r5   r5   r6   <module>	   s    L;               Y5   /+a 1