U
    [h                    @   s  d dl Z d dlZd dlZd dlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z! ddl"m#Z# ddl"m$Z$ ddl"m%Z% dd l&m'Z' dd!l&m(Z( dd"lm)Z) dd#lm*Z* dd$l+m,Z, dd%l-m.Z. dd&lm/Z/ dd'lm0Z0 dd(lm1Z1 dd)lm2Z2 dd*lm3Z3 d+\Z4Z5G d,d- d-ej6Z7G d.d/ d/e7Z8G d0d1 d1ej6Z9G d2d3 d3ej:Z;G d4d5 d5ej:Z<G d6d7 d7ej6Z=d8d9 Z>G d:d; d;e0e7Z?G d<d= d=ej:Z@G d>d? d?e/ej:ZAG d@dA dAej6ZBG dBdC dCejCZDG dDdE dEej6ZEG dFdG dGej6ZFdHZGdS )I    N   )config)engines)eq_)eq_regex)expect_raises)expect_raises_message)expect_warnings)fixtures)is_)get_temp_table_name)temp_table_keyword_argsColumn)Table   )Boolean)DateTime)event)
ForeignKey)func)Identity)inspect)Integer)MetaData)String)testing)types)	Inspector)
ObjectKind)ObjectScope)NoSuchTableError)UnreflectableTableError)DDL)Index)quoted_name)BLANK_SCHEMA)ComparesIndexes)ComparesTables)is_false)is_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   ZrequirementsZindependent_connectionsenabled
sqlalchemyr-   r   testing_enginedictZ
StaticPooldb)clsr-    r7   N./venv/lib/python3.8/site-packages/sqlalchemy/testing/suite/test_reflection.py
setup_bind;   s    
z"OneConnectionTablesTest.setup_bindN)__name__
__module____qualname__classmethodr9   r7   r7   r7   r8   r,   :   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schemasr1   r   test_schemaview_reflectiondefine_viewshas_temp_tabledefine_temp_tablesr6   metadatar7   r7   r8   define_tablesM   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   rH   rI   r1   r   rJ   )r6   rP   queryr7   r7   r8   rL   c   s     
zHasTableTest.define_viewsc                 C   s   t ttjdtj S NZ	user_tmp_r   r   r5   identr6   r7   r7   r8   temp_table_namey   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@   TrA   namerD   rR   =create temporary view user_tmp_v as select * from user_tmp_%srS   drop view user_tmp_v)r   r   r5   rZ   r   r   saINTVARCHARr   rH   rK   r1   temporary_viewsr   rT   r#   rX   r6   rP   kw
table_nameuser_tmpr7   r7   r8   rN      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?   rE   nonexistent_table)r   r5   beginr*   dialect	has_tabler)   selfconnr7   r7   r8   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   r5   r*   ri   r   r   r   r)   createdropclear_cache)rk   rP   inspntr7   r7   r8   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?   rF   rE   rf   )r   r5   rg   r)   rh   ri   rJ   r*   rj   r7   r7   r8   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_schemarF   )r   r5   rg   r)   rh   ri   rj   r7   r7   r8   !test_has_table_nonexistent_schema   s      z.HasTableTest.test_has_table_nonexistent_schemac                 C   s   t |}t|d d S NZvvr   r*   ri   rk   
connectionrr   r7   r7   r8   test_has_table_view   s    z HasTableTest.test_has_table_viewc                 C   s"   t |}|  }t|| d S N)r   rZ   r*   ri   )rk   rz   rr   rZ   r7   r7   r8   test_has_table_temp_table   s    z&HasTableTest.test_has_table_temp_tablec                 C   s   t |}t|d d S N
user_tmp_vrx   ry   r7   r7   r8   test_has_table_temp_view   s    z%HasTableTest.test_has_table_temp_viewc                 C   s   t |}t|dtj d S rw   )r   r*   ri   r   rJ   ry   r7   r7   r8   test_has_table_view_schema   s    z'HasTableTest.test_has_table_view_schemaN)r:   r;   r<   __backend__r=   rQ   rL   rZ   rN   rm   rt   r   rH   rI   ru   rv   viewsr{   rM   r}   rK   ra   r   r   r7   r7   r7   r8   r>   J   s4   







r>   c                   @   sX   e Zd ZdZdZedd ZejddddZ	d	d
 Z
e	dd Zejje	dd ZdS )HasIndexTestT)index_reflectionc              	   C   s   t d|tdtddtdtdtdtd}td|jj tjj	j
r|t d|tdtddtdtdtjd	}td
|jj d S )Nr?   r@   TrA   rC   rD   data2my_idxrF   my_idx_s)r   r   r   r   r$   crC   r   rH   rI   r1   r   rJ   )r6   rP   ttr7   r7   r8   rQ      s"    
zHasIndexTest.define_tablesrh   	inspectorkindZargnamesc                    s"   |dkr fddS t  jS d S )Nrh   c                     s   t jjj f| |S r|   )r   r5   rh   	has_index)akrl   r7   r8   <lambda>       z)HasIndexTest._has_index.<locals>.<lambda>)r   r   )rk   r   rl   r7   r   r8   
_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   rf   Znonexistent_idxZmy_idx_2Ztest_table_2Zmy_idx_3foor   T)r   AssertionErrorr$   tablesr?   r   r   r   r   r   ro   rp   __self__rq   )rk   r   rz   rP   methidxZtblr7   r7   r8   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   rF   r   rf   Znonexistent_idx_s)r   r   rJ   r   )rk   r   rz   r   r7   r7   r8   test_has_index_schema  s      
  z"HasIndexTest.test_has_index_schemaN)r:   r;   r<   r   __requires__r=   rQ   r   combinationsr   r   r   rH   rI   r   r7   r7   r7   r8   r      s   

r   c                   @   s   e Zd ZdZdd Zdd Zedddge e ejj	dd	 Z
e e ejjd
d Ze e ejjdd ZdS )BizarroCharacterTestTc                   C   s   t jddddddS )N)Z	plainname)z(3))zcol%p)z[brack]
columnnamer   r   r   r7   r7   r7   r8   column_names1  s    z!BizarroCharacterTest.column_namesc                   C   s   t jddddddS )N)Zplain)z(2))z
per % cent)z
[brackets]	tablenamer   r   r7   r7   r7   r8   table_names:  s    z BizarroCharacterTest.table_namesuse_compositeFc           
      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 )ztests for #10275r@   T)keyrB   test_needs_fkid2rA   otherrefref2autoload_withr      N)r   r   r   Zappend_columnr^   ForeignKeyConstraintr   r@   r   r   
create_allr   r   r   
referencesr   r   )
rk   rz   rP   r   r   r   r   m2Zo2t1r7   r7   r8   test_fk_refC  s@    


z BizarroCharacterTest.test_fk_refc              	   C   sL   t ||t|tt dd || t|}t||d d d d d S )NTrA   r   identitystartr   r   r   r   r   r   r   r   get_columnsrk   r   r   rz   rP   rr   r7   r7   r8   test_reflect_identityr  s    
z*BizarroCharacterTest.test_reflect_identityc              	   C   sP   t ||tdtddt|tdd || t|}t||d d d d S )Nr@   TrA   some commentcommentr   r   r   r   r   r   r   r   r   r   r7   r7   r8   test_reflect_comments  s    
z*BizarroCharacterTest.test_reflect_commentsN)r:   r;   r<   r   r   r   r   Z	variationrH   !foreign_key_constraint_reflectionr   identity_columnsr   comment_reflectionr   r7   r7   r7   r8   r   -  s    		+r   c                   @   sB   e Zd ZdZdZejdd Zejj	dd Z
ejjdd Zd	S )
TempTableElementsTestT)temp_table_reflectionc                 C   s   t ttjdtj S )NZ
ident_tmp_rW   rk   r7   r7   r8   r     s
      
zTempTableElementsTest.tablenamec              	   C   sL   t ||tdtt dd || t|}t||d d d d d S )Nr@   TrA   r   r   r   r   r   rk   r   rz   rP   rr   r7   r7   r8   r     s    
z+TempTableElementsTest.test_reflect_identityc              	   C   sP   t ||tdtddtdtdd || t|}t||d d d d S )	Nr@   TrA   Zfoobarr   r   r   r   r   r   r7   r7   r8   r     s    
z+TempTableElementsTest.test_reflect_commentsN)r:   r;   r<   r   r   r   fixturer   rH   r   r   Ztemp_table_comment_reflectionr   r7   r7   r7   r8   r     s   

r   c                   @   s   e Zd ZdZdZedd Zdd Zedd Zee	j
jd	d
 Zedd Zedd Zee	j
jdd Zee	j
jdd Zee	j
jdd Zee	j
jdd Zee	j
jdd ZdS )QuotedNameArgumentTestonceTc                 C   s  t d|tdttdtdtdtdtdttjdddtd	dtjdd
dtjdgdgddtj	dddddd t
jjj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@   r[   rD   rC   Z
related_idzpk quote ' oner[   zix quote ' onezuq quote' onez
related.idzfk quote ' onezname != 'foo'zck quote ' onezquote ' one commentT)r   r   quote " twozpk quote " twozix quote " twozuq quote" twozfk quote " twozck quote " two zquote " two commentZrelatedrA   r   z"CREATE VIEW %s AS SELECT * FROM %sview %srR   rS   zDROP VIEW %s)r   r   r   r   r^   PrimaryKeyConstraintr$   UniqueConstraintr   CheckConstraintr   rH   symbol_names_w_double_quoter1   view_column_reflectionr   r5   rh   Zidentifier_preparerquoter   rT   r#   )r6   rP   namesr[   rU   r7   r7   r8   rQ     s    
  

  

z$QuotedNameArgumentTest.define_tablesc                 C   s   t ddt jjf| S )N)r   r   )r   r   rH   r   )fnr7   r7   r8   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   r5   r   rH   reflect_table_optionsr1   get_table_optionsr*   
isinstancer4   r   NotImplementedError)rk   r[   rr   resr7   r7   r8   test_get_table_options  s    



z-QuotedNameArgumentTest.test_get_table_optionsc                 C   s    t tj}|d| std S )Nr   )r   r   r5   get_view_definitionr   rk   r[   rr   r7   r7   r8   test_get_view_definition"  s    
z/QuotedNameArgumentTest.test_get_view_definitionc                 C   s   t tj}||std S r|   )r   r   r5   r   r   r   r7   r7   r8   test_get_columns(  s    
z'QuotedNameArgumentTest.test_get_columnsc                 C   s   t tj}||std S r|   )r   r   r5   get_pk_constraintr   r   r7   r7   r8   test_get_pk_constraint-  s    
z-QuotedNameArgumentTest.test_get_pk_constraintc                 C   s   t tj}||std S r|   )r   r   r5   get_foreign_keysr   r   r7   r7   r8   test_get_foreign_keys2  s    
z,QuotedNameArgumentTest.test_get_foreign_keysc                 C   s   t tj}||std S r|   )r   r   r5   get_indexesr   r   r7   r7   r8   test_get_indexes8  s    
z'QuotedNameArgumentTest.test_get_indexesc                 C   s   t tj}||std S r|   )r   r   r5   get_unique_constraintsr   r   r7   r7   r8   test_get_unique_constraints>  s    
z2QuotedNameArgumentTest.test_get_unique_constraintsc                 C   s   t tj}||std S r|   )r   r   r5   get_table_commentr   r   r7   r7   r8   test_get_table_commentD  s    
z-QuotedNameArgumentTest.test_get_table_commentc                 C   s   t tj}||std S r|   )r   r   r5   get_check_constraintsr   r   r7   r7   r8   test_get_check_constraintsJ  s    
z1QuotedNameArgumentTest.test_get_check_constraintsN)r:   r;   r<   Zrun_create_tablesr   r=   rQ   r   r   r   rH   r   r   r   r   r   r   r   r   unique_constraint_reflectionr   r   r   check_constraint_reflectionr   r7   r7   r7   r8   r     s:   
R



r   c              
   C   s   t jd dd t jjfdd}t jtjtjtjdd}t jtj	tj
tjtjtjtj	tj
B tj	tjB dd}t jddd	d}||||| S )
Nc                   S   s   t jS r|   )r   rJ   r7   r7   r7   r8   r   U  r   z$_multi_combination.<locals>.<lambda>rG   r   r/   r   TF
use_filter)r   r   rH   rI   r    DEFAULT	TEMPORARYANYr   TABLEVIEWMATERIALIZED_VIEWZANY_VIEW)r   rG   r/   r   filter_namesr7   r7   r8   _multi_combinationQ  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   rH   rI   r1   r   rJ   rO   r7   r7   r8   rQ   t  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   r7   usersuser_idTrA   test1   Fnullabletest2parent_user_id	test2 > 0zz_test2_gt_zerousers check constraintr[   r   test2 <= 1000rG   r   
dingalingsdingaling_id
address_idz%semail_addresses.address_idzz_email_add_id_fgdi fk commentid_userrC      )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)rB   r   data % commentr   d2)Comment types type speedily ' " \ '' Fun!d3*   Comment
withescapesthe test % ' " \ table comment)rG   r   no_constraints"no
constraintshasescapedcommentlocal_table	remote_idz%s.remote_table_2.id)r   rG   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   rH   self_referential_foreign_keysr1   r   r   r   r^   r_   CHARZFloatr   r   r   r   r   r   r   cross_schema_fk_reflectionr   rJ   r5   rh   default_schema_namer   r$   r   r  indexes_with_ascdescreflect_indexes_with_ascdescr1  descr   rL   r   rN   )r6   rP   rG   Zschema_prefixZparent_id_argsr   r0  r2  r7   r7   r8   r   z  sJ   

 	
 
  

	   	z/ComponentReflectionTest.define_reflected_tablesc                 C   s   t ttjdtj S rV   rW   rY   r7   r7   r8   rZ   (  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@   TrA   r[   rD   r   user_tmp_uq_r   user_tmp_ixrR   r\   rS   r]   )r   r   r5   rZ   r   r   r^   r_   r`   r   rX   r$   r   rH   rK   r1   ra   r   rT   r#   rb   r7   r7   r8   rN   .  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 rR   	mat_indexoraclezCREATE INDEX z ON z(data)rS   zDROP )	r   rH   materialized_viewsr1   setr   rT   r#   against)r6   rP   rG   materializedrd   fullnameZ	view_nameprefixrU   Z
index_namer   r7   r7   r8   rL   P  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   )rk   r   r   r   rC  r   r7   r7   r8   _resolve_kindk  s    





z%ComponentReflectionTest._resolve_kindc                 C   s<   t jjjs|  |  nt jjjs8|| |  d S r|   )r   rH   r   r1   clearr@  rF  )rk   r   rC  r7   r7   r8   _resolve_viewsu  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 )NTr7   )_r7   r7   r8   r   ~  r   z8ComponentReflectionTest._resolve_names.<locals>.<lambda>c                 S   s   d| d kS NZtmpr   r7   r   r7   r7   r8   r     r   c                 S   s   d| d kS rK  r7   rL  r7   r7   r8   r     r   r+  r-  r)  r0  r2  r   c                    s>   i | ]6\}}|r|d   kr r4|d   kr||qS )r   r7   ).0r   vr   ZremovedrG   Zscope_filterr7   r8   
<dictcomp>  s     z:ComponentReflectionTest._resolve_names.<locals>.<dictcomp>)r    r   r   r   r   rJ   rZ   rH   r7  r1   addrF  r   r   temp_table_namesra   items)rk   rG   r/   r   valuesr   r7   rO  r8   _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-  r0  r2  r+   r   rI  rZ   rG  rU  )	rk   rG   r/   r   r   rC  r   r   r   r7   r7   r8   exp_options  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textrV  rW  rX  r   r   r  r  r  r&  r'  r(  r)  r+  r-  r0  r2  )rI  rZ   rG  rU  )
rk   rG   r/   r   r   emptyrC  r   r   r   r7   r7   r8   exp_comments  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)r[   autoincrementtypedefaultr   r  omitr^  )r+   r   pop)r[   autor`  r   r  r   r7   r7   r8   rn     s    
z0ComponentReflectionTest.exp_columns.<locals>.colc                    s   dt jdd|} | f|S )NTF)rc  r`  r  r+   r   )r[   rc   rn   r7   r8   pk  s    z/ComponentReflectionTest.exp_columns.<locals>.pkrV  r  ra  )rc  r  r  r  rC   rW  r  r  rX  r   r   r  r  r  r   r@   r[   r   r   r  r  r  r  r   r   r!  r"  r#  r%  r'  r)  r*  r+  r,  r-  r0  r1  r2  rY  )
rk   rG   r/   r   r   rf  rC  r   r   r   r7   re  r8   exp_columns  s       
	




	      
'z#ComponentReflectionTest.exp_columnsc                 C   s   ddddhS )Nr[   r_  r  r`  r7   r   r7   r7   r8   _required_column_keysK  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_columnsr[   r   )list)r[   r   colsr7   r7   r8   rf  V  s    z+ComponentReflectionTest.exp_pks.<locals>.pkr   rV  r  rW  rX  r   r   r   r  r  r  r  r  r  r@   r'  r)  r+  r-  r0  r2  r[   )r+   r   r   rH   Zmaterialized_views_reflect_pkr1   rI  rZ   reflects_pk_namesrT  rG  rU  )rk   rG   r/   r   r   rf  r\  rC  r   r   valr   r7   r7   r8   exp_pksO  s^    

               
 zComponentReflectionTest.exp_pksc                 C   s   ddhS )Nr[   ri  r7   r   r7   r7   r8   _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   r5   rh   r8  rk   r   r7   r7   r8   __eq__  s    z2ComponentReflectionTest.exp_fks.<locals>.tt.__eq__Nr:   r;   r<   rq  r7   r7   r7   r8   r     s   r   c                    s$   | ||t j|d k	r|n  ||dS )N)ri  referred_columnsr[   r0   referred_schemareferred_tabler   rd  )rk  Zref_colZ	ref_table
ref_schemar[   r   r   r7   r8   fk  s    	z+ComponentReflectionTest.exp_fks.<locals>.fkrV  rW  rX  r   r   r  r   r   r   r  r  r  r  r  r  r	  r  r  r'  r)  r*  r@   r-  )rv  r+  r,  r0  r2  r[   )r+   r   rI  r   rJ   rZ   r   rH   r5  r1   rH  named_constraintsrT  rG  rU  )rk   rG   r/   r   r   rx  rC  r   r   Zvalsrm  r   r7   rw  r8   exp_fks  s       
     
 #zComponentReflectionTest.exp_fksc                 C   s   dddddhS )Nr[   ri  rt  ru  rs  r7   r   r7   r7   r8   _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
duplicatesrx  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 )	Nr7   )r  r   r[   dialect_optionsinclude_columnsr|  r   expressionsc                    s   g | ]}| krd n|qS r|   r7   rM  r   r|  r7   r8   
<listcomp>	  s    zDComponentReflectionTest.exp_indexes.<locals>.idx.<locals>.<listcomp>Zduplicates_constraint)	r   rH   Zforeign_keys_reflect_as_indexZ#unique_constraints_reflect_as_indexZ*reflect_indexes_with_ascdesc_as_expressionr1   rj  r+   r   )r[   r  r|  r}  rx  rk  Zfk_reqZdup_reqZsorting_expressionr   origr7   r  r8   r     s4    


z0ComponentReflectionTest.exp_indexes.<locals>.idxrV  rW  rX  r   rC   r>  r   r   r  r   T)r[   rx  r   r  r   r/  r.  )r[   r  r  )r[   r  r}  r  r  r  r  r  r  r  r  r'  r)  r*  r+  r,  r-  r0  r1  r3  )r;  )r[   r|  r2  r4  r   r=  r[   r<  )r[   r}  r  )rI  extendr+   r   rZ   r   rX   r   rH   r9  r1   r:  rH  rG  rU  )
rk   rG   r/   r   r   r   rC  r   r   r   r7   r7   r8   exp_indexes  s    
%   
     


5z#ComponentReflectionTest.exp_indexesc                 C   s
   dddhS )Nr[   r   r  r7   r   r7   r7   r8   _required_index_keysZ  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 )Nr7   )r   r[   r   r  )r   rH   Z*unique_index_reflect_as_unique_constraintsr1   rj  )r[   r  r  r   rk  Zreqr   r7   r7   r8   ucf  s    
z+ComponentReflectionTest.exp_ucs.<locals>.ucrV  rW  rX  r   r   r   r  r.  T)r[   r  r  r  rC   )r[   r  r  r  r  r  )r[   r  r   r  r  r'  r)  r+  r-  r0  r2  r[   r<  r   )rI  r+   r   rZ   r   rX   rG  rU  )rk   rG   r/   r   r   all_r  rC  r   r   r   r7   r7   r8   exp_ucs^  sr    	     	
        
 
zComponentReflectionTest.exp_ucsc                 C   s   ddhS )Nr[   r   r7   r   r7   r7   r8   _required_unique_cst_keys  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)rk   r   r   r7   r7   r8   rq    s       z2ComponentReflectionTest.exp_ccs.<locals>.tt.__eq__Nrr  r7   r7   r7   r8   r     s   r   c                    s    | ||dS )N)sqltextr[   r   r7   )r[  r[   r   rw  r7   r8   cc  s    z+ComponentReflectionTest.exp_ccs.<locals>.ccrV  rW  rX  r   r   r
  r  r  r  r   r  z$address_id > 0 and address_id < 1000r  r   r  r  r'  r)  r+  r-  r0  r2  )N)strrI  r+   r   rZ   rG  rU  )
rk   rG   r/   r   r   r  rC  r   r   r   r7   rw  r8   exp_ccs  s^    
   
        
 zComponentReflectionTest.exp_ccsc                 C   s   ddhS )Nr[   r  r7   r   r7   r7   r8   _required_cc_keys  s    z)ComponentReflectionTest._required_cc_keysc                 C   s    t |}ttjj| k d S r|   )r   r*   r   r   rJ   get_schema_namesry   r7   r7   r8   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   rJ   r)   ry   r7   r7   r8   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   rJ   r   r*   r  ry   r7   r7   r8   %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   rJ   r   r*   r  r)   ry   r7   r7   r8   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  Zexecuter#   rq   r*   ry   r7   r7   r8   test_schema_cache  s    z)ComponentReflectionTest.test_schema_cachec                 C   s$   t  }t| t|jds td S )Nr8  )r   r3   r   hasattrrh   r   )rk   enginer7   r7   r8   test_dialect_initialize  s    z/ComponentReflectionTest.test_dialect_initializec                 C   s   t |}t|j|jj d S r|   )r   r   r8  rh   ry   r7   r7   r8   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  r2  r0  r)  r+  r-  r'  c                 S   s   g | ]}|d  r|d  qS )r   r7   )rM  Zrecr7   r7   r8   r  D  s   z@ComponentReflectionTest.test_get_table_names.<locals>.<listcomp>c                    s   g | ]}| kr|qS r7   r7   rM  tZ_ignore_tablesr7   r8   r  K  s      r  r   r  r  )r   rJ   r   Zget_sorted_table_and_fkc_namesget_table_namesr   sorted)	rk   rz   r  r  rG   rr   r   r   answerr7   r  r8   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 )NrW  rX  rV  )r   r   rJ   get_view_namesr   rH   r@  r1   r   r  get_materialized_view_names)rk   rz   r  rr   rG   r   r  r7   r7   r8   test_get_view_namesT  s    


z+ComponentReflectionTest.test_get_view_namesc                 C   s,   t |}| }tt|dtj g d S rV   )r   Zget_temp_table_namesr   r  r   rX   rk   rz   rr   rR  r7   r7   r8   test_get_temp_table_namese  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  r7   r7   r8   test_get_temp_view_namesk  s    z0ComponentReflectionTest.test_get_temp_view_namesc                 C   s   |  | d S r|   )_test_get_commentsrk   rz   r7   r7   r8   test_get_commentsr  s    z)ComponentReflectionTest.test_get_commentsc                 C   s   |  |tjj d S r|   )r  r   r   rJ   r  r7   r7   r8   test_get_comments_with_schemav  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 )NrF   r  r   )r   r]  r   r   r   r'  r[   )rk   rz   rG   rr   expno_cstr7   r7   r8   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 )NrX  rW  rV  r   r  rF   r   r[   r_  r?  z%s(%s), %s(%s)r`  )#r   rJ   r   r   r  r   zipr   r*   len	enumeratecolumnsr   r[   	__class__r_  r   r^   r   Z
TypeEnginer   rB  	sql_typesZDater   rA  __mro__intersectionr   NumericZTimer   Z_BinaryrB   r   )rk   rz   Z	use_viewsr  rG   r   	addressesr   rr   rd   tableZschema_namerk  irn   ZctypeZ	ctype_defr7   r7   r8   r     s\    
z(ComponentReflectionTest.test_get_columnsc                 C   s6   |   }| j| }t|t |d}| j||dd d S )Nr   F)Zstrict_constraints)rZ   r   r   r   Zassert_tables_equal)rk   rz   rd   re   Zreflected_user_tmpr7   r7   r8   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   r[   )
rZ   r   r   r   r*   r  r  r  r   r[   )rk   rz   rd   re   rr   rk  r  rn   r7   r7   r8   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   r7   rM  rn   r7   r7   r8   r    s     zFComponentReflectionTest.test_get_temp_view_columns.<locals>.<listcomp>r@   r[   r   )r   r   r   )rk   rz   rr   rk  r7   r7   r8   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 )NrF   ri  r[   r  )r   r   rJ   r   r   r  r   rn  r   r[   _check_listro  r   rH   rl  fail_ifr'  )rk   rz   r  rG   r   r  rr   r  Z
users_consZ	addr_consZexp_colsr  r7   r7   r8   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 )NrF   r   r[   r   rt  ru  rs  r   ri  r  r  )r   rJ   r   r   r  r   r   rH   r5  r1   r   r[   ry  r  r   implicitly_named_constraintsr*   r'  )rk   rz   r  rG   r   r  rr   Zexpected_schemaZusers_fkeysfkey1Z
addr_fkeysr  r7   r7   r8   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   rt  ru  rs  r@   ri  r*  rF   r,  )r   rh   r8  r   r   rJ   r   r   r[   r   r  r*   )
rk   rz   r)  r+  r-  rr   Zlocal_fkeysr  Zremote_fkeysZfkey2r7   r7   r8   "test_get_inter_schema_foreign_keysI  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   rF   )
r   rJ   r   r   r  r  r  r   r'  r[   )rk   rz   r  rG   rr   indexesr  r  r7   r7   r8   r   o  s"     
 

z(ComponentReflectionTest.test_get_indexes)r0  r3  )r2  r4  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   rj  r  r[   )rk   rz   tnameZixnamerr   r  Zexpected_indexesr  r7   r7   r8   test_get_noncol_index  s    	
z-ComponentReflectionTest.test_get_noncol_indexc                 C   sB   t |}|  }||}| jddd |f }| ||| j d S )NT)r  )r   rZ   r   r  r  r  )rk   rz   rr   r[   	reflectedr  r7   r7   r8   &test_get_temp_table_unique_constraints  s
    
z>ComponentReflectionTest.test_get_temp_table_unique_constraintsc                 C   sn   t |}|  }||}|D ]}|dd  qddgddg}tjjjrVg |d d< tdd	 |D | d S )
Nr~  Fr   r=  )r  r   r[   r   r  c                 S   s   g | ]}|d  dkr|qS )r[   r=  r7   rM  r   r7   r7   r8   r    s      zGComponentReflectionTest.test_get_temp_table_indexes.<locals>.<listcomp>)	r   rZ   r   rb  r   rH   index_reflects_included_columnsr1   r   )rk   rz   rr   rd   r  Zindexpectedr7   r7   r8   test_get_temp_table_indexes  s    

z3ComponentReflectionTest.test_get_temp_table_indexesc                 C   s  |rt j}nd }tddgdd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 ]N\}}|dd }|rT|
| t|dd 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   )r[   r   Zunique_a_b_cbr   Zunique_c_a_bZunique_asc_keyZascr   zi.have.dotszi have spacesr[   r   Ztesttblr  r  rF   r   r  r   r~  )r   rG   c                 S   s   h | ]
}|j qS r7   r   r  r7   r7   r8   	<setcomp>  s     zFComponentReflectionTest.test_get_unique_constraints.<locals>.<setcomp>c                 S   s   h | ]}t |tjr|jqS r7   )r   r^   r   r[   )rM  Zuqr7   r7   r8   r    s   )r   rJ   r  operator
itemgetterr   r   r^   r   r   Zappend_constraintr   ro   r   r   rA  r   r  r  rb  rQ  r   r  Zconstraints
differencer  r   r   r'  r[   )rk   rP   rz   r  rG   Zuniquesr  r  rr   r  Znames_that_duplicate_indexr  ZreflZdupeZreflected_metadataZ	idx_namesZuq_namesr  r7   r7   r8   r     sz    







z3ComponentReflectionTest.test_get_unique_constraintsc                 C   s@   |rt j}nd }t|}dD ]}|j||d}tt| qd S )N)rX  rW  rV  rF   )r   rJ   r   r   r*   bool)rk   rz   r  rG   rr   viewrN  r7   r7   r8   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   ry   r7   r7   r8   '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   r7   r  r7   r7   r8   rP  A  s      zBComponentReflectionTest.test_autoincrement_col.<locals>.<dictcomp>r^  TN)r   r   getr   )rk   rz   rr   r  Zcnamerk  Zid_r7   r7   r8   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   rF   r'  )r   r   r5   rJ   r   rH   r   r1   r   r*   r   r4   r   r   )rk   r  rr   rG   r   r7   r7   r8   r   D  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 )NrF   c                    s    i | ]}|f j |d qS )rF   )r   )rM  r  rr   rG   r7   r8   rP  \  s    zHComponentReflectionTest.test_multi_get_table_options.<locals>.<dictcomp>)r   r   r5   r   rH   r   r1   rJ   get_multi_table_optionsr  r   r   r   )rk   r  r   r  r7   r  r8   test_multi_get_table_optionsU  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-existrW  rV  rG   r   )rG   r/   r   r   r/   r   )r   r   r   r  r   r   r  r    r   copyrb  append)rG   r/   r   r   Zsingle_reflect_fnZ
exp_methodrr   rc   r   r  kwsZnkwrz   r7   r8   provide_fixtureg  sD    










z>ComponentReflectionTest.get_multi_exp.<locals>.provide_fixturer7   )rk   rz   r  r7   r  r8   get_multi_expe  s    .z%ComponentReflectionTest.get_multi_expc                 C   sH   |||||t j| j\}}}|D ]"}	|  |jf |	}
t|
| q d S r|   )r   r   rZ  rq   r  r   rk   r  rG   r/   r   r   rr   r  r  rc   resultr7   r7   r8   #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   r]  rq   r   Zget_multi_table_comment)
rk   r  rG   r/   r   r   rr   r  r  rc   r7   r7   r8   test_get_multi_table_comment  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r[  c                 S   s   t dd|  S )Nz['\" ]r   )resubr  r  r7   r7   r8   _clean  s    z:ComponentReflectionTest._check_expressions.<locals>._cleanc                    s   i | ]\}} ||qS r7   r7   )rM  erN  r  r7   r8   rP    s      z>ComponentReflectionTest._check_expressions.<locals>.<dictcomp>c                    s   g | ]} |qS r7   r7   )rM  r  r  r7   r8   r    s     z>ComponentReflectionTest._check_expressions.<locals>.<listcomp>)r  r   r4   r   rS  )rk   r  r  err_msgr7   r  r8   _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 - )r  r|  )r   r  r  rA  r  )	rk   r  r  req_keysmsgrr  r   r  r7   r7   r8   r    s    z#ComponentReflectionTest._check_listc                 C   s\   t t| t|  |D ]8}|| ||  }}|rF|g|g }}| |||| qd S r|   )r   rA  keysr  )rk   r  r  r  
make_listsr   r  r  r7   r7   r8   _check_table_dict  s    z)ComponentReflectionTest._check_table_dictc                 C   sN   |||||t j| j\}}}|D ](}	|  |jf |	}
| |
|| j q d S r|   )r   r   rg  rq   get_multi_columnsr   rh  r  r7   r7   r8   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   rn  rq   Zget_multi_pk_constraintr   ro  r  r7   r7   r8   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 )r[   N)r  r+   r   )rM  rN  r7   r7   r8   	<genexpr>	  s    z7ComponentReflectionTest._adjust_sort.<locals>.<genexpr>r  )r   rH   r  r1   rT  r  anysort)rk   r  r  r   objrm  r7   r7   r8   _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 )Nri  tupledr7   r7   r8   r   	  r   zEComponentReflectionTest.test_get_multi_foreign_keys.<locals>.<lambda>)r   r   rz  rq   Zget_multi_foreign_keysr  r   r{  r  r7   r7   r8   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  rq   Zget_multi_indexesr   r  r  r7   r7   r8   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 )Nr   r	  r  r7   r7   r8   r   ?	  r   zKComponentReflectionTest.test_get_multi_unique_constraints.<locals>.<lambda>)r   r   r  rq   Zget_multi_unique_constraintsr  r   r  r  r7   r7   r8   !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  r7   r7   r8   r   R	  r   zJComponentReflectionTest.test_get_multi_check_constraints.<locals>.<lambda>)r   r   r  rq   Zget_multi_check_constraintsr  r   r  r  r7   r7   r8    test_get_multi_check_constraintsB	  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!   )rk   r  rz   rr   r   r7   r7   r8   test_not_existing_tableU	  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mcr7   r8   patchedu	  s    z;ComponentReflectionTest.test_unreflectable.<locals>.patchedr  r  r  )r   r  r+   Zpatchobjectr   r"   r   Zreflect_tabler   r   )rk   rz   r  r7   r  r8   test_unreflectabler	  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)rG   r   Zresolve_fksc                    s   g | ]}  d | qS )r   r7   r  rF   r7   r8   r  	  s     z9ComponentReflectionTest.test_metadata.<locals>.<listcomp>)r   r   rJ   reflectr   r  r  r  r   r   r  r   )rk   rz   r  r   mrr   r   r7   rF   r8   test_metadata	  s    
z%ComponentReflectionTest.test_metadatac              	   C   s   t d|tdtddtdtdddd || t|}|d}t|ddi |d}d	d
 |D }ddd}t|| d S )Nunicode_commentsunicodeu   é試蛇ẟΩr   emojiu	   ☁️✨u   試蛇ẟΩ✨r[  c                 S   s   i | ]}|d  |d qS r	  r7   r  r7   r7   r8   rP  	  s      zAComponentReflectionTest.test_comments_unicode.<locals>.<dictcomp>)r!  r"  r   r   r   r   r   r   r   r   )rk   rz   rP   rr   tcrk  valuer  r7   r7   r8   test_comments_unicode	  s    



z-ComponentReflectionTest.test_comments_unicodec                 C   sp   t d|tdtdddd || t|}|d}t|ddi |dd }t|d |d	 iddi d S )
Nr   r"  u&   🐍🧙🝝🧙‍♂️🧙‍♀️r   u&   🎩🁰🝑🤷‍♀️🤷‍♂️r[  r   r[   r   r#  )rk   rz   rP   rr   r$  r   r7   r7   r8   test_comments_unicode_full	  s    

z2ComponentReflectionTest.test_comments_unicode_full)N)NN)NF)mr:   r;   r<   run_insertsrun_deletesr   r=   rQ   r   rZ   rN   rL   rG  rI  rU  r    r   r   rZ  r]  rg  propertyrh  rn  ro  rz  r{  r  r  r  r  r  r  r   rH   Zschema_reflectionr  r  r  r  Zschema_create_deleter  r  r  r   r   rI   r  r  rR  r  rK   ra   r  r   r  r  r  r   r   r  r  r   r  !primary_key_constraint_reflectionr   r   r7  r  r   r   r9  r:  r  r   r  Ztemp_table_reflect_indexesr  r   r   r  table_reflectionr  r   r  r   r  r   r   r  r  r  r  r   r  r  r  r  r  r  r   r  r  r  r   r  r&  Zcomment_reflection_full_unicoder'  r7   r7   r7   r8   r   o  s   

 .

!

-
!
&
`

0

X

u

E

:








  #
  




A


 
  
 &$ 
 

  X 
 



  


1	


	




  
r   c                   @   sh   e Zd ZdZdZejdd Zejdd Zdd Z	d	d
 Z
dd Zejjdd Zejjdd ZdS )TableNoColumnsTest)Zreflect_tables_no_columnsTc                 C   s   t d| || d S Nr\  )r   r   rk   rz   rP   r7   r7   r8   table_no_columns	  s    
z#TableNoColumnsTest.table_no_columnsc                 C   s<   t d| t|dtd t|dtd || d S )Nr\  rR   z*CREATE VIEW empty_v AS SELECT * FROM emptyrS   zDROP VIEW IF EXISTS empty_v)r   r   rT   r#   r   r/  r7   r7   r8   view_no_columns	  s    
  z"TableNoColumnsTest.view_no_columnsc                 C   s$   t dt |d}tt|jg  d S )Nr\  r   r   r   r   rj  r   )rk   rz   r0  t2r7   r7   r8   test_reflect_table_no_columns	  s    z0TableNoColumnsTest.test_reflect_table_no_columnsc                 C   s2   t |}t|dg  | }t|dg i d S )Nr\  r.  )r   r   r   r  )rk   rz   r0  rr   multir7   r7   r8   !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  rA  r   r  r   )rk   rz   r0  r  r7   r7   r8   "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   r2  )rk   rz   r1  r3  r7   r7   r8   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 )Nr8  )r   )Nr8  )r   r   r   r  r   r   )rk   rz   r1  rr   r5  r7   r7   r8    test_get_columns_view_no_columns	  s    z3TableNoColumnsTest.test_get_columns_view_no_columnsN)r:   r;   r<   r   r   r   r   r0  r1  r4  r6  r7  rH   r   r9  r:  r7   r7   r7   r8   r-  	  s   


r-  c                   @   s$  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ejejejejejej	jfejej	jfd!dd"d# Zej	jd$d% Z ejdd&dej	j!fddd'ej	j"fi dd(ej	j"fi d(dej	j#fddd)ej	j$fdd)dej	j%fd*dd+d, Z&eje'e()d-d.fe'd-d.fe*e(+ d/fe'e()d0d1ej	j,fe'e()d2d3ej	j,fe-e./ d4fe'e(0d5e(0d6 d1ej	j,fd7dej	j1d8d9 Z2dS ):ComponentReflectionTestExtraTF)paramsc                 C   s   |j rtjS d S d S r|   )Zparamr   rJ   )rk   Zrequestr7   r7   r8   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   rz   rP   r=  r7   r8   go	  s    z:ComponentReflectionTestExtra.inspect_for_table.<locals>.go)
contextlibcontextmanager)rk   rP   rz   r=  r?  r7   r>  r8   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  r7   r7   r8   	normalize	
  s    z5ComponentReflectionTestExtra.ck_eq.<locals>.normalizec                    s"   g | ]}|d   |d dqS )r[   r  r[   r  r7   )rM  itemrG  r7   r8   r  
  s   z6ComponentReflectionTestExtra.ck_eq.<locals>.<listcomp>c                 S   s   | d S r  r7   rI  r7   r7   r8   r   
  r   z4ComponentReflectionTestExtra.ck_eq.<locals>.<lambda>r  c                 S   s   | d S r  r7   rK  r7   r7   r8   r   
  r   )r  r   )rk   r  r  r7   rJ  r8   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'  rC   r  rF   )r   r   r^   r   rL  r   )rk   rP   rB  rG   r   r7   r7   r8   #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@   TrA   r   a > 1 AND a < 5r   rC   rD   rF   a > 1 and a < 5rH  )
r   r   r   r^   r   r   r   rL  r+   r   rk   rP   rB  rO  rG   r   r  r7   r7   r8   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 )NrP  r   za = 1 OR (a > 2 AND a < 5)r   rF   za = 1 or a > 2 and a < 5rH  )	r   r   r   r^   r   r   rL  r+   r   rS  r7   r7   r8    test_check_constraint_standaloneO
  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 )NrP  r@   TrA   r   rQ  r  zb > 1 AND b < 5rN  r   r   rC   rD   Zsome_uqzc > 1 AND c < 5Zcc1Z	some_c_uqrF   zc > 1 and c < 5rH  zb > 1 and b < 5rR  )r   r   r   r^   r   r   r   r   rL  r+   r   )rk   rP   rB  rG   r   r  r7   r7   r8   test_check_constraint_mixedm
  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)r[   r   r  r~  c                    s:   t jjjr*g | d<  jj dg i| d< n| di  d S )Nr  Z_includer~  )r   rH   r  r1   r  r[   r  )entryr  r7   r8   completeIndex
  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  rW  rX  r  )rk   r   Zolr7   r7   r8   rq  
  s    zbComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.lower_index_str.__eq__Nrr  r7   r7   r7   r8   lower_index_str
  s   r^  c                       s   e Zd Z fddZdS )z^ComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.coalesce_index_strc                    s   d|  ko |kS )Ncoalescer]  rp  long_strr7   r8   rq  
  s    zeComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.coalesce_index_str.__eq__Nrr  r7   r`  r7   r8   coalesce_index_str
  s   rb  zlower(x)zlower(y))r[   r   r  r  zcoalesce(x, 'z')r   z>Skipped unsupported reflection of expression-based index t_idx)r   r   r   r$   r   r  r   rW  rY  rX  r_  r   r   r  r   rH   Z reflect_indexes_with_expressionsr1   insertr  r   r   r   r	   Z!compare_table_index_with_expectedr  r[   )rk   rP   rz   r  rr   r  r\  r^  rb  Z
expr_indexZexpr_index_longr   r3  r7   )rz   ra  r8   %test_reflect_expression_based_indexes
  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  rW  r  rX  rZ  ZincludeF)r[   r   r  r  r~  r   r~  z
%s_includer   )r   r   r   r$   r   rW  r~  r  r[   r   r   r   r   r+   r   r   rj  r  )rk   rP   rz   r  r   rr   r   r3  r7   r7   r8   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   )rM  r  type_r7   r7   r8   r    s     zAComponentReflectionTestExtra._type_round_trip.<locals>.<listcomp>c                 S   s   g | ]}|d  qS )r_  r7   r  r7   r7   r8   r    s     )r   r  ro   r   r   )rk   rz   rP   r   r  r7   r7   r8   _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  )rg  r  r  r   r   r   Z	precisionZscale)rk   rz   rP   typr7   r7   r8   test_numeric_reflection  s      
z4ComponentReflectionTestExtra.test_numeric_reflectionrf  c                 C   s   |  |||dd }t|tjr4t|tjsbtn.t|tjrRt|tjsbtnt|tjsbtt|j	d t|j	t
s~td S )N4   r   )rg  
issubclassr  r`   r   r   r6  r   r   lengthint)rk   rz   rP   rf  ri  r7   r7   r8   test_string_length_reflection&  s    
z:ComponentReflectionTestExtra.test_string_length_reflectionc              	   C   sT   t d|tdtddtdtdd}|| tdd t|dD ddd	 d S )
Nr  r   Tr  r  Fc                 S   s   i | ]}|d  |d qS )r[   r  r7   r  r7   r7   r8   rP  E  s    zIComponentReflectionTestExtra.test_nullable_reflection.<locals>.<dictcomp>)r   r  )r   r   r   ro   r   r   r   )rk   rz   rP   r  r7   r7   r8   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onupdaterW  r@   TrA   r   r  Zx_idzx.idZxidr   Ztest
   userr[   rD   Fr  tidztable.idZmyfkr   r0   c                    s   i | ]} | r| | qS r7   r7   )rM  r   Zoptsr7   r8   rP    s       zMComponentReflectionTestExtra.test_get_foreign_key_options.<locals>.<dictcomp>)r   r   r   r   r   r^   r   r   r   r   r   )rk   rz   rP   r  rq  rr  r0   rr   r7   rv  r8   test_get_foreign_key_optionsL  sV    *	 
z9ComponentReflectionTestExtra.test_get_foreign_key_optionsZ10z'?10'?z1|truez3 + 5z3\+5z(3 * 5)z3\*5zcurrent_timestamp|now|getdate35zdatatype, default, expected_regc           	   	   C   sd   t d|tdtddtd||d}|| t|dd d }td	d
|}t||tj	d d S )Nr  r@   TrA   Zthecol)Zserver_defaultr   r`  z	[\(\) \']r   )flags)
r   r   r   ro   r   r   r  r  r   
IGNORECASE)	rk   rP   rz   Zdatatyper`  Zexpected_regr  r  Zreflected_sanitizedr7   r7   r8   test_server_defaults  s    
z1ComponentReflectionTestExtra.test_server_defaults)3r:   r;   r<   r   r   r   r=  rB  rL  rH   r   rM  Z"inline_check_constraint_reflectionr   rT  rU  rV  Zindexes_with_expressionsrd  r  re  rg  r,  rj  r  r   r`   r6  ZNVARCHARZnvarchar_typesZNCHARro  rp  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_restrictrw  r   r^   r[  r   trueZexpression_server_defaultsr   r   ZnowZliteral_columnZserver_defaultsr|  r7   r7   r7   r8   r;  	  s   

	
       

Z
*


'
6r;  c                   @   s0   e Zd ZdZdZedd Zdd Zdd Zd	S )
NormalizedNameTest)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@   rA   r3  t1idzt1.id)r   r%   r   r   r   rO   r7   r7   r8   rQ     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 )	Nr3  Tr  r   r   c                 S   s   |   dkS )Nr   r3  r]  )r[   r  r7   r7   r8   r     r   zINormalizedNameTest.test_reflect_lowercase_forced_tables.<locals>.<lambda>)Zonly)r   r   r%   r   r5   r   r   r  r   r@   r   r  )rk   r   Zt2_refZt1_refZm3r7   r7   r8   $test_reflect_lowercase_forced_tables  s    
  
 z7NormalizedNameTest.test_reflect_lowercase_forced_tablesc                 C   sP   dd t tj D }t|d  |d   t|d  |d   d S )Nc                 S   s   g | ]}|  d kr|qS )r  r]  r  r7   r7   r8   r    s   z;NormalizedNameTest.test_get_table_names.<locals>.<listcomp>r   r   )r   r   r5   r  r   upperr  )rk   Z
tablenamesr7   r7   r8   r    s
    z'NormalizedNameTest.test_get_table_namesN)	r:   r;   r<   r   r   r=   rQ   r  r  r7   r7   r7   r8   r~    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   r7   r  r7   r7   r8   rP    s      zLComputedReflectionTest.test_computed_col_default_not_set.<locals>.<dictcomp>Z42with_defaultr`  normalcomputed_col)r   r   r5   r   r*   r   )rk   rr   rk  Zcol_datar7   r7   r8   !test_computed_col_default_not_set  s    

z8ComputedReflectionTest.test_computed_col_default_not_setc                 C   s   t tj}|d}dd |D }dD ]}td|| 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   r7   r  r7   r7   r8   rP    s      zKComputedReflectionTest.test_get_column_returns_computed.<locals>.<dictcomp>)r@   r  r  computedr  r  	normal+42	persisted)r   r   r5   r   r*   r   rG  r   rH   "computed_columns_reflect_persistedr1   "computed_columns_default_persisted)rk   rr   rk  rC   r   compDatar7   r7   r8    test_get_column_returns_computed  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   rG  r   rH   r  r1   r   )rk   rC   columnr  r  r  r7   r7   r8   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   r7   r  r7   r7   r8   rP  )  s      zLComputedReflectionTest.test_get_column_returns_persisted.<locals>.<dictcomp>computed_no_flagr  computed_virtualznormal+2Fcomputed_storedz	normal-42T)r   r   r5   r   r  r   rH   r  r1   computed_columns_virtualcomputed_columns_storedrk   rr   rk  rC   r7   r7   r8   !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  rF   c                 S   s   i | ]}|d  |qS r   r7   r  r7   r7   r8   rP  G  s      zXComputedReflectionTest.test_get_column_returns_persisted_with_schema.<locals>.<dictcomp>r  z	normal/42r  znormal/2Fr  z	normal*42T)r   r   r5   r   rJ   r  r   rH   r  r1   r  r  r  r7   r7   r8   -test_get_column_returns_persisted_with_schema@  s4    
 

zDComputedReflectionTest.test_get_column_returns_persisted_with_schemaN)r:   r;   r<   r  r  r  r  r   rH   rI   r  r7   r7   r7   r8   r    s   	r  c                   @   sH   e Zd Zd ZZdZdZedd Zdd Z	dd	 Z
ejjd
d ZdS )IdentityReflectionTestNT)r   r,  c                 C   s|   t d|tdttdtt  t d|tdttdddd	d
ddd tjjjrxt d|tdttdttdddtj	d d S )Nr   r  id1r3  r   Tr   r   r$     alwaysr   	incrementminvaluemaxvaluecyclecacher  )r  r   rF   )
r   r   r   r   r   rH   rI   r1   r   rJ   rO   r7   r7   r8   rQ   e  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   rH   Zidentity_columns_standardr1   rj  rb  r   r  r*   )rk   r%  r  approxZcommon_keysr   r7   r7   r8   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   r3  r[   r  r   r  r^  r`  Fr   r  Tr  r   r   r   r  r$  r  )	r   r   r5   r   r)   r*   r   r  r4   rk   rr   rk  rn   r7   r7   r8   r     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   rF   r[   r  r   r  r^  r`  Tr  r   r  Fr  r  )
r   r   r5   r   rJ   r)   r*   r   r  r4   r  r7   r7   r8   test_reflect_identity_schema  s.    
	z3IdentityReflectionTest.test_reflect_identity_schema)r:   r;   r<   r(  r)  r   r   r=   rQ   r  r   r   rH   rI   r  r7   r7   r7   r8   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@   attrr[   r  Zpk_tb1r   Tr  tb2rA   pidpattrpnameZfk_tb1_name_id_attr)r   r   r   r  r`   r^   r   r   r   r[   r@   r  )r6   rP   r  r7   r7   r8   rQ     s2    
z(CompositeKeyReflectionTest.define_tablesc                 C   s2   t |}|| jjj}t|ddddg d S )Nri  r[   r@   r  )r   r   r   r  r[   r   r  )rk   rz   rr   rB   r7   r7   r8   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   rs  r[   r@   r  ri  r  r  r  )r   r   r   r  r[   r   r  r  )rk   rz   rr   Zforeign_keysr  r7   r7   r8   test_fk_column_order  s    z/CompositeKeyReflectionTest.test_fk_column_orderN)r:   r;   r<   r   r=   rQ   r   rH   r+  r  r   r  r7   r7   r7   r8   r    s   

r  )r   r;  r-  r   r   r>   r   r~  r  r  r  r   )Hr@  r  r  r2   r^   r   r   r   r   r   r   r   r	   r
   r   Z	provisionr   r   rG   r   r   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+   rP   r   Z
TablesTestr,   r>   r   ZTestBaser   r   r   r   r   r-  r;  r~  ZComputedReflectionFixtureTestr  r  r  __all__r7   r7   r7   r8   <module>	   s    Mg&               [5   e+a 1