a
    dh                    @   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   requirementsZindependent_connectionsenabled
sqlalchemyr-   r   testing_enginedictZ
StaticPooldb)clsr-    r8   d/var/www/html/requester/venv/lib/python3.9/site-packages/sqlalchemy/testing/suite/test_reflection.py
setup_bind;   s    
z"OneConnectionTablesTest.setup_bindN)__name__
__module____qualname__classmethodr:   r8   r8   r8   r9   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schemasr2   r   test_schemaview_reflectiondefine_viewshas_temp_tabledefine_temp_tablesr7   metadatar8   r8   r9   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   rI   rJ   r2   r   rK   )r7   rQ   queryr8   r8   r9   rM   c   s     
zHasTableTest.define_viewsc                 C   s   t ttjdtj S NZ	user_tmp_r   r   r6   identr7   r8   r8   r9   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i |}t	j
jjrt	j
jjrt|dtdtj  t|dtd	 d S )
NrA   TrB   namerE   rS   =create temporary view user_tmp_v as select * from user_tmp_%srT   drop view user_tmp_v)r   r   r6   r[   r   r   saINTVARCHARr   rI   rL   r2   temporary_viewsr   rU   r#   rY   r7   rQ   kw
table_nameuser_tmpr8   r8   r9   rO      s0    zHasTableTest.define_temp_tablesc                 C   sj   t j L}tt jj|d tt jj|d tt jj|d W d    n1 s\0    Y  d S )Nr@   rF   nonexistent_table)r   r6   beginr*   dialect	has_tabler)   selfconnr8   r8   r9   test_has_table   s    zHasTableTest.test_has_tablec              	   C   s   t tj}t|d td|tdt}t|d |	tj z4t|d |
  t|d W |tj n|tj 0 d S )Nr@   Z	new_tablecol)r   r   r6   r*   rj   r   r   r   r)   createclear_cachedrop)rl   rQ   inspntr8   r8   r9   test_has_table_cache   s    
z!HasTableTest.test_has_table_cachec                 C   s|   t j ^}tt jjj|dt jd tt jjj|dt jd tt jjj|dt jd W d    n1 sn0    Y  d S )Nr@   rG   rF   rg   )r   r6   rh   r)   ri   rj   rK   r*   rk   r8   r8   r9   test_has_table_schema   s     z"HasTableTest.test_has_table_schemac                 C   sF   t j (}tt jjj|ddd W d    n1 s80    Y  d S )Nr@   Znonexistent_schemarG   )r   r6   rh   r)   ri   rj   rk   r8   r8   r9   !test_has_table_nonexistent_schema   s    z.HasTableTest.test_has_table_nonexistent_schemac                 C   s   t |}t|d d S Nvvr   r*   rj   rl   
connectionrs   r8   r8   r9   test_has_table_view   s    z HasTableTest.test_has_table_viewc                 C   s"   t |}|  }t|| d S N)r   r[   r*   rj   )rl   r|   rs   r[   r8   r8   r9   test_has_table_temp_table   s    z&HasTableTest.test_has_table_temp_tablec                 C   s   t |}t|d d S N
user_tmp_vrz   r{   r8   r8   r9   test_has_table_temp_view   s    z%HasTableTest.test_has_table_temp_viewc                 C   s   t |}t|dtj d S rx   )r   r*   rj   r   rK   r{   r8   r8   r9   test_has_table_view_schema   s    z'HasTableTest.test_has_table_view_schemaN)r;   r<   r=   __backend__r>   rR   rM   r[   rO   rn   ru   r   rI   rJ   rv   rw   viewsr}   rN   r   rL   rb   r   r   r8   r8   r8   r9   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@   rA   TrB   rD   rE   data2my_idxrG   my_idx_s)r   r   r   r   r$   crD   r   rI   rJ   r2   r   rK   )r7   rQ   ttr8   r8   r9   rR      s"    
zHasIndexTest.define_tablesri   	inspectorkindargnamesc                    s"   |dkr fddS t  jS d S )Nri   c                     s   t jjj g| R i |S r~   )r   r6   ri   	has_index)akrm   r8   r9   <lambda>       z)HasIndexTest._has_index.<locals>.<lambda>)r   r   )rl   r   rm   r8   r   r9   
_has_index   s    zHasIndexTest._has_indexc              	   C   s&  |  ||}|ddsJ |ddr(J |ddr6J |ddrDJ |ddrRJ |ddr`J td| jjjj}td|td	ttdd	}|	| |	| zj|d
kr|ddrJ |ddrJ |j
  |dddu sJ |dddu sJ W || || n|| || 0 d S )Nr@   r   r   rg   Znonexistent_idxZmy_idx_2Ztest_table_2Zmy_idx_3foor   T)r   r$   tablesr@   r   r   r   r   r   rp   __self__rq   rr   )rl   r   r|   rQ   methidxZtblr8   r8   r9   test_has_index  s6    




zHasIndexTest.test_has_indexc                 C   s`   |  ||}|ddtjds J |ddtjdr4J |ddtjdrHJ |ddtjdr\J d S )Nr@   r   rG   r   rg   Znonexistent_idx_s)r   r   rK   )rl   r   r|   r   r8   r8   r9   test_has_index_schema  s    
z"HasIndexTest.test_has_index_schemaN)r;   r<   r=   r   __requires__r>   rR   r   combinationsr   r   r   rI   rJ   r   r8   r8   r8   r9   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   r8   r8   r8   r9   column_names1  s    z!BizarroCharacterTest.column_namesc                   C   s   t jddddddS )N)plain)z(2))z
per % cent)z
[brackets]	tablenamer   r   r8   r8   r8   r9   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 sJ |r|jj|	jd sJ dS )ztests for #10275rA   T)keyrC   test_needs_fkid2rB   otherrefref2autoload_withr      N)r   r   r   Zappend_columnr_   ForeignKeyConstraintr   rA   r   r   
create_allr   r   r   
referencesr   )
rl   r|   rQ   r   r   r   r   m2Zo2t1r8   r8   r9   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 )NTrB   r   identitystartr   r   r   r   r   r   r   r   get_columnsrl   r   r   r|   rQ   rs   r8   r8   r9   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 )NrA   TrB   some commentcommentr   r   r   r   r   r   r   r   r   r   r8   r8   r9   test_reflect_comments  s    
z*BizarroCharacterTest.test_reflect_commentsN)r;   r<   r=   r   r   r   r   Z	variationrI   !foreign_key_constraint_reflectionr   identity_columnsr   comment_reflectionr   r8   r8   r8   r9   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_rX   rl   r8   r8   r9   r     s    zTempTableElementsTest.tablenamec              	   C   sL   t ||tdtt dd || t|}t||d d d d d S )NrA   TrB   r   r   r   r   r   rl   r   r|   rQ   rs   r8   r8   r9   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 )	NrA   TrB   Zfoobarr   r   r   r   r   r   r8   r8   r9   r     s    
z+TempTableElementsTest.test_reflect_commentsN)r;   r<   r=   r   r   r   fixturer   rI   r   r   Ztemp_table_comment_reflectionr   r8   r8   r8   r9   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 ' onerA   r\   rE   rD   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 commentrelatedrB   r   z"CREATE VIEW %s AS SELECT * FROM %sview %srS   rT   zDROP VIEW %s)r   r   r   r   r_   PrimaryKeyConstraintr$   UniqueConstraintr   CheckConstraintr   rI   symbol_names_w_double_quoter2   view_column_reflectionr   r6   ri   Zidentifier_preparerquoter   rU   r#   )r7   rQ   namesr\   rV   r8   r8   r9   rR     s    






z$QuotedNameArgumentTest.define_tablesc                 C   s   t ddt jjf| S )N)r   r   )r   r   rI   r   )fnr8   r8   r9   quote_fixtures  s    
z%QuotedNameArgumentTest.quote_fixturesc                 C   sd   t tj}tjjjr.||}tt	|t
 n2tt || W d    n1 sV0    Y  d S r~   )r   r   r6   r   rI   reflect_table_optionsr2   get_table_optionsr*   
isinstancer5   r   NotImplementedError)rl   r\   rs   resr8   r8   r9   test_get_table_options  s    



z-QuotedNameArgumentTest.test_get_table_optionsc                 C   s    t tj}|d| sJ d S )Nr   )r   r   r6   get_view_definitionrl   r\   rs   r8   r8   r9   test_get_view_definition"  s    
z/QuotedNameArgumentTest.test_get_view_definitionc                 C   s   t tj}||sJ d S r~   )r   r   r6   r   r   r8   r8   r9   test_get_columns(  s    
z'QuotedNameArgumentTest.test_get_columnsc                 C   s   t tj}||sJ d S r~   )r   r   r6   get_pk_constraintr   r8   r8   r9   test_get_pk_constraint-  s    
z-QuotedNameArgumentTest.test_get_pk_constraintc                 C   s   t tj}||sJ d S r~   )r   r   r6   get_foreign_keysr   r8   r8   r9   test_get_foreign_keys2  s    
z,QuotedNameArgumentTest.test_get_foreign_keysc                 C   s   t tj}||sJ d S r~   )r   r   r6   get_indexesr   r8   r8   r9   test_get_indexes8  s    
z'QuotedNameArgumentTest.test_get_indexesc                 C   s   t tj}||sJ d S r~   )r   r   r6   get_unique_constraintsr   r8   r8   r9   test_get_unique_constraints>  s    
z2QuotedNameArgumentTest.test_get_unique_constraintsc                 C   s   t tj}||sJ d S r~   )r   r   r6   get_table_commentr   r8   r8   r9   test_get_table_commentD  s    
z-QuotedNameArgumentTest.test_get_table_commentc                 C   s   t tj}||sJ d S r~   )r   r   r6   get_check_constraintsr   r8   r8   r9   test_get_check_constraintsJ  s    
z1QuotedNameArgumentTest.test_get_check_constraintsN)r;   r<   r=   Zrun_create_tablesr   r>   rR   r   r   r   rI   r   r   r   r   r   r   r   r   unique_constraint_reflectionr   r   r   check_constraint_reflectionr   r8   r8   r8   r9   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   rK   r8   r8   r8   r9   r   U  r   z$_multi_combination.<locals>.<lambda>rH   r   r/   r   TF
use_filter)r   r   rI   rJ   r    DEFAULT	TEMPORARYANYr   TABLEVIEWMATERIALIZED_VIEWZANY_VIEW)r   rH   r/   r   filter_namesr8   r8   r9   _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   rI   rJ   r2   r   rK   rP   r8   r8   r9   rR   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g|R  tjddddtd|d	d
}td|tdtjd	d
tdtjtd| dddtdtjtd| tdtdd	d tjd!d"dtjddd#d$d|d	d
 td%|tdtjtd&tjt|jjtd'td(d	d)tjdd*d+d|d	d td,|td-tjd	d.d/tdtd(d0d1td2td(d3d1td4td5d6d1|d7d8 td9|tdtd(|d:d8 t jjjr|d u r6td;|td-tjd	d
tdtd(td<td=t jj d	tjjjd> nntd?|td-tjd	d
td@tdAtjjj tdtd(|d	d tdB|td-tjd	d
tdtd(|d	d t jjjrjtdC|jj|jjd	d  tdD|jj|jj|jj |sjtdE|tdFtdd	dG}tdH|td-tjd	d
tdFtdd	dG}t jjjrjt jjjrjtdI|jj  tdJ|jj  t jj jr| !|| |st jj"jr| #| d S )KN. z%susers.user_id
user_id_fkr   r8   usersuser_idTrB   test1   Fnullabletest2parent_user_id	test2 > 0zz_test2_gt_zerousers check constraintr\   r   test2 <= 1000rH   r   
dingalingsdingaling_id
address_idz%semail_addresses.address_idzz_email_add_id_fgdi fk commentid_userrD      )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_testrA   
id comment)rC   r   data % commentr   d2)Comment types type speedily ' " \ '' Fun!d3*   Comment
withescapesthe test % ' " \ table comment)rH   r   no_constraints"no
constraintshasescapedcommentlocal_table	remote_idz%s.remote_table_2.id)r   rH   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   rI   self_referential_foreign_keysr2   r   r   r   r_   r`   CHARZFloatr   r   r   r   r   r  r   cross_schema_fk_reflectionr   rK   r6   ri   default_schema_namer   r$   r  r  indexes_with_ascdescreflect_indexes_with_ascdescr5  descr   rM   r   rO   )r7   rQ   rH   Zschema_prefixZparent_id_argsr  r4  r6  r8   r8   r9   r   z  s>   

	
 


		z/ComponentReflectionTest.define_reflected_tablesc                 C   s   t ttjdtj S rW   rX   rZ   r8   r8   r9   r[   (  s    z'ComponentReflectionTest.temp_table_namec                 C   s   t ttj}|  }t||tdtjddtdtdtdtjtj	ddtj
 dtd	dfi |}tjjjrtjjjrt|d
tdtj
  t|dtd d S )NrA   TrB   r\   rE   r   user_tmp_uq_r   user_tmp_ixrS   r]   rT   r^   )r   r   r6   r[   r   r   r_   r`   ra   r   rY   r$   r   rI   rL   r2   rb   r   rU   r#   rc   r8   r8   r9   rO   .  s6    

z*ComponentReflectionTest.define_temp_tablesc              
   C   s   t jjjrdh}nt }dD ]}|}|r6| d| }|d }||v rJdnd}d| d| d	| }t|d
t| ||v rd}	|rt dr| d|	 }	d|	 d| d}
t|d
t|
 t|dtd| d|  qd S )Nr  r  r  r  r   Z_vzMATERIALIZED r   zCREATE zVIEW z AS SELECT * FROM rS   	mat_indexoraclezCREATE INDEX z ON z(data)rT   zDROP )	r   rI   materialized_viewsr2   setr   rU   r#   against)r7   rQ   rH   materializedre   fullnameZ	view_nameprefixrV   Z
index_namer   r8   r8   r9   rM   P  s*    
z$ComponentReflectionTest.define_viewsc                 C   sD   i }t j|v r|| t j|v r,|| t j|v r@|| |S r~   )r   r   updater   r   )rl   r   r   r   rH  r   r8   r8   r9   _resolve_kindk  s    





z%ComponentReflectionTest._resolve_kindc                 C   s<   t jjjs|  |  nt jjjs8|| |  d S r~   )r   rI   r   r2   clearrE  rK  )rl   r   rH  r8   r8   r9   _resolve_viewsu  s    



z&ComponentReflectionTest._resolve_viewsc              	      s   dd |t ju rdd |t ju r,dd d ddhtjjddd	d
|  hitjjj	s|d  
d tjj ddg tjjj	sd  dd	g tjjj	rtjjj	sd  d
|  g tjjj	s܈d  d
g  fdd| D }|S )Nc                 S   s   dS )NTr8   )_r8   r8   r9   r   ~  r   z8ComponentReflectionTest._resolve_names.<locals>.<lambda>c                 S   s   d| d vS Ntmpr   r8   r   r8   r8   r9   r     r   c                 S   s   d| d v S rP  r8   rR  r8   r8   r9   r     r   r/  r1  r-  r4  r6  r   c                    s>   i | ]6\}}|r|d   vr r4|d   v r||qS )r   r8   ).0r   vr   removedrH   Zscope_filterr8   r9   
<dictcomp>  s
   z:ComponentReflectionTest._resolve_names.<locals>.<dictcomp>)r    r   r   r   r   rK   r[   rI   r;  r2   addrK  r   r   temp_table_namesrb   items)rl   rH   r/   r   valuesr   r8   rU  r9   _resolve_names}  sD    





z&ComponentReflectionTest._resolve_namesc           	      C   s   |dft ji}|dft j|dft j|dft ji}| || |dft j|dft j|dft j|dft j|d	ft j|d
ft j|dft j|dft j|dft j|dft j||  ft ji}| ||||}| ||||}|S )Ndingalings_vemail_addresses_vusers_vr   r  r  r  r"  r+  r-  r/  r1  r4  r6  r+   r   rN  r[   rL  r\  )	rl   rH   r/   r   r   rH  r   r   r   r8   r8   r9   exp_options  s*    












z#ComponentReflectionTest.exp_optionsc           
      C   s   dd i}|df|i}|df||df||df|i}|  || |df||df||df||d	fdd
i|dfddi|df||df||df||df||df|||  f|i}| ||||}	| ||||	}	|	S )Ntextr]  r^  r_  r   r  r  r  r"  r*  r+  r,  r-  r/  r1  r4  r6  )rN  r[   rL  r\  )
rl   rH   r/   r   r   emptyrH  r   r   r   r8   r8   r9   exp_comments  s4    z$ComponentReflectionTest.exp_commentsc           
         s$  dt jd dfdd  fdd}|df dd	t jd
 d d dgi}|df dd	t jd
 d dg|df dd	t jd
 dt jd dt jd dg|df dd	t jd
 d dgi}| || |df|d ddd ddd dg|df|d d d dg|df|d d dg|df|ddd  dd!d  d"d#d  d$d%d g|d&f dg|d'f|d d d(g|d)f|d d* dg|d+f|d dg|d,f d-g|d.f|d d-g||  f|d d dgi}| ||||}	| ||||	}	|	S )/NFTc                 S   s*   | |t j|||d}|dkr&|d |S )N)r\   autoincrementtypedefaultr   r  omitre  )r+   r   pop)r\   autorg  r   r  r   r8   r8   r9   ro     s    
z0ComponentReflectionTest.exp_columns.<locals>.colc                    s"   dt jdd|} | fi |S )NTF)rj  rg  r  r+   r   )r\   rd   ro   r8   r9   pk  s    z/ComponentReflectionTest.exp_columns.<locals>.pkr]  r  rh  )rj  r  r  r  rD   r^  r  r  r_  r  r  r  r  r	  r   rA   r\   r   r  r  r  r"  r#  r   r$  r%  r&  r'  r)  r+  r-  r.  r/  r0  r1  r4  r5  r6  r`  )
rl   rH   r/   r   r   rm  rH  r   r   r   r8   rl  r9   exp_columns  s    

	




	
'z#ComponentReflectionTest.exp_columnsc                 C   s   h dS )N>   rg  rf  r  r\   r8   r   r8   r8   r9   _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 ur
t j|
d< q
| 
||	||}| ||||}|S )Nr  c                 W   s   t || |dS )N)constrained_columnsr\   r   )list)r\   r   colsr8   r8   r9   rm  V  s    z+ComponentReflectionTest.exp_pks.<locals>.pkr   r]  r  r^  r_  r   r  r  r  r  r  r   r!  r"  rA   r+  r-  r/  r1  r4  r6  r\   )r+   r   r   rI   Zmaterialized_views_reflect_pkr2   rN  r[   reflects_pk_namesr[  rL  r\  )rl   rH   r/   r   r   rm  rc  rH  r   r   valr   r8   r8   r9   exp_pksO  s>    

zComponentReflectionTest.exp_pksc                 C   s   ddhS )Nr\   rp  r8   r   r8   r8   r9   _required_pk_keys  s    z)ComponentReflectionTest._required_pk_keysc                    s  G dd d |t jd f fdd	}|dfg i}|dfg |dfg |dfg i}| || |d	f|d
gdgd	ddg|df|dgdgd	|dgdgddddg|df|dgdgd	g|dfg |dfg |df|dgdgdtjdg|df|dgdgdd dg|dfg |dfg |d fg ||  fg i}tjjj	s<||d	f 
  tjjj	s~| D ],}	|	D ] }
|
d! t jurXt j|
d!< qXqP| ||||}| ||||}|S )"Nc                   @   s   e Zd Zdd ZdS )z+ComponentReflectionTest.exp_fks.<locals>.ttc                 S   s   |d u pt jjj|kS r~   )r   r6   ri   r<  rl   r   r8   r8   r9   __eq__  s    z2ComponentReflectionTest.exp_fks.<locals>.tt.__eq__Nr;   r<   r=   rx  r8   r8   r8   r9   r     s   r   c                    s$   | ||t j|d ur|n  ||dS )N)rp  referred_columnsr\   r0   referred_schemareferred_tabler   rk  )rr  Zref_colZ	ref_table
ref_schemar\   r   r   r8   r9   fk  s    	z+ComponentReflectionTest.exp_fks.<locals>.fkr]  r^  r_  r   r  r	  r  r  r   r  r  r  r  r  r  r  r  r"  r+  r-  r.  rA   r1  )r}  r/  r0  r4  r6  r\   )r+   r   rN  r   rK   r[   r   rI   r9  r2   rM  named_constraintsr[  rL  r\  )rl   rH   r/   r   r   r  rH  r   r   valsrt  r   r8   r~  r9   exp_fks  sn    
#zComponentReflectionTest.exp_fksc                 C   s   h dS )N>   r{  r\   r|  rz  rp  r8   r   r8   r8   r9   _required_fk_keys  s    z)ComponentReflectionTest._required_fk_keysc           
      C   s
  dd ddddd}|dfg i}|dfg |dfg |dfg i}|  || |rf||df |d	d
d |dfg |dddd|ddddd|ddddd|dfg |d	tjddd|dtjdd|dddddd|dfg |dtjd|dtjdd|d fg |d!fg |d"fg |d#tjdd|d$fg |d%tjdd|d&fg |d'fg |d(d)d(d*id+|d,fg |d(d-d(d*id+||  fg |d.d/d|d0d1tj ddd2i}tjj	j
rtjjj
s||d'f   ||d,f   | ||||}	| ||||	}	|	S )3NF)r  column_sorting
duplicatesr  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 )	Nr8   )r  r   r\   dialect_optionsinclude_columnsr  r   expressionsc                    s   g | ]}| v rd n|qS r~   r8   rS  r   r  r8   r9   
<listcomp>	  s   zDComponentReflectionTest.exp_indexes.<locals>.idx.<locals>.<listcomp>Zduplicates_constraint)	r   rI   Zforeign_keys_reflect_as_indexZ#unique_constraints_reflect_as_indexZ*reflect_indexes_with_ascdesc_as_expressionr2   rq  r+   r   )r\   r  r  r  r  rr  Zfk_reqZdup_reqZsorting_expressionr   origr8   r  r9   r     s4    


z0ComponentReflectionTest.exp_indexes.<locals>.idxr]  r^  r_  r   rD   rC  r   r  r	  r  T)r\   r  r  r  r  r3  r2  )r\   r  r  )r\   r  r  r  r  r  r  r  r  r  r"  r+  r-  r.  r/  r0  r1  r4  r5  r7  )r?  )r\   r  r6  r8  r   rA  r\   r@  )r\   r  r  )rN  extendr+   r   r[   r   rY   r   rI   r=  r2   r>  rM  rL  r\  )
rl   rH   r/   r   r   r   rH  r   r   r   r8   r8   r9   exp_indexes  s    
%



5z#ComponentReflectionTest.exp_indexesc                 C   s   h dS )N>   r   r  r\   r8   r   r8   r8   r9   _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g |d
ddddd|dfg |dtjtjd|dddddd|dfg |dfg |dfg |dfg |dfg |dfg |dfg |dfg ||  fg |dd tj d!i}	|ri |||	S | ||	||}
| ||||
}
|
S d S )"NF)duplicates_indexis_indexr   c                 W   s8   t jj}|r|jsdS t|| |d}|r2||d< |gS )Nr8   )r   r\   r   r  )r   rI   Z*unique_index_reflect_as_unique_constraintsr2   rq  )r\   r  r  r   rr  reqr   r8   r8   r9   ucf  s    
z+ComponentReflectionTest.exp_ucs.<locals>.ucr]  r^  r_  r   r  r  r  r2  T)r\   r  r  r  rD   )r\   r  r  r  r  r  )r\   r  r   r  r"  r+  r-  r/  r1  r4  r6  r\   r@  r   )rN  r+   r   r[   r   rY   rL  r\  )rl   rH   r/   r   r   all_r  rH  r   r   r   r8   r8   r9   exp_ucs^  sZ    		
 zComponentReflectionTest.exp_ucsc                 C   s   ddhS )Nr\   r   r8   r   r8   r8   r9   _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}| |v S )N(r   )`)lowerreplace)rl   r   r   r8   r8   r9   rx    s    z2ComponentReflectionTest.exp_ccs.<locals>.tt.__eq__Nry  r8   r8   r8   r9   r     s   r   c                    s    | ||dS )N)sqltextr\   r   r8   )rb  r\   r   r~  r8   r9   cc  s    z+ComponentReflectionTest.exp_ccs.<locals>.ccr]  r^  r_  r   r  r  r
  r  r  r   r  z$address_id > 0 and address_id < 1000r  r   r  r"  r+  r-  r/  r1  r4  r6  )N)strrN  r+   r   r[   rL  r\  )
rl   rH   r/   r   r   r  rH  r   r   r   r8   r~  r9   exp_ccs  sF    

zComponentReflectionTest.exp_ccsc                 C   s   ddhS )Nr\   r  r8   r   r8   r8   r9   _required_cc_keys  s    z)ComponentReflectionTest._required_cc_keysc                 C   s    t |}ttjj| v  d S r~   )r   r*   r   r   rK   get_schema_namesr{   r8   r8   r9   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   rK   r)   r{   r8   r8   r9   test_has_schema  s    z'ComponentReflectionTest.test_has_schemac                 C   s8   |j ddttjjid}t|}ttjj| v  dS )z
test #7300r   barZschema_translate_mapN)execution_optionsr&   r   r   rK   r   r*   r  r{   r8   r8   r9   %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   rK   r   r*   r  r)   r{   r8   r8   r9   test_has_schema_w_translate_map   s    z7ComponentReflectionTest.test_has_schema_w_translate_mapc              
   C   s   t |}td| v  t|d |td zVtd| v  t|d |  td| v  t|d W |td n|td 0 d S )NZfoo_barzCREATE SCHEMA foo_barzDROP SCHEMA foo_bar)r   r)   r  r  executer#   rq   r*   r{   r8   r8   r9   test_schema_cache  s    z)ComponentReflectionTest.test_schema_cachec                 C   s$   t  }t| t|jds J d S )Nr<  )r   r4   r   hasattrri   )rl   enginer8   r8   r9   test_dialect_initialize  s    z/ComponentReflectionTest.test_dialect_initializec                 C   s   t |}t|j|jj d S r~   )r   r   r<  ri   r{   r8   r8   r9   test_get_default_schema_name$  s    z4ComponentReflectionTest.test_get_default_schema_nameforeign_keyorder_byr   
use_schemac           	         s   |rt j}nd }h d t|}|r:dd ||D }n
||} fdd|D }|dkrrg d}t|| ng d}tt|| d S )N>   r6  r+  r-  r/  r1  r4  r"  c                 S   s   g | ]}|d  r|d  qS )r   r8   )rS  Zrecr8   r8   r9   r  D  s   z@ComponentReflectionTest.test_get_table_names.<locals>.<listcomp>c                    s   g | ]}| vr|qS r8   r8   rS  tZ_ignore_tablesr8   r9   r  K  r   r  rB  )r  r  r  )r   rK   r   Zget_sorted_table_and_fkc_namesget_table_namesr   sorted)	rl   r|   r  r  rH   rs   r   r   answerr8   r  r9   test_get_table_names)  s     	

z,ComponentReflectionTest.test_get_table_namesc                 C   sl   t |}|rtj}nd }||}tjjjrRtt	|ddg t|
|dg ng d}tt	|| d S )Nr^  r_  r]  )r]  r^  r_  )r   r   rK   get_view_namesr   rI   rE  r2   r   r  get_materialized_view_names)rl   r|   r  rs   rH   r   r  r8   r8   r9   test_get_view_namesT  s    

z+ComponentReflectionTest.test_get_view_namesc                 C   s,   t |}| }tt|dtj g d S rW   )r   Zget_temp_table_namesr   r  r   rY   rl   r|   rs   rY  r8   r8   r9   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  r8   r8   r9   test_get_temp_view_namesk  s    z0ComponentReflectionTest.test_get_temp_view_namesc                 C   s   |  | d S r~   )_test_get_commentsrl   r|   r8   r8   r9   test_get_commentsr  s    z)ComponentReflectionTest.test_get_commentsc                 C   s   |  |tjj d S r~   )r  r   r   rK   r  r8   r8   r9   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 )NrG   r"  r  )r   rd  r   r   r   r+  r\   )rl   r|   rH   rs   expno_cstr8   r8   r9   r  {  s&    




z*ComponentReflectionTest._test_get_comments)FFzuse_views,use_schemac                 C   sj  |rt j}nd }| jj| jj }}|r0g d}nddg}t|}t|||fD ]\}	}
|}|j|	|d}tt	|dkt	| t
|
jD ]\}}t|j|| d  || d j}|j}t|tjjr|j}tdr|tjtjfv rtj}tt	t|j|jtjtjtjtjtjtjtj gdkd	|j|j|| d |f  |j!s|| d
 d u sJ qqNd S )Nr_  r^  r]  r  r  rG   r   r\   rf  rD  z%s(%s), %s(%s)rg  )"r   rK   r   r  r  r   zipr   r*   len	enumeratecolumnsr   r\   	__class__rf  r   r_   r   Z
TypeEnginer   rG  	sql_typesDater   rF  __mro__intersectionr   NumericZTimer   Z_BinaryrC   )rl   r|   Z	use_viewsr  rH   r  	addressesr   rs   re   tableZschema_namerr  iro   ctypeZ	ctype_defr8   r8   r9   r     s\    

z(ComponentReflectionTest.test_get_columnsc                 C   s6   |   }| j| }t|t |d}| j||dd d S )Nr   F)Zstrict_constraints)r[   r   r   r   Zassert_tables_equal)rl   r|   re   rf   Zreflected_user_tmpr8   r8   r9   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\   )
r[   r   r   r   r*   r  r  r  r   r\   )rl   r|   re   rf   rs   rr  r  ro   r8   r8   r9   test_get_temp_table_columns  s    

z3ComponentReflectionTest.test_get_temp_table_columnsc                 C   s.   t |}|d}tdd |D g d d S )Nr   c                 S   s   g | ]}|d  qS r   r8   rS  ro   r8   r8   r9   r    r   zFComponentReflectionTest.test_get_temp_view_columns.<locals>.<listcomp>)rA   r\   r   )r   r   r   )rl   r|   rs   rr  r8   r8   r9   test_get_temp_view_columns  s    
z2ComponentReflectionTest.test_get_temp_view_columns)Fc                 C   s  |rt jj}nd }| jj| jj }}t|}| j|d}|j|j	|d}| 
|g|||j	f g| j |j|j	|d}	|||j	f d }
t|	d |
 t jj  t|	d d W d    n1 s0    Y  | jjj	}| 
|j||dg|||f g| j d S )NrG   rp  r\   r   )r   r   rK   r   r  r  r   ru  r   r\   _check_listrv  r   rI   rs  fail_ifr+  )rl   r|   r  rH   r  r  rs   r  Z
users_consZ	addr_consZexp_colsr  r8   r8   r9   r     s*    
,
z.ComponentReflectionTest.test_get_pk_constraintc                 C   s~  |rt j}nd }| jj| jj }}t|}|}tjjj	r|j
|j|d}|d }	tjj  t|	d d W d    n1 s0    Y  t|	d | t|	d |j t|	d dg t|	d	 d
g |j
|j|d}
|
d }	tjj   t|	d d u W d    n1 s0    Y  t|	d | t|	d |j t|	d dg t|	d	 dg | jjj}t|j
||dg  d S )NrG   r   r\   r  r{  r|  rz  r  rp  r	  r  )r   rK   r   r  r  r   r   rI   r9  r2   r   r\   r  r  r   implicitly_named_constraintsr*   r+  )rl   r|   r  rH   r  r  rs   Zexpected_schemaZusers_fkeysfkey1Z
addr_fkeysr  r8   r8   r9   r     s2    
,0
z-ComponentReflectionTest.test_get_foreign_keysc           
      C   s  |  d|jj dtjj dtjj \}}}t|}||j}t	t
|d |d }t	|d tjj t	|d |j t	|d d	g t	|d
 dg |j|jtjjd}t	t
|d |d }	t|	d d |jjfv  t	|	d |j t	|	d d	g t	|	d
 dg d S )Nz%s.local_tablez%s.remote_tablez%s.remote_table_2r   r   r{  r|  rz  rA   rp  r.  rG   r0  )r   ri   r<  r   r   rK   r   r   r\   r   r  r*   )
rl   r|   r-  r/  r1  rs   Zlocal_fkeysr  Zremote_fkeysZfkey2r8   r8   r9   "test_get_inter_schema_foreign_keysI  s8    




z:ComponentReflectionTest.test_get_inter_schema_foreign_keysc                 C   sz   |rt j}nd }t|}|jd|d}| j|d}| |||df | j | jjj	}| |j||d|||f | j d S )Nr  rG   )
r   rK   r   r   r  r  r  r   r+  r\   )rl   r|   r  rH   rs   indexesr  r  r8   r8   r9   r   o  s    

z(ComponentReflectionTest.test_get_indexes)r4  r7  )r6  r8  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   rq  r  r\   )rl   r|   tnameZixnamers   r  Zexpected_indexesr  r8   r8   r9   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   r[   r   r  r  r  )rl   r|   rs   r\   	reflectedr  r8   r8   r9   &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   rA  )r  r   r\   r   r  c                 S   s   g | ]}|d  dkr|qS )r\   rA  r8   rS  r   r8   r8   r9   r    r   zGComponentReflectionTest.test_get_temp_table_indexes.<locals>.<listcomp>)	r   r[   r   ri  r   rI   index_reflects_included_columnsr2   r   )rl   r|   rs   re   r  indexpectedr8   r8   r9   test_get_temp_table_indexes  s    

z3ComponentReflectionTest.test_get_temp_table_indexesc                 C   s  |rt j}nd }tddgddg dddg dddd	d
gdddgdddgdgtdd}td|tdtdtdtdtdtj	td	tdtd
td|d}|D ]"}|
tj|d d|d i q|| t|}t|jd|dtdd}	t }
tt|t|	 t||	D ]N\}}|dd }|rP|
| t|dd d  |dd  t|| q,t }td|||d}	dd |	jD }dd |	jD dg}||rJ |
rt|
| t|t  | jjj}t|j||dg  d S )NZunique_ar   )r\   r   Zunique_a_b_c)r   br   Zunique_c_a_b)r   r   r  Zunique_asc_keyZascr   zi.have.dotsr  zi have spacesr   r\   r   Ztesttblr  r  rG   r   r  r   r  )r   rH   c                 S   s   h | ]
}|j qS r8   r   r  r8   r8   r9   	<setcomp>  r   zFComponentReflectionTest.test_get_unique_constraints.<locals>.<setcomp>c                 S   s   h | ]}t |tjr|jqS r8   )r   r_   r   r\   )rS  Zuqr8   r8   r9   r    s   )r   rK   r  operator
itemgetterr   r   r_   r   r   Zappend_constraintr   rp   r   r   rF  r   r  r  ri  rX  r   r  constraints
differencer  r   r+  r\   )rl   rQ   r|   r  rH   Zuniquesr  r  rs   r  Znames_that_duplicate_indexr  ZreflZdupeZreflected_metadataZ	idx_namesZuq_namesr  r8   r8   r9   r     sz    







z3ComponentReflectionTest.test_get_unique_constraintsc                 C   s@   |rt j}nd }t|}dD ]}|j||d}tt| qd S )Nr  rG   )r   rK   r   r   r*   bool)rl   r|   r  rH   rs   viewrT  r8   r8   r9   r     s    z0ComponentReflectionTest.test_get_view_definitionc                 C   sp   t |}tt |d W d    n1 s00    Y  tt |d W d    n1 sb0    Y  d S )NZview_does_not_existr  )r   r   r!   r   r{   r8   r8   r9   'test_get_view_definition_does_not_exist#  s
    
(
z?ComponentReflectionTest.test_get_view_definition_does_not_existc                 C   sF   t |}dD ]4\}}||}dd |D | }|ddsJ qdS )a  test that 'autoincrement' is reflected according to sqla's policy.

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

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

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

        ))r  r  )r  r  )r  r  c                 S   s   i | ]}|d  |qS r   r8   r  r8   r8   r9   rW  A  r   zBComponentReflectionTest.test_autoincrement_col.<locals>.<dictcomp>re  TN)r   r   get)rl   r|   rs   r  cnamerr  Zid_r8   r8   r9   test_autoincrement_col+  s
    
z.ComponentReflectionTest.test_autoincrement_colc                 C   s   t tj}|rtjnd }tjjjr\|jd|d}t	t
|t |jd|d}t	t
|t n6tt |jd|d W d    n1 s0    Y  d S )Nr  rG   r+  )r   r   r6   rK   r   rI   r   r2   r   r*   r   r5   r   r   )rl   r  rs   rH   r   r8   r8   r9   r   D  s    


z.ComponentReflectionTest.test_get_table_optionsc                    s   t tj tjjjrV|rtjnd  jd} fdd j	dD }t
|| n0tt    W d    n1 s|0    Y  d S )NrG   c                    s    i | ]}|f j |d qS )rG   )r   )rS  r  rs   rH   r8   r9   rW  \  s   zHComponentReflectionTest.test_multi_get_table_options.<locals>.<dictcomp>)r   r   r6   r   rI   r   r2   rK   get_multi_table_optionsr  r   r   r   )rl   r  r   r  r8   r  r9   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|v rB|g d tj|v rZ|ddg tj|v rr|ddg | r~| |d< |r||d< || |||dd	}	|g}
|tjkr|	 }|
d
 |
| |tjkr|	 }|
d |
| t  |
|	fS )Nr  )r/   r   )r"  r  does-not-existr^  r  r]  rH   r   )rH   r/   r   r   r/   r   )r   r   r   r  r   r   r  r    r   copyri  append)rH   r/   r   r   Zsingle_reflect_fnZ
exp_methodrs   rd   r   r  kwsZnkwr|   r8   r9   provide_fixtureg  sD    










z>ComponentReflectionTest.get_multi_exp.<locals>.provide_fixturer8   )rl   r|   r  r8   r  r9   get_multi_expe  s    .z%ComponentReflectionTest.get_multi_expc                 C   sL   |||||t j| j\}}}|D ]&}	|  |jf i |	}
t|
| q d S r~   )r   r   ra  rq   r  r   rl   r  rH   r/   r   r   rs   r  r  rd   resultr8   r8   r9   #test_multi_get_table_options_tables  s    
z;ComponentReflectionTest.test_multi_get_table_options_tablesc           
      C   sH   |||||t j| j\}}}|D ]"}	|  t|jf i |	| q d S r~   )r   r   rd  rq   r   Zget_multi_table_comment)
rl   r  rH   r/   r   r   rs   r  r  rd   r8   r8   r9   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rb  c                 S   s   t dd|  S )Nz['\" ]r   )resubr  r  r8   r8   r9   _clean  s    z:ComponentReflectionTest._check_expressions.<locals>._cleanc                    s   i | ]\}} ||qS r8   r8   )rS  erT  r  r8   r9   rW    r   z>ComponentReflectionTest._check_expressions.<locals>.<dictcomp>c                    s   g | ]} |qS r8   r8   )rS  r  r	  r8   r9   r    r   z>ComponentReflectionTest._check_expressions.<locals>.<listcomp>)r  r   r5   r   rZ  )rl   r  r  err_msgr8   r	  r9   _check_expressions  s    
 z*ComponentReflectionTest._check_expressionsc           	      C   s   |d u rt ||| nt t|t|| t||D ]~\}}t|t|B D ]d}||v sh||v rL||v rL| d| d| }|dv r| || || | qLt || || | qLq4d S )Nz - )r  r  )r   r  r  rF  r  )	rl   r  r  req_keysmsgrr  r   r
  r8   r8   r9   r    s    z#ComponentReflectionTest._check_listc                 C   s\   t t| t|  |D ]8}|| ||  }}|rF|g|g }}| |||| qd S r~   )r   rF  keysr  )rl   r  r  r  
make_listsr   r  r  r8   r8   r9   _check_table_dict  s    z)ComponentReflectionTest._check_table_dictc                 C   sR   |||||t j| j\}}}|D ],}	|  |jf i |	}
| |
|| j q d S r~   )r   r   rn  rq   get_multi_columnsr  ro  r   r8   r8   r9   test_get_multi_columns  s    
	z.ComponentReflectionTest.test_get_multi_columnsc                 C   sV   |||||t j| j\}}}|D ]0}	|  |jf i |	}
| j|
|| jdd q d S )NT)r  )r   r   ru  rq   Zget_multi_pk_constraintr  rv  r   r8   r8   r9   test_get_multi_pk_constraint  s    

z4ComponentReflectionTest.test_get_multi_pk_constraintc                 C   sT   t jjjsP||fD ]<}| D ].}t|dkrtdd |D r|j|d qqd S )Nr   c                 s   s"   | ]}| d dtjfv V  qdS )r\   N)r  r+   r   )rS  rT  r8   r8   r9   	<genexpr>	  s   z7ComponentReflectionTest._adjust_sort.<locals>.<genexpr>r  )r   rI   r  r2   r[  r  anysort)rl   r  r  r   objrt  r8   r8   r9   _adjust_sort  s    
z$ComponentReflectionTest._adjust_sortc                 C   sd   |||||t j| j\}}}|D ]>}	|  |jf i |	}
| |
|dd  | |
|| j q d S )Nc                 S   s   t | d S )Nrp  tupledr8   r8   r9   r   	  r   zEComponentReflectionTest.test_get_multi_foreign_keys.<locals>.<lambda>)r   r   r  rq   Zget_multi_foreign_keysr  r  r  r   r8   r8   r9   test_get_multi_foreign_keys	  s    

z3ComponentReflectionTest.test_get_multi_foreign_keysc                 C   sR   |||||t j| j\}}}|D ],}	|  |jf i |	}
| |
|| j q d S r~   )r   r   r  rq   Zget_multi_indexesr  r  r   r8   r8   r9   test_get_multi_indexes	  s    
z.ComponentReflectionTest.test_get_multi_indexesc                 C   sd   |||||t j| j\}}}|D ]>}	|  |jf i |	}
| |
|dd  | |
|| j q d S )Nc                 S   s   t | d S )Nr   r  r  r8   r8   r9   r   ?	  r   zKComponentReflectionTest.test_get_multi_unique_constraints.<locals>.<lambda>)r   r   r  rq   Zget_multi_unique_constraintsr  r  r  r   r8   r8   r9   !test_get_multi_unique_constraints/	  s    
z9ComponentReflectionTest.test_get_multi_unique_constraintsc                 C   sd   |||||t j| j\}}}|D ]>}	|  |jf i |	}
| |
|dd  | |
|| j q d S )Nc                 S   s   t | d S Nr  r  r  r8   r8   r9   r   R	  r   zJComponentReflectionTest.test_get_multi_check_constraints.<locals>.<lambda>)r   r   r  rq   Zget_multi_check_constraintsr  r  r  r   r8   r8   r9    test_get_multi_check_constraintsB	  s    
z8ComponentReflectionTest.test_get_multi_check_constraintsr   r   r   r   r   r   r   r   methodc                 C   sF   t |}t||}tt |d W d    n1 s80    Y  d S )NZtable_does_not_exists)r   getattrr   r!   )rl   r#  r|   rs   r   r8   r8   r9   test_not_existing_tableU	  s    

z/ComponentReflectionTest.test_not_existing_tablec              	      s   t j  fdd}tjt d|R ttd( t|t	dt
 d  W d    n1 s\0    Y  W d    n1 sz0    Y  d S )Nc                     s&   | di }td|d<  | i |S )NZunreflectableerr)N
some_table)
setdefaultr"   )r   r   urZmcr8   r9   patchedu	  s    z;ComponentReflectionTest.test_unreflectable.<locals>.patchedr  r&  r'  )r   r  r+   patchobjectr   r"   r   Zreflect_tabler   r   )rl   r|   r+  r8   r*  r9   test_unreflectabler	  s    z*ComponentReflectionTest.test_unreflectabler   c                    s   t  }|rtjnd  |j| |dd t|}| }|rp|| 7 }z|| 7 }W n tyn   Y n0  r fdd|D }t	t
|jt
| d S )NF)rH   r   Zresolve_fksc                    s   g | ]}  d | qS )r   r8   r  rG   r8   r9   r  	  r   z9ComponentReflectionTest.test_metadata.<locals>.<listcomp>)r   r   rK   reflectr   r  r  r  r   r   r  r   )rl   r|   r  r   mrs   r   r8   rG   r9   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   試蛇ẟΩ✨rb  c                 S   s   i | ]}|d  |d qS r  r8   r  r8   r8   r9   rW  	  r   zAComponentReflectionTest.test_comments_unicode.<locals>.<dictcomp>)r3  r4  r   r   r   r   r   r   r   r   )rl   r|   rQ   rs   tcrr  valuer  r8   r8   r9   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 )
Nr2  r4  u&   🐍🧙🝝🧙‍♂️🧙‍♀️r   u&   🎩🁰🝑🤷‍♀️🤷‍♂️rb  r   r\   r   r5  )rl   r|   rQ   rs   r6  r   r8   r8   r9   test_comments_unicode_full	  s    

z2ComponentReflectionTest.test_comments_unicode_full)N)NN)NF)mr;   r<   r=   run_insertsrun_deletesr   r>   rR   r   r[   rO   rM   rL  rN  r\  r    r   r   ra  rd  rn  propertyro  ru  rv  r  r  r  r  r  r  r  r  r   rI   Zschema_reflectionr  r  r  r  Zschema_create_deleter  r  r  r   r   rJ   r  r  rY  r  rL   rb   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  r   r  r   r   r  r  r  r  r  r  r  r  r  r  r   r   r"  r%  r.  r   r1  r8  Zcomment_reflection_full_unicoder9  r8   r8   r8   r9   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 Nrc  )r   r   rl   r|   rQ   r8   r8   r9   table_no_columns	  s    
z#TableNoColumnsTest.table_no_columnsc                 C   s<   t d| t|dtd t|dtd || d S )Nrc  rS   z*CREATE VIEW empty_v AS SELECT * FROM emptyrT   zDROP VIEW IF EXISTS empty_v)r   r   rU   r#   r   rA  r8   r8   r9   view_no_columns	  s    

z"TableNoColumnsTest.view_no_columnsc                 C   s$   t dt |d}tt|jg  d S )Nrc  r   r   r   r   rq  r   )rl   r|   rB  t2r8   r8   r9   test_reflect_table_no_columns	  s    z0TableNoColumnsTest.test_reflect_table_no_columnsc                 C   s2   t |}t|dg  | }t|dg i d S )Nrc  r@  )r   r   r   r  )rl   r|   rB  rs   multir8   r8   r9   !test_get_columns_table_no_columns	  s    z4TableNoColumnsTest.test_get_columns_table_no_columnsc                 C   s*   t  }|| t|jdgs&J d S r@  )r   r/  rF  r   r  )rl   r|   rB  r0  r8   r8   r9   "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   rD  )rl   r|   rC  rE  r8   r8   r9   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 )NrJ  )r   )NrJ  )r   r   r   r  r   r   )rl   r|   rC  rs   rG  r8   r8   r9    test_get_columns_view_no_columns	  s    z3TableNoColumnsTest.test_get_columns_view_no_columnsN)r;   r<   r=   r   r   r   r   rB  rC  rF  rH  rI  rI   r   rK  rL  r8   r8   r8   r9   r?  	  s   


r?  c                   @   s4  e Zd ZdZejddgddd Ze dd Zdd	 Zej	j
d
d Zej	jejddddddd Zej	j
ejddddddd Zej	jdd Zej	jdd Zej	jdd Zej	jdd Zdd  Zej	jd!d" Zej	jejejejejejej	jfej ej	jfd#dd$d% Z!ej	jd&d' Z"ejdd(dej	j#fddd)ej	j$fi dd*ej	j$fi d*dej	j%fddd+ej	j&fdd+dej	j'fd,dd-d. Z(eje)e*+d/d0fe)d/d0fe,e*- d1fe)e*+d2d3ej	j.fe)e*+d4d5ej	j.fe/e01 d6fe)e*2d7e*2d8 d3ej	j.fd9dej	j3d:d; Z4dS )<ComponentReflectionTestExtraTF)paramsc                 C   s   |j rtjS d S d S r~   )paramr   rK   )rl   requestr8   r8   r9   use_schema_fixture	  s    z/ComponentReflectionTestExtra.use_schema_fixturec                    s   t j fdd}|S )Nc                 3   s   t  fV    d S r~   )r   r   )r   r|   rQ   rQ  r8   r9   go	  s    z:ComponentReflectionTestExtra.inspect_for_table.<locals>.go)
contextlibcontextmanager)rl   rQ   r|   rQ  rS  r8   rR  r9   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  r8   r8   r9   	normalize	
  s    z5ComponentReflectionTestExtra.ck_eq.<locals>.normalizec                    s"   g | ]}|d   |d dqS )r\   r  r\   r  r8   )rS  itemr[  r8   r9   r  
  s   z6ComponentReflectionTestExtra.ck_eq.<locals>.<listcomp>c                 S   s   | d S r!  r8   r]  r8   r8   r9   r   
  r   z4ComponentReflectionTestExtra.ck_eq.<locals>.<lambda>r  c                 S   s   | d S r!  r8   r_  r8   r8   r9   r   
  r   )r  r   )rl   r  r  r8   r^  r9   ck_eq
  s    
z"ComponentReflectionTestExtra.ck_eqc              	   C   sb   |d0\}}t d|tdtd|d W d    n1 s>0    Y  | |jd|dg  d S )Nr+  rD   r  rG   )r   r   r_   r   r`  r   )rl   rQ   rV  rH   r   r8   r8   r9   #test_check_constraint_no_constraint
  s    $z@ComponentReflectionTestExtra.test_check_constraint_no_constraint	my_inlineZMyInlineNconstraint_namer   c                 C   s   |dR\}}t d|tdt ddtdt tjd|dtdtd	|d
 W d    n1 s`0    Y  |jd|d
}| ||ptj	ddg d S )Nsa_ccrA   TrB   r   a > 1 AND a < 5r   rD   rE   rG   a > 1 and a < 5r\  )
r   r   r   r_   r   r   r   r`  r+   r   rl   rQ   rV  rc  rH   r   r  r8   r8   r9   test_check_constraint_inline+
  s.    $z9ComponentReflectionTestExtra.test_check_constraint_inlineZmy_ck_constZ	MyCkConstc              	   C   s|   |d8\}}t d|tdt tjd|d|d W d    n1 sF0    Y  |jd|d}| ||pltjddg d S )Nrd  r   za = 1 OR (a > 2 AND a < 5)r   rG   za = 1 or a > 2 and a < 5r\  )	r   r   r   r_   r   r   r`  r+   r   rg  r8   r8   r9    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 d    n1 s0    Y  |jd|d}| |dddd	ddt	j
ddg d S )Nrd  rA   TrB   r   re  r  zb > 1 AND b < 5rb  r   r   rD   rE   Zsome_uqzc > 1 AND c < 5Zcc1Z	some_c_uqrG   zc > 1 and c < 5r\  zb > 1 and b < 5rf  )r   r   r   r_   r   r   r   r   r`  r+   r   )rl   rQ   rV  rH   r   r  r8   r8   r9   test_check_constraint_mixedm
  s4    
$
z8ComponentReflectionTestExtra.test_check_constraint_mixedc              	   C   s   |dT\}}t d|tdtddtdttdt}td|jj|jj|jj W d   n1 sb0    Y  |d}t	|d	 d
 g d dS )ztest for #12894Zsa_multi_indexColumn1TrB   Column2Column3ZIndex_ExampleNr   r   )rm  rk  rl  )
r   r   r   r$   r   rm  rk  rl  r   r   )rl   rQ   rV  rH   r   r@   r  r8   r8   r9   test_index_column_order
  s     "
z4ComponentReflectionTestExtra.test_index_column_orderc              	      s  t d|tdtdtdtdtdtd}tdt|jj|jjt|jj	 dtdt
|jj td	|jj |  t }d	dgd
i dg} fdd}||d  G dd dt}G fdddt}tjjjrrdg d|dd|dgd
d}	||	 |d|	 dd g|d dgd
d}
||
 ||
 t|d| t }t d| d}nNtd4 t|d| t }t d| d}W d    n1 s0    Y  | || jj d S )Nr  xr  yzt_idxa  long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string Z
t_idx_longZt_idx_2F)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   rI   r  r2   r  r\   r(  )entryr  r8   r9   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|v od|v pd|v S )Nr  ro  rp  r  )rl   r   olr8   r8   r9   rx  
  s    zbComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.lower_index_str.__eq__Nry  r8   r8   r8   r9   lower_index_str
  s   rw  c                       s   e Zd Z fddZdS )z^ComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.coalesce_index_strc                    s   d|  v o |v S )Ncoalesceru  rw  long_strr8   r9   rx  
  s    zeComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.coalesce_index_str.__eq__Nry  r8   ry  r8   r9   coalesce_index_str
  s   r{  )Nrq  Nz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   ro  rq  rp  rx  r   r   r  r   rI   Z reflect_indexes_with_expressionsr2   insertr  r   r   r   r	   Z!compare_table_index_with_expectedr  r\   )rl   rQ   r|   r  rs   r  rt  rw  r{  Z
expr_indexZexpr_index_longr   rE  r8   )r|   rz  r9   %test_reflect_expression_based_indexes
  sl    &
		

.
zBComponentReflectionTestExtra.test_reflect_expression_based_indexesc                 C   s   t d|tdtdtdtd}td|jj}dg|j|jj d< |	| t
|}|d}t|ddgdgdtjdg t|d	 d
 d|jj  dg t dt |d}tt|jd	 j|jj d dg d S )Nr  ro  r  rp  rr  includeF)r\   r   r  r  r  r   r  z
%s_includer   )r   r   r   r$   r   ro  r  r  r\   r   r   r   r   r+   r   r   rq  r  )rl   rQ   r|   r  r   rs   r   rE  r8   r8   r9   test_reflect_covering_index
  sD    



z8ComponentReflectionTestExtra.test_reflect_covering_indexc                 G   sB   t d|gdd t|D R  }|| dd t|dD S )Nr  c                 S   s   g | ]\}}t d | |qS )zt%dr   )rS  r  type_r8   r8   r9   r  +  r   zAComponentReflectionTestExtra._type_round_trip.<locals>.<listcomp>c                 S   s   g | ]}|d  qS )rf  r8   r  r8   r8   r9   r  /  r   )r   r  rp   r   r   )rl   r|   rQ   r   r  r8   r8   r9   _type_round_trip'  s    
z-ComponentReflectionTestExtra._type_round_tripc                 C   sH   |  ||tddD ],}t|tjs*J t|jd t|jd qd S )N   r  )r  r  r  r   r   Z	precisionZscale)rl   r|   rQ   typr8   r8   r9   test_numeric_reflection1  s    z4ComponentReflectionTestExtra.test_numeric_reflectionr  c                 C   s   |  |||dd }t|tjr4t|tjsbJ n.t|tjrRt|tjsbJ nt|tjsbJ t|jd t|jt	s~J d S )N4   r   )
r  
issubclassr  ra   r   r:  r   r   lengthint)rl   r|   rQ   r  r  r8   r8   r9   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  r8   r  r8   r8   r9   rW  Y  s   zIComponentReflectionTestExtra.test_nullable_reflection.<locals>.<dictcomp>)r   r  )r   r   r   rp   r   r   r   )rl   r|   rQ   r  r8   r8   r9   test_nullable_reflectionO  s    
z5ComponentReflectionTestExtra.test_nullable_reflectionZCASCADEzSET NULLz	NO ACTIONZRESTRICTzexpected,ondelete,onupdatec                    s"  i }|r||d< |r||d< |d u r(|}t d|tdtdddd t d|tdtddtd	ttd
ddtdtddd t d|tdtddtdtdddtdttjdgdgfddi|dd || t|}|	dd d  t
 fdd D i  |	dd d  t
 | d S )Nondeleteonupdatero  rA   TrB   r   r  Zx_idzx.idxidr   test
   userr\   rE   Fr  tidztable.idZmyfkr   r0   c                    s   i | ]} | r| | qS r8   r8   )rS  r   optsr8   r9   rW    r   zMComponentReflectionTestExtra.test_get_foreign_key_options.<locals>.<dictcomp>)r   r   r   r   r   r_   r   r   r   r   r   )rl   r|   rQ   r  r  r  r0   rs   r8   r  r9   test_get_foreign_key_options`  sT    *	
z9ComponentReflectionTestExtra.test_get_foreign_key_options10z'?10'?z1|truez3 + 5z3\+5z(3 * 5)z3\*5zcurrent_timestamp|now|getdate35zdatatype, default, expected_regc           	   	   C   sd   t d|tdtddtd||d}|| t|dd d }td	d
|}t||tj	d d S )Nr  rA   TrB   Zthecol)Zserver_defaultr   rg  z	[\(\) \']r   )flags)
r   r   r   rp   r   r   r  r  r   
IGNORECASE)	rl   rQ   r|   datatyperg  Zexpected_regr  r  Zreflected_sanitizedr8   r8   r9   test_server_defaults  s    
z1ComponentReflectionTestExtra.test_server_defaults)5r;   r<   r=   r   r   r   rQ  rV  r`  rI   r   ra  Z"inline_check_constraint_reflectionr   rh  ri  rj  Zindexes_check_column_orderrn  Zindexes_with_expressionsr}  r  r  r  r>  r  r  r   ra   r:  ZNVARCHARZnvarchar_typesZNCHARr  r  Z1foreign_key_constraint_option_reflection_ondeleteZ1foreign_key_constraint_option_reflection_onupdateZ1fk_constraint_option_reflection_ondelete_noactionZ1fk_constraint_option_reflection_onupdate_restrictZ1fk_constraint_option_reflection_ondelete_restrictr  r   r_   rb  r   trueZexpression_server_defaultsr   r   nowZliteral_columnZserver_defaultsr  r8   r8   r8   r9   rM  	  s   

	
 


Z
*


'
6rM  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   rA   rB   rE  t1idzt1.id)r   r%   r   r   r   rP   r8   r8   r9   rR     s    

z NormalizedNameTest.define_tablesc                 C   s~   t  }ttddd|tjd}|jd }|jj|jj	s>J t  }|j
tjdd d |jd jj|jd jj	szJ d S )	NrE  Tr  r   r   c                 S   s   |   dv S )Nr   rE  ru  )r\   r0  r8   r8   r9   r     r   zINormalizedNameTest.test_reflect_lowercase_forced_tables.<locals>.<lambda>)only)r   r   r%   r   r6   r   r   r  r   rA   r/  )rl   r   Zt2_refZt1_refZm3r8   r8   r9   $test_reflect_lowercase_forced_tables  s    

z7NormalizedNameTest.test_reflect_lowercase_forced_tablesc                 C   sP   dd t tj D }t|d  |d   t|d  |d   d S )Nc                 S   s   g | ]}|  d v r|qS )r  ru  r  r8   r8   r9   r    s   z;NormalizedNameTest.test_get_table_names.<locals>.<listcomp>r   r   )r   r   r6   r  r   upperr  )rl   Z
tablenamesr8   r8   r9   r    s
    z'NormalizedNameTest.test_get_table_namesN)	r;   r<   r=   r   r   r>   rR   r  r  r8   r8   r8   r9   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 v  t|d d d  t|d d d  d S )	Ncomputed_default_tablec                 S   s   i | ]}|d  |qS r   r8   r  r8   r8   r9   rW    r   zLComputedReflectionTest.test_computed_col_default_not_set.<locals>.<dictcomp>Z42with_defaultrg  normalcomputed_col)r   r   r6   r   r*   r   )rl   rs   rr  Zcol_datar8   r8   r9   !test_computed_col_default_not_set  s    

z8ComputedReflectionTest.test_computed_col_default_not_setc                 C   s   t tj}|d}dd |D }dD ]}td|| v q&|d }td|v  td|d v  t| |d d d td	|d v tjj	j
 tjj	j
rt|d d	 tjjj
 d S )
Nr  c                 S   s   i | ]}|d  |qS r   r8   r  r8   r8   r9   rW     r   zKComputedReflectionTest.test_get_column_returns_computed.<locals>.<dictcomp>)rA   r  r  computedr  r  	normal+42	persisted)r   r   r6   r   r*   r   r[  r   rI   "computed_columns_reflect_persistedr2   "computed_columns_default_persisted)rl   rs   rr  rD   r   compDatar8   r8   r9    test_get_column_returns_computed  s$    




z7ComputedReflectionTest.test_get_column_returns_computedc                 C   sX   t d|| v  || d }t| |d | tjjjrTt d|v  t|d | d S )Nr  r  r  )r*   r   r[  r   rI   r  r2   r   )rl   rD   columnr  r  r  r8   r8   r9   check_column1  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   r8   r  r8   r8   r9   rW  =  r   zLComputedReflectionTest.test_get_column_returns_persisted.<locals>.<dictcomp>computed_no_flagr  computed_virtualznormal+2Fcomputed_storedz	normal-42T)r   r   r6   r   r  r   rI   r  r2   computed_columns_virtualcomputed_columns_storedrl   rs   rr  rD   r8   r8   r9   !test_get_column_returns_persisted9  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  rG   c                 S   s   i | ]}|d  |qS r   r8   r  r8   r8   r9   rW  [  r   zXComputedReflectionTest.test_get_column_returns_persisted_with_schema.<locals>.<dictcomp>r  z	normal/42r  znormal/2Fr  z	normal*42T)r   r   r6   r   rK   r  r   rI   r  r2   r  r  r  r8   r8   r9   -test_get_column_returns_persisted_with_schemaT  s2    


zDComputedReflectionTest.test_get_column_returns_persisted_with_schemaN)r;   r<   r=   r  r  r  r  r   rI   rJ   r  r8   r8   r8   r9   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  id1rE  r   Tr   r   r(     alwaysr   	incrementminvaluemaxvaluecyclecacher  )r  r   rG   )
r   r   r   r   r   rI   rJ   r2   r   rK   rP   r8   r8   r9   rR   y  s>    
z$IdentityReflectionTest.define_tablesc                 C   s   t jjjrd}t|D ]}||vr|| q|rtt|t| |D ]T}|dkrjt|| || k qH|dv rt|| || k qHt|| || | qHqt|| n$t|d |d  t|d |d  d S )Nr  r  >   r  r  r   r  )	r   rI   Zidentity_columns_standardr2   rq  ri  r   r  r*   )rl   r7  r  approxZcommon_keysr   r8   r8   r9   check  s     
	zIdentityReflectionTest.checkc                 C   s  t tj}|d|d }|D ]}|d dkr@td|v  q"|d dkrd|v r`t|d  t|d d  td|v  | j|d td	d
d
d
dd	d
ddd q"|d dkr"d|v rt|d  t|d d  td|v  | j|d tddddddddd	d q"d S )Nr   rE  r\   r  r   r  re  rg  Fr   r  Tr  r   r   r   r  r(  r  )	r   r   r6   r   r)   r*   r   r  r5   rl   rs   rr  ro   r8   r8   r9   r     sR    
		z,IdentityReflectionTest.test_reflect_identityc                 C   s   t tj}|jdtjd}|D ]~}|d dkr<td|v  q|d dkrd|v r\t|d  t|d d  td|v  | j|d t	d	d
ddddddd	d qd S )Nr   rG   r\   r  r   r  re  rg  Tr  r   r  Fr  r  )
r   r   r6   r   rK   r)   r*   r   r  r5   r  r8   r8   r9   test_reflect_identity_schema  s.    
	z3IdentityReflectionTest.test_reflect_identity_schema)r;   r<   r=   r:  r;  r   r   r>   rR   r  r   r   rI   rJ   r  r8   r8   r8   r9   r  s  s   
!,r  c                   @   s<   e Zd ZdZedd Zejjdd Z	ejj
dd ZdS )	CompositeKeyReflectionTestTc                 C   s   t d|tdttdttdtdtjdddddd dd	}t d
|tdtddtdttdttdtdtjg d|jj	|jj
|jjgddd dd		 d S )Ntb1rA   attrr\   r  Zpk_tb1r   Tr  tb2rB   pidpattrpnamer  r  r  Zfk_tb1_name_id_attr)r   r   r   r  ra   r_   r   r   r   r\   rA   r  )r7   rQ   r  r8   r8   r9   rR     s2    
z(CompositeKeyReflectionTest.define_tablesc                 C   s0   t |}|| jjj}t|dg d d S )Nrp  r\   rA   r  )r   r   r   r  r\   r   r  )rl   r|   rs   rC   r8   r8   r9   test_pk_column_order  s    z/CompositeKeyReflectionTest.test_pk_column_orderc                 C   sZ   t |}|| jjj}tt|d |d }t|dg d t|dg d d S )Nr   r   rz  r  rp  r  )r   r   r   r  r\   r   r  r  )rl   r|   rs   Zforeign_keysr  r8   r8   r9   test_fk_column_order&  s    z/CompositeKeyReflectionTest.test_fk_column_orderN)r;   r<   r=   r   r>   rR   r   rI   r=  r  r   r  r8   r8   r8   r9   r     s   

r  )r   rM  r?  r   r   r?   r   r  r  r  r  r   )HrT  r  r  r3   r_   r   r   r   r   r   r   r   r	   r
   r   Z	provisionr   r   rH   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+   rQ   r  Z
TablesTestr,   r?   r   ZTestBaser   r   r   r   r   r?  rM  r  ZComputedReflectionFixtureTestr  r  r  __all__r8   r8   r8   r9   <module>	   s    Mg&               [5   y+a 1