o
    `^hP                    @   s  d dl Z d dlZd dlZd dlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddlm!Z! ddlm"Z" ddl#m$Z$ ddl#m%Z% ddlm&Z& dd lm'Z' dd!l(m)Z) dd"l*m+Z+ dd#lm,Z, dd$lm-Z- dd%lm.Z. dd&lm/Z/ dd'lm0Z0 d(\Z1Z2G d)d* d*ej3Z4G d+d, d,e4Z5G d-d. d.ej3Z6G d/d0 d0ej7Z8G d1d2 d2ej3Z9d3d4 Z:G d5d6 d6e-e4Z;G d7d8 d8ej7Z<G d9d: d:e,ej7Z=G d;d< d<ej3Z>G d=d> d>ej?Z@G d?d@ d@ej3ZAG dAdB dBej3ZBdCZCdS )D    N   )config)engines)eq_)expect_raises)expect_raises_message)expect_warnings)fixtures)is_)get_temp_table_name)temp_table_keyword_argsColumn)Table   )event)
ForeignKey)func)Identity)inspect)Integer)MetaData)String)testing)types)	Inspector)
ObjectKind)ObjectScope)NoSuchTableError)UnreflectableTableError)DDL)Index)quoted_name)BLANK_SCHEMA)ComparesIndexes)ComparesTables)is_false)is_true)mockNNc                   @   s   e Zd Zedd ZdS )OneConnectionTablesTestc                 C   s2   t jjjrddlm} tjt|j	dddS t j
S )Nr   )poolclass)	poolclassscope)options)r   requirementsindependent_connectionsenabled
sqlalchemyr+   r   testing_enginedict
StaticPooldb)clsr+    r9   f/home/air/shanriGPT/back/venv/lib/python3.10/site-packages/sqlalchemy/testing/suite/test_reflection.py
setup_bind8   s   
z"OneConnectionTablesTest.setup_bindN)__name__
__module____qualname__classmethodr;   r9   r9   r9   r:   r*   7   s    r*   c                   @   s   e Zd ZdZedd Zedd Zedd Zedd	 Zd
d Z	dd Z
ejjdd Zejjdd Zejjdd Zejjdd Zejjejjejjdd Zejjejjdd ZdS )HasTableTestTc                 C   s   t d|tdtddtdtd tjjj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schemasr2   r   test_schemaview_reflectiondefine_viewshas_temp_tabledefine_temp_tablesr8   metadatar9   r9   r:   define_tablesJ   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   r2   r   rL   )r8   rR   queryr9   r9   r:   rN   `   s"   
zHasTableTest.define_viewsc                 C      t ttjdtj S N	user_tmp_r   r   r7   identr8   r9   r9   r:   temp_table_namev      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   r2   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   	new_tablecol)r   r   r7   r'   rn   r   r   r   r&   createclear_cachedrop)rp   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   rk   )r   r7   rl   r&   rm   rn   rL   r'   ro   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   nonexistent_schemarH   )r   r7   rl   r&   rm   rn   ro   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'   rn   rp   
connectionrx   r9   r9   r:   test_has_table_view   s   z HasTableTest.test_has_table_viewc                 C   s"   t |}|  }t|| d S N)r   r^   r'   rn   )rp   r   rx   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'   rn   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   rr   rz   r   rJ   rK   r{   r}   viewsr   rO   r   rM   rf   r   r   r9   r9   r9   r:   r@   G   s6    







r@   c                   @   sT   e Zd ZdZedd ZejddddZdd	 Z	ed
d Z
ejjedd ZdS )HasIndexTestTc              	   C   s   t d|tdtddtdtdtdtd}td|jj tjj	j
r@t d|tdtddtdtdtjd	}td
|jj d S d S )NrA   rB   TrC   rE   rF   data2my_idxrH   my_idx_s)r   r   r   r   r!   crE   r   rJ   rK   r2   r   rL   )r8   rR   ttr9   r9   r:   rS      s$   
zHasIndexTest.define_tablesrm   	inspectorkindargnamesc                    s   |dkr
 fddS t  jS )Nrm   c                     s   t jjj g| R i |S r   )r   r7   rm   	has_index)akrq   r9   r:   <lambda>       z)HasIndexTest._has_index.<locals>.<lambda>)r   r   )rp   r   rq   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   rk   nonexistent_idxmy_idx_2test_table_2my_idx_3foor   T)r   r!   tablesrA   r   r   r   r   r   ru   __self__rv   rw   )rp   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   rk   nonexistent_idx_s)r   r   rL   )rp   r   r   r   r9   r9   r:   test_has_index_schema  s   
z"HasIndexTest.test_has_index_schemaN)r<   r=   r>   r   r?   rS   r   combinationsr   r   r   rJ   rK   r   r9   r9   r9   r:   r      s    

r   c                	   @   sT   e Zd ZdZdZejdddddded	dd
gejdddddddd ZdS ) BizarroCharacterFKResolutionTestztests for #10275T)rB   )z(3))zcol%p)z[brack]
columnnamer   use_compositeF)plain)z(2))z
per % cent)z
[brackets]	tablenamec           
      C   s  t ||t|tddddd}|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 )NrB   T)keyrD   test_needs_fkid2rC   otherrefref2autoload_withr      )r   r   r   append_columnrc   ForeignKeyConstraintr   rB   r   r   
create_allr   r   r   
referencesr   )
rp   r   rR   r   r   r   r   m2o2t1r9   r9   r:   test_fk_ref.  sD   


z,BizarroCharacterFKResolutionTest.test_fk_refN)	r<   r=   r>   __doc__r   r   r   	variationr   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dd Zedd Zee	j
jdd Zee	j
jdd Zee	j
jdd ZdS )QuotedNameArgumentTestonceTc                 C   s  t d|tdttdtdtdtdtdttjdddtd	dtjdd
dtjdgdgddtj	dddddd t
jjj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   
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)commentr   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   rc   PrimaryKeyConstraintr!   UniqueConstraintr   CheckConstraintr   rJ   symbol_names_w_double_quoter2   view_column_reflectionr   r7   rm   identifier_preparerquoter   rV   r    )r8   rR   namesr`   rW   r9   r9   r:   rS   h  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_optionsr2   get_table_optionsr'   
isinstancer5   r   NotImplementedError)rp   r`   rx   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rp   r`   rx   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   get_columnsr   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_keys  r   z,QuotedNameArgumentTest.test_get_foreign_keysc                 C   r   r   )r   r   r7   get_indexesr   r9   r9   r:   test_get_indexes  r   z'QuotedNameArgumentTest.test_get_indexesc                 C   r   r   )r   r   r7   get_unique_constraintsr   r9   r9   r:   test_get_unique_constraints     
z2QuotedNameArgumentTest.test_get_unique_constraintsc                 C   r   r   )r   r   r7   get_table_commentr   r9   r9   r:   test_get_table_comment  r   z-QuotedNameArgumentTest.test_get_table_commentc                 C   r   r   )r   r   r7   get_check_constraintsr   r9   r9   r:   test_get_check_constraints  r   z1QuotedNameArgumentTest.test_get_check_constraintsN)r<   r=   r>   run_create_tablesr   r?   rS   r   r   r   rJ   r   r   r   r   r   r   unique_constraint_reflectionr   comment_reflectionr   check_constraint_reflectionr   r9   r9   r9   r:   r   d  s8    
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     s    z$_multi_combination.<locals>.<lambda>rI   r   r.   r   TF
use_filter)r   r   rJ   rK   r   DEFAULT	TEMPORARYANYr   TABLEVIEWMATERIALIZED_VIEWANY_VIEW)r   rI   r.   r   filter_namesr9   r9   r:   _multi_combination  s2   


r   c                   @   s$  e Zd Zd ZZdZedd Zedd Zedd Z	ed	d
 Z
edd Zdd Zdd Zdd ZdejejdfddZdejejdfddZdejejdfddZedd ZdejejdfddZedd Zdejejdfdd Zed!d" Zdejejdfd#d$Zed%d& Zdejejdd'fd(d)Zed*d+ Zdejejdfd,d-Zed.d/ Z e!j"j#d0d1 Z$e!j"j#d2d3 Z%e!j"j#d4d5 Z&e!j"j#d6d7 Z'e!j"j#e!j"j(d8d9 Z)e!j"j#d:d; Z*e!j"j#d<d= Z+e!j,dd>e!j"j-fd?d@e!j,de!j"j.fd'dAd@dBdC Z/e!j,de!j"j.fd'dAd@dDdE Z0e!j"j1dFdG Z2e!j"j3e!j"j4dHdI Z5e!j"j6dJdK Z7e!j"j6e!j"j.dLdM Z8ddNdOZ9e!j,dPd'de!j"j.fdd'e!j"j3fdde!j"j.e!j"j3 fdQd@dRdS Z:e!j"j;dTdU Z<e!j"j;dVdW Z=e!j"j;e!j"j>e!j"j4dXdY Z?e!j,dZde!j"j.fdAd@e!j"j@d[d\ ZAe!j,dZde!j"j.fdAd@e!j"j-d]d^ ZBe!j"jCe!j"j.d_d` ZDe!j,dZde!j"j.fdAd@e!j"jEdadb ZFe!j,dcddded@e!j"jEe!j"jGe!j"jHdfdg ZIe!j"j;e!j"jJdhdi ZKe!j"jLdjdk ZMe!j,de!j"j.fdZdAd@e!j"jJdldm ZNe!j"j3e!j,dZde!j"j.fdAd@dndo ZOe!j"j3dpdq ZPe!j"jQdrds ZRe!j,de!j"j.fdZdAd@dtdu ZSe!,de!j"j.fd'dvdw ZTe!jUdxdy ZVe!j"jWeXdzd{ ZYe!j"j6eXd|d} ZZd~d Z[dddZ\dddZ]eXdd Z^e!j"j@eXdd Z_dd Z`e!j"j-eXdd Zae!j"jEeXdd Zbe!j"jJeXdd Zce!j"jdeXdd Zee!j,de!j"jWfdde!j"j@fde!j"j-fde!j"jEfde!j"jJfde!j"jdfde!j"j6fdd@	dd Zfdd Zge!j,dd'dAd@e!j,de!j"jhfd'dd@dd Zie!j"j6dd Zje!j"jkdd ZldS )ComponentReflectionTestNTc                 C   s.   |  |d  tjjjr|  |tjj d S d S r   )define_reflected_tablesr   rJ   rK   r2   r   rL   rQ   r9   r9   r:   rS     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 % commentr   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_keysr2   r   r   r   rc   rd   CHARFloatr   r   r   r   r   r  r   cross_schema_fk_reflectionr   rL   r7   rm   default_schema_nameindex_reflectionr!   r  r  indexes_with_ascdescreflect_indexes_with_ascdescr9  descr   rN   temp_table_reflectionrP   )r8   rR   rI   schema_prefixparent_id_argsr  r8  r:  r9   r9   r:   r  "  s@  

	
 


		z/ComponentReflectionTest.define_reflected_tablesc                 C   rX   rY   r[   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   ra   rU   rb   )r   r   r7   r^   r   r   rc   rd   re   r   r\   r!   r   rJ   rM   r2   rf   r   rV   r    rg   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_viewsr2   setr   rV   r    against)r8   rR   rI   materializedri   fullname	view_nameprefixrW   
index_namer   r9   r9   r:   rN     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   )rp   r   r   r   rR  r   r9   r9   r:   _resolve_kind  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   r2   clearrO  rW  )rp   r   rR  r9   r9   r:   _resolve_views  s   


z&ComponentReflectionTest._resolve_viewsc              	      s   dd |t ju rdd |t ju rdd d ddhtjjddd	d
|  hitjjj	s>d  
d tjj ddg tjjj	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   *  r_  r3  r5  r1  r8  r:  r   c                    s>   i | ]\}}|r|d   vr r|d   v r||qS )r   r9   ).0r   vr   removedrI   scope_filterr9   r:   
<dictcomp>G  s    z:ComponentReflectionTest._resolve_names.<locals>.<dictcomp>)r   r   r   r   r   rL   r^   rJ   r@  r2   addrW  rB  rF  temp_table_namesrf   items)rp   rI   r.   r   valuesr   r9   rb  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%  r/  r1  r3  r5  r8  r:  r(   r   rZ  r^   rX  rj  )	rp   rI   r.   r   r   rR  r   r   r   r9   r9   r:   exp_optionsP  s*   












z#ComponentReflectionTest.exp_optionsc           
      C   s   dd i}|df|i}|df||df||df|i}|  || |df||df||df||d	fdd
i|dfddi|df||df||df||df||df|||  f|i}| ||||}	| ||||	}	|	S )Ntextrk  rl  rm  r   r  r  r  r%  r.  r/  r0  r1  r3  r5  r8  r:  )rZ  r^   rX  rj  )
rp   rI   r.   r   r   emptyrR  r   r   r   r9   r9   r:   exp_commentso  s4   z$ComponentReflectionTest.exp_commentsc           
         s$  dt jd dfdd  fdd}|df dd	t jd
 d d dgi}|df dd	t jd
 d dg|df dd	t jd
 dt jd dt jd dg|df dd	t jd
 d dgi}| || |df|d ddd ddd dg|df|d d d dg|df|d d dg|df|ddd  dd!d  d"d#d  d$d%d g|d&f dg|d'f|d d d(g|d)f|d d* dg|d+f|d dg|d,f d-g|d.f|d d-g||  f|d d dgi}| ||||}	| ||||	}	|	S )/NFTc                 S   s*   | |t j|||d}|dkr|d |S )N)r`   autoincrementtypedefaultr   r
  omitrs  )r(   r   pop)r`   autoru  r   r
  r   r9   r9   r:   rt     s   
z0ComponentReflectionTest.exp_columns.<locals>.colc                    s"   dt jdd|} | fi |S )NTF)rx  ru  r
  r(   r   )r`   rh   rt   r9   r:   pk  s   z/ComponentReflectionTest.exp_columns.<locals>.pkrk  r  rv  )rx  r
  r  r  rE   rl  r  r   rm  r  r  r	  r  r  r   rB   r`   r   r  r  r  r%  r&  r(  r'  r)  r*  r+  r-  r/  r1  r2  r3  r4  r5  r8  r9  r:  rn  )
rp   rI   r.   r   r   r{  rR  r   r   r   r9   rz  r:   exp_columns  s   

	




	
'z#ComponentReflectionTest.exp_columnsc                 C      h dS )N>   r`   rt  ru  r
  r9   rp   r9   r9   r:   _required_column_keys     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{    s   z+ComponentReflectionTest.exp_pks.<locals>.pkr   rk  r  rl  rm  r   r  r  r  r  r  r#  r$  r%  rB   r/  r1  r3  r5  r8  r:  r`   )r(   r   r   rJ   materialized_views_reflect_pkr2   rZ  r^   reflects_pk_namesri  rX  rj  )rp   rI   r.   r   r   r{  rq  rR  r   r   valr   r9   r9   r:   exp_pks  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   rm   rA  rp   r   r9   r9   r:   __eq__3  s   z2ComponentReflectionTest.exp_fks.<locals>.tt.__eq__Nr<   r=   r>   r  r9   r9   r9   r:   r   2      r   c                    s$   | ||t j|d ur|n  ||dS )N)r  referred_columnsr`   r/   referred_schemareferred_tabler   ry  )r  ref_col	ref_table
ref_schemar`   r   r   r9   r:   fk9  s   	z+ComponentReflectionTest.exp_fks.<locals>.fkrk  rl  rm  r   r  r  r  r  r   r  r  r  r  r  r  r  r  r%  r/  r1  r2  rB   r5  )r  r3  r4  r8  r:  r`   )r(   r   rZ  r   rL   r^   r   rJ   r=  r2   rY  named_constraintsri  rX  rj  )rp   rI   r.   r   r   r  rR  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  column_namesr`   dialect_optionsinclude_columnsr  r  expressionsc                    s   g | ]
}| v r
d n|qS r   r9   r`  r   r  r9   r:   
<listcomp>  s    zDComponentReflectionTest.exp_indexes.<locals>.idx.<locals>.<listcomp>duplicates_constraint)	r   rJ   foreign_keys_reflect_as_index#unique_constraints_reflect_as_index*reflect_indexes_with_ascdesc_as_expressionr2   r  r(   r   )r`   r  r  r  r  r  fk_reqdup_reqsorting_expressionr   origr9   r  r:   r     s4   


z0ComponentReflectionTest.exp_indexes.<locals>.idxrk  rl  rm  r   rE   rM  r   r  r  r  T)r`   r  r  r  r  r7  r6  )r`   r  r  )r`   r  r  r  r  r  r  r  r   r  r%  r/  r1  r2  r3  r4  r5  r8  r9  r;  )rE  )r`   r  r:  r<  r   rJ  r`   rI  )r`   r  r  )rZ  extendr(   r   r^   r   r\   r   rJ   rC  r2   rD  rY  rX  rj  )
rp   rI   r.   r   r   r   rR  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_keys  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   *unique_index_reflect_as_unique_constraintsr2   r  )r`   r  r  r   r  reqr   r9   r9   r:   uc  s   
z+ComponentReflectionTest.exp_ucs.<locals>.ucrk  rl  rm  r   r  r  r  r6  T)r`   r  r  r  rE   )r`   r  r  r  r  r  )r`   r  r   r  r%  r/  r1  r3  r5  r8  r:  r`   rI  r   )rZ  r(   r   r^   r   r\   rX  rj  )rp   rI   r.   r   r   all_r  rR  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_keysK  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)rp   r   r   r9   r9   r:   r  W  s   z2ComponentReflectionTest.exp_ccs.<locals>.tt.__eq__Nr  r9   r9   r9   r:   r   V  r  r   c                    s    | ||dS )N)sqltextr`   r   r9   )rp  r`   r   r  r9   r:   cc`  s   z+ComponentReflectionTest.exp_ccs.<locals>.ccrk  rl  rm  r   r  r  r  r  r  r(  r  z$address_id > 0 and address_id < 1000r  r   r  r%  r/  r1  r3  r5  r8  r:  r   )strrZ  r(   r   r^   rX  rj  )
rp   rI   r.   r   r   r  rR  r   r   r   r9   r  r:   exp_ccsO  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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 )Nfoo_barzCREATE SCHEMA foo_barzDROP SCHEMA foo_bar)r   r&   r  r  executer    rv   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 )NrA  )r   r4   r   hasattrrm   )rp   enginer9   r9   r:   test_dialect_initialize  s   z/ComponentReflectionTest.test_dialect_initializec                 C   s   t |}t|j|jj d S r   )r   r   rA  rm   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>   r1  r%  r3  r/  r5  r:  r8  c                 S   s   g | ]
}|d  r|d  qS )r   r9   )r`  recr9   r9   r:   r    s    z@ComponentReflectionTest.test_get_table_names.<locals>.<listcomp>c                    s   g | ]}| vr|qS r9   r9   r`  t_ignore_tablesr9   r:   r    s    r  rK  )r  r  r  )r   rL   r   get_sorted_table_and_fkc_namesget_table_namesr   sorted)	rp   r   r  r  rI   rx   r   table_names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 )Nrl  rm  rk  )rk  rl  rm  )r   r   rL   get_view_namesr   rJ   rO  r2   r   r  get_materialized_view_names)rp   r   r  rx   rI   r  r  r9   r9   r:   test_get_view_names  s   

z+ComponentReflectionTest.test_get_view_namesc                 C   s,   t |}| }tt|dtj g d S rY   )r   get_temp_table_namesr   r  r   r\   rp   r   rx   rg  r9   r9   r:   test_get_temp_table_names  s   z1ComponentReflectionTest.test_get_temp_table_namesc                 C   s$   t |}| }tt|dg d S r   )r   get_temp_view_namesr   r  r  r9   r9   r:   test_get_temp_view_names  s   z0ComponentReflectionTest.test_get_temp_view_namesc                 C   s   |  | d S r   )_test_get_commentsrp   r   r9   r9   r:   test_get_comments  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_schema  s   z5ComponentReflectionTest.test_get_comments_with_schemac                 C   s   t |}| j|d}t|jd|d||df  t|jd|d||df  t|jd|d||df  | jjj}t|j||d|||f  d S )NrH   r%  r  )r   rr  r   r   r   r/  r`   )rp   r   rI   rx   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rm  rl  rk  r  r  rH   r   r`   rt  rN  z%s(%s), %s(%s)ru  )"r   rL   r   r  r  r   zipr   r'   len	enumeratecolumnsr   r`   	__class__rt  r   rc   r   
TypeEnginer   rQ  	sql_typesDateDateTimerP  __mro__intersectionr   NumericTimer   _BinaryrD   )rp   r   	use_viewsr  rI   r  	addressesr  rx   ri   tableschema_namer  irt   ctype	ctype_defr9   r9   r:   r   ;  sb   
z(ComponentReflectionTest.test_get_columnsc                 C   s6   |   }| j| }t|t |d}| j||dd d S )Nr   F)strict_constraints)r^   r   r   r   assert_tables_equal)rp   r   ri   rj   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`   )rp   r   ri   rj   rx   r  r  rt   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   r`  rt   r9   r9   r:   r        zFComponentReflectionTest.test_get_temp_view_columns.<locals>.<listcomp>)rB   r`   r   )r   r   r   )rp   r   rx   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_ifr/  )rp   r   r  rI   r  r  rx   r  
users_cons	addr_cons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   r=  r2   r   r`   r  r  r   implicitly_named_constraintsr'   r/  )rp   r   r  rI   r  r  rx   expected_schemausers_fkeysfkey1
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  r2  rH   r4  )r   rm   rA  r   r   rL   r   r   r`   r   r  r'   )
rp   r   r1  r3  r5  rx   local_fkeysr  remote_fkeysfkey2r9   r9   r:   "test_get_inter_schema_foreign_keys  s8   




z:ComponentReflectionTest.test_get_inter_schema_foreign_keysc                 C   sz   |rt j}nd }t|}|jd|d}| j|d}| |||df | j | jjj	}| |j||d|||f | j d S )Nr  rH   )
r   rL   r   r   r  r  r  r   r/  r`   )rp   r   r  rI   rx   indexesr  r  r9   r9   r:   r     s   

z(ComponentReflectionTest.test_get_indexes)r8  r;  )r:  r<  ztname,ixnamec                 C   s   t |}||}|  d |f }| ||| j t|t |d}tt|j	d t
t|j	d j| tt|j	d j| d S )Nr   r   r   )r   r   r  r  r  r   r   r   r  r  r
   r  r   r`   )rp   r   tnameixnamerx   r  expected_indexesr  r9   r9   r:   test_get_noncol_index1  s   	
z-ComponentReflectionTest.test_get_noncol_indexc                 C   sB   t |}|  }||}| jddd |f }| ||| j d S )NT)r  )r   r^   r   r  r  r  )rp   r   rx   r`   	reflectedr  r9   r9   r:   &test_get_temp_table_unique_constraintsG  s
   
z>ComponentReflectionTest.test_get_temp_table_unique_constraintsc                 C   sn   t |}|  }||}|D ]}|dd  qddgddg}tjjjr+g |d d< tdd	 |D | d S )
Nr  Fr   rJ  )r  r  r`   r   r  c                 S   s   g | ]
}|d  dkr|qS )r`   rJ  r9   r`  r   r9   r9   r:   r  ]  r   zGComponentReflectionTest.test_get_temp_table_indexes.<locals>.<listcomp>)	r   r^   r   rw  r   rJ   index_reflects_included_columnsr2   r   )rp   r   rx   ri   r  indexpectedr9   r9   r:   test_get_temp_table_indexesP  s   

z3ComponentReflectionTest.test_get_temp_table_indexesc                 C   s  |rt j}nd }tddgddg dddg dddd	d
gdddgdddgdgtdd}td|tdtdtdtdtdtj	td	tdtd
td|d}|D ]}|
tj|d d|d i q\|| t|}t|jd|dtdd}	t }
tt|t|	 t||	D ]\}}|dd }|r|
| t|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 )Nunique_ar   )r`   r  unique_a_b_c)r   br   unique_c_a_b)r   r   r*  unique_asc_keyascr   zi.have.dotsr*  zi have spacesr   r`   r   testtblr!  r  rH   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   rc   r   r`   )r`  uqr9   r9   r:   r0    s    
)r   rL   r  operator
itemgetterr   r   rc   r   r   append_constraintr   ru   r   r   rP  r   r  r  rw  rf  r   r  constraints
differencer  r   r/  r`   )rp   rR   r   r  rI   uniquesr   r  rx   r!  names_that_duplicate_indexr  refldupereflected_metadata	idx_namesuq_namesr  r9   r9   r:   r   a  sx   







z3ComponentReflectionTest.test_get_unique_constraintsc                 C   s@   |rt j}nd }t|}dD ]}|j||d}tt| qd S )Nr  rH   )r   rL   r   r   r'   bool)rp   r   r  rI   rx   viewra  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 )N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:   re        zBComponentReflectionTest.test_autoincrement_col.<locals>.<dictcomp>rs  TN)r   r   get)rp   r   rx   r  cnamer  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   r/  )r   r   r7   rL   r   rJ   r   r2   r   r'   r   r5   r   r   )rp   r  rx   rI   r   r9   r9   r:   r     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   )r`  r   rx   rI   r9   r:   re    s    zHComponentReflectionTest.test_multi_get_table_options.<locals>.<dictcomp>)r   r   r7   r   rJ   r   r2   rL   get_multi_table_optionsr  r   r   r   )rp   r  r   r  r9   rH  r:   test_multi_get_table_options  s   




"z4ComponentReflectionTest.test_multi_get_table_optionsc                    s    fdd}|S )Nc                    s   t  }||d ||d}| r|  } g }tj|v 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  )r.   r   )r%  r  does-not-existrl  rK  rk  rI   r   )rI   r.   r   r   r.   r   )r   r   r   r  r   r   rD  r   r   copyrw  append)rI   r.   r   r   single_reflect_fn
exp_methodrx   rh   r   r  kwsnkwr   r9   r:   provide_fixture  sD   










z>ComponentReflectionTest.get_multi_exp.<locals>.provide_fixturer9   )rp   r   rS  r9   rR  r:   get_multi_exp  s   .z%ComponentReflectionTest.get_multi_expc                 C   sL   |||||t j| j\}}}|D ]}	|  |jdi |	}
t|
| qd S Nr9   )r   r   ro  rv   rI  r   rp   rT  rI   r.   r   r   rx   rP  r  rh   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 rU  )r   r   rr  rv   r   get_multi_table_comment)
rp   rT  rI   r.   r   r   rx   rP  r  rh   r9   r9   r:   test_get_multi_table_commentO  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 )Nrp  c                 S   s   t dd|  S )Nz['\" ]r  )resubr  )rp  r9   r9   r:   _cleana  s   z:ComponentReflectionTest._check_expressions.<locals>._cleanc                    s   i | ]	\}} ||qS r9   r9   )r`  era  r]  r9   r:   re  e      z>ComponentReflectionTest._check_expressions.<locals>.<dictcomp>c                    s   g | ]} |qS r9   r9   )r`  r^  r_  r9   r:   r  g  r  z>ComponentReflectionTest._check_expressions.<locals>.<listcomp>)r  r   r5   r   rh  )rp   rW  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  rP  rb  )	rp   rW  r  req_keysmsgrr^  r   ra  r9   r9   r:   r  i  s   z#ComponentReflectionTest._check_listc                 C   s\   t t| t|  |D ]}|| || }}|r#|g|g}}| |||| qd S r   )r   rP  keysr  )rp   rW  r  rc  
make_listsr   re  r^  r9   r9   r:   _check_table_dictw  s   z)ComponentReflectionTest._check_table_dictc                 C   R   |||||t j| j\}}}|D ]}	|  |jdi |	}
| |
|| j qd S rU  )r   r   r|  rv   get_multi_columnsrh  r  rV  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)rg  r9   )r   r   r  rv   get_multi_pk_constraintrh  r  rV  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)rD  r(   r   )r`  ra  r9   r9   r:   	<genexpr>  s    
z7ComponentReflectionTest._adjust_sort.<locals>.<genexpr>r.  )r   rJ   r  r2   ri  r  anysort)rp   rW  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     r_  zEComponentReflectionTest.test_get_multi_foreign_keys.<locals>.<lambda>r9   )r   r   r  rv   get_multi_foreign_keysrr  rh  r  rV  r9   r9   r:   test_get_multi_foreign_keys  s    

z3ComponentReflectionTest.test_get_multi_foreign_keysc                 C   ri  rU  )r   r   r  rv   get_multi_indexesrh  r  rV  r9   r9   r:   test_get_multi_indexes  s   
z.ComponentReflectionTest.test_get_multi_indexesc                 C   rs  )Nc                 S   rt  )Nr  ru  rw  r9   r9   r:   r     r_  zKComponentReflectionTest.test_get_multi_unique_constraints.<locals>.<lambda>r9   )r   r   r  rv   get_multi_unique_constraintsrr  rh  r  rV  r9   r9   r:   !test_get_multi_unique_constraints     
z9ComponentReflectionTest.test_get_multi_unique_constraintsc                 C   rs  )Nc                 S   rt  Nr  ru  rw  r9   r9   r:   r     r_  zJComponentReflectionTest.test_get_multi_check_constraints.<locals>.<lambda>r9   )r   r   r  rv   get_multi_check_constraintsrr  rh  r  rV  r9   r9   r:    test_get_multi_check_constraints  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 )Ntable_does_not_exists)r   getattrr   r   )rp   r  r   rx   r   r9   r9   r:   test_not_existing_table  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 )Nunreflectableerr)N
some_table)
setdefaultr   )r   r   urmcr9   r:   patched	  s   z;ComponentReflectionTest.test_unreflectable.<locals>.patchedrj  r  r  )r   rj  r(   patchobjectr   r   r   reflect_tabler   r   )rp   r   r  r9   r  r:   test_unreflectable	  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   resolve_fksc                    s   g | ]	}  d | qS )r  r9   r  rH   r9   r:   r  8	  r`  z9ComponentReflectionTest.test_metadata.<locals>.<listcomp>)r   r   rL   reflectr   r  r  r  r   r   r  r   )rp   r   r  r   mrx   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   試蛇ẟΩ✨rp  c                 S      i | ]	}|d  |d qS r  r9   r  r9   r9   r:   re  L	  r`  zAComponentReflectionTest.test_comments_unicode.<locals>.<dictcomp>)r  r  r   r   r   r   r   r   r   r   )rp   r   rR   rx   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 )
Nr  r  u&   🐍🧙🝝🧙‍♂️🧙‍♀️r(  u&   🎩🁰🝑🤷‍♀️🤷‍♂️rp  r   r`   r   r  )rp   r   rR   rx   r  r   r9   r9   r:   test_comments_unicode_fullP	  s   

z2ComponentReflectionTest.test_comments_unicode_fullr   r)   )NF)mr<   r=   r>   run_insertsrun_deletesr   r?   rS   r  r^   rP   rN   rX  rZ  rj  r   r   r   ro  rr  r|  propertyr  r  r  r  r  r  r  r  r  r  r  r   rJ   schema_reflectionr  r  r  r  schema_create_deleter  r  r  r   !foreign_key_constraint_reflectionrK   r  r  rg  r  rM   rf   r  r   r  r  r  r   rF  r  r	  r   r  !primary_key_constraint_reflectionr   r   r@  r  rB  r   rC  rD  r   r   r"  temp_table_reflect_indexesr'  r   r   rA  table_reflectionrG  r   rJ  fixturerT  r   r   rX  rZ  rb  r  rh  rk  rm  rr  rz  r|  r~  r   r  r  r  r   r  r  comment_reflection_full_unicoder  r9   r9   r9   r:   r     s   

 .

!

-
!
&
`

0

X

u

E

:







#




A


&$
V





1
	

	




r   c                   @   sh   e Zd ZdZdZejdd Zejdd Zdd Z	d	d
 Z
dd Zejjdd Zejjdd ZdS )TableNoColumnsTest)reflect_tables_no_columnsTc                 C   s   t d| || d S Nrq  )r   r   rp   r   rR   r9   r9   r:   table_no_columnsf	  s   
z#TableNoColumnsTest.table_no_columnsc                 C   s<   t d| t|dtd t|dtd || d S )Nrq  rT   z*CREATE VIEW empty_v AS SELECT * FROM emptyrU   zDROP VIEW IF EXISTS empty_v)r   r   rV   r    r   r  r9   r9   r:   view_no_columnsk	  s   

z"TableNoColumnsTest.view_no_columnsc                 C   $   t dt |d}tt|jg  d S )Nrq  r   r   r   r   r  r   )rp   r   r  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 )Nrq  r  )r   r   r   rj  )rp   r   r  rx   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   r  rP  r   r  )rp   r   r  r  r9   r9   r:   "test_reflect_incl_table_no_columns	  s   
z5TableNoColumnsTest.test_reflect_incl_table_no_columnsc                 C   r  )Nempty_vr   r  )rp   r   r  r  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 )Nr  )r   )Nr  )r   r   r   rj  r   r   )rp   r   r  rx   r  r9   r9   r:    test_get_columns_view_no_columns	  s   z3TableNoColumnsTest.test_get_columns_view_no_columnsN)r<   r=   r>   __requires__r   r   r  r  r  r  r  r  rJ   r   r  r  r9   r9   r9   r:   r  b	  s    


r  c                
   @   sd  e Zd ZdZejddgddd Ze dd Zdd	 Zej	j
d
d Zej	jejddddddd Zej	j
ejddddddd Zej	jdd Zej	jdd Zej	jdd Zdd Zej	jdd  Zej	jd!d" Zej	jd#d$ Zejdd%dej	jfddd&ej	jfi dd'ej	jfi d'dej	jfddd(ej	jfdd(dej	jfd)dd*d+ ZdS ),ComponentReflectionTestExtraTF)paramsc                 C   s   |j rtjS d S r   )paramr   rL   )rp   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   r  r9   r:   go	  s   z:ComponentReflectionTestExtra.inspect_for_table.<locals>.go)
contextlibcontextmanager)rp   rR   r   r  r  r9   r  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   )r`  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   )rp   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 )Nr/  rE   r!  rH   )r   r   rc   r   r  r   )rp   rR   r  rI   r   r9   r9   r:   #test_check_constraint_no_constraint	  s   z@ComponentReflectionTestExtra.test_check_constraint_no_constraint	my_inline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   rc   r   r   r   r  r(   r   rp   rR   r  r  rI   r   r!  r9   r9   r:   test_check_constraint_inline	  s0   z9ComponentReflectionTestExtra.test_check_constraint_inlinemy_ck_const	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   rc   r   r   r  r(   r   r  r9   r9   r:    test_check_constraint_standalone	  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   some_uqzc > 1 AND c < 5cc1	some_c_uqrH   zc > 1 and c < 5r  zb > 1 and b < 5r  )r   r   r   rc   r   r   r   r   r  r(   r   )rp   rR   r  rI   r   r!  r9   r9   r:   test_check_constraint_mixed
  s6   

z8ComponentReflectionTestExtra.test_check_constraint_mixedc              	      s  t d|tdtdtdtdtdtd}tdt|jj|jjt|jj	 dtdt
|jj td	|jj |  t }d	dgd
i dg} fdd}||d  G dd dt}G fdddt}tjjj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 
t_idx_long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  _includer  )r   rJ   r$  r2   r  r`   r  )entryrR  r9   r:   completeIndexO
  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  )rp   r   olr9   r9   r:   r  [
  s   zbComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.lower_index_str.__eq__Nr  r9   r9   r9   r:   lower_index_strZ
  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  a
  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    reflect_indexes_with_expressionsr2   insertrM  r   r   r   r   !compare_table_index_with_expectedr  r`   )rp   rR   r   r  rx   r&  r  r  r  
expr_indexexpr_index_longr   r  r9   )r   r  r:   %test_reflect_expression_based_indexes3
  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  )rp   rR   r   r  r   rx   r   r  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   )r`  r  type_r9   r9   r:   r  
      zAComponentReflectionTestExtra._type_round_trip.<locals>.<listcomp>c                 S   r
  )rt  r9   r  r9   r9   r:   r  
  r  )r   r  ru   r   r   )rp   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rp   r   rR   typr9   r9   r:   test_numeric_reflection
  s   z4ComponentReflectionTestExtra.test_numeric_reflectionc                 C   s8   |  ||tdd }t|tjsJ t|jd d S )N4   r   )r  r  r   r   r   lengthr   r9   r9   r:   test_varchar_reflection
  s   z4ComponentReflectionTestExtra.test_varchar_reflectionc              	   C   sT   t d|tdtddtdtdd}|| tdd t|dD ddd	 d S )
Nr  r   Tr	  r*  Fc                 S   r  )r`   r
  r9   r  r9   r9   r:   re  
  s    zIComponentReflectionTestExtra.test_nullable_reflection.<locals>.<dictcomp>)r   r*  )r   r   r   ru   r   r   r   )rp   r   rR   r  r9   r9   r:   test_nullable_reflection
  s   
z5ComponentReflectionTestExtra.test_nullable_reflectionCASCADEzSET NULLz	NO ACTION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   x_idzx.idxidr   test
   userr`   rF   Fr	  tidztable.idmyfkr   r/   c                    s   i | ]} | r| | qS r9   r9   )r`  r   optsr9   r:   re  <  r  zMComponentReflectionTestExtra.test_get_foreign_key_options.<locals>.<dictcomp>)r   r   r   r   r   rc   r   r   r   r   r   )rp   r   rR   r&  r	  r
  r/   rx   r9   r  r:   test_get_foreign_key_options
  sT   *	
z9ComponentReflectionTestExtra.test_get_foreign_key_options) r<   r=   r>   r   r   r  r  r  r  rJ   r   r  "inline_check_constraint_reflectionr   r  r  r  indexes_with_expressionsr  r$  r  r  r  r  r  r  1foreign_key_constraint_option_reflection_ondelete1foreign_key_constraint_option_reflection_onupdate1fk_constraint_option_reflection_ondelete_noaction1fk_constraint_option_reflection_onupdate_restrict1fk_constraint_option_reflection_ondelete_restrictr  r9   r9   r9   r:   r  	  s    

	
 

Z
*



'r  c                   @   s0   e Zd ZdZdZedd Zdd Zdd Zd	S )
NormalizedNameTest)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   r  t1idzt1.id)r   r"   r   r   r   rQ   r9   r9   r:   rS   G  s   

z NormalizedNameTest.define_tablesc                 C   s~   t  }ttddd|tjd}|jd }|jj|jj	sJ t  }|j
tjdd d |jd jj|jd jj	s=J d S )	Nr  Tr  r   r   c                 S   s   |   dv S )Nr   r  r  )r`   r  r9   r9   r:   r   _  r_  zINormalizedNameTest.test_reflect_lowercase_forced_tables.<locals>.<lambda>)only)r   r   r"   r   r7   r   r   r  r   rB   r  )rp   r   t2_reft1_refm3r9   r9   r:   $test_reflect_lowercase_forced_tablesU  s   

&z7NormalizedNameTest.test_reflect_lowercase_forced_tablesc                 C   sP   dd t tj D }t|d  |d   t|d  |d   d S )Nc                 S   s   g | ]
}|  d v r|qS )r   r  r  r9   r9   r:   r  d  s
    z;NormalizedNameTest.test_get_table_names.<locals>.<listcomp>r   r   )r   r   r7   r  r   upperr  )rp   
tablenamesr9   r9   r:   r  c  s
   z'NormalizedNameTest.test_get_table_namesN)	r<   r=   r>   r  r   r?   rS   r%  r  r9   r9   r9   r:   r  C  s    
r  c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zejj	d	d
 Z
dS )ComputedReflectionTestc                 C   s^   t tj}|d}dd |D }td|d d v  t|d d d  t|d d d  d S )	Ncomputed_default_tablec                 S   rB  r   r9   r  r9   r9   r:   re  s  rC  zLComputedReflectionTest.test_computed_col_default_not_set.<locals>.<dictcomp>42with_defaultru  normalcomputed_col)r   r   r7   r   r'   r
   )rp   rx   r  col_datar9   r9   r:   !test_computed_col_default_not_seto  s   

z8ComputedReflectionTest.test_computed_col_default_not_setc                 C   s   t tj}|d}dd |D }dD ]
}td|| v q|d }td|v  td|d v  t| |d d d td	|d v tjj	j
 tjj	j
r[t|d d	 tjjj
 d S d S )
Nr)  c                 S   rB  r   r9   r  r9   r9   r:   re  |  rC  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_persistedr2   "computed_columns_default_persisted)rp   rx   r  rE   r   compDatar9   r9   r:    test_get_column_returns_computedx  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 )Nr0  r  r2  )r'   r   r  r   rJ   r3  r2   r
   )rp   rE   columnr  r2  r5  r9   r9   r:   check_column  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   rB  r   r9   r  r9   r9   r:   re    rC  zLComputedReflectionTest.test_get_column_returns_persisted.<locals>.<dictcomp>computed_no_flagr1  computed_virtualznormal+2Fcomputed_storedz	normal-42T)r   r   r7   r   r8  r   rJ   r4  r2   computed_columns_virtualcomputed_columns_storedrp   rx   r  rE   r9   r9   r:   !test_get_column_returns_persisted  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 )Nr9  rH   c                 S   rB  r   r9   r  r9   r9   r:   re    rC  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   r8  r   rJ   r4  r2   r=  r>  r?  r9   r9   r:   -test_get_column_returns_persisted_with_schema  s4   


zDComputedReflectionTest.test_get_column_returns_persisted_with_schemaN)r<   r=   r>   r/  r6  r8  r@  r   rJ   rK   rA  r9   r9   r9   r:   r(  n  s    	r(  c                   @   sH   e Zd Zd ZZdZdZedd Zdd Z	dd	 Z
ejjd
d ZdS )IdentityReflectionTestNT)identity_columnsr  c                 C   s   t d|tdttdtt  t d|tdttdddd	d
ddd tjjjr>t d|tdttdttdddtj	d d S d S )Nr   r,  id1r  r   Tr   r   r,     alwaysstart	incrementminvaluemaxvaluecyclecacher!  )rH  rI  rH   )
r   r   r   r   r   rJ   rK   r2   r   rL   rQ   r9   r9   r:   rS     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 )NrG  rK  >   rN  rL  rI  rJ  )	r   rJ   identity_columns_standardr2   r  rw  r   r  r'   )rp   r  r  approx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   r  r`   r,  identityrD  rs  ru  Fr   rG  TrP  r   r   r   rE  r,  rF  )	r   r   r7   r   r&   r'   r   rR  r5   rp   rx   r  rt   r9   r9   r:   test_reflect_identity  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,  rS  rD  rs  ru  Tr!  r   rT  FrG  rU  )
r   r   r7   r   rL   r&   r'   r   rR  r5   rV  r9   r9   r:   test_reflect_identity_schema@  s2   
	z3IdentityReflectionTest.test_reflect_identity_schema)r<   r=   r>   r  r  r   r  r?   rS   rR  rW  r   rJ   rK   rX  r9   r9   r9   r:   rB    s    
!,rB  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!  pk_tb1r   Tr  tb2rC   pidpattrpnamer`  r^  r_  fk_tb1_name_id_attr)r   r   r   r  re   rc   r   r   r   r`   rB   r[  )r8   rR   rZ  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   rZ  r`   r   rD  )rp   r   rx   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  rc  r  ra  )r   r   r   r]  r`   r   r  rD  )rp   r   rx   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  rd  r  rf  r9   r9   r9   r:   rY  \  s    

rY  )r   r  r  r   r   r@   r   r  r(  rB  rY  )Dr  r2  r[  r3   rc   r  r   r   r   r   r   r   r	   r
   	provisionr   r   rI   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r   r   excr   r   r    r!   sql.elementsr"   
sql.schemar#   r$   r%   r&   r'   r(   rR   r  
TablesTestr*   r@   r   TestBaser   r   r   r   r  r  r  ComputedReflectionFixtureTestr(  rB  rY  __all__r9   r9   r9   r:   <module>   s    L;               Y5   /+a 1