o
    fqi                    @   s  d dl Z d dlZd dlZd dlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z! ddl"m#Z# ddl"m$Z$ ddl"m%Z% dd l&m'Z' dd!l&m(Z( dd"lm)Z) dd#lm*Z* dd$l+m,Z, dd%l-m.Z. dd&lm/Z/ dd'lm0Z0 dd(lm1Z1 dd)lm2Z2 dd*lm3Z3 d+\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   s2   t jjjrddlm} tjt|j	dddS t j
S )Nr   )poolclass)Z	poolclassscope)options)r   requirementsZindependent_connectionsenabled
sqlalchemyr.   r   testing_enginedictZ
StaticPooldb)clsr.    r9   o/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/sqlalchemy/testing/suite/test_reflection.py
setup_bind;   s   
z"OneConnectionTablesTest.setup_bindN)__name__
__module____qualname__classmethodr;   r9   r9   r9   r:   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r*t d|tdtddtdtdtj	d tjj
r3| | tjjjr?| | d S d S )	N
test_tableidTprimary_keydata2   test_table_sschema)r   r   r   r   r   requiresschemasr3   r   test_schemaview_reflectiondefine_viewshas_temp_tabledefine_temp_tablesr8   metadatar9   r9   r:   define_tablesM   s&   


zHasTableTest.define_tablesc                 C   st   d}t |dt| t |dtd tjjjr8dtjtjf }t |dt| t |dtdtj  d S d S )Nz1CREATE VIEW vv AS SELECT id, data FROM test_tableafter_createbefore_dropzDROP VIEW vvz9CREATE VIEW %s.vv AS SELECT id, data FROM %s.test_table_szDROP VIEW %s.vv)	r   listenr#   r   rJ   rK   r3   r   rL   )r8   rR   queryr9   r9   r:   rN   c   s"   
zHasTableTest.define_viewsc                 C      t ttjdtj S NZ	user_tmp_r   r   r7   identr8   r9   r9   r:   temp_table_namey      zHasTableTest.temp_table_namec              	   C   s   t ttj}|  }t||tdtjddtdtdfi |}t	j
jjrBt	j
jjrDt|dtdtj  t|dtd	 d S d S d S )
NrB   TrC   namerF   rT   =create temporary view user_tmp_v as select * from user_tmp_%srU   drop view user_tmp_v)r   r   r7   r]   r   r   saINTVARCHARr   rJ   rM   r3   temporary_viewsr   rV   r#   r[   r8   rR   kw
table_nameuser_tmpr9   r9   r:   rP      s2   zHasTableTest.define_temp_tablesc                 C   sl   t j '}tt jj|d tt jj|d tt jj|d W d    d S 1 s/w   Y  d S )NrA   rG   nonexistent_table)r   r7   beginr*   dialect	has_tabler)   selfconnr9   r9   r:   test_has_table   s
   "zHasTableTest.test_has_tablec              	   C   s   t tj}t|d td|tdt}t|d |	tj zt|d |
  t|d W |tj d S |tj w )NrA   Z	new_tablecol)r   r   r7   r*   rm   r   r   r   r)   createclear_cachedrop)ro   rR   inspntr9   r9   r:   test_has_table_cache   s   
z!HasTableTest.test_has_table_cachec                 C   s~   t j 0}tt jjj|dt jd tt jjj|dt jd tt jjj|dt jd W d    d S 1 s8w   Y  d S )NrA   rH   rG   rj   )r   r7   rk   r)   rl   rm   rL   r*   rn   r9   r9   r:   test_has_table_schema   s"   "z"HasTableTest.test_has_table_schemac                 C   sH   t j }tt jjj|ddd W d    d S 1 sw   Y  d S )NrA   Znonexistent_schemarH   )r   r7   rk   r)   rl   rm   rn   r9   r9   r:   !test_has_table_nonexistent_schema   s   "z.HasTableTest.test_has_table_nonexistent_schemac                 C      t |}t|d d S Nvvr   r*   rm   ro   
connectionrv   r9   r9   r:   test_has_table_view   s   z HasTableTest.test_has_table_viewc                 C   s"   t |}|  }t|| d S N)r   r]   r*   rm   )ro   r   rv   r]   r9   r9   r:   test_has_table_temp_table   s   z&HasTableTest.test_has_table_temp_tablec                 C   r{   N
user_tmp_vr~   r   r9   r9   r:   test_has_table_temp_view   s   z%HasTableTest.test_has_table_temp_viewc                 C   s   t |}t|dtj d S r|   )r   r*   rm   r   rL   r   r9   r9   r:   test_has_table_view_schema   s   z'HasTableTest.test_has_table_view_schemaN)r<   r=   r>   __backend__r?   rS   rN   r]   rP   rq   rx   r   rJ   rK   ry   rz   viewsr   rO   r   rM   re   r   r   r9   r9   r9   r:   r@   J   s6    







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 d S )NrA   rB   TrC   rE   rF   data2my_idxrH   my_idx_s)r   r   r   r   r$   crE   r   rJ   rK   r3   r   rL   )r8   rR   ttr9   r9   r:   rS      s$   
zHasIndexTest.define_tablesrl   	inspectorkindargnamesc                    s   |dkr
 fddS t  jS )Nrl   c                     s   t jjj g| R i |S r   )r   r7   rl   	has_index)akrp   r9   r:   <lambda>       z)HasIndexTest._has_index.<locals>.<lambda>)r   r   )ro   r   rp   r9   r   r:   
_has_index   s   
zHasIndexTest._has_indexc              	   C   s$  |  ||}|ddsJ |ddrJ |ddrJ |ddr"J |ddr)J |ddr0J td| jjjj}td|td	ttdd	}|	| |	| z6|d
krh|ddr\J |ddrcJ |j
  |dddu sqJ |dddu szJ W || || d S || || w )NrA   r   r   rj   Znonexistent_idxZmy_idx_2Ztest_table_2Zmy_idx_3foor   T)r   r$   tablesrA   r   r   r   r   r   rs   __self__rt   ru   )ro   r   r   rR   methidxtblr9   r9   r:   test_has_index  s6   




zHasIndexTest.test_has_indexc                 C   s`   |  ||}|ddtjdsJ |ddtjdrJ |ddtjdr$J |ddtjdr.J d S )NrA   r   rH   r   rj   Znonexistent_idx_s)r   r   rL   )ro   r   r   r   r9   r9   r:   test_has_index_schema  s   
z"HasIndexTest.test_has_index_schemaN)r<   r=   r>   r   __requires__r?   rS   r   combinationsr   r   r   rJ   rK   r   r9   r9   r9   r:   r      s    

r   c                   @   s   e Zd ZdZdd Zdd Zedddge e ejj	dd	 Z
e e ejjd
d Ze e ejjdd ZdS )BizarroCharacterTestTc                   C      t jddddddS )N)Z	plainname)z(3))zcol%p)z[brack]
columnnamer   r   r   r9   r9   r9   r:   column_names1     z!BizarroCharacterTest.column_namesc                   C   r   )N)plain)z(2))z
per % cent)z
[brackets]	tablenamer   r   r9   r9   r9   r:   table_names:  r   z BizarroCharacterTest.table_namesuse_compositeFc           
      C   s  t ||t|tddddd}|r|tdtdd |r?t d|tdtddtdttd	ttdd	g|jj|jjgdd nt d|tdtddtdt	|jjdd |
| t }t d||d
}|j| }	|jj|	jd stJ |r|jj|	jd sJ dS dS )ztests for #10275rB   T)keyrD   test_needs_fkid2rC   otherrefref2autoload_withr      N)r   r   r   append_columnrb   ForeignKeyConstraintr   rB   r   r   
create_allr   r   r   
referencesr   )
ro   r   rR   r   r   r   r   m2o2t1r9   r9   r:   test_fk_refC  sD   


z BizarroCharacterTest.test_fk_refc              	   C   sL   t ||t|tt dd || t|}t||d d d d d S )NTrC   r   identitystartr   r   r   r   r   r   r   r   get_columnsro   r   r   r   rR   rv   r9   r9   r:   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 )NrB   TrC   some commentcommentr   r   r   r   r   r   r   r   r   r   r9   r9   r:   test_reflect_comments  s   
z*BizarroCharacterTest.test_reflect_commentsN)r<   r=   r>   r   r   r   r   Z	variationrJ   !foreign_key_constraint_reflectionr   identity_columnsr   comment_reflectionr   r9   r9   r9   r:   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   rX   )NZ
ident_tmp_rZ   ro   r9   r9   r:   r     r^   zTempTableElementsTest.tablenamec              	   C   sL   t ||tdtt dd || t|}t||d d d d d S )NrB   TrC   r   r   r   r   r   ro   r   r   rR   rv   r9   r9   r:   r     s   
 z+TempTableElementsTest.test_reflect_identityc              	   C   sP   t ||tdtddtdtdd || t|}t||d d d d S )	NrB   TrC   Zfoobarr   r   r   r   r   r   r9   r9   r:   r     s   
z+TempTableElementsTest.test_reflect_commentsN)r<   r=   r>   r   r   r   fixturer   rJ   r   r   Ztemp_table_comment_reflectionr   r9   r9   r9   r:   r     s    

r   c                   @   s   e Zd ZdZdZedd Zdd Zedd Zee	j
jd	d
 Zedd Zedd Zee	j
jdd Zee	j
jdd Zee	j
jdd Zee	j
jdd Zee	j
jdd ZdS )QuotedNameArgumentTestonceTc                 C   s  t d|tdttdtdtdtdtdttjdddtd	dtjdd
dtjdgdgddtj	dddddd t
jjjr}t d|tdttdtdtdtdtdttjdddtddtjdddtjdgdgddtj	dddddd t d|tdtddtdtdd t
jjjrt
jjjrddg}ndg}|D ]4}dtjjjd| tjjj|f }t|dt| t|dtd tjjjd|   qd S d S )!Nquote ' onerB   r_   rF   rE   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relatedrC   r   z"CREATE VIEW %s AS SELECT * FROM %sview %srT   rU   zDROP VIEW %s)r   r   r   r   rb   PrimaryKeyConstraintr$   UniqueConstraintr   CheckConstraintr   rJ   symbol_names_w_double_quoter3   view_column_reflectionr   r7   rl   Zidentifier_preparerquoter   rV   r#   )r8   rR   namesr_   rW   r9   r9   r:   rS     s   









z$QuotedNameArgumentTest.define_tablesc                 C   s   t ddt jjf| S )N)r   r   )r   r   rJ   r   )fnr9   r9   r:   quote_fixtures  s   
z%QuotedNameArgumentTest.quote_fixturesc                 C   sh   t tj}tjjjr||}tt	|t
 d S tt || W d    d S 1 s-w   Y  d S r   )r   r   r7   r   rJ   reflect_table_optionsr3   get_table_optionsr*   
isinstancer6   r   NotImplementedError)ro   r_   rv   resr9   r9   r:   test_get_table_options  s   



"z-QuotedNameArgumentTest.test_get_table_optionsc                 C   s    t tj}|d| sJ d S )Nr   )r   r   r7   get_view_definitionro   r_   rv   r9   r9   r:   test_get_view_definition"  s   
z/QuotedNameArgumentTest.test_get_view_definitionc                 C      t tj}||sJ d S r   )r   r   r7   r   r   r9   r9   r:   test_get_columns(     
z'QuotedNameArgumentTest.test_get_columnsc                 C   r   r   )r   r   r7   get_pk_constraintr   r9   r9   r:   test_get_pk_constraint-  r   z-QuotedNameArgumentTest.test_get_pk_constraintc                 C   r   r   )r   r   r7   get_foreign_keysr   r9   r9   r:   test_get_foreign_keys2     
z,QuotedNameArgumentTest.test_get_foreign_keysc                 C   r   r   )r   r   r7   get_indexesr   r9   r9   r:   test_get_indexes8  r   z'QuotedNameArgumentTest.test_get_indexesc                 C   r   r   )r   r   r7   get_unique_constraintsr   r9   r9   r:   test_get_unique_constraints>  r   z2QuotedNameArgumentTest.test_get_unique_constraintsc                 C   r   r   )r   r   r7   get_table_commentr   r9   r9   r:   test_get_table_commentD  r   z-QuotedNameArgumentTest.test_get_table_commentc                 C   r   r   )r   r   r7   get_check_constraintsr   r9   r9   r:   test_get_check_constraintsJ  r   z1QuotedNameArgumentTest.test_get_check_constraintsN)r<   r=   r>   Zrun_create_tablesr   r?   rS   r   r   r   rJ   r   r   r   r   r   r   r   r   unique_constraint_reflectionr   r   r   check_constraint_reflectionr   r9   r9   r9   r:   r     s<    
R



r   c              
   C   s   t jd dd t jjfdd}t jtjtjtjdd}t jtj	tj
tjtjtjtj	tj
B tj	tjB dd}t jddd	d}||||| S )
Nc                   S   s   t jS r   )r   rL   r9   r9   r9   r:   r   U  s    z$_multi_combination.<locals>.<lambda>rI   r   r0   r   TF
use_filter)r   r   rJ   rK   r    DEFAULT	TEMPORARYANYr   TABLEVIEWMATERIALIZED_VIEWZANY_VIEW)r   rI   r0   r   filter_namesr9   r9   r:   _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 d S r   )define_reflected_tablesr   rJ   rK   r3   r   rL   rQ   r9   r9   r:   rS   t  s   
z%ComponentReflectionTest.define_tablesc                 C   s  |r|d }nd}t jjjrtd| ddf}nd}td|tdtjd	d
tdt	dddtdt
 ddtdtjg|R  tjddddtd|d	d
}td|tdtjd	d
tdtjtd| dddtdtjtd| tdtdd	d tjd!d"dtjddd#d$d|d	d
 td%|tdtjtd&tjt|jjtd'td(d	d)tjdd*d+d|d	d td,|td-tjd	d.d/tdtd(d0d1td2td(d3d1td4td5d6d1|d7d8 td9|tdtd(|d:d8 t jjjrR|d u rtd;|td-tjd	d
tdtd(td<td=t jj d	tjjjd> n7td?|td-tjd	d
td@tdAtjjj tdtd(|d	d tdB|td-tjd	d
tdtd(|d	d t jjjrtdC|jj|jjd	d  tdD|jj|jj|jj |stdE|tdFtdd	dG}tdH|td-tjd	d
tdFtdd	dG}t jjjrt jjjrtdI|jj  tdJ|jj  t jj jr| !|| |st jj"jr| #| d S d S d S )KN. z%susers.user_id
user_id_fkr   r9   usersuser_idTrC   test1   Fnullabletest2parent_user_id	test2 > 0zz_test2_gt_zerousers check constraintr_   r   test2 <= 1000rI   r   
dingalingsdingaling_id
address_idz%semail_addresses.address_idzz_email_add_id_fgdi fk commentid_userrE      )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_testrB   
id comment)rD   r   data % commentr   d2)Comment types type speedily ' " \ '' Fun!d3*   Comment
withescapesthe test % ' " \ table comment)rI   r   no_constraints"no
constraintshasescapedcommentlocal_table	remote_idz%s.remote_table_2.id)r   rI   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   rJ   self_referential_foreign_keysr3   r   r   r   rb   rc   CHARFloatr   r   r   r   r   r  r   cross_schema_fk_reflectionr   rL   r7   rl   default_schema_namer   r$   r  r  indexes_with_ascdescreflect_indexes_with_ascdescrA  descr   rN   r   rP   )r8   rR   rI   Zschema_prefixZparent_id_argsr  r@  rB  r9   r9   r:   r
  z  s@  

	
 


		z/ComponentReflectionTest.define_reflected_tablesc                 C   rX   rY   rZ   r\   r9   r9   r:   r]   (  r^   z'ComponentReflectionTest.temp_table_namec                 C   s   t ttj}|  }t||tdtjddtdtdtdtjtj	ddtj
 dtd	dfi |}tjjjrVtjjjrXt|d
tdtj
  t|dtd d S d S d S )NrB   TrC   r_   rF   r   user_tmp_uq_r   user_tmp_ixrT   r`   rU   ra   )r   r   r7   r]   r   r   rb   rc   rd   r   r[   r$   r   rJ   rM   r3   re   r   rV   r#   rf   r9   r9   r:   rP   .  s8   

z*ComponentReflectionTest.define_temp_tablesc              
   C   s   t jjjr	dh}nt }dD ]b}|}|r| d| }|d }||v r%dnd}d| d| d	| }t|d
t| ||v rad}	|rOt drO| d|	 }	d|	 d| d}
t|d
t|
 t|dtd| d|  qd S )Nr  r  r'  r  r  _vzMATERIALIZED r  zCREATE zVIEW z AS SELECT * FROM rT   	mat_indexoraclezCREATE INDEX z ON z(data)rU   zDROP )	r   rJ   materialized_viewsr3   setr   rV   r#   against)r8   rR   rI   materializedrh   fullnameZ	view_nameprefixrW   Z
index_namer   r9   r9   r:   rN   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  )ro   r   r   r   rV  r   r9   r9   r:   _resolve_kindk  s   





z%ComponentReflectionTest._resolve_kindc                 C   sB   t jjjs|  |  d S t jjjs|| |  d S d S r   )r   rJ   r   r3   clearrS  rY  )ro   r   rV  r9   r9   r:   _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	sLd  dd	g tjjj	rVtjjj	sad  d
|  g tjjj	snd  d
g  fdd| D }|S )Nc                 S   s   dS )NTr9   )_r9   r9   r:   r   ~  s    z8ComponentReflectionTest._resolve_names.<locals>.<lambda>c                 S   s   d| d vS Ntmpr   r9   r   r9   r9   r:   r         c                 S   s   d| d v S r^  r9   r`  r9   r9   r:   r     ra  r;  r=  r9  r@  rB  r   c                    s>   i | ]\}}|r|d   vr r|d   v r||qS )r   r9   ).0r   vr  removedrI   Zscope_filterr9   r:   
<dictcomp>  s    z:ComponentReflectionTest._resolve_names.<locals>.<dictcomp>)r    r  r  r   r   rL   r]   rJ   rH  r3   addrY  r   r   temp_table_namesre   items)ro   rI   r0   r  valuesr   r9   rd  r:   _resolve_names}  sD   





z&ComponentReflectionTest._resolve_namesc           	      C   s   |dft ji}|dft j|dft j|dft ji}| || |dft j|dft j|dft j|dft j|d	ft j|d
ft j|dft j|dft j|dft j|dft j||  ft ji}| ||||}| ||||}|S )Ndingalings_vemail_addresses_vusers_vr   r  r  r'  r.  r7  r9  r;  r=  r@  rB  r+   r  r\  r]   rZ  rk  )	ro   rI   r0   r   r  rV  r   r   r   r9   r9   r:   exp_options  s*   












z#ComponentReflectionTest.exp_optionsc           
      C   s   dd i}|df|i}|df||df||df|i}|  || |df||df||df||d	fdd
i|dfddi|df||df||df||df||df|||  f|i}| ||||}	| ||||	}	|	S )Ntextrl  rm  rn  r   r  r  r'  r.  r6  r7  r8  r9  r;  r=  r@  rB  )r\  r]   rZ  rk  )
ro   rI   r0   r   r  emptyrV  r   r   r   r9   r9   r:   exp_comments  s4   z$ComponentReflectionTest.exp_commentsc           
         s$  dt jd dfdd  fdd}|df dd	t jd
 d d dgi}|df dd	t jd
 d dg|df dd	t jd
 dt jd dt jd dg|df dd	t jd
 d dgi}| || |df|d ddd ddd dg|df|d d d dg|df|d d dg|df|ddd  dd!d  d"d#d  d$d%d g|d&f dg|d'f|d d d(g|d)f|d d* dg|d+f|d dg|d,f d-g|d.f|d d-g||  f|d d dgi}| ||||}	| ||||	}	|	S )/NFTc                 S   s*   | |t j|||d}|dkr|d |S )N)r_   autoincrementtypedefaultr   r  omitrt  )r+   r  pop)r_   autorv  r   r  r   r9   r9   r:   rr     s   
z0ComponentReflectionTest.exp_columns.<locals>.colc                    s"   dt jdd|} | fi |S )NTF)ry  rv  r  r+   r  )r_   rg   rr   r9   r:   pk  s   z/ComponentReflectionTest.exp_columns.<locals>.pkrl  r  rw  )ry  r  r  r!  rE   rm  r(  r)  rn  r  r  r  r  r  r   rB   r_   r   r  r  r'  r.  r/  r   r0  r1  r2  r3  r5  r7  r9  r:  r;  r<  r=  r@  rA  rB  ro  )
ro   rI   r0   r   r  r|  rV  r   r   r   r9   r{  r:   exp_columns  s   

	




	
'z#ComponentReflectionTest.exp_columnsc                 C      h dS )N>   ru  rv  r_   r  r9   r   r9   r9   r:   _required_column_keysK     z-ComponentReflectionTest._required_column_keysc                 C   sH  t jd ddd}|d d}tjjjr|df|di}n|df|i}|df||df||d	f|i}| || |d
f|d|df|d|df|dddd|df|d|df||df|d|df|d|df|d|df||df|d||  f|di}	tjjjs|		 D ]}
|
d d urt j|
d< q| 
||	||}| ||||}|S )Nr  c                 W   s   t || |dS )N)constrained_columnsr_   r   )list)r_   r   colsr9   r9   r:   r|  V  s   z+ComponentReflectionTest.exp_pks.<locals>.pkr   rl  r  rm  rn  r   r  r  r  r'  r  r,  r-  r.  rB   r7  r9  r;  r=  r@  rB  r_   )r+   r  r   rJ   Zmaterialized_views_reflect_pkr3   r\  r]   reflects_pk_namesrj  rZ  rk  )ro   rI   r0   r   r  r|  rr  rV  r   r   valr   r9   r9   r:   exp_pksO  s@   



zComponentReflectionTest.exp_pksc                 C      ddhS )Nr_   r  r9   r   r9   r9   r:   _required_pk_keys  r  z)ComponentReflectionTest._required_pk_keysc                    s  G dd d |t jd f fdd	}|dfg i}|dfg |dfg |dfg i}| || |d	f|d
gdgd	ddg|df|dgdgd	|dgdgddddg|df|dgdgd	g|dfg |dfg |df|dgdgdtjdg|df|dgdgdd dg|dfg |dfg |d fg ||  fg i}tjjj	s||d	f 
  tjjj	s| D ]}	|	D ]}
|
d! t jurt j|
d!< qq| ||||}| ||||}|S )"Nc                   @      e Zd Zdd ZdS )z+ComponentReflectionTest.exp_fks.<locals>.ttc                 S   s   |d u p
t jjj|kS r   )r   r7   rl   rI  ro   r   r9   r9   r:   __eq__  s   z2ComponentReflectionTest.exp_fks.<locals>.tt.__eq__Nr<   r=   r>   r  r9   r9   r9   r:   r         r   c                    s$   | ||t j|d ur|n  ||dS )N)r  referred_columnsr_   r1   referred_schemareferred_tabler   rz  )r  ref_colZ	ref_table
ref_schemar_   r   r   r9   r:   fk  s   	z+ComponentReflectionTest.exp_fks.<locals>.fkrl  rm  rn  r   r  r  r  r  r   r  r!  r  r'  r  r   r  r(  r.  r7  r9  r:  rB   r=  )r  r;  r<  r@  rB  r_   )r+   r  r\  r   rL   r]   r   rJ   rE  r3   r[  named_constraintsrj  rZ  rk  )ro   rI   r0   r   r  r  rV  r   r   valsr  r   r9   r  r:   exp_fks  sr   

#

zComponentReflectionTest.exp_fksc                 C   r~  )N>   r  r  r  r_   r  r9   r   r9   r9   r:   _required_fk_keys  r  z)ComponentReflectionTest._required_fk_keysc           
      C   s  dd ddddd}|dfg i}|dfg |dfg |dfg i}|  || |r3||df |d	d
d |dfg |dddd|ddddd|ddddd|dfg |d	tjddd|dtjdd|dddddd|dfg |dtjd|dtjdd|d fg |d!fg |d"fg |d#tjdd|d$fg |d%tjdd|d&fg |d'fg |d(d)d(d*id+|d,fg |d(d-d(d*id+||  fg |d.d/d|d0d1tj ddd2i}tjj	j
rtjjj
s||d'f   ||d,f   | ||||}	| ||||	}	|	S )3NF)r#  column_sorting
duplicatesr  c                    s   t jj}t jj}t jj}|r|jr|r|jsdS |t|| tjg d}	 r? |	d< |jr?|	d  |	d< }
 fdd|
D |	d< |rE| |	d< |	gS )	Nr9   )r#  r   r_   dialect_optionsinclude_columnsr  r   expressionsc                    s   g | ]
}| v r
d n|qS r   r9   rb  r   r  r9   r:   
<listcomp>	  s    zDComponentReflectionTest.exp_indexes.<locals>.idx.<locals>.<listcomp>Zduplicates_constraint)	r   rJ   Zforeign_keys_reflect_as_indexZ#unique_constraints_reflect_as_indexZ*reflect_indexes_with_ascdesc_as_expressionr3   r  r+   r  )r_   r#  r  r  r  r  Zfk_reqZdup_reqZsorting_expressionr   origr9   r  r:   r     s4   


z0ComponentReflectionTest.exp_indexes.<locals>.idxrl  rm  rn  r   rE   rQ  r   r  r  r  T)r_   r  r  r  r  r?  r>  )r_   r#  r  )r_   r#  r  r!  r  r  r%  r'  r)  r(  r.  r7  r9  r:  r;  r<  r=  r@  rA  rC  )rL  )r_   r  rB  rD  r   rN  r_   rM  )r_   r  r#  )r\  extendr+   r  r]   r   r[   r   rJ   rJ  r3   rK  r[  rZ  rk  )
ro   rI   r0   r   r  r   rV  r   r   r   r9   r9   r:   exp_indexes  s   
%



5z#ComponentReflectionTest.exp_indexesc                 C   r~  )N>   r   r#  r_   r9   r   r9   r9   r:   _required_index_keysZ  r  z,ComponentReflectionTest._required_index_keysFc                 C   s(  d dd ddd}|dfg i}|dfg |dfg |dfg i}|  || |d	fg |d
ddddd|dfg |dtjtjd|dddddd|dfg |dfg |dfg |dfg |dfg |dfg |dfg |dfg ||  fg |dd tj d!i}	|ri |||	S | ||	||}
| ||||
}
|
S )"NF)duplicates_indexis_indexr   c                 W   s8   t jj}|r|jsdS t|| |d}|r||d< |gS )Nr9   )r   r_   r   r  )r   rJ   Z*unique_index_reflect_as_unique_constraintsr3   r  )r_   r  r  r   r  reqr   r9   r9   r:   ucf  s   
z+ComponentReflectionTest.exp_ucs.<locals>.ucrl  rm  rn  r   r  r  r  r>  T)r_   r  r  r  rE   )r_   r  r  r  r%  r&  )r_   r  r   r'  r.  r7  r9  r;  r=  r@  rB  r_   rM  r   )r\  r+   r  r]   r   r[   rZ  rk  )ro   rI   r0   r   r  all_r  rV  r   r   r   r9   r9   r:   exp_ucs^  sZ   		
 zComponentReflectionTest.exp_ucsc                 C   r  )Nr_   r   r9   r   r9   r9   r:   _required_unique_cst_keys  r  z1ComponentReflectionTest._required_unique_cst_keysc           
         s   G dd dt  d fdd	}|dfg i}|dfg |dfg |dfg i}| || |d	f|d
tj|ddddg|df|dddg|dfg |dfg |dfg |dfg |dfg |dfg |dfg |dfg ||  fg i}| ||||}	| ||||	}	|	S )Nc                   @   r  )z+ComponentReflectionTest.exp_ccs.<locals>.ttc                 S   s(   |  dddddd}| |v S )N(r  )`)lowerreplace)ro   r   r   r9   r9   r:   r    s   z2ComponentReflectionTest.exp_ccs.<locals>.tt.__eq__Nr  r9   r9   r9   r:   r     r  r   c                    s    | ||dS )N)sqltextr_   r   r9   )rq  r_   r   r  r9   r:   cc  s   z+ComponentReflectionTest.exp_ccs.<locals>.ccrl  rm  rn  r   r  r  r  r  r  r   r  z$address_id > 0 and address_id < 1000r$  r   r'  r.  r7  r9  r;  r=  r@  rB  r   )strr\  r+   r  r]   rZ  rk  )
ro   rI   r0   r   r  r  rV  r   r   r   r9   r  r:   exp_ccs  sF   

zComponentReflectionTest.exp_ccsc                 C   r  )Nr_   r  r9   r   r9   r9   r:   _required_cc_keys  r  z)ComponentReflectionTest._required_cc_keysc                 C   s    t |}ttjj| v  d S r   )r   r*   r   r   rL   get_schema_namesr   r9   r9   r:   test_get_schema_names  s   z-ComponentReflectionTest.test_get_schema_namesc                 C   s,   t |}t|tjj t|d d S )Nsa_fake_schema_foo)r   r*   
has_schemar   r   rL   r)   r   r9   r9   r:   test_has_schema  s   z'ComponentReflectionTest.test_has_schemac                 C   s8   |j ddttjjid}t|}ttjj| v  dS )z
test #7300r   barZschema_translate_mapN)execution_optionsr&   r   r   rL   r   r*   r  r   r9   r9   r:   %test_get_schema_names_w_translate_map  s   z=ComponentReflectionTest.test_get_schema_names_w_translate_mapc                 C   sD   |j ddttjjid}t|}t|tjj t|d d S )Nr   r  r  r  )	r  r&   r   r   rL   r   r*   r  r)   r   r9   r9   r:   test_has_schema_w_translate_map   s   z7ComponentReflectionTest.test_has_schema_w_translate_mapc              
   C   s   t |}td| v  t|d |td z,td| v  t|d |  td| v  t|d W |td d S |td w )NZfoo_barzCREATE SCHEMA foo_barzDROP SCHEMA foo_bar)r   r)   r  r  executer#   rt   r*   r   r9   r9   r:   test_schema_cache  s   "z)ComponentReflectionTest.test_schema_cachec                 C   s$   t  }t| t|jdsJ d S )NrI  )r   r5   r   hasattrrl   )ro   enginer9   r9   r:   test_dialect_initialize  s   z/ComponentReflectionTest.test_dialect_initializec                 C   s   t |}t|j|jj d S r   )r   r   rI  rl   r   r9   r9   r:   test_get_default_schema_name$  s   z4ComponentReflectionTest.test_get_default_schema_nameforeign_keyorder_byr   
use_schemac           	         s   |rt j}nd }h d t|}|rdd ||D }n||} fdd|D }|dkr:g d}t|| d S g d}tt|| d S )N>   r=  r@  r;  r.  rB  r7  r9  c                 S   s   g | ]
}|d  r|d  qS )r   r9   )rb  Zrecr9   r9   r:   r  D  s    z@ComponentReflectionTest.test_get_table_names.<locals>.<listcomp>c                    s   g | ]}| vr|qS r9   r9   rb  tZ_ignore_tablesr9   r:   r  K  s    r  rO  )r  r'  r  )r   rL   r   Zget_sorted_table_and_fkc_namesget_table_namesr   sorted)	ro   r   r  r  rI   rv   r   r   answerr9   r  r:   test_get_table_names)  s    	

z,ComponentReflectionTest.test_get_table_namesc                 C   sn   t |}|r
tj}nd }||}tjjjr*tt	|ddg t|
|dg d S g d}tt	|| d S )Nrm  rn  rl  )rl  rm  rn  )r   r   rL   get_view_namesr   rJ   rS  r3   r   r  get_materialized_view_names)ro   r   r  rv   rI   r   r  r9   r9   r:   test_get_view_namesT  s   

z+ComponentReflectionTest.test_get_view_namesc                 C   s,   t |}| }tt|dtj g d S rY   )r   Zget_temp_table_namesr   r  r   r[   ro   r   rv   rh  r9   r9   r:   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  r9   r9   r:   test_get_temp_view_namesk  s   z0ComponentReflectionTest.test_get_temp_view_namesc                 C   s   |  | d S r   )_test_get_commentsro   r   r9   r9   r:   test_get_commentsr  s   z)ComponentReflectionTest.test_get_commentsc                 C   s   |  |tjj d S r   )r  r   r   rL   r  r9   r9   r:   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 )NrH   r.  r  )r   rs  r   r   r   r7  r_   )ro   r   rI   rv   expno_cstr9   r9   r:   r  {  s&   




z*ComponentReflectionTest._test_get_comments)FFzuse_views,use_schemac                 C   sh  |rt j}nd }| jj| jj}}|rg d}nddg}t|}t|||fD ]\}	}
|}|j|	|d}tt	|dkt	| t
|
jD ]l\}}t|j|| d  || d j}|j}t|tjjrf|j}tdrv|tjtjfv rvtj}tt	t|j|jtjtjtjtjtjtjtj gdkd	|j|j|| d |f  |j!s|| d
 d u sJ qDq'd S )Nrn  rm  rl  r  r'  rH   r   r_   ru  rR  z%s(%s), %s(%s)rv  )"r   rL   r   r  r'  r   zipr   r*   len	enumeratecolumnsr   r_   	__class__ru  r   rb   r   Z
TypeEnginer   rU  	sql_typesDater   rT  __mro__intersectionr   NumericZTimer   Z_BinaryrD   )ro   r   Z	use_viewsr  rI   r  	addressesr   rv   rh   tableZschema_namer  irr   ctypeZ	ctype_defr9   r9   r:   r     sb   
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)ro   r   rh   ri   Zreflected_user_tmpr9   r9   r:   test_reflect_table_temp_table  s   

z5ComponentReflectionTest.test_reflect_table_temp_tablec                 C   sf   |   }| j| }t|}||}tt|dkt| t|jD ]\}}t|j	|| d  q"d S )Nr   r_   )
r]   r   r   r   r*   r  r  r  r   r_   )ro   r   rh   ri   rv   r  r  rr   r9   r9   r:   test_get_temp_table_columns  s   

z3ComponentReflectionTest.test_get_temp_table_columnsc                 C   s.   t |}|d}tdd |D g d d S )Nr   c                 S      g | ]}|d  qS r   r9   rb  rr   r9   r9   r:   r        zFComponentReflectionTest.test_get_temp_view_columns.<locals>.<listcomp>)rB   r_   r   )r   r   r   )ro   r   rv   r  r9   r9   r:   test_get_temp_view_columns  s   
z2ComponentReflectionTest.test_get_temp_view_columns)Fc                 C   s  |rt jj}nd }| jj| jj}}t|}| j|d}|j|j	|d}| 
|g|||j	f g| j |j|j	|d}	|||j	f d }
t|	d |
 t jj  t|	d d W d    n1 scw   Y  | jjj	}| 
|j||dg|||f g| j d S )NrH   r  r_   r,  )r   r   rL   r   r  r'  r   r  r   r_   _check_listr  r   rJ   r  fail_ifr7  )ro   r   r  rI   r  r  rv   r  Z
users_consZ	addr_consZexp_colsr  r9   r9   r:   r     s,   

z.ComponentReflectionTest.test_get_pk_constraintc                 C   s|  |rt j}nd }| jj| jj}}t|}|}tjjj	rd|j
|j|d}|d }	tjj  t|	d d W d    n1 s@w   Y  t|	d | t|	d |j t|	d dg t|	d	 d
g |j
|j|d}
|
d }	tjj  t|	d d u W d    n1 sw   Y  t|	d | t|	d |j t|	d dg t|	d	 dg | jjj}t|j
||dg  d S )NrH   r   r_   r  r  r  r  r  r  r  r(  )r   rL   r   r  r'  r   r   rJ   rE  r3   r   r_   r  r  r   implicitly_named_constraintsr*   r7  )ro   r   r  rI   r  r  rv   Zexpected_schemaZusers_fkeysfkey1Z
addr_fkeysr  r9   r9   r:   r     s6   

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  r  rB   r  r:  rH   r<  )r   rl   rI  r   r   rL   r   r   r_   r   r  r*   )
ro   r   r9  r;  r=  rv   Zlocal_fkeysr  Zremote_fkeysZfkey2r9   r9   r:   "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  rH   )
r   rL   r   r   r  r  r  r   r7  r_   )ro   r   r  rI   rv   indexesr  r  r9   r9   r:   r   o  s   

z(ComponentReflectionTest.test_get_indexes)r@  rC  )rB  rD  ztname,ixnamec                 C   s   t |}||}|  d |f }| ||| j t|t |d}tt|j	d t
t|j	d j| tt|j	d j| d S )Nr   r   r   )r   r   r  r  r  r   r   r   r  r  r   r  r  r_   )ro   r   tnameZixnamerv   r  Zexpected_indexesr  r9   r9   r:   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  )ro   r   rv   r_   	reflectedr  r9   r9   r:   &test_get_temp_table_unique_constraints  s
   
z>ComponentReflectionTest.test_get_temp_table_unique_constraintsc                 C   sn   t |}|  }||}|D ]}|dd  qddgddg}tjjjr+g |d d< tdd	 |D | d S )
Nr  Fr   rN  )r#  r   r_   r   r  c                 S   s   g | ]
}|d  dkr|qS )r_   rN  r9   rb  r   r9   r9   r:   r    r   zGComponentReflectionTest.test_get_temp_table_indexes.<locals>.<listcomp>)	r   r]   r   rx  r   rJ   index_reflects_included_columnsr3   r   )ro   r   rv   rh   r  indexpectedr9   r9   r:   test_get_temp_table_indexes  s   

z3ComponentReflectionTest.test_get_temp_table_indexesc                 C   s   |rt j}nd }tddgddg dddg dddd	d
gdddgdddgdgtdd}td|tdtdtdtdtdtj	td	tdtd
td|d}|D ]}|
tj|d d|d i q\|| t|}t|jd|dtdd}	t }
tt|t|	 t||	D ]%\}}|dd }|r|
| t|dd d  |dd  t|| qt }td|||d}	dd |	jD }dd |	jD dg}||rJ |
rt|
| t|t  | jjj}t|j||dg  d S )NZunique_ar   )r_   r   Zunique_a_b_c)r   br   Zunique_c_a_b)r   r   r   Zunique_asc_keyascr   zi.have.dotsr   zi have spacesr   r_   r   Ztesttblr*  r"  rH   r   r  r   r  )r   rI   c                 S   s   h | ]}|j qS r9   r   r  r9   r9   r:   	<setcomp>  s    zFComponentReflectionTest.test_get_unique_constraints.<locals>.<setcomp>c                 S   s   h | ]}t |tjr|jqS r9   )r   rb   r   r_   )rb  Zuqr9   r9   r:   r    s    
)r   rL   r  operator
itemgetterr   r   rb   r   r   Zappend_constraintr   rs   r   r   rT  r   r  r  rx  rg  r   r  constraints
differencer  r   r7  r_   )ro   rR   r   r  rI   Zuniquesr  r  rv   r  Znames_that_duplicate_indexr  ZreflZdupeZreflected_metadataZ	idx_namesZuq_namesr  r9   r9   r:   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  rH   )r   rL   r   r   r*   bool)ro   r   r  rI   rv   viewrc  r9   r9   r:   r     s   z0ComponentReflectionTest.test_get_view_definitionc                 C   sr   t |}tt |d W d    n1 sw   Y  tt |d W d    d S 1 s2w   Y  d S )NZview_does_not_existr  )r   r   r!   r   r   r9   r9   r:   'test_get_view_definition_does_not_exist#  s   

"z?ComponentReflectionTest.test_get_view_definition_does_not_existc                 C   sF   t |}dD ]\}}||}dd |D | }|dds J qdS )a  test that 'autoincrement' is reflected according to sqla's policy.

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

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

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

        ))r  r  )r'  r  )r  r  c                 S      i | ]}|d  |qS r   r9   r  r9   r9   r:   rf  A      zBComponentReflectionTest.test_autoincrement_col.<locals>.<dictcomp>rt  TN)r   r   get)ro   r   rv   r  cnamer  Zid_r9   r9   r:   test_autoincrement_col+  s   
z.ComponentReflectionTest.test_autoincrement_colc                 C   s   t tj}|r
tjnd }tjjjr/|jd|d}t	t
|t |jd|d}t	t
|t d S tt |jd|d W d    d S 1 sFw   Y  d S )Nr  rH   r7  )r   r   r7   rL   r   rJ   r   r3   r   r*   r   r6   r   r   )ro   r  rv   rI   r   r9   r9   r:   r   D  s   


"z.ComponentReflectionTest.test_get_table_optionsc                    s   t tj tjjjr,|rtjnd  jd} fdd j	dD }t
|| d S tt    W d    d S 1 s@w   Y  d S )NrH   c                    s    i | ]}|f j |d qS )rH   )r   )rb  r  rv   rI   r9   r:   rf  \  s    zHComponentReflectionTest.test_multi_get_table_options.<locals>.<dictcomp>)r   r   r7   r   rJ   r   r3   rL   get_multi_table_optionsr  r   r   r   )ro   r  r   r  r9   r  r:   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 r!|g d tj|v r-|ddg tj|v r9|ddg | r?| |d< |rE||d< || |||dd	}	|g}
|tjkrf|	 }|
d
 |
| |tjkry|	 }|
d |
| t  |
|	fS )Nr'  )r0   r   )r.  r  does-not-existrm  r  rl  rI   r  )rI   r0   r   r  r0   r   )r   r   r  r  r  r  r  r    r  copyrx  append)rI   r0   r   r   Zsingle_reflect_fnZ
exp_methodrv   rg   r  r  kwsZnkwr   r9   r:   provide_fixtureg  sD   










z>ComponentReflectionTest.get_multi_exp.<locals>.provide_fixturer9   )ro   r   r  r9   r  r:   get_multi_expe  s   .z%ComponentReflectionTest.get_multi_expc                 C   sL   |||||t j| j\}}}|D ]}	|  |jdi |	}
t|
| qd S Nr9   )r   r   rp  rt   r  r   ro   r  rI   r0   r   r   rv   r  r  rg   resultr9   r9   r:   #test_multi_get_table_options_tables  s   
z;ComponentReflectionTest.test_multi_get_table_options_tablesc           
      C   sH   |||||t j| j\}}}|D ]}	|  t|jdi |	| qd S r  )r   r   rs  rt   r   Zget_multi_table_comment)
ro   r  rI   r0   r   r   rv   r  r  rg   r9   r9   r:   test_get_multi_table_comment  s   
z4ComponentReflectionTest.test_get_multi_table_commentc                    sX   dt fdd t|trt fdd| D || d S t fdd|D || d S )Nrq  c                 S   s   t dd|  S )Nz['\" ]r  )resubr  )rq  r9   r9   r:   _clean  s   z:ComponentReflectionTest._check_expressions.<locals>._cleanc                    s   i | ]	\}} ||qS r9   r9   )rb  erc  r!  r9   r:   rf        z>ComponentReflectionTest._check_expressions.<locals>.<dictcomp>c                    s   g | ]} |qS r9   r9   )rb  r"  r#  r9   r:   r    r  z>ComponentReflectionTest._check_expressions.<locals>.<listcomp>)r  r   r6   r   ri  )ro   r  r  err_msgr9   r#  r:   _check_expressions  s   
"z*ComponentReflectionTest._check_expressionsc           	      C   s   |d u rt ||| d S t t|t|| t||D ]?\}}t|t|B D ]2}||v s5||v rY||v rY| d| d| }|dv rO| || || | q't || || | q'qd S )Nz - )r  r  )r   r  r  rT  r&  )	ro   r  r  req_keysmsgrr"  r   r%  r9   r9   r:   r    s   z#ComponentReflectionTest._check_listc                 C   s\   t t| t|  |D ]}|| || }}|r#|g|g}}| |||| qd S r   )r   rT  keysr  )ro   r  r  r'  
make_listsr   r)  r"  r9   r9   r:   _check_table_dict  s   z)ComponentReflectionTest._check_table_dictc                 C   R   |||||t j| j\}}}|D ]}	|  |jdi |	}
| |
|| j qd S r  )r   r   r}  rt   get_multi_columnsr,  r  r  r9   r9   r:   test_get_multi_columns  s   
	z.ComponentReflectionTest.test_get_multi_columnsc                 C   sV   |||||t j| j\}}}|D ]}	|  |jdi |	}
| j|
|| jdd qd S )NT)r+  r9   )r   r   r  rt   Zget_multi_pk_constraintr,  r  r  r9   r9   r:   test_get_multi_pk_constraint  s   

z4ComponentReflectionTest.test_get_multi_pk_constraintc                 C   sX   t jjjs(||fD ] }| D ]}t|dkr&tdd |D r&|j|d qq	d S d S )Nr   c                 s   s$    | ]}| d dtjfv V  qdS )r_   N)r  r+   r  )rb  rc  r9   r9   r:   	<genexpr>	  s    
z7ComponentReflectionTest._adjust_sort.<locals>.<genexpr>r  )r   rJ   r  r3   rj  r  anysort)ro   r  r  r   objr  r9   r9   r:   _adjust_sort  s   
z$ComponentReflectionTest._adjust_sortc                 C   d   |||||t j| j\}}}|D ]}	|  |jdi |	}
| |
|dd  | |
|| j qd S )Nc                 S      t | d S )Nr  tupledr9   r9   r:   r   	  ra  zEComponentReflectionTest.test_get_multi_foreign_keys.<locals>.<lambda>r9   )r   r   r  rt   Zget_multi_foreign_keysr5  r,  r  r  r9   r9   r:   test_get_multi_foreign_keys	  s    

z3ComponentReflectionTest.test_get_multi_foreign_keysc                 C   r-  r  )r   r   r  rt   Zget_multi_indexesr,  r  r  r9   r9   r:   test_get_multi_indexes	  s   
z.ComponentReflectionTest.test_get_multi_indexesc                 C   r6  )Nc                 S   r7  )Nr   r8  r:  r9   r9   r:   r   ?	  ra  zKComponentReflectionTest.test_get_multi_unique_constraints.<locals>.<lambda>r9   )r   r   r  rt   Zget_multi_unique_constraintsr5  r,  r  r  r9   r9   r:   !test_get_multi_unique_constraints/	     
z9ComponentReflectionTest.test_get_multi_unique_constraintsc                 C   r6  )Nc                 S   r7  Nr  r8  r:  r9   r9   r:   r   R	  ra  zJComponentReflectionTest.test_get_multi_check_constraints.<locals>.<lambda>r9   )r   r   r  rt   Zget_multi_check_constraintsr5  r,  r  r  r9   r9   r:    test_get_multi_check_constraintsB	  r?  z8ComponentReflectionTest.test_get_multi_check_constraintsr   r   r   r   r   r   r   r   methodc                 C   sH   t |}t||}tt |d W d    d S 1 sw   Y  d S )NZtable_does_not_exists)r   getattrr   r!   )ro   rB  r   rv   r   r9   r9   r:   test_not_existing_tableU	  s
   


"z/ComponentReflectionTest.test_not_existing_tablec              	      s   t j  fdd}tjt d|2 ttd t|t	dt
 d  W d    n1 s.w   Y  W d    d S W d    d S 1 sFw   Y  d S )Nc                     s&   | di }td|d<  | i |S )NZunreflectableerr)N
some_table)
setdefaultr"   )r   r   urZmcr9   r:   patchedu	  s   z;ComponentReflectionTest.test_unreflectable.<locals>.patchedr.  rE  rF  )r   r.  r+   patchobjectr   r"   r   Zreflect_tabler   r   )ro   r   rJ  r9   rI  r:   test_unreflectabler	  s   "z*ComponentReflectionTest.test_unreflectabler   c                    s   t  }|rtjnd  |j| |dd t|}| }|r8|| 7 }z	|| 7 }W n	 ty7   Y nw  rC fdd|D }t	t
|jt
| d S )NF)rI   r   Zresolve_fksc                    s   g | ]	}  d | qS )r  r9   r  rH   r9   r:   r  	  r$  z9ComponentReflectionTest.test_metadata.<locals>.<listcomp>)r   r   rL   reflectr   r  r  r  r   r   r  r   )ro   r   r  r   mrv   r   r9   rH   r:   test_metadata	  s   
z%ComponentReflectionTest.test_metadatac              	   C   s   t d|tdtddtdtdddd || t|}|d}t|ddi |d}d	d
 |D }ddd}t|| d S )Nunicode_commentsunicodeu   é試蛇ẟΩr   emojiu	   ☁️✨u   試蛇ẟΩ✨rq  c                 S      i | ]	}|d  |d qS r  r9   r  r9   r9   r:   rf  	  r$  zAComponentReflectionTest.test_comments_unicode.<locals>.<dictcomp>)rR  rS  r   r   r   r   r   r   r   r   )ro   r   rR   rv   tcr  valuer  r9   r9   r:   test_comments_unicode	  s   



z-ComponentReflectionTest.test_comments_unicodec                 C   sp   t d|tdtdddd || t|}|d}t|ddi |dd }t|d |d	 iddi d S )
NrQ  rS  u&   🐍🧙🝝🧙‍♂️🧙‍♀️r   u&   🎩🁰🝑🤷‍♀️🤷‍♂️rq  r   r_   r   rU  )ro   r   rR   rv   rV  r   r9   r9   r:   test_comments_unicode_full	  s   

z2ComponentReflectionTest.test_comments_unicode_fullr   r,   )NF)mr<   r=   r>   run_insertsrun_deletesr   r?   rS   r
  r]   rP   rN   rZ  r\  rk  r    r  r   rp  rs  r}  propertyr  r  r  r  r  r  r  r  r  r  r  r   rJ   Zschema_reflectionr  r  r  r  Zschema_create_deleter  r  r  r   r   rK   r  r  rh  r  rM   re   r  r   r  r  r  r   r   r  r  r   r  !primary_key_constraint_reflectionr   r   rH  r  r   r   rJ  rK  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/  r0  r5  r<  r=  r>  r   rA  rD  rM  r   rP  rX  Zcomment_reflection_full_unicoderY  r9   r9   r9   r:   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 Nrr  )r   r   ro   r   rR   r9   r9   r:   table_no_columns	  s   
z#TableNoColumnsTest.table_no_columnsc                 C   s<   t d| t|dtd t|dtd || d S )Nrr  rT   z*CREATE VIEW empty_v AS SELECT * FROM emptyrU   zDROP VIEW IF EXISTS empty_v)r   r   rV   r#   r   ra  r9   r9   r:   view_no_columns	  s   

z"TableNoColumnsTest.view_no_columnsc                 C   $   t dt |d}tt|jg  d S )Nrr  r   r   r   r   r  r   )ro   r   rb  t2r9   r9   r:   test_reflect_table_no_columns	  s   z0TableNoColumnsTest.test_reflect_table_no_columnsc                 C   s2   t |}t|dg  | }t|dg i d S )Nrr  r`  )r   r   r   r.  )ro   r   rb  rv   multir9   r9   r:   !test_get_columns_table_no_columns	  s   z4TableNoColumnsTest.test_get_columns_table_no_columnsc                 C   s*   t  }|| t|jdgsJ d S r`  )r   rN  rT  r   r  )ro   r   rb  rO  r9   r9   r:   "test_reflect_incl_table_no_columns	  s   
z5TableNoColumnsTest.test_reflect_incl_table_no_columnsc                 C   rd  )Nempty_vr   re  )ro   r   rc  rf  r9   r9   r:   test_reflect_view_no_columns	  s   z/TableNoColumnsTest.test_reflect_view_no_columnsc                 C   s8   t |}t|dg  |jtjd}t|dg i d S )Nrk  )r   )Nrk  )r   r   r   r.  r   r  )ro   r   rc  rv   rh  r9   r9   r:    test_get_columns_view_no_columns	  s   z3TableNoColumnsTest.test_get_columns_view_no_columnsN)r<   r=   r>   r   r   r   r   rb  rc  rg  ri  rj  rJ   r   rl  rm  r9   r9   r9   r:   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 r   )paramr   rL   )ro   requestr9   r9   r:   use_schema_fixture	  s   z/ComponentReflectionTestExtra.use_schema_fixturec                    s   t j fdd}|S )Nc                 3   s    t  fV    d S r   )r   r   )r   r   rR   rr  r9   r:   go	  s   z:ComponentReflectionTestExtra.inspect_for_table.<locals>.go)
contextlibcontextmanager)ro   rR   r   rr  rt  r9   rs  r:   inspect_for_table	  s   z.ComponentReflectionTestExtra.inspect_for_tablec                    sD   dd  t  fdd|D dd d}t |dd d}t|| d S )	Nc                 S   s   d td|  tjS )N zand|\d|=|a|b|c|or|<|>)joinr  findallr  I)r  r9   r9   r:   	normalize	
  s   z5ComponentReflectionTestExtra.ck_eq.<locals>.normalizec                    s"   g | ]}|d   |d dqS )r_   r  r_   r  r9   )rb  itemr|  r9   r:   r  
  s    z6ComponentReflectionTestExtra.ck_eq.<locals>.<listcomp>c                 S      | d S r@  r9   r~  r9   r9   r:   r   
      z4ComponentReflectionTestExtra.ck_eq.<locals>.<lambda>r  c                 S   r  r@  r9   r  r9   r9   r:   r   
  r  )r  r   )ro   r  r  r9   r  r:   ck_eq
  s   
z"ComponentReflectionTestExtra.ck_eqc              	   C   sb   |d\}}t d|tdtd|d W d    n1 sw   Y  | |jd|dg  d S )Nr7  rE   r*  rH   )r   r   rb   r   r  r   )ro   rR   rw  rI   r   r9   r9   r:   #test_check_constraint_no_constraint
  s   z@ComponentReflectionTestExtra.test_check_constraint_no_constraint	my_inlineZMyInlineNconstraint_namer   c                 C   s   |d)\}}t d|tdt ddtdt tjd|dtdtd	|d
 W d    n1 s0w   Y  |jd|d
}| ||pCtj	ddg d S )Nsa_ccrB   TrC   r   a > 1 AND a < 5r   rE   rF   rH   a > 1 and a < 5r}  )
r   r   r   rb   r   r   r   r  r+   r  ro   rR   rw  r  rI   r   r  r9   r9   r:   test_check_constraint_inline+
  s0   z9ComponentReflectionTestExtra.test_check_constraint_inlineZmy_ck_constZ	MyCkConstc              	   C   s|   |d\}}t d|tdt tjd|d|d W d    n1 s#w   Y  |jd|d}| ||p6tjddg d S )Nr  r   za = 1 OR (a > 2 AND a < 5)r   rH   za = 1 or a > 2 and a < 5r}  )	r   r   r   rb   r   r   r  r+   r  r  r9   r9   r:    test_check_constraint_standaloneO
  s&   
z=ComponentReflectionTestExtra.test_check_constraint_standalonec                 C   s   |dI\}}t d|tdt ddtdt tdtdt tjdd	d
tdt tdtdtjddd
tjddd
tjddd
|d W d    n1 sPw   Y  |jd|d}| |dddd	ddt	j
ddg d S )Nr  rB   TrC   r   r  r   zb > 1 AND b < 5r  r   r   rE   rF   Zsome_uqzc > 1 AND c < 5Zcc1Z	some_c_uqrH   zc > 1 and c < 5r}  zb > 1 and b < 5r  )r   r   r   rb   r   r   r   r   r  r+   r  )ro   rR   rw  rI   r   r  r9   r9   r:   test_check_constraint_mixedm
  s6   

z8ComponentReflectionTestExtra.test_check_constraint_mixedc              	   C   s   |d*\}}t d|tdtddtdttdt}td|jj|jj|jj W d   n1 s1w   Y  |d}t	|d	 d
 g d dS )ztest for #12894Zsa_multi_indexColumn1TrC   Column2Column3ZIndex_ExampleNr   r   )r  r  r  )
r   r   r   r$   r   r  r  r  r   r   )ro   rR   rw  rI   r   rA   r  r9   r9   r:   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rdg d|dd|dgd
d}	||	 |d|	 dd g|d dgd
d}
||
 ||
 t|d| t }t d| d}n&td t|d| t }t d| d}W d    n1 sw   Y  | || jj d S )Nr  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< d S | di  d S )Nr  Z_includer  )r   rJ   r  r3   r  r_   rG  )entryr  r9   r:   completeIndex
  s
   
zYComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.completeIndexr   c                   @   r  )z[ComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.lower_index_strc                 S   s    |  }d|v od|v pd|v S )Nr  r  r  r  )ro   r   olr9   r9   r:   r  
  s   zbComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.lower_index_str.__eq__Nr  r9   r9   r9   r:   lower_index_str
  r  r  c                       s   e Zd Z fddZdS )z^ComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.coalesce_index_strc                    s   d|  v o	 |v S )Ncoalescer  r  long_strr9   r:   r  
  s   zeComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.coalesce_index_str.__eq__Nr  r9   r  r9   r:   coalesce_index_str
  s    r  )Nr  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   r  r  r  r  r   r   r  r   rJ   Z reflect_indexes_with_expressionsr3   insertr  r   r   r   r	   Z!compare_table_index_with_expectedr  r_   )ro   rR   r   r  rv   r  r  r  r  Z
expr_indexZexpr_index_longr   rf  r9   )r   r  r:   %test_reflect_expression_based_indexes
  sn   &
		



zBComponentReflectionTestExtra.test_reflect_expression_based_indexesc                 C   s   t d|tdtdtdtd}td|jj}dg|j|jj d< |	| t
|}|d}t|ddgdgdtjdg t|d	 d
 d|jj  dg t dt |d}tt|jd	 j|jj d dg d S )Nr  r  r"  r  r  includeF)r_   r   r  r#  r  r   r  z
%s_includer   )r   r   r   r$   r   r  r  r  r_   r   r   r   r   r+   r  r   r  r  )ro   rR   r   r  r   rv   r   rf  r9   r9   r:   test_reflect_covering_index
  sD   



z8ComponentReflectionTestExtra.test_reflect_covering_indexc                 G   sB   t d|gdd t|D R  }|| dd t|dD S )Nr  c                 S   s   g | ]\}}t d | |qS )zt%dr   )rb  r  type_r9   r9   r:   r  +      zAComponentReflectionTestExtra._type_round_trip.<locals>.<listcomp>c                 S   r  )ru  r9   r  r9   r9   r:   r  /  r  )r   r  rs   r   r   )ro   r   rR   r   r  r9   r9   r:   _type_round_trip'  s   
z-ComponentReflectionTestExtra._type_round_tripc                 C   sH   |  ||tddD ]}t|tjsJ t|jd t|jd qd S )N   r  )r  r  r  r   r   	precisionscale)ro   r   rR   typr9   r9   r:   test_numeric_reflection1  s   z4ComponentReflectionTestExtra.test_numeric_reflectionr  c                 C   s   |  |||dd }t|tjrt|tjsJ nt|tjr)t|tjs(J nt|tjs1J t|jd t|jt	s?J d S )N4   r   )
r  
issubclassr  rd   r   rF  r   r   lengthint)ro   r   rR   r  r  r9   r9   r:   test_string_length_reflection:  s   
z:ComponentReflectionTestExtra.test_string_length_reflectionc              	   C   sT   t d|tdtddtdtdd}|| tdd t|dD ddd	 d S )
Nr  r   Tr  r   Fc                 S   rT  )r_   r  r9   r  r9   r9   r:   rf  Y  s    zIComponentReflectionTestExtra.test_nullable_reflection.<locals>.<dictcomp>)r   r   )r   r   r   rs   r   r   r   )ro   r   rR   r  r9   r9   r:   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onupdater  rB   TrC   r   r  Zx_idzx.idxidr   test
   userr_   rF   Fr  tidztable.idZmyfkr   r1   c                    s   i | ]} | r| | qS r9   r9   )rb  r   optsr9   r:   rf    r  zMComponentReflectionTestExtra.test_get_foreign_key_options.<locals>.<dictcomp>)r   r   r   r   r   rb   r   r   r   r   r   )ro   r   rR   r  r  r  r1   rv   r9   r  r:   test_get_foreign_key_options`  sT   *	
z9ComponentReflectionTestExtra.test_get_foreign_key_options10z'?10'?z1|truez3 + 5z3\+5z(3 * 5)z3\*5zcurrent_timestamp|now|getdate35zdatatype, default, expected_regc           	   	   C   sd   t d|tdtddtd||d}|| t|dd d }td	d
|}t||tj	d d S )Nr  rB   TrC   Zthecol)Zserver_defaultr   rv  z	[\(\) \']r  )flags)
r   r   r   rs   r   r   r  r   r   
IGNORECASE)	ro   rR   r   datatyperv  Zexpected_regr  r  Zreflected_sanitizedr9   r9   r:   test_server_defaults  s   
z1ComponentReflectionTestExtra.test_server_defaults)5r<   r=   r>   r   r   r   rr  rw  r  rJ   r   r  Z"inline_check_constraint_reflectionr   r  r  r  Zindexes_check_column_orderr  Zindexes_with_expressionsr  r  r  r  r^  r  r  r   rd   rF  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   rb   rq  r   trueZexpression_server_defaultsr   r   nowZliteral_columnZserver_defaultsr  r9   r9   r9   r:   rn  	  s    

	
 


Z
*



'6rn  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   rB   rC   rf  t1idzt1.id)r   r%   r   r   r   rQ   r9   r9   r:   rS     s   

z NormalizedNameTest.define_tablesc                 C   s~   t  }ttddd|tjd}|jd }|jj|jj	sJ t  }|j
tjdd d |jd jj|jd jj	s=J d S )	Nrf  Tr  r   r   c                 S   s   |   dv S )Nr   rf  r  )r_   rO  r9   r9   r:   r     ra  zINormalizedNameTest.test_reflect_lowercase_forced_tables.<locals>.<lambda>)only)r   r   r%   r   r7   r   r   r  r   rB   rN  )ro   r   Zt2_refZt1_refZm3r9   r9   r:   $test_reflect_lowercase_forced_tables  s   

&z7NormalizedNameTest.test_reflect_lowercase_forced_tablesc                 C   sP   dd t tj D }t|d  |d   t|d  |d   d S )Nc                 S   s   g | ]
}|  d v r|qS )r  r  r  r9   r9   r:   r    s
    z;NormalizedNameTest.test_get_table_names.<locals>.<listcomp>r   r   )r   r   r7   r  r   upperr  )ro   Z
tablenamesr9   r9   r:   r    s
   z'NormalizedNameTest.test_get_table_namesN)	r<   r=   r>   r   r   r?   rS   r  r  r9   r9   r9   r:   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   r  r   r9   r  r9   r9   r:   rf    r  zLComputedReflectionTest.test_computed_col_default_not_set.<locals>.<dictcomp>Z42with_defaultrv  normalcomputed_col)r   r   r7   r   r*   r   )ro   rv   r  Zcol_datar9   r9   r:   !test_computed_col_default_not_set  s   

z8ComputedReflectionTest.test_computed_col_default_not_setc                 C   s   t tj}|d}dd |D }dD ]
}td|| v q|d }td|v  td|d v  t| |d d d td	|d v tjj	j
 tjj	j
r[t|d d	 tjjj
 d S d S )
Nr  c                 S   r  r   r9   r  r9   r9   r:   rf     r  zKComputedReflectionTest.test_get_column_returns_computed.<locals>.<dictcomp>)rB   r  r  computedr  r  	normal+42	persisted)r   r   r7   r   r*   r   r|  r   rJ   "computed_columns_reflect_persistedr3   "computed_columns_default_persisted)ro   rv   r  rE   r   compDatar9   r9   r:    test_get_column_returns_computed  s&   




z7ComputedReflectionTest.test_get_column_returns_computedc                 C   s\   t d|| v  || d }t| |d | tjjjr,t d|v  t|d | d S d S )Nr  r  r  )r*   r   r|  r   rJ   r  r3   r   )ro   rE   columnr  r  r  r9   r9   r:   check_column1  s   
z#ComputedReflectionTest.check_columnc                 C   st   t tj}|d}dd |D }| |ddtjjj tjj	jr)| |ddd tjj
jr8| |d	d
d d S d S )Ncomputed_column_tablec                 S   r  r   r9   r  r9   r9   r:   rf  =  r  zLComputedReflectionTest.test_get_column_returns_persisted.<locals>.<dictcomp>computed_no_flagr  computed_virtualznormal+2Fcomputed_storedz	normal-42T)r   r   r7   r   r  r   rJ   r  r3   computed_columns_virtualcomputed_columns_storedro   rv   r  rE   r9   r9   r:   !test_get_column_returns_persisted9  s0   



z8ComputedReflectionTest.test_get_column_returns_persistedc                 C   sz   t tj}|jdtjd}dd |D }| |ddtjjj	 tjj
j	r,| |ddd	 tjjj	r;| |d
dd d S d S )Nr  rH   c                 S   r  r   r9   r  r9   r9   r:   rf  [  r  zXComputedReflectionTest.test_get_column_returns_persisted_with_schema.<locals>.<dictcomp>r  z	normal/42r  znormal/2Fr  z	normal*42T)r   r   r7   r   rL   r  r   rJ   r  r3   r  r  r  r9   r9   r:   -test_get_column_returns_persisted_with_schemaT  s4   


zDComputedReflectionTest.test_get_column_returns_persisted_with_schemaN)r<   r=   r>   r  r  r  r  r   rJ   rK   r  r9   r9   r9   r:   r    s    	r  c                   @   sH   e Zd Zd ZZdZdZedd Zdd Z	dd	 Z
ejjd
d ZdS )IdentityReflectionTestNT)r   r^  c                 C   s   t d|tdttdtt  t d|tdttdddd	d
ddd tjjjr>t d|tdttdttdddtj	d d S d S )Nr   r  id1rf  r   Tr   r   r4     alwaysr   	incrementminvaluemaxvaluecyclecacher*  )r  r   rH   )
r   r   r   r   r   rJ   rK   r3   r   rL   rQ   r9   r9   r:   rS   y  s@   

z$IdentityReflectionTest.define_tablesc                 C   s   t jjjrXd}t|D ]}||vr|| q|rQtt|t| |D ]*}|dkr5t|| || k q$|dv rDt|| || k q$t|| || | q$d S t|| d S t|d |d  t|d |d  d S )Nr  r  >   r  r  r   r  )	r   rJ   Zidentity_columns_standardr3   r  rx  r   r  r*   )ro   rW  r  approxZcommon_keysr   r9   r9   r:   check  s$   
	
zIdentityReflectionTest.checkc                 C   s  t tj}|d|d }|D ]p}|d dkr td|v  q|d dkrQd|v r0t|d  t|d d  td|v  | j|d td	d
d
d
dd	d
ddd q|d dkrd|v rat|d  t|d d  td|v  | j|d tddddddddd	d qd S )Nr   rf  r_   r  r   r  rt  rv  Fr   r  Tr  r   r   r   r  r4  r  )	r   r   r7   r   r)   r*   r   r  r6   ro   rv   r  rr   r9   r9   r:   r     sV   
		z,IdentityReflectionTest.test_reflect_identityc                 C   s   t tj}|jdtjd}|D ]?}|d dkrtd|v  q|d dkrNd|v r.t|d  t|d d  td|v  | j|d t	d	d
ddddddd	d qd S )Nr   rH   r_   r  r   r  rt  rv  Tr*  r   r  Fr  r  )
r   r   r7   r   rL   r)   r*   r   r  r6   r  r9   r9   r:   test_reflect_identity_schema  s2   
	z3IdentityReflectionTest.test_reflect_identity_schema)r<   r=   r>   rZ  r[  r   r   r?   rS   r  r   r   rJ   rK   r  r9   r9   r9   r:   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tb1rB   attrr_   r*  Zpk_tb1r   Tr  tb2rC   pidpattrpnamer  r  r  Zfk_tb1_name_id_attr)r   r   r   r  rd   rb   r   r   r   r_   rB   r  )r8   rR   r  r9   r9   r:   rS     s2   

z(CompositeKeyReflectionTest.define_tablesc                 C   s0   t |}|| jjj}t|dg d d S )Nr  r_   rB   r  )r   r   r   r  r_   r   r  )ro   r   rv   rD   r9   r9   r:   test_pk_column_order  s   z/CompositeKeyReflectionTest.test_pk_column_orderc                 C   sZ   t |}|| jjj}tt|d |d }t|dg d t|dg d d S )Nr   r   r  r  r  r  )r   r   r   r  r_   r   r  r  )ro   r   rv   Zforeign_keysr  r9   r9   r:   test_fk_column_order&  s   z/CompositeKeyReflectionTest.test_fk_column_orderN)r<   r=   r>   r   r?   rS   r   rJ   r]  r  r   r  r9   r9   r9   r:   r     s    

r  )r	  rn  r_  r   r   r@   r   r  r  r  r  r   )Hru  r  r  r4   rb   r  r   r   r   r   r   r   r	   r
   r   Z	provisionr   r   rI   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+   rR   r  Z
TablesTestr-   r@   r   ZTestBaser   r   r   r  r	  r_  rn  r  ZComputedReflectionFixtureTestr  r  r  __all__r9   r9   r9   r:   <module>   s    Mg&               [5   y+a 1