U
    ovgP                    @   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   L/tmp/pip-unpacked-wheel-uqd9otp_/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|}t	j
jjr|t	j
jjr|t|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   sV   t j B}tt jj|d tt jj|d tt jj|d W 5 Q R X 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 z(t|d |  t|d W 5 |
tj X d S )Nr=   Z	new_tablecol)r   r   r3   r'   rg   r   r   r   r&   createdropclear_cache)ri   rN   inspntr5   r5   r6   test_has_table_cache   s    
z!HasTableTest.test_has_table_cachec              	   C   sh   t j T}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 5 Q R X 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   s2   t j }tt jjj|ddd W 5 Q R X 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 f| |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t|ddr(t|ddr6t|ddrDt|ddrRt|ddr`ttd| jjjj}td|td	t	tdd	}|
| |
| zV|d
kr|ddrt|ddrt|j  |dddkst|dddkstW 5 || || X d S )Nr=   r   r   rd   Znonexistent_idxZmy_idx_2Ztest_table_2Zmy_idx_3foor   T)r   AssertionErrorr!   tablesr=   r   r   r   r   r   rm   rn   __self__ro   )ri   r   ry   rN   methidxZtblr5   r5   r6   test_has_index   s2    



zHasIndexTest.test_has_indexc                 C   s`   |  ||}|ddtjds t|ddtjdr4t|ddtjdrHt|ddtjdr\td S )Nr=   r   rD   r   rd   Znonexistent_idx_s)r   r   rH   r   )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 st|r|jj|	jd std S )Nr>   T)keyr@   test_needs_fkid2r?   otherrefref2autoload_withr      )r   r   r   Zappend_columnr\   ForeignKeyConstraintr   r>   r   r   
create_allr   r   r   
referencesr   r   )
ri   ry   rN   r   r   r   r   m2Z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   sP   t tj}tjjjr.||}tt	|t
 ntt ||}W 5 Q R X 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td S )Nr   )r   r   r3   get_view_definitionr   ri   rY   rp   r5   r5   r6   test_get_view_definition  s    
z/QuotedNameArgumentTest.test_get_view_definitionc                 C   s   t tj}||std S r{   )r   r   r3   get_columnsr   r   r5   r5   r6   test_get_columns  s    
z'QuotedNameArgumentTest.test_get_columnsc                 C   s   t tj}||std S r{   )r   r   r3   get_pk_constraintr   r   r5   r5   r6   test_get_pk_constraint  s    
z-QuotedNameArgumentTest.test_get_pk_constraintc                 C   s   t tj}||std S r{   )r   r   r3   get_foreign_keysr   r   r5   r5   r6   test_get_foreign_keys  s    
z,QuotedNameArgumentTest.test_get_foreign_keysc                 C   s   t tj}||std S r{   )r   r   r3   get_indexesr   r   r5   r5   r6   test_get_indexes  s    
z'QuotedNameArgumentTest.test_get_indexesc                 C   s   t tj}||std S r{   )r   r   r3   get_unique_constraintsr   r   r5   r5   r6   test_get_unique_constraints  s    
z2QuotedNameArgumentTest.test_get_unique_constraintsc                 C   s   t tj}||std S r{   )r   r   r3   get_table_commentr   r   r5   r5   r6   test_get_table_comment  s    
z-QuotedNameArgumentTest.test_get_table_commentc                 C   s   t tj}||std S r{   )r   r   r3   get_check_constraintsr   r   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f| 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 kr4t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rhtdC|jj|jjd	d  tdD|jj|jj|jj |shtdE|tdFtdd	dG}tdH|td-tjd	d
tdFtdd	dG}t jjjrht jjjrht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CHARZ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   "  sJ   

 	
 
  

	   	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|}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 }||krJdnd}d| d| d	| }t|d
t| ||krd}	|rt dr| d|	 }	d|	 d| d}
t|d
t|
 t|dtd| d|  qd S )Nr   )r   r  r   r   Z_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|kr|| t j|kr,|| t j|kr@|| |S r{   )r   r   updater   r   )ri   r   r   r   r3  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/   clearr0  r6  )ri   r   r3  r5   r5   r6   _resolve_views  s    



z&ComponentReflectionTest._resolve_viewsc              	      s   dd |t jkrdd |t jk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 kS Ntmpr   r5   r   r5   r5   r6   r   (  r   c                 S   s   d| d kS r;  r5   r=  r5   r5   r6   r   *  r   r  r  r  r  r!  r~   c                    s>   i | ]6\}}|r|d   kr r4|d   k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/   addr6  r'  r+  temp_table_namesr_   items)ri   rE   r,   r   valuesr   r5   r@  r6   _resolve_names%  sF    

 



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   r9  rX   r7  rG  )	ri   rE   r,   r   r   r3  r   r   r   r5   r5   r6   exp_optionsP  sF                 
 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textrH  rI  rJ  r~   r   r   r  r  r  r  r  r  r  r  r  r!  )r9  rX   r7  rG  )
ri   rE   r,   r   r   emptyr3  r   r   r   r5   r5   r6   exp_commentso  sP                 
 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   omitrP  )r(   r   pop)rY   autorR  r   r   r   r5   r5   r6   rl     s    
z0ComponentReflectionTest.exp_columns.<locals>.colc                    s   dt jdd|} | f|S )NTF)rU  rR  r   r(   r   )rY   ra   rl   r5   r6   pk  s    z/ComponentReflectionTest.exp_columns.<locals>.pkrH  r   rS  )rU  r   r   r   rA   rI  r  r  rJ  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!  rK  )
ri   rE   r,   r   r   rX  r3  r   r   r   r5   rW  r6   exp_columns  s       
	




	      
'z#ComponentReflectionTest.exp_columnsc                 C   s   ddddhS )NrY   rQ  r   rR  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 k	r
t j|
d< q
| 
||	||}| ||||}|S )Nr   c                 W   s   t || |dS )N)constrained_columnsrY   r   )list)rY   r   colsr5   r5   r6   rX    s    z+ComponentReflectionTest.exp_pks.<locals>.pkr   rH  r   rI  rJ  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/   r9  rX   reflects_pk_namesrF  r7  rG  )ri   rE   r,   r   r   rX  rN  r3  r   r   valr   r5   r5   r6   exp_pks  s^    

               
 zComponentReflectionTest.exp_pksc                 C   s   ddhS )NrY   r\  r5   rZ  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k	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 k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:   rd  r5   r5   r5   r6   r   2  s   r   c                    s$   | ||t j|d k	r|n  ||dS )N)r\  referred_columnsrY   r-   referred_schemareferred_tabler   rV  )r^  Zref_colZ	ref_table
ref_schemarY   r   r   r5   r6   fk9  s    	z+ComponentReflectionTest.exp_fks.<locals>.fkrH  rI  rJ  r~   r   r   r   r   r   r   r   r   r  r   r   r   r  r  r  r  r  r>   r  )ri  r  r  r  r!  rY   )r(   r   r9  r   rH   rX   r   rF   r$  r/   r8  named_constraintsrF  r7  rG  )ri   rE   r,   r   r   rk  r3  r   r   valsr`  r   r5   rj  r6   exp_fks+  s       
     
 #zComponentReflectionTest.exp_fksc                 C   s   dddddhS )NrY   r\  rg  rh  rf  r5   rZ  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|dddd|ddddd|ddddd|df|d	tjddd|dtjdd|dddddd|df|dtjd|dtjdd|d fg |d!fg |d"f|d#tjdd|d$f|d%tjdd|d&fg |d'f|d(d)d(d*id+|d,f|d(d-d(d*id+||  f|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
duplicatesrk  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_columnsrp  rr  expressionsc                    s   g | ]}| krd n|qS r{   r5   r>  r   rp  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/   r]  r(   r   )rY   r  rp  rq  rk  r^  Zfk_reqZdup_reqZsorting_expressionr   origr5   rw  r6   r     s4    


z0ComponentReflectionTest.exp_indexes.<locals>.idxrH  rI  rJ  r~   rA   r.  r   r   r   r   T)rY   rk  r   r   r   r  r  )rY   r  r   )rY   r  rq  r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r   r"  )r*  )rY   rp  r!  r#  r   r-  rY   r,  )rY   rq  r  )r9  extendr(   r   rX   r   rV   r   rF   r(  r/   r)  r8  r7  rG  )
ri   rE   r,   r   r   r   r3  r   r   r   r5   r5   r6   exp_indexes  s    
%   
     


5z#ComponentReflectionTest.exp_indexesc                 C   s
   dddhS )NrY   rr  r  r5   rZ  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|d
ddddd|df|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|dd tj d!i}	|r|||	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   )rr  rY   r   r}  )r   rF   Z*unique_index_reflect_as_unique_constraintsr/   r]  )rY   r}  r~  r   r^  reqr   r5   r5   r6   uc  s    
z+ComponentReflectionTest.exp_ucs.<locals>.ucrH  rI  rJ  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   )r9  r(   r   rX   r   rV   r7  rG  )ri   rE   r,   r   r   all_r  r3  r   r   r   r5   r5   r6   exp_ucs  sr    	     	
        
 
zComponentReflectionTest.exp_ucsc                 C   s   ddhS )NrY   rr  r5   rZ  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}| |kS )N(r   )`)lowerreplace)ri   r   r   r5   r5   r6   rd  W  s       z2ComponentReflectionTest.exp_ccs.<locals>.tt.__eq__Nre  r5   r5   r5   r6   r   V  s   r   c                    s    | ||dS )N)sqltextrY   r   r5   )rM  rY   r   rj  r5   r6   cc`  s    z+ComponentReflectionTest.exp_ccs.<locals>.ccrH  rI  rJ  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)strr9  r(   r   rX   r7  rG  )
ri   rE   r,   r   r   r  r3  r   r   r   r5   rj  r6   exp_ccsO  s^    
   
        
 zComponentReflectionTest.exp_ccsc                 C   s   ddhS )NrY   r  r5   rZ  r5   r5   r6   _required_cc_keys  s    z)ComponentReflectionTest._required_cc_keysc                 C   s    t |}ttjj| k 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| k 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| k t|d |td zHtd| k t|d |  td| k t|d W 5 |td X d S )NZfoo_barzCREATE SCHEMA foo_barzDROP SCHEMA foo_bar)r   r&   r  r  executer    ro   r'   rx   r5   r5   r6   test_schema_cache  s    z)ComponentReflectionTest.test_schema_cachec                 C   s$   t  }t| t|jds td S )Nr&  )r   r1   r   hasattrrf   r   )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 }dddddddh t|}|rDdd	 ||D }n
||} fd
d	|D }|dkr~dddg}t|| ndddg}tt|| d S )Nr  r!  r  r  r  r  r  c                 S   s   g | ]}|d  r|d  qS )r   r5   )r>  Zrecr5   r5   r6   rx    s   z@ComponentReflectionTest.test_get_table_names.<locals>.<listcomp>c                    s   g | ]}| kr|qS r5   r5   r>  tZ_ignore_tablesr5   r6   rx    s      r  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   sn   t |}|rtj}nd }||}tjjjrRtt	|ddg t|
|dg ndddg}tt	|| d S )NrI  rJ  rH  )r   r   rH   get_view_namesr   rF   r0  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   rD  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   rO  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   sl  |rt j}nd }| jj| jj }}|r2dddg}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k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 kst"qqPd S )NrJ  rI  rH  r   r  rD   r   rY   rQ  r/  z%s(%s), %s(%s)rR  )#r   rH   r   r   r  r   zipr   r'   len	enumeratecolumnsr   rY   	__class__rQ  r   r\   r   Z
TypeEnginer   r2  	sql_typesDateDateTimer1  __mro__intersectionr   NumericZTimer   Z_Binaryr@   r   )ri   ry   Z	use_viewsr  rE   r   	addressesr  rp   rb   tableZschema_namer^  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   r^  r  rl   r5   r5   r6   test_get_temp_table_columns  s    

z3ComponentReflectionTest.test_get_temp_table_columnsc                 C   s0   t |}|d}tdd |D dddg d S )Nr~   c                 S   s   g | ]}|d  qS r   r5   r>  rl   r5   r5   r6   rx    s     zFComponentReflectionTest.test_get_temp_view_columns.<locals>.<listcomp>r>   rY   r   )r   r   r   )ri   ry   rp   r^  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 5 Q R X | jjj	}| 
|j||dg|||f g| j d S )NrD   r\  rY   r
  )r   r   rH   r   r   r  r   ra  r   rY   _check_listrb  r   rF   r_  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   sT  |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 5 Q R X t|	d | t|	d |j t|	d dg t|	d	 d
g |j
|j|d}
|
d }	tjj  t|	d d k	 W 5 Q R X 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   rg  rh  rf  r   r\  r   r  )r   rH   r   r   r  r   r   rF   r$  r/   r   rY   rl  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    

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k 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   rg  rh  rf  r>   r\  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  s:    



 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
   r]  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 )
Nrs  Fr   r-  )r  rr  rY   r   rt  c                 S   s   g | ]}|d  dkr|qS )rY   r-  r5   r>  r   r5   r5   r6   rx  ]  s      zGComponentReflectionTest.test_get_temp_table_indexes.<locals>.<listcomp>)	r   rX   r   rT  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dddgdddddg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 }|rT|
| t|dd d  t|| q0t }td|||d}	dd |	jD }dd |	jD dg}||rt|
rt|
| t|t  | jjj}t|j||dg  d S )NZunique_ar   )rY   rr  Zunique_a_b_cbr   Zunique_c_a_bZunique_asc_keyZascr   zi.have.dotszi have spacesrY   r   Ztesttblr  r   rD   rr  r}  r   )r   rE   c                 S   s   h | ]
}|j qS r5   r   r  r5   r5   r6   	<setcomp>  s     zFComponentReflectionTest.test_get_unique_constraints.<locals>.<setcomp>c                 S   s   h | ]}t |tjr|jqS r5   )r   r\   r   rY   )r>  Zuqr5   r5   r6   r    s   )r   rH   r  operator
itemgetterr   r   r\   r   r   Zappend_constraintr   rm   r   r   r1  r   r  r  rT  rC  r   r  constraints
differencer  r   r   r  rY   )ri   rN   ry   r  rE   Zuniquesr  r  rp   r  Znames_that_duplicate_indexry  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 )N)rJ  rI  rH  rD   )r   rH   r   r   r'   bool)ri   ry   r  rE   rp   viewr?  r5   r5   r6   r     s    z0ComponentReflectionTest.test_get_view_definitionc              	   C   sH   t |}tt |d W 5 Q R X tt |d W 5 Q R X 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t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   rv  r5   r5   r6   rB    s      zBComponentReflectionTest.test_autoincrement_col.<locals>.<dictcomp>rP  TN)r   r   getr   )ri   ry   rp   r  cnamer^  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 n"tt |jd|d}W 5 Q R X 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              	      sv   t tj tjjjrV|rtjnd  jd} fdd j	dD }t
|| ntt   }W 5 Q R X d S )NrD   c                    s    i | ]}|f j |d qS )rD   )r   )r>  r  rp   rE   r5   r6   rB    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|krD|dddg tj|kr\|ddg tj|krt|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   zdoes-not-existrI  rH  rE   r   )rE   r,   r   r   r,   r   )r   r   r   rz  r   r   r  r   r   copyrT  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   sH   |||||t j| j\}}}|D ]"}	|  |jf |	}
t|
| q d S r{   )r   r   rL  ro   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   sD   |||||t j| j\}}}|D ]}	|  t|jf |	| q d S r{   )r   r   rO  ro   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rM  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   )r>  er?  r  r5   r6   rB  e  s      z>ComponentReflectionTest._check_expressions.<locals>.<dictcomp>c                    s   g | ]} |qS r5   r5   )r>  r  r  r5   r6   rx  g  s     z>ComponentReflectionTest._check_expressions.<locals>.<listcomp>)r  r   r2   r   rE  )ri   r  r  err_msgr5   r  r6   _check_expressions`  s    
 z*ComponentReflectionTest._check_expressionsc           	      C   s   |d krt ||| nt t|t|| t||D ]~\}}t|t|B D ]d}||ksh||krL||krL| d| d| }|dkr| || || | qLt || || | qLq4d S )Nz - )ru  rp  )r   r  r  r1  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   r1  keysr  )ri   r  r  r  
make_listsr   r  r  r5   r5   r6   _check_table_dictw  s    z)ComponentReflectionTest._check_table_dictc                 C   sN   |||||t j| j\}}}|D ](}	|  |jf |	}
| |
|| j q d S r{   )r   r   rY  ro   get_multi_columnsr  r[  r  r5   r5   r6   test_get_multi_columns  s    
	z.ComponentReflectionTest.test_get_multi_columnsc                 C   sR   |||||t j| j\}}}|D ],}	|  |jf |	}
| j|
|| jdd q d S )NT)r  )r   r   ra  ro   Zget_multi_pk_constraintr  rb  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kV  qdS )rY   N)r  r(   r   )r>  r?  r5   r5   r6   	<genexpr>  s    z7ComponentReflectionTest._adjust_sort.<locals>.<genexpr>r  )r   rF   r  r/   rF  r  anysort)ri   r  r  r   objr`  r5   r5   r6   _adjust_sort  s    
z$ComponentReflectionTest._adjust_sortc                 C   s`   |||||t j| j\}}}|D ]:}	|  |jf |	}
| |
|dd  | |
|| j q d S )Nc                 S   s   t | d S )Nr\  tupledr5   r5   r6   r     r   zEComponentReflectionTest.test_get_multi_foreign_keys.<locals>.<lambda>)r   r   rn  ro   Zget_multi_foreign_keysr  r  ro  r  r5   r5   r6   test_get_multi_foreign_keys  s"    
  z3ComponentReflectionTest.test_get_multi_foreign_keysc                 C   sN   |||||t j| j\}}}|D ](}	|  |jf |	}
| |
|| j q d S r{   )r   r   r{  ro   Zget_multi_indexesr  r|  r  r5   r5   r6   test_get_multi_indexes  s    
z.ComponentReflectionTest.test_get_multi_indexesc                 C   s`   |||||t j| j\}}}|D ]:}	|  |jf |	}
| |
|dd  | |
|| j q d S )Nc                 S   s   t | d S )Nrr  r  r	  r5   r5   r6   r     r   zKComponentReflectionTest.test_get_multi_unique_constraints.<locals>.<lambda>)r   r   r  ro   Zget_multi_unique_constraintsr  r  r  r  r5   r5   r6   !test_get_multi_unique_constraints  s    
z9ComponentReflectionTest.test_get_multi_unique_constraintsc                 C   s`   |||||t j| j\}}}|D ]:}	|  |jf |	}
| |
|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  ro   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   s2   t |}t||}tt |d W 5 Q R X 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|4 ttd t|t	dt
 d  W 5 Q R X W 5 Q R X d S )Nc                     s"   | di }td|d<  | |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|}| }|rr|| 7 }z|| 7 }W n tk
rp   Y nX  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   rx  8	  s     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   試蛇ẟΩ✨rM  c                 S   s   i | ]}|d  |d qS r   r5   rv  r5   r5   r6   rB  L	  s      zAComponentReflectionTest.test_comments_unicode.<locals>.<dictcomp>)r   r!  r   r   r   r   r   r   r   r   )ri   ry   rN   rp   tcr^  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&   🎩🁰🝑🤷‍♀️🤷‍♂️rM  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   r7  r9  rG  r   r   r   rL  rO  rY  propertyr[  ra  rb  rn  ro  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  rD  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 NrN  )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 )NrN  rP   z*CREATE VIEW empty_v AS SELECT * FROM emptyrQ   zDROP VIEW IF EXISTS empty_v)r   r   rR   r    r   r0  r5   r5   r6   view_no_columnsk	  s    
  z"TableNoColumnsTest.view_no_columnsc                 C   s$   t dt |d}tt|jg  d S )NrN  r   r   r   r   r]  r   )ri   ry   r1  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 )NrN  r/  )r   r   r   r  )ri   ry   r1  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&td S r/  )r   r  r1  r   r  r   )ri   ry   r1  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   r3  )ri   ry   r2  r4  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 )Nr9  )r   )Nr9  )r   r   r   r  r   r   )ri   ry   r2  rp   r6  r5   r5   r6    test_get_columns_view_no_columns	  s    z3TableNoColumnsTest.test_get_columns_view_no_columnsN)r8   r9   r:   __requires__r   r   r-  r1  r2  r5  r7  r8  rF   r   r:  r;  r5   r5   r5   r6   r.  b	  s   


r.  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   rA  r5   r6   go	  s    z:ComponentReflectionTestExtra.inspect_for_table.<locals>.go)
contextlibcontextmanager)ri   rN   ry   rA  rC  r5   rB  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   )r>  itemrK  r5   r6   rx  	  s   z6ComponentReflectionTestExtra.ck_eq.<locals>.<listcomp>c                 S   s   | d S r  r5   rM  r5   r5   r6   r   	  r   z4ComponentReflectionTestExtra.ck_eq.<locals>.<lambda>r  c                 S   s   | d S r  r5   rO  r5   r5   r6   r   	  r   )r  r   )ri   r  r  r5   rN  r6   ck_eq	  s    
z"ComponentReflectionTestExtra.ck_eqc              	   C   sN   |d&\}}t d|tdtd|d W 5 Q R X | |jd|dg  d S )Nr  rA   r  rD   )r   r   r\   r   rP  r   )ri   rN   rF  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H\}}t d|tdt ddtdt tjd|dtdtd	|d
 W 5 Q R X |jd|d
}| ||prtj	ddg d S )Nsa_ccr>   Tr?   r   a > 1 AND a < 5r   rA   rB   rD   a > 1 and a < 5rL  )
r   r   r   r\   r   r   r   rP  r(   r   ri   rN   rF  rS  rE   r   r  r5   r5   r6   test_check_constraint_inline	  s0     z9ComponentReflectionTestExtra.test_check_constraint_inlineZmy_ck_constZ	MyCkConstc              	   C   sh   |d.\}}t d|tdt tjd|d|d W 5 Q R X |jd|d}| ||pXtjddg d S )NrT  r   za = 1 OR (a > 2 AND a < 5)r   rD   za = 1 or a > 2 and a < 5rL  )	r   r   r   r\   r   r   rP  r(   r   rW  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 5 Q R X |jd|d}| |dddd	ddt	j
ddg d S )NrT  r>   Tr?   r   rU  r  zb > 1 AND b < 5rR  r   r   rA   rB   Zsome_uqzc > 1 AND c < 5Zcc1Z	some_c_uqrD   zc > 1 and c < 5rL  zb > 1 and b < 5rV  )r   r   r   r\   r   r   r   r   rP  r(   r   )ri   rN   rF  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rtdd dd g|dd|dgd
d}	||	 |d|	 dd g|d dgd
d}
||
 ||
 t|d| t }t d| d}n8td* t|d| t }t d| d}W 5 Q R X | || 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   rr  r  rs  c                    s:   t jjjr*g | d<  jj dg i| d< n| di  d S )Nrt  Z_includers  )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|kod|kpd|kS )Nr  r[  r\  r  )ri   r   olr5   r5   r6   rd  [
  s    zbComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.lower_index_str.__eq__Nre  r5   r5   r5   r6   lower_index_strZ
  s   rc  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|  ko |kS )Ncoalescera  rc  long_strr5   r6   rd  a
  s    zeComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.coalesce_index_str.__eq__Nre  r5   re  r5   r6   coalesce_index_str`
  s   rg  zlower(x)zlower(y))rY   rr  ru  r  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\  rd  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  r`  rc  rg  Z
expr_indexZexpr_index_longr   r4  r5   )ry   rf  r6   %test_reflect_expression_based_indexes3
  sp    &
		

  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[  r   r\  r^  includeF)rY   rr  rt  r  rs  r   rs  z
%s_includer   )r   r   r   r!   r   r[  rs  r  rY   r   r   r   r   r(   r   r   r]  r  )ri   rN   ry   r  r   rp   r   r4  r5   r5   r6   test_reflect_covering_index
  sD    



z8ComponentReflectionTestExtra.test_reflect_covering_indexc                 G   s@   t d|fdd t|D  }|| dd t|dD S )Nr  c                 S   s   g | ]\}}t d | |qS )zt%dr   )r>  r  type_r5   r5   r6   rx  
  s     zAComponentReflectionTestExtra._type_round_trip.<locals>.<listcomp>c                 S   s   g | ]}|d  qS )rQ  r5   rv  r5   r5   r6   rx  
  s     )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*tt|jd t|jd qd S )N   r   )rm  r  r  r   r   r   Z	precisionZscaleri   ry   rN   typr5   r5   r6   test_numeric_reflection
  s      
z4ComponentReflectionTestExtra.test_numeric_reflectionc                 C   s8   |  ||tdd }t|tjs(tt|jd d S )N4   r   )rm  r  r   r   r   r   lengthro  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   rB  
  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 k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[  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   )r>  r   optsr5   r6   rB  <  s       zMComponentReflectionTestExtra.test_get_foreign_key_options.<locals>.<dictcomp>)r   r   r   r   r   r\   r   r   r   r   r   )ri   ry   rN   r  rv  rw  r-   rp   r5   r}  r6   test_get_foreign_key_options
  sV    *	 
z9ComponentReflectionTestExtra.test_get_foreign_key_options) r8   r9   r:   r   r   r-  rA  rF  rP  rF   r   rQ  Z"inline_check_constraint_reflectionr   rX  rY  rZ  Zindexes_with_expressionsri  r  rk  rm  r,  rq  rt  ru  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   r=  	  s   

	
       

Z
*



'r=  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?   r4  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>t
t  }|jtjdd d |jd jj|jd jj	szt
d S )	Nr4  Tr  r   r   c                 S   s   |   dkS )Nr   r4  ra  )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   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 kr|qS )r  ra  r  r5   r5   r6   rx  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:   r<  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 k t|d d d  t|d d d  d S )	Ncomputed_default_tablec                 S   s   i | ]}|d  |qS r   r5   rv  r5   r5   r6   rB  s  s      zLComputedReflectionTest.test_computed_col_default_not_set.<locals>.<dictcomp>Z42with_defaultrR  normalcomputed_col)r   r   r3   r   r'   r
   )ri   rp   r^  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|| k q&|d }td|k td|d k t| |d d d td	|d k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   rv  r5   r5   r6   rB  |  s      zKComputedReflectionTest.test_get_column_returns_computed.<locals>.<dictcomp>)r>   r  r  computedr  r  	normal+42	persisted)r   r   r3   r   r'   r   rK  r   rF   "computed_columns_reflect_persistedr/   "computed_columns_default_persisted)ri   rp   r^  rA   r   compDatar5   r5   r6    test_get_column_returns_computedx  s$    




z7ComputedReflectionTest.test_get_column_returns_computedc                 C   sX   t d|| k || d }t| |d | tjjjrTt d|k t|d | d S )Nr  r  r  )r'   r   rK  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   rv  r5   r5   r6   rB    s      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   r^  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   rv  r5   r5   r6   rB    s      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  s4    
 

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_columnsr,  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  id1r4  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 ]}||kr|| q|rtt|t| |D ]T}|dkrjt|| || k qH|dk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/   r]  rT  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|k q"|d dkrd|kr`t|d  t|d d  td|k | j|d td	d
d
d
dd	d
ddd q"|d dkr"d|krt|d  t|d d  td|k | j|d tddddddddd	d q"d S )Nr   r4  rY   r  identityr  rP  rR  Fr   r  Tr  r   r   r   r  r  r  )	r   r   r3   r   r&   r'   r   r  r2   ri   rp   r^  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|k q|d dkrd|kr\t|d  t|d d  td|k | j|d t	d	d
ddddddd	d qd S )Nr   rD   rY   r  r  r  rP  rR  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:   r'  r(  r   r<  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dddg|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pnameZ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   s2   t |}|| jjj}t|ddddg d S )Nr\  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   s^   t |}|| jjj}tt|d |d }t|ddddg t|ddd	d
g d S )Nr   r   rf  rY   r>   r  r\  r  r  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   r+  r  r*  r  r5   r5   r5   r6   r  \  s   

r  )r   r=  r.  r   r   r<   r   r  r  r  r  )DrD  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   r.  r=  r  ZComputedReflectionFixtureTestr  r  r  __all__r5   r5   r5   r6   <module>	   s    L;               Y5   /+a 1