U
    ui                    @   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d+lm4Z4 d,\Z5Z6G d-d. d.ej7Z8G d/d0 d0e8Z9G d1d2 d2ej7Z:G d3d4 d4ej;Z<G d5d6 d6ej;Z=G d7d8 d8ej7Z>d9d: Z?G d;d< d<e0e8Z@G d=d> d>ej;ZAG d?d@ d@e/ej;ZBG dAdB dBej7ZCG dCdD dDejDZEG dEdF dFej7ZFG dGdH dHej7ZGdIZHdS )J    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_none)is_true)mock)NNc                   @   s   e Zd Zedd ZdS )OneConnectionTablesTestc                 C   s6   t jjjr,ddlm} tjt|j	dddS t j
S d S )Nr   )poolclass)Z	poolclassscope)options)r   requirementsZindependent_connectionsenabled
sqlalchemyr.   r   testing_enginedictZ
StaticPooldb)clsr.    r9   b/home/lhs5088/backend/venv/lib/python3.8/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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 )HasTableTestTNc                 C   s~   t d|tdtddtdtd tjjjrTt d|tdtddtdtdtj	d tjj
rf| | tjjjrz| | d S )	N
test_tableidTprimary_keydata2   test_table_sschema)r   r   r   r   r   requiresschemasr3   r   test_schemaview_reflectiondefine_viewshas_temp_tabledefine_temp_tablesr8   metadatar9   r9   r:   define_tablesP   s$    


zHasTableTest.define_tablesc                 C   sp   d}t |dt| t |dtd tjjjrldtjtjf }t |dt| t |dtdtj  d S )Nz1CREATE VIEW vv AS SELECT id, data FROM test_tableafter_createbefore_dropzDROP VIEW vvz9CREATE VIEW %s.vv AS SELECT id, data FROM %s.test_table_szDROP VIEW %s.vv)	r   listenr#   r   rJ   rK   r3   r   rL   )r8   rR   queryr9   r9   r:   rN   f   s     
zHasTableTest.define_viewsc                 C   s   t ttjdtj S NZ	user_tmp_r   r   r7   identr8   r9   r9   r:   temp_table_name|   s
      
zHasTableTest.temp_table_namec              	   C   s   t ttj}|  }t||tdtjddtdtdf|}t	j
jjr|t	j
jjr|t|dtdtj  t|dtd	 d S )
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#   rZ   r8   rR   kw
table_nameuser_tmpr9   r9   r:   rP      s0    zHasTableTest.define_temp_tablesc              	   C   sV   t j B}tt jj|d tt jj|d tt jj|d W 5 Q R X d S )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 5 |
tj X d S )NrA   Z	new_tablecol)r   r   r7   r+   rk   r   r   r   r)   createdropclear_cache)rm   rR   inspntr9   r9   r:   test_has_table_cache   s    
z!HasTableTest.test_has_table_cachec              	   C   sh   t j T}tt jjj|dt jd tt jjj|dt jd tt jjj|dt jd W 5 Q R X d S )NrA   rH   rG   rh   )r   r7   ri   r)   rj   rk   rL   r+   rl   r9   r9   r:   test_has_table_schema   s,          z"HasTableTest.test_has_table_schemac              	   C   s2   t j }tt jjj|ddd W 5 Q R X d S )NrA   Znonexistent_schemarH   )r   r7   ri   r)   rj   rk   rl   r9   r9   r:   !test_has_table_nonexistent_schema   s      z.HasTableTest.test_has_table_nonexistent_schemac                 C   s   t |}t|d d S NZvvr   r+   rk   rm   
connectionrt   r9   r9   r:   test_has_table_view   s    z HasTableTest.test_has_table_viewc                 C   s"   t |}|  }t|| d S N)r   r\   r+   rk   )rm   r|   rt   r\   r9   r9   r:   test_has_table_temp_table   s    z&HasTableTest.test_has_table_temp_tablec                 C   s   t |}t|d d S N
user_tmp_vrz   r{   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 ry   )r   r+   rk   r   rL   r{   r9   r9   r:   test_has_table_view_schema   s    z'HasTableTest.test_has_table_view_schema)r<   r=   r>   __sparse_driver_backend__run_deletesr?   rS   rN   r\   rP   ro   rv   r   rJ   rK   rw   rx   viewsr}   rO   r   rM   rc   r   r   r9   r9   r9   r:   r@   K   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 )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_tablesrj   	inspectorkindargnamesc                    s"   |dkr fddS t  jS d S )Nrj   c                     s   t jjj f| |S r~   )r   r7   rj   	has_index)akrn   r9   r:   <lambda>       z)HasIndexTest._has_index.<locals>.<lambda>)r   r   )rm   r   rn   r9   r   r:   
_has_index   s    zHasIndexTest._has_indexc              	   C   s  |  ||}|ddst|ddr(t|ddr6t|ddrDt|ddrRt|ddr`ttd| jjjj}td|td	t	tdd	}|
| |
| zV|d
kr|ddrt|ddrt|j  |dddkst|dddkstW 5 || || X d S )NrA   r   r   rh   Znonexistent_idxZmy_idx_2Ztest_table_2Zmy_idx_3foor   T)r   AssertionErrorr$   tablesrA   r   r   r   r   r   rq   rr   __self__rs   )rm   r   r|   rR   methidxZtblr9   r9   r:   test_has_index  s2    



zHasIndexTest.test_has_indexc                 C   s`   |  ||}|ddtjds t|ddtjdr4t|ddtjdrHt|ddtjdr\td S )NrA   r   rH   r   rh   Znonexistent_idx_s)r   r   rL   r   )rm   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   s   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_names4  s    z!BizarroCharacterTest.column_namesc                   C   s   t jddddddS )N)plain)z(2))z
per % cent)z
[brackets]	tablenamer   r   r9   r9   r9   r:   table_names=  s    z BizarroCharacterTest.table_namesuse_compositeFc           
      C   s  t ||t|tddddd}|r4|tdtdd |r~t d|tdtddtdttd	ttdd	g|jj|jjgdd n*t d|tdtddtdt	|jjdd |
| t }t d||d
}|j| }	|jj|	jd st|r|jj|	jd stdS )ztests for #10275rB   T)keyrD   test_needs_fkid2rC   otherrefref2autoload_withr      N)r   r   r   append_columnr`   ForeignKeyConstraintr   rB   r   r   
create_allr   r   r   
referencesr   r   )
rm   r|   rR   r   r   r   r   m2o2t1r9   r9   r:   test_fk_refF  s@    


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rm   r   r   r|   rR   rt   r9   r9   r:   test_reflect_identityu  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   0  s    		+r   c                   @   sB   e Zd ZdZdZejdd Zejj	dd Z
ejjdd Zd	S )
TempTableElementsTestT)temp_table_reflectionc                 C   s   t ttjdtj S )NZ
ident_tmp_rY   rm   r9   r9   r:   r     s
      
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   rm   r   r|   rR   rt   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rt d|tdttdtdtdtdtdttjdddtddtjdddtjdgdgddtj	dddddd t d|tdtddtdtdd t
jjjrt
jjjr>ddg}ndg}|D ]f}dtjjjd| tjjj|f }t|dt| t|dtd tjjjd|   qHd S )!Nquote ' 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   r`   PrimaryKeyConstraintr$   UniqueConstraintr   CheckConstraintr   rJ   symbol_names_w_double_quoter3   view_column_reflectionr   r7   rj   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   sP   t tj}tjjjr.||}tt	|t
 ntt || W 5 Q R X d S r~   )r   r   r7   r   rJ   reflect_table_optionsr3   get_table_optionsr+   
isinstancer6   r   NotImplementedError)rm   r]   rt   resr9   r9   r:   test_get_table_options  s    



z-QuotedNameArgumentTest.test_get_table_optionsc                 C   s    t tj}|d| std S )Nr   )r   r   r7   get_view_definitionr   rm   r]   rt   r9   r9   r:   test_get_view_definition%  s    
z/QuotedNameArgumentTest.test_get_view_definitionc                 C   s   t tj}||std S r~   )r   r   r7   r   r   r   r9   r9   r:   test_get_columns+  s    
z'QuotedNameArgumentTest.test_get_columnsc                 C   s   t tj}||std S r~   )r   r   r7   get_pk_constraintr   r   r9   r9   r:   test_get_pk_constraint0  s    
z-QuotedNameArgumentTest.test_get_pk_constraintc                 C   s   t tj}||std S r~   )r   r   r7   get_foreign_keysr   r   r9   r9   r:   test_get_foreign_keys5  s    
z,QuotedNameArgumentTest.test_get_foreign_keysc                 C   s   t tj}||std S r~   )r   r   r7   get_indexesr   r   r9   r9   r:   test_get_indexes;  s    
z'QuotedNameArgumentTest.test_get_indexesc                 C   s   t tj}||std S r~   )r   r   r7   get_unique_constraintsr   r   r9   r9   r:   test_get_unique_constraintsA  s    
z2QuotedNameArgumentTest.test_get_unique_constraintsc                 C   s   t tj}||std S r~   )r   r   r7   get_table_commentr   r   r9   r9   r:   test_get_table_commentG  s    
z-QuotedNameArgumentTest.test_get_table_commentc                 C   s   t tj}||std S r~   )r   r   r7   get_check_constraintsr   r   r9   r9   r:   test_get_check_constraintsM  s    
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   X  r   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_combinationT  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,d]d^d_d`dad@e!j"j@e!j"jBdbdc ZCe!j,dZde!j"j.fdAd@e!j"j-ddde ZDe!j,dfdgdhdidjd@e!j"j-dkdl ZEe!j"jFe!j"j.dmdn ZGe!j,dZde!j"j.fdAd@e!j"jHdodp ZIe!j,dqdrdsd@e!j"jHe!j"jJe!j"jKdtdu ZLe!j,dvdwdxdydzd@e!j"jHd{d| ZMe!j"j;e!j"jNd}d~ ZOe!j"jPdd ZQe!j,de!j"j.fdZdAd@e!j"jNdd ZRe!j,dddddd@e!j"jNdd ZSe!j"j3e!j,dZde!j"j.fdAd@dd ZTe!j"j3dd ZUe!j"jVdd ZWe!j,de!j"j.fdZdAd@dd ZXe!,de!j"j.fd'dd ZYe!jZdd Z[e!j"j\e]dd Z^e!j"j6e]dd Z_dd Z`dddZadddZbe]dd Zce!j"j@e]dd Zddd Zee!j"j-e]dd Zfe!j"jHe]dd Zge!j"jNe]dd Zhe!j"jie]dd Zje!j,de!j"j\fdde!j"j@fde!j"j-fde!j"jHfde!j"jNfde!j"jifde!j"j6fdd@	dd Zkdd Zle!j,dd'dAd@e!j,de!j"jmfd'dd@dd Zne!j"j6dd Zoe!j"jpdd Zqe!j"jre!j"jsddÄ ZtdS )ComponentReflectionTestNTc                 C   s*   |  |d  tjjjr&|  |tjj d S r~   )define_reflected_tablesr   rJ   rK   r3   r   rL   rQ   r9   r9   r:   rS   w  s    
z%ComponentReflectionTest.define_tablesc                 C   s  |r|d }nd}t jjjr0td| ddf}nd}td|tdtjd	d
tdt	dddtdt
 ddtdtjf| tjddddtd|d	d
}td|tdtjd	d
tdtjtd| dddtdtjtd| tdtdd	d tjd!d"dtjddd#d$d|d	d
 td%|tdtjtd&tjt|jjtd'td(d	d)tjdd*d+d|d	d td,|td-tjd	d.d/tdtd(d0d1td2td(d3d1td4td5d6d1|d7d8 td9|tdtd(|d:d8 t jjjr|d kr4td;|td-tjd	d
tdtd(td<td=t jj d	tjjjd> nntd?|td-tjd	d
td@tdAtjjj tdtd(|d	d tdB|td-tjd	d
tdtd(|d	d t jjjrhtdC|jj|jjd	d  tdD|jj|jj|jj |shtdE|tdFtdd	dG}tdH|td-tjd	d
tdFtdd	dG}t jjjrht jjjrhtdI|jj  tdJ|jj  t jj jr| !|| |st jj"jr| #| d S )KN. z%susers.user_id
user_id_fkr   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   r`   ra   CHARFloatr   r   r   r   r   r  r   cross_schema_fk_reflectionr   rL   r7   rj   default_schema_namer   r$   r  r  indexes_with_ascdescreflect_indexes_with_ascdescr9  descr   rN   r   rP   )r8   rR   rI   Zschema_prefixZparent_id_argsr  r8  r:  r9   r9   r:   r  }  sJ   

 	
 
  

	   	z/ComponentReflectionTest.define_reflected_tablesc                 C   s   t ttjdtj S rX   rY   r[   r9   r9   r:   r\   +  s
      
z'ComponentReflectionTest.temp_table_namec                 C   s   t ttj}|  }t||tdtjddtdtdtdtjtj	ddtj
 dtd	df|}tjjjrtjjjrt|d
tdtj
  t|dtd d S )NrB   TrC   r]   rF   r   user_tmp_uq_r   user_tmp_ixrT   r^   rU   r_   )r   r   r7   r\   r   r   r`   ra   rb   r   rZ   r$   r   rJ   rM   r3   rc   r   rV   r#   rd   r9   r9   r:   rP   1  s6    

z*ComponentReflectionTest.define_temp_tablesc              
   C   s   t jjjrdh}nt }dD ]}|}|r6| d| }|d }||krJdnd}d| d| d	| }t|d
t| ||krd}	|rt dr| d|	 }	d|	 d| d}
t|d
t|
 t|dtd| d|  qd S )Nr  )r  r  r  r  _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   materializedrf   fullnameZ	view_nameprefixrW   Z
index_namer   r9   r9   r:   rN   S  s.    
  z$ComponentReflectionTest.define_viewsc                 C   sD   i }t j|kr|| t j|kr,|| t j|kr@|| |S r~   )r   r   updater   r   )rm   r   r   r   rM  r   r9   r9   r:   _resolve_kindn  s    





z%ComponentReflectionTest._resolve_kindc                 C   s<   t jjjs|  |  nt jjjs8|| |  d S r~   )r   rJ   r   r3   clearrJ  rP  )rm   r   rM  r9   r9   r:   _resolve_viewsx  s    



z&ComponentReflectionTest._resolve_viewsc              	      s   dd |t jkrdd |t jkr,dd d ddhtjjddd	d
|  hitjjj	s|d  
d tjj ddg tjjj	sd  dd	g tjjj	rtjjj	sd  d
|  g tjjj	s܈d  d
g  fdd| D }|S )Nc                 S   s   dS )NTr9   )_r9   r9   r:   r     r   z8ComponentReflectionTest._resolve_names.<locals>.<lambda>c                 S   s   d| d kS Ntmpr   r9   r   r9   r9   r:   r     r   c                 S   s   d| d kS rU  r9   rW  r9   r9   r:   r     r   r3  r5  r1  r8  r:  r   c                    s>   i | ]6\}}|r|d   kr r4|d   kr||qS )r   r9   ).0r   vr   ZremovedrI   Zscope_filterr9   r:   
<dictcomp>  s     z:ComponentReflectionTest._resolve_names.<locals>.<dictcomp>)r    r   r   r   r   rL   r\   rJ   r@  r3   addrP  r   r   temp_table_namesrc   items)rm   rI   r0   r   valuesr   r9   rZ  r:   _resolve_names  sF    

 



z&ComponentReflectionTest._resolve_namesc           	      C   s   |dft ji}|dft j|dft j|dft ji}| || |dft j|dft j|dft j|dft j|d	ft j|d
ft j|dft j|dft j|dft j|dft j||  ft ji}| ||||}| ||||}|S )Ndingalings_vemail_addresses_vusers_vr   r  r  r  r&  r/  r1  r3  r5  r8  r:  r,   r   rS  r\   rQ  r`  )	rm   rI   r0   r   r   rM  r   r   r   r9   r9   r:   exp_options  sF                 
 z#ComponentReflectionTest.exp_optionsc           
      C   s   dd i}|df|i}|df||df||df|i}|  || |df||df||df||d	fdd
i|dfddi|df||df||df||df||df|||  f|i}| ||||}	| ||||	}	|	S )Ntextra  rb  rc  r   r  r  r  r&  r.  r/  r0  r1  r3  r5  r8  r:  )rS  r\   rQ  r`  )
rm   rI   r0   r   r   emptyrM  r   r   r   r9   r9   r:   exp_comments  sP                 
 z$ComponentReflectionTest.exp_commentsc           
         s$  dt jd dfdd  fdd}|df dd	t jd
 d d dgi}|df dd	t jd
 d dg|df dd	t jd
 dt jd dt jd dg|df dd	t jd
 d dgi}| || |df|d ddd ddd dg|df|d d d dg|df|d d dg|df|ddd  dd!d  d"d#d  d$d%d g|d&f dg|d'f|d d d(g|d)f|d d* dg|d+f|d dg|d,f d-g|d.f|d d-g||  f|d d dgi}| ||||}	| ||||	}	|	S )/NFTc                 S   s*   | |t j|||d}|dkr&|d |S )N)r]   autoincrementtypedefaultr   r  omitri  )r,   r   pop)r]   autork  r   r  r   r9   r9   r:   rp     s    
z0ComponentReflectionTest.exp_columns.<locals>.colc                    s   dt jdd|} | f|S )NTF)rn  rk  r  r,   r   )r]   re   rp   r9   r:   pk  s    z/ComponentReflectionTest.exp_columns.<locals>.pkra  r  rl  )rn  r  r  r  rE   rb  r   r!  rc  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:  rd  )
rm   rI   r0   r   r   rq  rM  r   r   r   r9   rp  r:   exp_columns  s       
	




	      
'z#ComponentReflectionTest.exp_columnsc                 C   s   ddddhS )Nr]   rj  r  rk  r9   r   r9   r9   r:   _required_column_keysN  s    z-ComponentReflectionTest._required_column_keysc                 C   sN  t jd ddd}|d d}tjjjr8|df|di}n|df|i}|df||df||d	f|i}| || |d
f|d|df|d|df|dddd|df|d|df||df|d|df|d|df|d|df||df|d||  f|di}	tjjjs*|		 D ]}
|
d d k	r
t j|
d< q
| 
||	||}| ||||}|S )Nr  c                 W   s   t || |dS )N)constrained_columnsr]   r   )list)r]   r   colsr9   r9   r:   rq  Y  s    z+ComponentReflectionTest.exp_pks.<locals>.pkr   ra  r  rb  rc  r   r  r  r  r  r  r$  r%  r&  rB   r/  r1  r3  r5  r8  r:  r]   )r,   r   r   rJ   Zmaterialized_views_reflect_pkr3   rS  r\   reflects_pk_namesr_  rQ  r`  )rm   rI   r0   r   r   rq  rg  rM  r   r   valr   r9   r9   r:   exp_pksR  s^    

               
 zComponentReflectionTest.exp_pksc                 C   s   ddhS )Nr]   rt  r9   r   r9   r9   r:   _required_pk_keys  s    z)ComponentReflectionTest._required_pk_keysc                    s  G dd d |t jd f fdd	}|dfg i}|dfg |dfg |dfg i}| || |d	f|d
gdgd	ddg|df|dgdgd	|dgdgddddg|df|dgdgd	g|dfg |dfg |df|dgdgdtjdg|df|dgdgdd dg|dfg |dfg |d fg ||  fg i}tjjj	s<||d	f 
  tjjj	s~| D ],}	|	D ] }
|
d! t jk	rXt j|
d!< qXqP| ||||}| ||||}|S )"Nc                   @   s   e Zd Zdd ZdS )z+ComponentReflectionTest.exp_fks.<locals>.ttc                 S   s   |d kpt jjj|kS r~   )r   r7   rj   rA  rm   r   r9   r9   r:   __eq__  s    z2ComponentReflectionTest.exp_fks.<locals>.tt.__eq__Nr<   r=   r>   r|  r9   r9   r9   r:   r     s   r   c                    s$   | ||t j|d k	r|n  ||dS )N)rt  referred_columnsr]   r1   referred_schemareferred_tabler   ro  )rv  Zref_colZ	ref_table
ref_schemar]   r   r   r9   r:   fk  s    	z+ComponentReflectionTest.exp_fks.<locals>.fkra  rb  rc  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   rS  r   rL   r\   r   rJ   r=  r3   rR  named_constraintsr_  rQ  r`  )rm   rI   r0   r   r   r  rM  r   r   valsrx  r   r9   r  r:   exp_fks  s       
     
 #zComponentReflectionTest.exp_fksc                 C   s   dddddhS )Nr]   rt  r  r  r~  r9   r   r9   r9   r:   _required_fk_keys  s    z)ComponentReflectionTest._required_fk_keysc           
      C   s  dd ddddd}|dfg i}|dfg |dfg |dfg i}|  || |rf||df |d	d
d |df|dddd|ddddd|ddddd|df|d	tjddd|dtjdd|dddddd|df|dtjd|dtjdd|d fg |d!fg |d"f|d#tjdd|d$f|d%tjdd|d&fg |d'f|d(d)d(d*id+|d,f|d(d-d(d*id+||  f|d.d/d|d0d1tj ddd2i}tjj	j
rtjjj
s||d'f   ||d,f   | ||||}	| ||||	}	|	S )3NF)r  column_sorting
duplicatesr  c                    s   t jj}t jj}t jj}|r"|jr,|r0|js0dS |t|| tjg d}	 r~ |	d< |jr~|	d  |	d< }
 fdd|
D |	d< |r| |	d< |	gS )	Nr9   )r  r   r]   dialect_optionsinclude_columnsr  r   expressionsc                    s   g | ]}| krd n|qS r~   r9   rX  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   ru  r,   r   )r]   r  r  r  r  rv  Zfk_reqZdup_reqZsorting_expressionr   origr9   r  r:   r     s4    


z0ComponentReflectionTest.exp_indexes.<locals>.idxra  rb  rc  r   rE   rH  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;  )rD  )r]   r  r:  r<  r   rF  r]   rE  )r]   r  r  )rS  extendr,   r   r\   r   rZ   r   rJ   rB  r3   rC  rR  rQ  r`  )
rm   rI   r0   r   r   r   rM  r   r   r   r9   r9   r:   exp_indexes  s    
%   
     


5z#ComponentReflectionTest.exp_indexesc                 C   s
   dddhS )Nr]   r   r  r9   r   r9   r9   r:   _required_index_keys]  s    z,ComponentReflectionTest._required_index_keysFc                 C   s  d dd ddd}|dfg i}|dfg |dfg |dfg i}|  || |d	f|d
ddddd|df|dtjtjd|dddddd|dfg |dfg |dfg |dfg |dfg |dfg |dfg |dfg ||  f|dd tj d!i}	|r|||	S | ||	||}
| ||||
}
|
S d S )"NF)duplicates_indexis_indexr   c                 W   s8   t jj}|r|jsdS t|| |d}|r2||d< |gS )Nr9   )r   r]   r   r  )r   rJ   Z*unique_index_reflect_as_unique_constraintsr3   ru  )r]   r  r  r   rv  reqr   r9   r9   r:   uci  s    
z+ComponentReflectionTest.exp_ucs.<locals>.ucra  rb  rc  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]   rE  r   )rS  r,   r   r\   r   rZ   rQ  r`  )rm   rI   r0   r   r   all_r  rM  r   r   r   r9   r9   r:   exp_ucsa  sr    	     	
        
 
zComponentReflectionTest.exp_ucsc                 C   s   ddhS )Nr]   r   r9   r   r9   r9   r:   _required_unique_cst_keys  s    z1ComponentReflectionTest._required_unique_cst_keysc           
         s   G dd dt  d fdd	}|dfg i}|dfg |dfg |dfg i}| || |d	f|d
tj|ddddg|df|dddg|dfg |dfg |dfg |dfg |dfg |dfg |dfg |dfg ||  fg i}| ||||}	| ||||	}	|	S )Nc                   @   s   e Zd Zdd ZdS )z+ComponentReflectionTest.exp_ccs.<locals>.ttc                 S   s(   |  dddddd}| |kS )N(r  )`)lowerreplace)rm   r   r   r9   r9   r:   r|    s       z2ComponentReflectionTest.exp_ccs.<locals>.tt.__eq__Nr}  r9   r9   r9   r:   r     s   r   c                    s    | ||dS )N)sqltextr]   r   r9   )rf  r]   r   r  r9   r:   cc  s    z+ComponentReflectionTest.exp_ccs.<locals>.ccra  rb  rc  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:  )N)strrS  r,   r   r\   rQ  r`  )
rm   rI   r0   r   r   r  rM  r   r   r   r9   r  r:   exp_ccs  s^    
   
        
 zComponentReflectionTest.exp_ccsc                 C   s   ddhS )Nr]   r  r9   r   r9   r9   r:   _required_cc_keys  s    z)ComponentReflectionTest._required_cc_keysc                 C   s    t |}ttjj| k 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| k 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| k t|d |td zHtd| k t|d |  td| k t|d W 5 |td X d S )NZfoo_barzCREATE SCHEMA foo_barzDROP SCHEMA foo_bar)r   r)   r  r  executer#   rs   r+   r{   r9   r9   r:   test_schema_cache  s    z)ComponentReflectionTest.test_schema_cachec                 C   s$   t  }t| t|jds td S )NrA  )r   r5   r   hasattrrj   r   )rm   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  rj   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 }dddddddh t|}|rDdd	 ||D }n
||} fd
d	|D }|dkr~dddg}t|| ndddg}tt|| d S )Nr&  r:  r8  r1  r3  r5  r/  c                 S   s   g | ]}|d  r|d  qS )r   r9   )rX  Zrecr9   r9   r:   r  G  s   z@ComponentReflectionTest.test_get_table_names.<locals>.<listcomp>c                    s   g | ]}| kr|qS r9   r9   rX  tZ_ignore_tablesr9   r:   r  N  s      r  r  r  r  )r   rL   r   Zget_sorted_table_and_fkc_namesget_table_namesr   sorted)	rm   r|   r  r  rI   rt   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rRtt	|ddg t|
|dg ndddg}tt	|| d S )Nrb  rc  ra  )r   r   rL   get_view_namesr   rJ   rJ  r3   r   r  get_materialized_view_names)rm   r|   r  rt   rI   r   r  r9   r9   r:   test_get_view_namesW  s    


z+ComponentReflectionTest.test_get_view_namesc                 C   s,   t |}| }tt|dtj g d S rX   )r   Zget_temp_table_namesr   r  r   rZ   rm   r|   rt   r]  r9   r9   r:   test_get_temp_table_namesh  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_namesn  s    z0ComponentReflectionTest.test_get_temp_view_namesc                 C   s   |  | d S r~   )_test_get_commentsrm   r|   r9   r9   r:   test_get_commentsu  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_schemay  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   rh  r   r   r   r/  r]   )rm   r|   rI   rt   expno_cstr9   r9   r:   r  ~  s&    




z*ComponentReflectionTest._test_get_comments)FFzuse_views,use_schemac                 C   sl  |rt j}nd }| jj| jj }}|r2dddg}nddg}t|}t|||fD ]\}	}
|}|j|	|d}tt	|dkt	| t
|
jD ]\}}t|j|| d  || d	 j}|j}t|tjjr|j}td
r|tjtjfkrtj}tt	t|j|jtjtjtjtjtjtjtj gdkd|j|j|| d |f  |j!s|| d d kst"qqPd S )Nrc  rb  ra  r  r  rH   r   r]   rj  rI  z%s(%s), %s(%s)rk  )#r   rL   r   r  r  r   zipr   r+   len	enumeratecolumnsr   r]   	__class__rj  r   r`   r   Z
TypeEnginer   rL  	sql_typesDater   rK  __mro__intersectionr   NumericZTimer   Z_BinaryrD   r   )rm   r|   Z	use_viewsr  rI   r  	addressesr   rt   rf   tableZschema_namerv  irp   ctypeZ	ctype_defr9   r9   r:   r     s\    
z(ComponentReflectionTest.test_get_columnsc                 C   s6   |   }| j| }t|t |d}| j||dd d S )Nr   F)Zstrict_constraints)r\   r   r   r   Zassert_tables_equal)rm   r|   rf   rg   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  qDd S )Nr   r]   )
r\   r   r   r   r+   r  r  r  r   r]   )rm   r|   rf   rg   rt   rv  r  rp   r9   r9   r:   test_get_temp_table_columns  s    

z3ComponentReflectionTest.test_get_temp_table_columnsc                 C   s0   t |}|d}tdd |D dddg d S )Nr   c                 S   s   g | ]}|d  qS r   r9   rX  rp   r9   r9   r:   r    s     zFComponentReflectionTest.test_get_temp_view_columns.<locals>.<listcomp>rB   r]   r   )r   r   r   )rm   r|   rt   rv  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 5 Q R X | jjj	}| 
|j||dg|||f g| j d S )NrH   rt  r]   r$  )r   r   rL   r   r  r  r   ry  r   r]   _check_listrz  r   rJ   rw  fail_ifr/  )rm   r|   r  rI   r  r  rt   r  Z
users_consZ	addr_consZexp_colsr  r9   r9   r:   r     s.    
  
z.ComponentReflectionTest.test_get_pk_constraintZPK_test_tableZpk_test_tableZmixedCasePKzpk.with.dotspk_namec              	   C   sh   t d|tdttdtdtjd|d || t|}|d}t	|d | t	|d dg dS )	zZTest that primary key constraint names with various casing are
        properly reflected.rA   rB   rE   rF   r   r]   rt  N)
r   r   r   r   r`   r   r   r   r   r   )rm   r|   rR   r  rt   Zpk_consr9   r9   r:   "test_get_pk_constraint_quoted_name"  s    

z:ComponentReflectionTest.test_get_pk_constraint_quoted_namec              	   C   sT  |rt j}nd }| jj| jj }}t|}|}tjjj	r|j
|j|d}|d }	tjj  t|	d d W 5 Q R X t|	d | t|	d |j t|	d dg t|	d	 d
g |j
|j|d}
|
d }	tjj  t|	d d k	 W 5 Q R X t|	d | t|	d |j t|	d dg t|	d	 dg | jjj}t|j
||dg  d S )NrH   r   r]   r  r  r  r~  r  rt  r  r   )r   rL   r   r  r  r   r   rJ   r=  r3   r   r]   r  r  r   implicitly_named_constraintsr+   r/  )rm   r|   r  rI   r  r  rt   Zexpected_schemaZusers_fkeysfkey1Z
addr_fkeysr  r9   r9   r:   r   A  s2    

z-ComponentReflectionTest.test_get_foreign_keysZFK_users_idZfk_users_idZmixedCaseNamezfk.with.dotsfk_namec              
   C   s   t d|tdtdddd t d|tdtddtdttjdgdg|d	dd || t|}|d}tt	|d
 |d }t
jj  t|d | W 5 Q R X t|d d t|d dg t|d dg dS )zZTest that foreign key constraint names with various casing are
        properly reflected.Z	users_refr  TrC   r   Zuser_ordersZorder_idzusers_ref.user_idr   r   r   r]   r  r~  rt  N)r   r   r   r`   r   r   r   r   r   r  r   rJ   r  r  )rm   r|   rR   r  rt   ZfkeysZfkeyr9   r9   r:   !test_get_foreign_keys_quoted_namek  s8    

z9ComponentReflectionTest.test_get_foreign_keys_quoted_namec           
      C   s  |  d|jj dtjj dtjj \}}}t|}||j}t	t
|d |d }t	|d tjj t	|d |j t	|d d	g t	|d
 dg |j|jtjjd}t	t
|d |d }	t|	d d |jjfk t	|	d |j t	|	d d	g t	|	d
 dg d S )Nz%s.local_tablez%s.remote_tablez%s.remote_table_2r   r   r  r  r~  rB   rt  r2  rH   r4  )r   rj   rA  r   r   rL   r   r   r]   r   r  r+   )
rm   r|   r1  r3  r5  rt   Zlocal_fkeysr  Zremote_fkeysZfkey2r9   r9   r:   "test_get_inter_schema_foreign_keys  s:    



 z:ComponentReflectionTest.test_get_inter_schema_foreign_keysc                 C   sz   |rt j}nd }t|}|jd|d}| j|d}| |||df | j | jjj	}| |j||d|||f | j d S )Nr  rH   )
r   rL   r   r   r  r  r  r   r/  r]   )rm   r|   r  rI   rt   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   ru  r  r]   )rm   r|   tnameZixnamert   r  Zexpected_indexesr  r9   r9   r:   test_get_noncol_index  s    	
z-ComponentReflectionTest.test_get_noncol_indexZIX_test_dataZix_test_dataZmixedCaseIndexzix.with.dotsidx_namec           	         s   t d|tdtddtdtd}t |jj || t|}|	d}dd |D } |ksvt
d	  d
|  fdd|D }tt|d t|d d dg dS )zATest that index names with various casing are properly reflected.rA   rB   TrC   rE   rF   c                 S   s   g | ]}|d  qS r   r9   rX  r   r9   r9   r:   r    s     zHComponentReflectionTest.test_get_indexes_quoted_name.<locals>.<listcomp>z	Expected z in c                    s   g | ]}|d   kr|qS r   r9   r  r  r9   r:   r    s      r   r   r   N)r   r   r   r   r$   r   rE   r   r   r   r   r   r  )	rm   r|   rR   r  r  rt   r  Zindex_namesZmatching_idxr9   r  r:   test_get_indexes_quoted_name  s    

z4ComponentReflectionTest.test_get_indexes_quoted_namec                 C   sB   t |}|  }||}| jddd |f }| ||| j d S )NT)r  )r   r\   r   r  r  r  )rm   r|   rt   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rVg |d d< tdd	 |D | d S )
Nr  Fr   rF  )r  r   r]   r   r  c                 S   s   g | ]}|d  dkr|qS )r]   rF  r9   r  r9   r9   r:   r  &  s      zGComponentReflectionTest.test_get_temp_table_indexes.<locals>.<listcomp>)	r   r\   r   rm  r   rJ   index_reflects_included_columnsr3   r   )rm   r|   rt   rf   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dddgdddddgddd	d
gdddgdddgdgtdd}td|tdtdtdtdtdtj	td	tdtd
td|d}|D ]"}|
tj|d d|d i q|| t|}t|jd|dtdd}	t }
tt|t|	 t||	D ]N\}}|dd }|rT|
| t|dd d  |dd  t|| q0t }td|||d}	dd |	jD }dd |	jD dg}||rt|
rt|
| t|t  | jjj}t|j||dg  d S )NZunique_ar   )r]   r   Zunique_a_b_cbr   Zunique_c_a_bZunique_asc_keyascr   zi.have.dotszi have spacesr]   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>w  s     zFComponentReflectionTest.test_get_unique_constraints.<locals>.<setcomp>c                 S   s   h | ]}t |tjr|jqS r9   )r   r`   r   r]   )rX  Zuqr9   r9   r:   r  x  s   )r   rL   r  operator
itemgetterr   r   r`   r   r   Zappend_constraintr   rq   r   r   rK  r   r  r  rm  r\  r   r  constraints
differencer  r   r   r/  r]   )rm   rR   r|   r  rI   Zuniquesr  r  rt   r  Znames_that_duplicate_indexr  ZreflZdupeZreflected_metadataZ	idx_namesZuq_namesr  r9   r9   r:   r   *  sz    







z3ComponentReflectionTest.test_get_unique_constraintsZUQ_emailZuq_emailZmixedCaseUQzuq.with.dotsuq_namec              	   C   s   t d|tdtddtdtdtjd|d || t|}|d}t	t
|d t	|d	 d
 | t	|d	 d dg dS )zUTest that unique constraint names with various casing are
        properly reflected.rA   rB   TrC   emailrF   r   r   r   r]   r   N)r   r   r   r   r`   r   r   r   r   r   r  )rm   r|   rR   r  rt   Zuq_consr9   r9   r:   'test_get_unique_constraints_quoted_name  s    

z?ComponentReflectionTest.test_get_unique_constraints_quoted_namec                 C   s@   |rt j}nd }t|}dD ]}|j||d}tt| qd S )N)rc  rb  ra  rH   )r   rL   r   r   r+   bool)rm   r|   r  rI   rt   viewrY  r9   r9   r:   r     s    z0ComponentReflectionTest.test_get_view_definitionc              	   C   sH   t |}tt |d W 5 Q R X tt |d W 5 Q R X d S )NZview_does_not_existr  )r   r   r!   r   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 ]4\}}||}dd |D | }|ddstqdS )a  test that 'autoincrement' is reflected according to sqla's policy.

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

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

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

        ))r  r  )r  r  )r  r  c                 S   s   i | ]}|d  |qS r   r9   r  r9   r9   r:   r[    s      zBComponentReflectionTest.test_autoincrement_col.<locals>.<dictcomp>ri  TN)r   r   getr   )rm   r|   rt   r  cnamerv  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 n"tt |jd|d W 5 Q R X d S )Nr  rH   r/  )r   r   r7   rL   r   rJ   r   r3   r   r+   r   r6   r   r   )rm   r  rt   rI   r   r9   r9   r:   r     s    


z.ComponentReflectionTest.test_get_table_optionsc              	      sv   t tj tjjjrV|rtjnd  jd} fdd j	dD }t
|| ntt    W 5 Q R X d S )NrH   c                    s    i | ]}|f j |d qS )rH   )r   )rX  r  rt   rI   r9   r:   r[    s    zHComponentReflectionTest.test_multi_get_table_options.<locals>.<dictcomp>)r   r   r7   r   rJ   r   r3   rL   get_multi_table_optionsr  r   r   r   )rm   r  r   r  r9   r  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|krD|dddg tj|kr\|ddg tj|krt|ddg | r| |d< |r||d	< || |||d	d
}	|g}
|tjkr|	 }|
d |
| |tjkr|	 }|
d |
| t  |
|	fS )Nr  )r0   r   r&  r  zdoes-not-existrb  ra  rI   r   )rI   r0   r   r   r0   r   )r   r   r   r  r   r   r  r    r   copyrm  append)rI   r0   r   r   Zsingle_reflect_fnZ
exp_methodrt   re   r   r  kwsZnkwr|   r9   r:   provide_fixture  sD    










z>ComponentReflectionTest.get_multi_exp.<locals>.provide_fixturer9   )rm   r|   r  r9   r
  r:   get_multi_exp  s    .z%ComponentReflectionTest.get_multi_expc                 C   sH   |||||t j| j\}}}|D ]"}	|  |jf |	}
t|
| q d S r~   )r   r   re  rs   r  r   rm   r  rI   r0   r   r   rt   r	  r  re   resultr9   r9   r:   #test_multi_get_table_options_tables'	  s    
z;ComponentReflectionTest.test_multi_get_table_options_tablesc           
      C   sD   |||||t j| j\}}}|D ]}	|  t|jf |	| q d S r~   )r   r   rh  rs   r   Zget_multi_table_comment)
rm   r  rI   r0   r   r   rt   r	  r  re   r9   r9   r:   test_get_multi_table_comment9	  s    
z4ComponentReflectionTest.test_get_multi_table_commentc                    sV   t ddd t|tr8t fdd| D || nt fdd|D || d S )Nrf  c                 S   s   t dd|  S )Nz['\" ]r  )resubr  r  r9   r9   r:   _cleanK	  s    z:ComponentReflectionTest._check_expressions.<locals>._cleanc                    s   i | ]\}} ||qS r9   r9   )rX  erY  r  r9   r:   r[  O	  s      z>ComponentReflectionTest._check_expressions.<locals>.<dictcomp>c                    s   g | ]} |qS r9   r9   )rX  r  r  r9   r:   r  Q	  s     z>ComponentReflectionTest._check_expressions.<locals>.<listcomp>)r  r   r6   r   r^  )rm   r  r  err_msgr9   r  r:   _check_expressionsJ	  s    
 z*ComponentReflectionTest._check_expressionsc           	      C   s   |d krt ||| nt t|t|| t||D ]~\}}t|t|B D ]d}||ksh||krL||krL| d| d| }|dkr| || || | qLt || || | qLq4d S )Nz - )r  r  )r   r  r  rK  r  )	rm   r  r  req_keysmsgrr  r   r  r9   r9   r:   r  S	  s    z#ComponentReflectionTest._check_listc                 C   s\   t t| t|  |D ]8}|| ||  }}|rF|g|g }}| |||| qd S r~   )r   rK  keysr  )rm   r  r  r  
make_listsr   r  r  r9   r9   r:   _check_table_dicta	  s    z)ComponentReflectionTest._check_table_dictc                 C   sN   |||||t j| j\}}}|D ](}	|  |jf |	}
| |
|| j q d S r~   )r   r   rr  rs   get_multi_columnsr  rs  r  r9   r9   r:   test_get_multi_columnsi	  s    
	z.ComponentReflectionTest.test_get_multi_columnsc                 C   sR   |||||t j| j\}}}|D ],}	|  |jf |	}
| j|
|| jdd q d S )NT)r  )r   r   ry  rs   Zget_multi_pk_constraintr  rz  r  r9   r9   r:   test_get_multi_pk_constraint{	  s"    
   z4ComponentReflectionTest.test_get_multi_pk_constraintc                 C   sT   t jjjsP||fD ]<}| D ].}t|dkrtdd |D r|j|d qqd S )Nr   c                 s   s"   | ]}| d dtjfkV  qdS )r]   N)r  r,   r   )rX  rY  r9   r9   r:   	<genexpr>	  s    z7ComponentReflectionTest._adjust_sort.<locals>.<genexpr>r  )r   rJ   r  r3   r_  r  anysort)rm   r  r  r   objrx  r9   r9   r:   _adjust_sort	  s    
z$ComponentReflectionTest._adjust_sortc                 C   s`   |||||t j| j\}}}|D ]:}	|  |jf |	}
| |
|dd  | |
|| j q d S )Nc                 S   s   t | d S )Nrt  tupledr9   r9   r:   r   	  r   zEComponentReflectionTest.test_get_multi_foreign_keys.<locals>.<lambda>)r   r   r  rs   Zget_multi_foreign_keysr&  r  r  r  r9   r9   r:   test_get_multi_foreign_keys	  s"    
  z3ComponentReflectionTest.test_get_multi_foreign_keysc                 C   sN   |||||t j| j\}}}|D ](}	|  |jf |	}
| |
|| j q d S r~   )r   r   r  rs   Zget_multi_indexesr  r  r  r9   r9   r:   test_get_multi_indexes	  s    
z.ComponentReflectionTest.test_get_multi_indexesc                 C   s`   |||||t j| j\}}}|D ]:}	|  |jf |	}
| |
|dd  | |
|| j q d S )Nc                 S   s   t | d S )Nr   r'  r)  r9   r9   r:   r   	  r   zKComponentReflectionTest.test_get_multi_unique_constraints.<locals>.<lambda>)r   r   r  rs   Zget_multi_unique_constraintsr&  r  r  r  r9   r9   r:   !test_get_multi_unique_constraints	  s    
z9ComponentReflectionTest.test_get_multi_unique_constraintsc                 C   s`   |||||t j| j\}}}|D ]:}	|  |jf |	}
| |
|dd  | |
|| j q d S )Nc                 S   s   t | d S Nr  r'  r)  r9   r9   r:   r   	  r   zJComponentReflectionTest.test_get_multi_check_constraints.<locals>.<lambda>)r   r   r  rs   Zget_multi_check_constraintsr&  r  r  r  r9   r9   r:    test_get_multi_check_constraints	  s    
z8ComponentReflectionTest.test_get_multi_check_constraintsr   r   r   r   r   r   r   r   methodc              	   C   s2   t |}t||}tt |d W 5 Q R X d S )NZtable_does_not_exists)r   getattrr   r!   )rm   r0  r|   rt   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|4 ttd t|t	dt
 d  W 5 Q R X W 5 Q R X d S )Nc                     s"   | di }td|d<  | |S )NZunreflectableerr)N
some_table)
setdefaultr"   )r   r   urZmcr9   r:   patched
  s    z;ComponentReflectionTest.test_unreflectable.<locals>.patchedr  r3  r4  )r   r  r,   patchobjectr   r"   r   Zreflect_tabler   r   )rm   r|   r8  r9   r7  r:   test_unreflectable
  s    
 z*ComponentReflectionTest.test_unreflectabler   c                    s   t  }|rtjnd  |j| |dd t|}| }|rr|| 7 }z|| 7 }W n tk
rp   Y nX  r fdd|D }t	t
|jt
| d S )NF)rI   r   Zresolve_fksc                    s   g | ]}  d | qS )r  r9   r  rH   r9   r:   r  "
  s     z9ComponentReflectionTest.test_metadata.<locals>.<listcomp>)r   r   rL   reflectr   r  r  r  r   r   r  r   )rm   r|   r  r   mrt   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   試蛇ẟΩ✨rf  c                 S   s   i | ]}|d  |d qS r  r9   r  r9   r9   r:   r[  6
  s      zAComponentReflectionTest.test_comments_unicode.<locals>.<dictcomp>)r@  rA  r   r   r   r   r   r   r   r   )rm   r|   rR   rt   tcrv  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?  rA  u&   🐍🧙🝝🧙‍♂️🧙‍♀️r   u&   🎩🁰🝑🤷‍♀️🤷‍♂️rf  r   r]   r   rB  )rm   r|   rR   rt   rC  r   r9   r9   r:   test_comments_unicode_full:
  s    

z2ComponentReflectionTest.test_comments_unicode_fullc           	      C   s   t jt}td|tdtj|dtdt  || t	 }td||d}t
|jjjj| t|jjjj t|}|d\}}t
|d j| t|d j d S )Nr  collated)	collationnot_collatedr   rj  )r   rJ   Zget_order_by_collationr   r   r   r`   r   r   r   r   r   rG  rj  rH  r*   rI  r   r   )	rm   r|   rR   rH  r   t2rt   rG  rI  r9   r9   r:    test_column_collation_reflectionK
  s     
z8ComponentReflectionTest.test_column_collation_reflection)N)NN)NF)ur<   r=   r>   run_insertsr   r   r?   rS   r  r\   rP   rN   rQ  rS  r`  r    r   r   re  rh  rr  propertyrs  ry  rz  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  r]  r  rM   rc   r  r   r  r  r  r   r   r  r  r   r  !primary_key_constraint_reflectionr   rw  r  r   r  r@  r  r   r   rB  rC  r  r  r   r  Ztemp_table_reflect_indexesr  r   r  r   r   table_reflectionr  r   r  r   r  r   r   r  r  r  r  r  r   r!  r&  r+  r,  r-  r   r/  r2  r;  r   r>  rE  Zcomment_reflection_full_unicoderF  Zcolumn_collation_reflectionZorder_by_collationrK  r9   r9   r9   r:   r  r  sP  

 .

!

-
!
&
`

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 Nrg  )r   r   rm   r|   rR   r9   r9   r:   table_no_columnsg
  s    
z#TableNoColumnsTest.table_no_columnsc                 C   s<   t d| t|dtd t|dtd || d S )Nrg  rT   z*CREATE VIEW empty_v AS SELECT * FROM emptyrU   zDROP VIEW IF EXISTS empty_v)r   r   rV   r#   r   rR  r9   r9   r:   view_no_columnsl
  s    
  z"TableNoColumnsTest.view_no_columnsc                 C   s$   t dt |d}tt|jg  d S )Nrg  r   r   r   r   ru  r   )rm   r|   rS  rJ  r9   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 )Nrg  rQ  )r   r   r   r  )rm   r|   rS  rt   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&td S rQ  )r   r<  rK  r   r  r   )rm   r|   rS  r=  r9   r9   r:   "test_reflect_incl_table_no_columns
  s    
z5TableNoColumnsTest.test_reflect_incl_table_no_columnsc                 C   s$   t dt |d}tt|jg  d S )Nempty_vr   rU  )rm   r|   rT  rJ  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 )NrZ  )r   )NrZ  )r   r   r   r  r   r   )rm   r|   rT  rt   rW  r9   r9   r:    test_get_columns_view_no_columns
  s    z3TableNoColumnsTest.test_get_columns_view_no_columnsN)r<   r=   r>   r   r   r   r   rS  rT  rV  rX  rY  rJ   r   r[  r\  r9   r9   r9   r:   rP  c
  s   


rP  c                   @   s4  e Zd ZdZejddgddd Ze dd Zdd	 Zej	j
d
d Zej	jejddddddd Zej	j
ejddddddd Zej	jdd Zej	jdd Zej	jdd Zej	jdd Zdd  Zej	jd!d" Zej	jejejejejejej	jfej ej	jfd#dd$d% Z!ej	jd&d' Z"ejdd(dej	j#fddd)ej	j$fi dd*ej	j$fi d*dej	j%fddd+ej	j&fdd+dej	j'fd,dd-d. Z(eje)e*+d/d0fe)d/d0fe,e*- d1fe)e*+d2d3ej	j.fe)e*+d4d5ej	j.fe/e01 d6fe)e*2d7e*2d8 d3ej	j.fd9dej	j3d:d; Z4dS )<ComponentReflectionTestExtraTF)paramsc                 C   s   |j rtjS d S d S r~   )paramr   rL   )rm   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   ra  r9   r:   go
  s    z:ComponentReflectionTestExtra.inspect_for_table.<locals>.go)
contextlibcontextmanager)rm   rR   r|   ra  rc  r9   rb  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   )rX  itemrk  r9   r:   r  
  s   z6ComponentReflectionTestExtra.ck_eq.<locals>.<listcomp>c                 S   s   | d S r.  r9   rm  r9   r9   r:   r   
  r   z4ComponentReflectionTestExtra.ck_eq.<locals>.<lambda>r  c                 S   s   | d S r.  r9   ro  r9   r9   r:   r   
  r   )r  r   )rm   r  r  r9   rn  r:   ck_eq
  s    
z"ComponentReflectionTestExtra.ck_eqc              	   C   sN   |d&\}}t d|tdtd|d W 5 Q R X | |jd|dg  d S )Nr/  rE   r"  rH   )r   r   r`   r   rp  r   )rm   rR   rf  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H\}}t d|tdt ddtdt tjd|dtdtd	|d
 W 5 Q R X |jd|d
}| ||prtj	ddg d S )Nsa_ccrB   TrC   r   a > 1 AND a < 5r   rE   rF   rH   a > 1 and a < 5rl  )
r   r   r   r`   r   r   r   rp  r,   r   rm   rR   rf  rs  rI   r   r  r9   r9   r:   test_check_constraint_inline
  s0     z9ComponentReflectionTestExtra.test_check_constraint_inlineZmy_ck_constZ	MyCkConstc              	   C   sh   |d.\}}t d|tdt tjd|d|d W 5 Q R X |jd|d}| ||pXtjddg d S )Nrt  r   za = 1 OR (a > 2 AND a < 5)r   rH   za = 1 or a > 2 and a < 5rl  )	r   r   r   r`   r   r   rp  r,   r   rw  r9   r9   r:    test_check_constraint_standalone
  s&    
 
z=ComponentReflectionTestExtra.test_check_constraint_standalonec                 C   s   |d\}}t d|tdt ddtdt tdtdt tjdd	d
tdt tdtdtjddd
tjddd
tjddd
|d W 5 Q R X |jd|d}| |dddd	ddt	j
ddg d S )Nrt  rB   TrC   r   ru  r  zb > 1 AND b < 5rr  r   r   rE   rF   Zsome_uqzc > 1 AND c < 5Zcc1Z	some_c_uqrH   zc > 1 and c < 5rl  zb > 1 and b < 5rv  )r   r   r   r`   r   r   r   r   rp  r,   r   )rm   rR   rf  rI   r   r  r9   r9   r:   test_check_constraint_mixed  s4    

z8ComponentReflectionTestExtra.test_check_constraint_mixedc              	   C   s~   |dJ\}}t d|tdtddtdttdt}td|jj|jj|jj W 5 Q R X |d}t	|d d	 dddg d
S )ztest for #12894Zsa_multi_indexColumn1TrC   Column2Column3ZIndex_Exampler   r   N)
r   r   r   r$   r   r}  r{  r|  r   r   )rm   rR   rf  rI   r   rA   r  r9   r9   r:   test_index_column_order4  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rtdd dd g|dd|dgd
d}	||	 |d|	 dd g|d dgd
d}
||
 ||
 t|d| t }t d| d}n8td* t|d| t }t d| d}W 5 Q R X | || jj d S )Nr  xr  yzt_idxa  long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string Z
t_idx_longZt_idx_2F)r]   r   r  r  c                    s:   t jjjr*g | d<  jj dg i| d< n| di  d S )Nr  Z_includer  )r   rJ   r  r3   r  r]   r5  )entryr
  r9   r:   completeIndexd  s    
 
zYComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.completeIndexr   c                   @   s   e Zd Zdd ZdS )z[ComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.lower_index_strc                 S   s    |  }d|kod|kpd|kS )Nr  r  r  r  )rm   r   olr9   r9   r:   r|  p  s    zbComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.lower_index_str.__eq__Nr}  r9   r9   r9   r:   lower_index_stro  s   r  c                       s   e Zd Z fddZdS )z^ComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.coalesce_index_strc                    s   d|  ko |kS )Ncoalescer  r{  long_strr9   r:   r|  v  s    zeComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.coalesce_index_str.__eq__Nr}  r9   r  r9   r:   coalesce_index_stru  s   r  zlower(x)zlower(y))r]   r   r  r  zcoalesce(x, 'z')r   z>Skipped unsupported reflection of expression-based index t_idx)r   r   r   r$   r   r  r   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]   )rm   rR   r|   r  rt   r  r  r  r  Z
expr_indexZexpr_index_longr   rJ  r9   )r|   r  r:   %test_reflect_expression_based_indexesH  sp    &
		

  zBComponentReflectionTestExtra.test_reflect_expression_based_indexesc                 C   s   t d|tdtdtdtd}td|jj}dg|j|jj d< |	| t
|}|d}t|ddgdgdtjdg t|d	 d
 d|jj  dg t dt |d}tt|jd	 j|jj d dg d S )Nr  r  r  r  r  includeF)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   ru  r  )rm   rR   r|   r  r   rt   r   rJ  r9   r9   r:   test_reflect_covering_index  sD    



z8ComponentReflectionTestExtra.test_reflect_covering_indexc                 G   s@   t d|fdd t|D  }|| dd t|dD S )Nr  c                 S   s   g | ]\}}t d | |qS )zt%dr   )rX  r  type_r9   r9   r:   r    s     zAComponentReflectionTestExtra._type_round_trip.<locals>.<listcomp>c                 S   s   g | ]}|d  qS )rj  r9   r  r9   r9   r:   r    s     )r   r  rq   r   r   )rm   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*tt|jd t|jd qd S )N   r	  )r  r  r  r   r   r   	precisionscale)rm   r|   rR   typr9   r9   r:   test_numeric_reflection  s      
z4ComponentReflectionTestExtra.test_numeric_reflectionr  c                 C   s   |  |||dd }t|tjr4t|tjsbtn.t|tjrRt|tjsbtnt|tjsbtt|j	d t|j	t
s~td S )N4   r   )r  
issubclassr  rb   r   r   r>  r   r   lengthint)rm   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   s   i | ]}|d  |d qS )r]   r  r9   r  r9   r9   r:   r[     s    zIComponentReflectionTestExtra.test_nullable_reflection.<locals>.<dictcomp>)r   r  )r   r   r   rq   r   r   r   )rm   r|   rR   r  r9   r9   r:   test_nullable_reflection  s    
z5ComponentReflectionTestExtra.test_nullable_reflectionZCASCADEzSET NULLz	NO ACTIONZRESTRICTzexpected,ondelete,onupdatec                    s"  i }|r||d< |r||d< |d kr(|}t d|tdtdddd t d|tdtddtd	ttd
ddtdtddd t d|tdtddtdtdddtdttjdgdgfddi|dd || t|}|	dd d  t
 fdd D i  |	dd d  t
 | d S )Nondeleteonupdater  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   )rX  r   optsr9   r:   r[  ^  s       zMComponentReflectionTestExtra.test_get_foreign_key_options.<locals>.<dictcomp>)r   r   r   r   r   r`   r   r   r   r   r   )rm   r|   rR   r  r  r  r1   rt   r9   r  r:   test_get_foreign_key_options  sV    *	 
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   rk  z	[\(\) \']r  )flags)
r   r   r   rq   r   r   r  r  r   
IGNORECASE)	rm   rR   r|   datatyperk  Zexpected_regr  r  Zreflected_sanitizedr9   r9   r:   test_server_defaultsd  s    
z1ComponentReflectionTestExtra.test_server_defaults)5r<   r=   r>   r   r   r   ra  rf  rp  rJ   r   rq  Z"inline_check_constraint_reflectionr   rx  ry  rz  Zindexes_check_column_orderr~  Zindexes_with_expressionsr  r  r  r  rO  r  r  r   rb   r>  ZNVARCHARZnvarchar_typesZNCHARr  r  Z1foreign_key_constraint_option_reflection_ondeleteZ1foreign_key_constraint_option_reflection_onupdateZ1fk_constraint_option_reflection_ondelete_noactionZ1fk_constraint_option_reflection_onupdate_restrictZ1fk_constraint_option_reflection_ondelete_restrictr  r   r`   rf  r   trueZexpression_server_defaultsr   r   nowZliteral_columnZserver_defaultsr  r9   r9   r9   r:   r]  
  s   

	
       


Z
*


'
6r]  c                   @   s0   e Zd ZdZdZedd Zdd Zdd Zd	S )
NormalizedNameTest)Zdenormalized_namesTc                 C   sL   t tddd|tdtdd t tddd|tdtddtdtd d S )	Nr   Tr   rB   rC   rJ  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>t
t  }|jtjdd d |jd jj|jd jj	szt
d S )	NrJ  Tr  r   r   c                 S   s   |   dkS )Nr   rJ  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   r<  )rm   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 k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  )rm   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 k t|d d d  t|d d d  d S )	Ncomputed_default_tablec                 S   s   i | ]}|d  |qS r   r9   r  r9   r9   r:   r[    s      zLComputedReflectionTest.test_computed_col_default_not_set.<locals>.<dictcomp>Z42with_defaultrk  normalcomputed_col)r   r   r7   r   r+   r   )rm   rt   rv  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|| k q&|d }td|k td|d k t| |d d d td	|d ktjj	j
 tjj	j
rt|d d	 tjjj
 d S )
Nr  c                 S   s   i | ]}|d  |qS r   r9   r  r9   r9   r:   r[    s      zKComputedReflectionTest.test_get_column_returns_computed.<locals>.<dictcomp>)rB   r  r  computedr  r  	normal+42	persisted)r   r   r7   r   r+   r   rk  r   rJ   "computed_columns_reflect_persistedr3   "computed_columns_default_persisted)rm   rt   rv  rE   r   compDatar9   r9   r:    test_get_column_returns_computed  s$    




z7ComputedReflectionTest.test_get_column_returns_computedc                 C   sX   t d|| k || d }t| |d | tjjjrTt d|k t|d | d S )Nr  r  r  )r+   r   rk  r   rJ   r  r3   r   )rm   rE   columnr  r  r  r9   r9   r:   check_column  s    
z#ComputedReflectionTest.check_columnc                 C   sp   t tj}|d}dd |D }| |ddtjjj tjj	jrR| |ddd tjj
jrl| |d	d
d d S )Ncomputed_column_tablec                 S   s   i | ]}|d  |qS r   r9   r  r9   r9   r:   r[    s      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rm   rt   rv  rE   r9   r9   r:   !test_get_column_returns_persisted  s.    



z8ComputedReflectionTest.test_get_column_returns_persistedc                 C   sv   t tj}|jdtjd}dd |D }| |ddtjjj	 tjj
j	rX| |ddd	 tjjj	rr| |d
dd d S )Nr  rH   c                 S   s   i | ]}|d  |qS r   r9   r  r9   r9   r:   r[    s      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_schema  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   rO  c                 C   s|   t d|tdttdtt  t d|tdttdddd	d
ddd tjjjrxt d|tdttdttdddtj	d d S )Nr   r  id1rJ  r   Tr   r   r,     alwaysr   	incrementminvaluemaxvaluecyclecacher"  )r  r   rH   )
r   r   r   r   r   rJ   rK   r3   r   rL   rQ   r9   r9   r:   rS      s>    
z$IdentityReflectionTest.define_tablesc                 C   s   t jjjrd}t|D ]}||kr|| q|rtt|t| |D ]T}|dkrjt|| || k qH|dkrt|| || k qHt|| || | qHqt|| n$t|d |d  t|d |d  d S )Nr  r  >   r  r  r   r  )	r   rJ   Zidentity_columns_standardr3   ru  rm  r   r  r+   )rm   rD  r  approxZcommon_keysr   r9   r9   r:   checkB  s     
	zIdentityReflectionTest.checkc                 C   s  t tj}|d|d }|D ]}|d dkr@td|k q"|d dkrd|kr`t|d  t|d d  td|k | j|d td	d
d
d
dd	d
ddd q"|d dkr"d|krt|d  t|d d  td|k | j|d tddddddddd	d q"d S )Nr   rJ  r]   r  r   r  ri  rk  Fr   r  Tr  r   r   r   r  r,  r  )	r   r   r7   r   r)   r+   r   r  r6   rm   rt   rv  rp   r9   r9   r:   r   _  sR    
		z,IdentityReflectionTest.test_reflect_identityc                 C   s   t tj}|jdtjd}|D ]~}|d dkr<td|k q|d dkrd|kr\t|d  t|d d  td|k | j|d t	d	d
ddddddd	d qd S )Nr   rH   r]   r  r   r  ri  rk  Tr"  r   r  Fr  r  )
r   r   r7   r   rL   r)   r+   r   r  r6   r  r9   r9   r:   test_reflect_identity_schema  s.    
	z3IdentityReflectionTest.test_reflect_identity_schema)r<   r=   r>   rL  r   r   r   r?   rS   r  r   r   rJ   rK   r  r9   r9   r9   r:   r    s   
!,r  c                   @   s<   e Zd ZdZedd Zejjdd Z	ejj
dd ZdS )	CompositeKeyReflectionTestTc                 C   s   t d|tdttdttdtdtjdddddd dd	}t d
|tdtddtdttdttdtdtjdddg|jj	|jj
|jjgddd dd		 d S )Ntb1rB   attrr]   r"  Zpk_tb1r   Tr  tb2rC   pidpattrpnameZfk_tb1_name_id_attr)r   r   r   r  rb   r`   r   r   r   r]   rB   r  )r8   rR   r  r9   r9   r:   rS     s2    
z(CompositeKeyReflectionTest.define_tablesc                 C   s2   t |}|| jjj}t|ddddg d S )Nrt  r]   rB   r  )r   r   r   r  r]   r   r  )rm   r|   rt   rD   r9   r9   r:   test_pk_column_order  s    z/CompositeKeyReflectionTest.test_pk_column_orderc                 C   s^   t |}|| jjj}tt|d |d }t|ddddg t|ddd	d
g d S )Nr   r   r~  r]   rB   r  rt  r  r  r  )r   r   r   r  r]   r   r  r  )rm   r|   rt   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   rN  r  r   r  r9   r9   r9   r:   r    s   

r  )r  r]  rP  r   r   r@   r   r  r  r  r  r   )Ird  r  r  r4   r`   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+   r,   rR   r  Z
TablesTestr-   r@   r   ZTestBaser   r   r   r   r  rP  r]  r  ZComputedReflectionFixtureTestr  r  r  __all__r9   r9   r9   r:   <module>	   s    Mg&                 5   y+a 1