o
    h                    @   s  d dl Z d dlZd dlZd dlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z! ddl"m#Z# ddl"m$Z$ ddl"m%Z% dd l&m'Z' dd!l&m(Z( dd"lm)Z) dd#lm*Z* dd$l+m,Z, dd%l-m.Z. dd&lm/Z/ dd'lm0Z0 dd(lm1Z1 dd)lm2Z2 dd*lm3Z3 d+\Z4Z5G d,d- d-ej6Z7G d.d/ d/e7Z8G d0d1 d1ej6Z9G d2d3 d3ej:Z;G d4d5 d5ej6Z<d6d7 Z=G d8d9 d9e0e7Z>G d:d; d;ej:Z?G d<d= d=e/ej:Z@G d>d? d?ej6ZAG d@dA dAejBZCG dBdC dCej6ZDG dDdE dEej6ZEdFZFdS )G    N   )config)engines)eq_)eq_regex)expect_raises)expect_raises_message)expect_warnings)fixtures)is_)get_temp_table_name)temp_table_keyword_argsColumn)Table   )Boolean)DateTime)event)
ForeignKey)func)Identity)inspect)Integer)MetaData)String)testing)types)	Inspector)
ObjectKind)ObjectScope)NoSuchTableError)UnreflectableTableError)DDL)Index)quoted_name)BLANK_SCHEMA)ComparesIndexes)ComparesTables)is_false)is_true)mockNNc                   @   s   e Zd Zedd ZdS )OneConnectionTablesTestc                 C   s2   t jjjrddlm} tjt|j	dddS t j
S )Nr   )poolclass)	poolclassscope)options)r   requirementsindependent_connectionsenabled
sqlalchemyr.   r   testing_enginedict
StaticPooldb)clsr.    r<   |/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sqlalchemy/testing/suite/test_reflection.py
setup_bind;   s   
z"OneConnectionTablesTest.setup_bindN)__name__
__module____qualname__classmethodr>   r<   r<   r<   r=   r-   :   s    r-   c                   @   s   e Zd ZdZedd Zedd Zedd Zedd	 Zd
d Z	dd Z
ejjdd Zejjdd Zejjdd Zejjdd Zejjejjejjdd Zejjejjdd ZdS )HasTableTestTc                 C   s   t d|tdtddtdtd tjjjr*t d|tdtddtdtdtj	d tjj
r3| | tjjjr?| | d S d S )	N
test_tableidTprimary_keydata2   test_table_sschema)r   r   r   r   r   requiresschemasr5   r   test_schemaview_reflectiondefine_viewshas_temp_tabledefine_temp_tablesr;   metadatar<   r<   r=   define_tablesM   s&   


zHasTableTest.define_tablesc                 C   st   d}t |dt| t |dtd tjjjr8dtjtjf }t |dt| t |dtdtj  d S d S )Nz1CREATE VIEW vv AS SELECT id, data FROM test_tableafter_createbefore_dropzDROP VIEW vvz9CREATE VIEW %s.vv AS SELECT id, data FROM %s.test_table_szDROP VIEW %s.vv)	r   listenr#   r   rM   rN   r5   r   rO   )r;   rU   queryr<   r<   r=   rQ   c   s"   
zHasTableTest.define_viewsc                 C      t ttjdtj S N	user_tmp_r   r   r:   identr;   r<   r<   r=   temp_table_namey      zHasTableTest.temp_table_namec              	   C   s   t ttj}|  }t||tdtjddtdtdfi |}t	j
jjrBt	j
jjrDt|dtdtj  t|dtd	 d S d S d S )
NrE   TrF   namerI   rW   =create temporary view user_tmp_v as select * from user_tmp_%srX   drop view user_tmp_v)r   r   r:   ra   r   r   saINTVARCHARr   rM   rP   r5   temporary_viewsr   rY   r#   r_   r;   rU   kw
table_nameuser_tmpr<   r<   r=   rS      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 )NrD   rJ   nonexistent_table)r   r:   beginr*   dialect	has_tabler)   selfconnr<   r<   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 )NrD   	new_tablecol)r   r   r:   r*   rq   r   r   r   r)   createclear_cachedrop)rs   rU   inspntr<   r<   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 )NrD   rK   rJ   rn   )r   r:   ro   r)   rp   rq   rO   r*   rr   r<   r<   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 )NrD   nonexistent_schemarK   )r   r:   ro   r)   rp   rq   rr   r<   r<   r=   !test_has_table_nonexistent_schema   s   "z.HasTableTest.test_has_table_nonexistent_schemac                 C      t |}t|d d S Nvvr   r*   rq   rs   
connectionr{   r<   r<   r=   test_has_table_view   s   z HasTableTest.test_has_table_viewc                 C   s"   t |}|  }t|| d S N)r   ra   r*   rq   )rs   r   r{   ra   r<   r<   r=   test_has_table_temp_table   s   z&HasTableTest.test_has_table_temp_tablec                 C   r   N
user_tmp_vr   r   r<   r<   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*   rq   r   rO   r   r<   r<   r=   test_has_table_view_schema   s   z'HasTableTest.test_has_table_view_schemaN)r?   r@   rA   __backend__rB   rV   rQ   ra   rS   ru   r}   r   rM   rN   r~   r   viewsr   rR   r   rP   ri   r   r   r<   r<   r<   r=   rC   J   s6    







rC   c                   @   sX   e Zd ZdZdZedd ZejddddZ	d	d
 Z
e	dd Zejje	dd ZdS )HasIndexTestT)index_reflectionc              	   C   s   t d|tdtddtdtdtdtd}td|jj tjj	j
r@t d|tdtddtdtdtjd	}td
|jj d S d S )NrD   rE   TrF   rH   rI   data2my_idxrK   my_idx_s)r   r   r   r   r$   crH   r   rM   rN   r5   r   rO   )r;   rU   ttr<   r<   r=   rV      s$   
zHasIndexTest.define_tablesrp   	inspectorkindargnamesc                    s   |dkr
 fddS t  jS )Nrp   c                     s   t jjj g| R i |S r   )r   r:   rp   	has_index)akrt   r<   r=   <lambda>       z)HasIndexTest._has_index.<locals>.<lambda>)r   r   )rs   r   rt   r<   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 )NrD   r   r   rn   nonexistent_idxmy_idx_2test_table_2my_idx_3foor   T)r   r$   tablesrD   r   r   r   r   r   rx   __self__ry   rz   )rs   r   r   rU   methidxtblr<   r<   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 )NrD   r   rK   r   rn   nonexistent_idx_s)r   r   rO   )rs   r   r   r   r<   r<   r=   test_has_index_schema  s   
z"HasIndexTest.test_has_index_schemaN)r?   r@   rA   r   __requires__rB   rV   r   combinationsr   r   r   rM   rN   r   r<   r<   r<   r=   r      s    

r   c                	   @   sX   e Zd 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)!foreign_key_constraint_reflection)rE   )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 )NrE   T)keyrG   test_needs_fkid2rF   otherrefref2autoload_withr      )r   r   r   append_columnrf   ForeignKeyConstraintr   rE   r   r   
create_allr   r   r   
referencesr   )
rs   r   rU   r   r   r   r   m2o2t1r<   r<   r=   test_fk_ref3  sD   


z,BizarroCharacterFKResolutionTest.test_fk_refN)
r?   r@   rA   __doc__r   r   r   r   	variationr   r<   r<   r<   r=   r   -  s     
r   c                   @   s   e Zd ZdZdZedd Zdd Zedd Zee	j
jd	d
 Zedd Zedd Zee	j
jdd Zee	j
jdd Zee	j
jdd Zee	j
jdd Zee	j
jdd ZdS )QuotedNameArgumentTestonceTc                 C   s  t d|tdttdtdtdtdtdttjdddtd	dtjdd
dtjdgdgddtj	dddddd t
jjjr}t d|tdttdtdtdtdtdttjdddtddtjdddtjdgdgddtj	dddddd t d|tdtddtdtdd t
jjjrt
jjjrddg}ndg}|D ]4}dtjjjd| tjjj|f }t|dt| t|dtd tjjjd|   qd S d S )!Nquote ' onerE   rc   rI   rH   
related_idzpk quote ' onerc   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relatedrF   r   z"CREATE VIEW %s AS SELECT * FROM %sview %srW   rX   zDROP VIEW %s)r   r   r   r   rf   PrimaryKeyConstraintr$   UniqueConstraintr   CheckConstraintr   rM   symbol_names_w_double_quoter5   view_column_reflectionr   r:   rp   identifier_preparerquoter   rY   r#   )r;   rU   namesrc   rZ   r<   r<   r=   rV   m  s   









z$QuotedNameArgumentTest.define_tablesc                 C   s   t ddt jjf| S )N)r   r   )r   r   rM   r   )fnr<   r<   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   r:   r   rM   reflect_table_optionsr5   get_table_optionsr*   
isinstancer8   r   NotImplementedError)rs   rc   r{   resr<   r<   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   r:   get_view_definitionrs   rc   r{   r<   r<   r=   test_get_view_definition  s   
z/QuotedNameArgumentTest.test_get_view_definitionc                 C      t tj}||sJ d S r   )r   r   r:   get_columnsr   r<   r<   r=   test_get_columns     
z'QuotedNameArgumentTest.test_get_columnsc                 C   r   r   )r   r   r:   get_pk_constraintr   r<   r<   r=   test_get_pk_constraint  r   z-QuotedNameArgumentTest.test_get_pk_constraintc                 C   r   r   )r   r   r:   get_foreign_keysr   r<   r<   r=   test_get_foreign_keys     
z,QuotedNameArgumentTest.test_get_foreign_keysc                 C   r   r   )r   r   r:   get_indexesr   r<   r<   r=   test_get_indexes  r   z'QuotedNameArgumentTest.test_get_indexesc                 C   r   r   )r   r   r:   get_unique_constraintsr   r<   r<   r=   test_get_unique_constraints  r   z2QuotedNameArgumentTest.test_get_unique_constraintsc                 C   r   r   )r   r   r:   get_table_commentr   r<   r<   r=   test_get_table_comment  r   z-QuotedNameArgumentTest.test_get_table_commentc                 C   r   r   )r   r   r:   get_check_constraintsr   r<   r<   r=   test_get_check_constraints  r   z1QuotedNameArgumentTest.test_get_check_constraintsN)r?   r@   rA   run_create_tablesr   rB   rV   r   r   r   rM   r   r   r   r   r   r   r   r   unique_constraint_reflectionr   comment_reflectionr   check_constraint_reflectionr   r<   r<   r<   r=   r   i  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   rO   r<   r<   r<   r=   r     s    z$_multi_combination.<locals>.<lambda>rL   r   r1   r   TF
use_filter)r   r   rM   rN   r    DEFAULT	TEMPORARYANYr   TABLEVIEWMATERIALIZED_VIEWANY_VIEW)r   rL   r1   r   filter_namesr<   r<   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   rM   rN   r5   r   rO   rT   r<   r<   r=   rV   #  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   r<   usersuser_idTrF   test1   Fnullabletest2parent_user_id	test2 > 0zz_test2_gt_zerousers check constraintrc   r   test2 <= 1000rL   r   
dingalingsdingaling_id
address_idz%semail_addresses.address_idzz_email_add_id_fgdi fk commentid_userrH      )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_testrE   
id comment)rG   r   data % commentr   d2)Comment types type speedily ' " \ '' Fun!d3*   Comment
withescapesthe test % ' " \ table comment)rL   r   no_constraints"no
constraintshasescapedcommentlocal_table	remote_idz%s.remote_table_2.id)r   rL   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   rM   self_referential_foreign_keysr5   r   r   r   rf   rg   CHARFloatr   r   r   r   r   r  r   cross_schema_fk_reflectionr   rO   r:   rp   default_schema_namer   r$   r  r  indexes_with_ascdescreflect_indexes_with_ascdescr?  descr   rQ   temp_table_reflectionrS   )r;   rU   rL   schema_prefixparent_id_argsr  r>  r@  r<   r<   r=   r  )  s@  

	
 


		z/ComponentReflectionTest.define_reflected_tablesc                 C   r[   r\   r^   r`   r<   r<   r=   ra     rb   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 )NrE   TrF   rc   rI   r   user_tmp_uq_r   user_tmp_ixrW   rd   rX   re   )r   r   r:   ra   r   r   rf   rg   rh   r   r_   r$   r   rM   rP   r5   ri   r   rY   r#   rj   r<   r<   r=   rS     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 rW   	mat_indexoraclezCREATE INDEX z ON z(data)rX   zDROP )	r   rM   materialized_viewsr5   setr   rY   r#   against)r;   rU   rL   materializedrl   fullname	view_nameprefixrZ   
index_namer   r<   r<   r=   rQ     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  )rs   r   r   r   rW  r   r<   r<   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   rM   r   r5   clearrT  r\  )rs   r   rW  r<   r<   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 )NTr<   )_r<   r<   r=   r   -  s    z8ComponentReflectionTest._resolve_names.<locals>.<lambda>c                 S   s   d| d vS Ntmpr   r<   r   r<   r<   r=   r   /      c                 S   s   d| d v S ra  r<   rc  r<   r<   r=   r   1  rd  r9  r;  r7  r>  r@  r   c                    s>   i | ]\}}|r|d   vr r|d   v r||qS )r   r<   ).0r   vr  removedrL   scope_filterr<   r=   
<dictcomp>N  s    z:ComponentReflectionTest._resolve_names.<locals>.<dictcomp>)r    r   r   r   r   rO   ra   rM   rF  r5   addr\  r   rK  temp_table_namesri   items)rs   rL   r1   r  valuesr   r<   rg  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+  r5  r7  r9  r;  r>  r@  r+   r   r_  ra   r]  ro  )	rs   rL   r1   r   r  rW  r   r   r   r<   r<   r=   exp_optionsW  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textrp  rq  rr  r   r  r  r$  r+  r4  r5  r6  r7  r9  r;  r>  r@  )r_  ra   r]  ro  )
rs   rL   r1   r   r  emptyrW  r   r   r   r<   r<   r=   exp_commentsv  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)rc   autoincrementtypedefaultr   r  omitrx  )r+   r   pop)rc   autorz  r   r  r   r<   r<   r=   rw     s   
z0ComponentReflectionTest.exp_columns.<locals>.colc                    s"   dt jdd|} | fi |S )NTF)r}  rz  r  r+   r   )rc   rk   rw   r<   r=   pk  s   z/ComponentReflectionTest.exp_columns.<locals>.pkrp  r  r{  )r}  r  r  r  rH   rq  r%  r&  rr  r  r  r  r  r  r   rE   rc   r   r  r  r$  r+  r,  r.  r-  r/  r0  r1  r3  r5  r7  r8  r9  r:  r;  r>  r?  r@  rs  )
rs   rL   r1   r   r  r  rW  r   r   r   r<   r  r=   exp_columns  s   

	




	
'z#ComponentReflectionTest.exp_columnsc                 C      h dS )N>   rc   ry  rz  r  r<   rs   r<   r<   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_columnsrc   r   )list)rc   r   colsr<   r<   r=   r    s   z+ComponentReflectionTest.exp_pks.<locals>.pkr   rp  r  rq  rr  r   r  r  r  r$  r  r)  r*  r+  rE   r5  r7  r9  r;  r>  r@  rc   )r+   r   r   rM   materialized_views_reflect_pkr5   r_  ra   reflects_pk_namesrn  r]  ro  )rs   rL   r1   r   r  r  rv  rW  r   r   valr   r<   r<   r=   exp_pks  s@   



zComponentReflectionTest.exp_pksc                 C      ddhS )Nrc   r  r<   r  r<   r<   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   r:   rp   rG  rs   r   r<   r<   r=   __eq__:  s   z2ComponentReflectionTest.exp_fks.<locals>.tt.__eq__Nr?   r@   rA   r  r<   r<   r<   r=   r   9      r   c                    s$   | ||t j|d ur|n  ||dS )N)r  referred_columnsrc   r2   referred_schemareferred_tabler   r~  )r  ref_col	ref_table
ref_schemarc   r   r   r<   r=   fk@  s   	z+ComponentReflectionTest.exp_fks.<locals>.fkrp  rq  rr  r   r  r  r  r
  r   r  r  r  r$  r  r  r  r%  r+  r5  r7  r8  rE   r;  )r  r9  r:  r>  r@  rc   )r+   r   r_  r   rO   ra   r   rM   rC  r5   r^  named_constraintsrn  r]  ro  )rs   rL   r1   r   r  r  rW  r   r   valsr  r   r<   r  r=   exp_fks2  sr   

#

zComponentReflectionTest.exp_fksc                 C   r  )N>   rc   r  r  r  r  r<   r  r<   r<   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 )	Nr<   )r   column_namesrc   dialect_optionsinclude_columnsr  r  expressionsc                    s   g | ]
}| v r
d n|qS r   r<   re  r   r  r<   r=   
<listcomp>  s    zDComponentReflectionTest.exp_indexes.<locals>.idx.<locals>.<listcomp>duplicates_constraint)	r   rM   foreign_keys_reflect_as_index#unique_constraints_reflect_as_index*reflect_indexes_with_ascdesc_as_expressionr5   r  r+   r   )rc   r   r  r  r  r  fk_reqdup_reqsorting_expressionr   origr<   r  r=   r     s4   


z0ComponentReflectionTest.exp_indexes.<locals>.idxrp  rq  rr  r   rH   rR  r   r  r  r
  T)rc   r  r  r  r  r=  r<  )rc   r   r  )rc   r   r  r  r  r  r"  r$  r&  r%  r+  r5  r7  r8  r9  r:  r;  r>  r?  rA  )rJ  )rc   r  r@  rB  r   rO  rc   rN  )rc   r  r   )r_  extendr+   r   ra   r   r_   r   rM   rH  r5   rI  r^  r]  ro  )
rs   rL   r1   r   r  r   rW  r   r   r   r<   r<   r=   exp_indexes  s   
%



5z#ComponentReflectionTest.exp_indexesc                 C   r  )N>   rc   r   r  r<   r  r<   r<   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 )Nr<   )r  rc   r   r  )r   rM   *unique_index_reflect_as_unique_constraintsr5   r  )rc   r  r  r   r  reqr   r<   r<   r=   uc  s   
z+ComponentReflectionTest.exp_ucs.<locals>.ucrp  rq  rr  r   r  r  r  r<  T)rc   r  r  r  rH   )rc   r  r  r  r"  r#  )rc   r  r   r$  r+  r5  r7  r9  r;  r>  r@  rc   rN  r   )r_  r+   r   ra   r   r_   r]  ro  )rs   rL   r1   r   r  all_r  rW  r   r   r   r<   r<   r=   exp_ucs  sZ   		
 zComponentReflectionTest.exp_ucsc                 C   r  )Nrc   r  r<   r  r<   r<   r=   _required_unique_cst_keysR  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)rs   r   r   r<   r<   r=   r  ^  s   z2ComponentReflectionTest.exp_ccs.<locals>.tt.__eq__Nr  r<   r<   r<   r=   r   ]  r  r   c                    s    | ||dS )N)sqltextrc   r   r<   )ru  rc   r   r  r<   r=   ccg  s   z+ComponentReflectionTest.exp_ccs.<locals>.ccrp  rq  rr  r   r  r  r  r  r  r.  r  z$address_id > 0 and address_id < 1000r!  r   r$  r+  r5  r7  r9  r;  r>  r@  r   )strr_  r+   r   ra   r]  ro  )
rs   rL   r1   r   r  r  rW  r   r   r   r<   r  r=   exp_ccsV  sF   

zComponentReflectionTest.exp_ccsc                 C   r  )Nrc   r  r<   r  r<   r<   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   rO   get_schema_namesr   r<   r<   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   rO   r)   r   r<   r<   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   rO   r   r*   r  r   r<   r<   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   rO   r   r*   r  r)   r   r<   r<   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#   ry   r*   r   r<   r<   r=   test_schema_cache  s   "z)ComponentReflectionTest.test_schema_cachec                 C   s$   t  }t| t|jdsJ d S )NrG  )r   r7   r   hasattrrp   )rs   enginer<   r<   r=   test_dialect_initialize  s   z/ComponentReflectionTest.test_dialect_initializec                 C   s   t |}t|j|jj d S r   )r   r   rG  rp   r   r<   r<   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>   r7  r+  r9  r5  r;  r@  r>  c                 S   s   g | ]
}|d  r|d  qS )r   r<   )re  recr<   r<   r=   r    s    z@ComponentReflectionTest.test_get_table_names.<locals>.<listcomp>c                    s   g | ]}| vr|qS r<   r<   re  t_ignore_tablesr<   r=   r    s    r  rP  )r  r$  r  )r   rO   r   get_sorted_table_and_fkc_namesget_table_namesr   sorted)	rs   r   r  r  rL   r{   r   table_namesanswerr<   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 )Nrq  rr  rp  )rp  rq  rr  )r   r   rO   get_view_namesr   rM   rT  r5   r   r  get_materialized_view_names)rs   r   r  r{   rL   r  r  r<   r<   r=   test_get_view_names  s   

z+ComponentReflectionTest.test_get_view_namesc                 C   s,   t |}| }tt|dtj g d S r\   )r   get_temp_table_namesr   r  r   r_   rs   r   r{   rl  r<   r<   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  r<   r<   r=   test_get_temp_view_names  s   z0ComponentReflectionTest.test_get_temp_view_namesc                 C   s   |  | d S r   )_test_get_commentsrs   r   r<   r<   r=   test_get_comments!  s   z)ComponentReflectionTest.test_get_commentsc                 C   s   |  |tjj d S r   )r  r   r   rO   r  r<   r<   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 )NrK   r+  r  )r   rw  r   r   r   r5  rc   )rs   r   rL   r{   expno_cstr<   r<   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rr  rq  rp  r  r$  rK   r   rc   ry  rS  z%s(%s), %s(%s)rz  )"r   rO   r   r  r$  r   zipr   r*   len	enumeratecolumnsr   rc   	__class__ry  r   rf   r   
TypeEnginer   rV  	sql_typesDater   rU  __mro__intersectionr   NumericTimer   _BinaryrG   )rs   r   	use_viewsr  rL   r  	addressesr  r{   rl   tableschema_namer  irw   ctype	ctype_defr<   r<   r=   r   B  sb   
z(ComponentReflectionTest.test_get_columnsc                 C   s6   |   }| j| }t|t |d}| j||dd d S )Nr   F)strict_constraints)ra   r   r   r   assert_tables_equal)rs   r   rl   rm   reflected_user_tmpr<   r<   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   rc   )
ra   r   r   r   r*   r  r  r  r   rc   )rs   r   rl   rm   r{   r  r  rw   r<   r<   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   r<   re  rw   r<   r<   r=   r        zFComponentReflectionTest.test_get_temp_view_columns.<locals>.<listcomp>)rE   rc   r   )r   r   r   )rs   r   r{   r  r<   r<   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 )NrK   r  rc   r)  )r   r   rO   r   r  r$  r   r  r   rc   _check_listr  r   rM   r  fail_ifr5  )rs   r   r  rL   r  r  r{   r  
users_cons	addr_consexp_colsr  r<   r<   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 )NrK   r   rc   r
  r  r  r  r  r  r  r%  )r   rO   r   r  r$  r   r   rM   rC  r5   r   rc   r  r  r   implicitly_named_constraintsr*   r5  )rs   r   r  rL   r  r  r{   expected_schemausers_fkeysfkey1
addr_fkeysr  r<   r<   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  rE   r  r8  rK   r:  )r   rp   rG  r   r   rO   r   r   rc   r   r  r*   )
rs   r   r7  r9  r;  r{   local_fkeysr  remote_fkeysfkey2r<   r<   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  rK   )
r   rO   r   r   r  r  r  r   r5  rc   )rs   r   r  rL   r{   indexesr  r  r<   r<   r=   r     s   

z(ComponentReflectionTest.test_get_indexes)r>  rA  )r@  rB  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  rc   )rs   r   tnameixnamer{   r   expected_indexesr  r<   r<   r=   test_get_noncol_index8  s   	
z-ComponentReflectionTest.test_get_noncol_indexc                 C   sB   t |}|  }||}| jddd |f }| ||| j d S )NT)r  )r   ra   r   r  r  r  )rs   r   r{   rc   	reflectedr  r<   r<   r=   &test_get_temp_table_unique_constraintsN  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   rO  )r   r  rc   r   r  c                 S   s   g | ]
}|d  dkr|qS )rc   rO  r<   re  r   r<   r<   r=   r  d  r   zGComponentReflectionTest.test_get_temp_table_indexes.<locals>.<listcomp>)	r   ra   r   r|  r   rM   index_reflects_included_columnsr5   r   )rs   r   r{   rl   r   indexpectedr<   r<   r=   test_get_temp_table_indexesW  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   )rc   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   rc   r   testtblr'  r  rK   r  r  r   )r   rL   c                 S   s   h | ]}|j qS r<   r   r'  r<   r<   r=   	<setcomp>  s    zFComponentReflectionTest.test_get_unique_constraints.<locals>.<setcomp>c                 S   s   h | ]}t |tjr|jqS r<   )r   rf   r   rc   )re  uqr<   r<   r=   r4    s    
)r   rO   r  operator
itemgetterr   r   rf   r   r   append_constraintr   rx   r   r   rU  r   r  r  r|  rk  r   r   constraints
differencer  r   r5  rc   )rs   rU   r   r  rL   uniquesr  r  r{   r%  names_that_duplicate_indexr  refldupereflected_metadata	idx_namesuq_namesr  r<   r<   r=   r   h  sx   







z3ComponentReflectionTest.test_get_unique_constraintsc                 C   s@   |rt j}nd }t|}dD ]}|j||d}tt| qd S )Nr  rK   )r   rO   r   r   r*   bool)rs   r   r  rL   r{   viewrf  r<   r<   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   r<   r<   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   r<   r  r<   r<   r=   rj        zBComponentReflectionTest.test_autoincrement_col.<locals>.<dictcomp>rx  TN)r   r   get)rs   r   r{   r!  cnamer  id_r<   r<   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  rK   r5  )r   r   r:   rO   r   rM   r   r5   r   r*   r   r8   r   r   )rs   r  r{   rL   r   r<   r<   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 )NrK   c                    s    i | ]}|f j |d qS )rK   )r   )re  r  r{   rL   r<   r=   rj  	  s    zHComponentReflectionTest.test_multi_get_table_options.<locals>.<dictcomp>)r   r   r:   r   rM   r   r5   rO   get_multi_table_optionsr  r   r   r   )rs   r  r   r  r<   rL  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$  )r1   r   )r+  r  does-not-existrq  rO  rp  rL   r  )rL   r1   r   r  r1   r   )r   r   r   r  r  r  rH  r    r   copyr|  append)rL   r1   r   r   single_reflect_fn
exp_methodr{   rk   r  r  kwsnkwr   r<   r=   provide_fixture  sD   










z>ComponentReflectionTest.get_multi_exp.<locals>.provide_fixturer<   )rs   r   rW  r<   rV  r=   get_multi_exp  s   .z%ComponentReflectionTest.get_multi_expc                 C   sL   |||||t j| j\}}}|D ]}	|  |jdi |	}
t|
| qd S Nr<   )r   r   rt  ry   rM  r   rs   rX  rL   r1   r   r   r{   rT  r  rk   resultr<   r<   r=   #test_multi_get_table_options_tablesD  s   
z;ComponentReflectionTest.test_multi_get_table_options_tablesc           
      C   sH   |||||t j| j\}}}|D ]}	|  t|jdi |	| qd S rY  )r   r   rw  ry   r   get_multi_table_comment)
rs   rX  rL   r1   r   r   r{   rT  r  rk   r<   r<   r=   test_get_multi_table_commentV  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 )Nru  c                 S   s   t dd|  S )Nz['\" ]r	  )resubr  )ru  r<   r<   r=   _cleanh  s   z:ComponentReflectionTest._check_expressions.<locals>._cleanc                    s   i | ]	\}} ||qS r<   r<   )re  erf  ra  r<   r=   rj  l      z>ComponentReflectionTest._check_expressions.<locals>.<dictcomp>c                    s   g | ]} |qS r<   r<   )re  rb  rc  r<   r=   r  n  r  z>ComponentReflectionTest._check_expressions.<locals>.<listcomp>)r  r   r8   r   rm  )rs   r[  r  err_msgr<   rc  r=   _check_expressionsg  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  rU  rf  )	rs   r[  r  req_keysmsgrrb  r   re  r<   r<   r=   r  p  s   z#ComponentReflectionTest._check_listc                 C   s\   t t| t|  |D ]}|| || }}|r#|g|g}}| |||| qd S r   )r   rU  keysr  )rs   r[  r  rg  
make_listsr   ri  rb  r<   r<   r=   _check_table_dict~  s   z)ComponentReflectionTest._check_table_dictc                 C   R   |||||t j| j\}}}|D ]}	|  |jdi |	}
| |
|| j qd S rY  )r   r   r  ry   get_multi_columnsrl  r  rZ  r<   r<   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)rk  r<   )r   r   r  ry   get_multi_pk_constraintrl  r  rZ  r<   r<   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 )rc   N)rH  r+   r   )re  rf  r<   r<   r=   	<genexpr>  s    
z7ComponentReflectionTest._adjust_sort.<locals>.<genexpr>r2  )r   rM   r  r5   rn  r  anysort)rs   r[  r*  r   objr  r<   r<   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dr<   r<   r=   r     rd  zEComponentReflectionTest.test_get_multi_foreign_keys.<locals>.<lambda>r<   )r   r   r  ry   get_multi_foreign_keysrv  rl  r  rZ  r<   r<   r=   test_get_multi_foreign_keys  s    

z3ComponentReflectionTest.test_get_multi_foreign_keysc                 C   rm  rY  )r   r   r  ry   get_multi_indexesrl  r  rZ  r<   r<   r=   test_get_multi_indexes  s   
z.ComponentReflectionTest.test_get_multi_indexesc                 C   rw  )Nc                 S   rx  )Nr  ry  r{  r<   r<   r=   r     rd  zKComponentReflectionTest.test_get_multi_unique_constraints.<locals>.<lambda>r<   )r   r   r  ry   get_multi_unique_constraintsrv  rl  r  rZ  r<   r<   r=   !test_get_multi_unique_constraints     
z9ComponentReflectionTest.test_get_multi_unique_constraintsc                 C   rw  )Nc                 S   rx  Nr  ry  r{  r<   r<   r=   r     rd  zJComponentReflectionTest.test_get_multi_check_constraints.<locals>.<lambda>r<   )r   r   r  ry   get_multi_check_constraintsrv  rl  r  rZ  r<   r<   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!   )rs   r  r   r{   r   r<   r<   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mcr<   r=   patched"	  s   z;ComponentReflectionTest.test_unreflectable.<locals>.patchedrn  r  r  )r   rn  r+   patchobjectr   r"   r   reflect_tabler   r   )rs   r   r  r<   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)rL   r   resolve_fksc                    s   g | ]	}  d | qS )r  r<   r  rK   r<   r=   r  ?	  rd  z9ComponentReflectionTest.test_metadata.<locals>.<listcomp>)r   r   rO   reflectr   r  r  r  r   r   r  r   )rs   r   r  r   mr{   r   r<   rK   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   試蛇ẟΩ✨ru  c                 S      i | ]	}|d  |d qS r  r<   r  r<   r<   r=   rj  S	  rd  zAComponentReflectionTest.test_comments_unicode.<locals>.<dictcomp>)r  r  r   r   r   r   r   r   r   r   )rs   r   rU   r{   tcr  valuer  r<   r<   r=   test_comments_unicodeB	  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&   🎩🁰🝑🤷‍♀️🤷‍♂️ru  r   rc   r   r  )rs   r   rU   r{   r  r   r<   r<   r=   test_comments_unicode_fullW	  s   

z2ComponentReflectionTest.test_comments_unicode_fullr   r,   )NF)mr?   r@   rA   run_insertsrun_deletesr   rB   rV   r  ra   rS   rQ   r]  r_  ro  r    r   r   rt  rw  r  propertyr  r  r  r  r  r  r  r  r  r  r  r   rM   schema_reflectionr  r  r  r  schema_create_deleter  r  r  r   r   rN   r  r  rl  r  rP   ri   r  r   r  r  r  r   rK  r  r  r   r  !primary_key_constraint_reflectionr   r   rF  r  r   r   rH  rI  r$  r   r&  temp_table_reflect_indexesr+  r   r   rE  table_reflectionrK  r   rN  fixturerX  r   r  r\  r^  rf  r  rl  ro  rq  rv  r~  r  r  r   r  r  r  r   r  r  comment_reflection_full_unicoder  r<   r<   r<   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 Nrv  )r   r   rs   r   rU   r<   r<   r=   table_no_columnsm	  s   
z#TableNoColumnsTest.table_no_columnsc                 C   s<   t d| t|dtd t|dtd || d S )Nrv  rW   z*CREATE VIEW empty_v AS SELECT * FROM emptyrX   zDROP VIEW IF EXISTS empty_v)r   r   rY   r#   r   r  r<   r<   r=   view_no_columnsr	  s   

z"TableNoColumnsTest.view_no_columnsc                 C   $   t dt |d}tt|jg  d S )Nrv  r   r   r   r   r  r   )rs   r   r  t2r<   r<   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 )Nrv  r  )r   r   r   rn  )rs   r   r  r{   multir<   r<   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  rU  r   r  )rs   r   r  r  r<   r<   r=   "test_reflect_incl_table_no_columns	  s   
z5TableNoColumnsTest.test_reflect_incl_table_no_columnsc                 C   r  )Nempty_vr   r  )rs   r   r  r  r<   r<   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   rn  r   r  )rs   r   r  r{   r  r<   r<   r=    test_get_columns_view_no_columns	  s   z3TableNoColumnsTest.test_get_columns_view_no_columnsN)r?   r@   rA   r   r   r   r  r  r  r  r  r  rM   r   r  r  r<   r<   r<   r=   r  i	  s    


r  c                   @   s  e Zd ZdZejddgddd Ze dd Zdd	 Zej	j
d
d Zej	jejddddddd Zej	j
ejddddddd Zej	jdd Zej	jdd Zej	jdd Zdd Zej	jdd  Zej	jd!d" Zej	jd#d$ Zejdd%dej	jfddd&ej	jfi dd'ej	jfi d'dej	jfddd(ej	jfdd(dej	jfd)dd*d+ Zeje e!"d,d-fe d,d-fe#e!$ d.fe e!"d/d0ej	j%fe e!"d1d2ej	j%fe&e'( d3fe e!)d4e!)d5 d0ej	j%fd6dej	j*d7d8 Z+dS )9ComponentReflectionTestExtraTF)paramsc                 C   s   |j rtjS d S r   )paramr   rO   )rs   requestr<   r<   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   rU   r  r<   r=   go	  s   z:ComponentReflectionTestExtra.inspect_for_table.<locals>.go)
contextlibcontextmanager)rs   rU   r   r  r  r<   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  r<   r<   r=   	normalize	  s   z5ComponentReflectionTestExtra.ck_eq.<locals>.normalizec                    s"   g | ]}|d   |d dqS )rc   r  rc   r  r<   )re  itemr  r<   r=   r  	  s    z6ComponentReflectionTestExtra.ck_eq.<locals>.<listcomp>c                 S      | d S r  r<   r  r<   r<   r=   r   	      z4ComponentReflectionTestExtra.ck_eq.<locals>.<lambda>r2  c                 S   r  r  r<   r  r<   r<   r=   r   	  r  )r  r   )rs   r%  r*  r<   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 )Nr5  rH   r'  rK   )r   r   rf   r   r  r   )rs   rU   r  rL   r   r<   r<   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_ccrE   TrF   r   a > 1 AND a < 5r   rH   rI   rK   a > 1 and a < 5r  )
r   r   r   rf   r   r   r   r  r+   r   rs   rU   r  r  rL   r   r%  r<   r<   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   rK   za = 1 or a > 2 and a < 5r  )	r   r   r   rf   r   r   r  r+   r   r  r<   r<   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  rE   TrF   r   r  r.  zb > 1 AND b < 5r  r   r   rH   rI   some_uqzc > 1 AND c < 5cc1	some_c_uqrK   zc > 1 and c < 5r  zb > 1 and b < 5r  )r   r   r   rf   r   r   r   r   r  r+   r   )rs   rU   r  rL   r   r%  r<   r<   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)rc   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   rM   r(  r5   r  rc   r  )entryrV  r<   r=   completeIndexV
  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  )rs   r   olr<   r<   r=   r  b
  s   zbComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.lower_index_str.__eq__Nr  r<   r<   r<   r=   lower_index_stra
  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_strr<   r=   r  h
  s   zeComponentReflectionTestExtra.test_reflect_expression_based_indexes.<locals>.coalesce_index_str.__eq__Nr  r<   r  r<   r=   coalesce_index_strg
  s    r  )Nr  Nzlower(x)zlower(y))rc   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   rM    reflect_indexes_with_expressionsr5   insertrQ  r   r   r   r	   !compare_table_index_with_expectedr  rc   )rs   rU   r   r  r{   r*  r  r  r  
expr_indexexpr_index_longr   r  r<   )r   r  r=   %test_reflect_expression_based_indexes:
  sn   &
		



zBComponentReflectionTestExtra.test_reflect_expression_based_indexesc                 C   s   t d|tdtdtdtd}td|jj}dg|j|jj d< |	| t
|}|d}t|ddgdgdtjdg t|d	 d
 d|jj  dg t dt |d}tt|jd	 j|jj d dg d S )Nr  r  r  r  r  includeF)rc   r  r  r   r  r   r  z
%s_includer   )r   r   r   r$   r   r  r  r  rc   r   r   r   r   r+   r   r   r  r   )rs   rU   r   r  r   r{   r   r  r<   r<   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   )re  r  type_r<   r<   r=   r  
      zAComponentReflectionTestExtra._type_round_trip.<locals>.<listcomp>c                 S   r  )ry  r<   r  r<   r<   r=   r  
  r  )r   r  rx   r   r   )rs   r   rU   r   r  r<   r<   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rs   r   rU   typr<   r<   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  r<   r<   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  )rc   r  r<   r  r<   r<   r=   rj  
  s    zIComponentReflectionTestExtra.test_nullable_reflection.<locals>.<dictcomp>)r   r.  )r   r   r   rx   r   r   r   )rs   r   rU   r  r<   r<   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  rE   TrF   r   r  x_idzx.idxidr   test
   userrc   rI   Fr  tidztable.idmyfkr   r2   c                    s   i | ]} | r| | qS r<   r<   )re  r   optsr<   r=   rj  C  r  zMComponentReflectionTestExtra.test_get_foreign_key_options.<locals>.<dictcomp>)r   r   r   r   r   rf   r   r   r   r   r   )rs   r   rU   r*  r  r  r2   r{   r<   r  r=   test_get_foreign_key_options
  sT   *	
z9ComponentReflectionTestExtra.test_get_foreign_key_options10z'?10'?z1|truez3 + 5z3\+5z(3 * 5)z3\*5zcurrent_timestamp|now|getdate35zdatatype, default, expected_regc           	   	   C   sd   t d|tdtddtd||d}|| t|dd d }td	d
|}t||tj	d d S )Nr  rE   TrF   thecol)server_defaultr   rz  z	[\(\) \']r	  )flags)
r   r   r   rx   r   r   r_  r`  r   
IGNORECASE)	rs   rU   r   datatyperz  expected_regr  r%  reflected_sanitizedr<   r<   r=   test_server_defaultsI  s   
z1ComponentReflectionTestExtra.test_server_defaults),r?   r@   rA   r   r   r  r  r  r  rM   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  r   rf   ru  r   trueexpression_server_defaultsr   r   nowliteral_columnserver_defaultsr!  r<   r<   r<   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)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   rE   rF   r  t1idzt1.id)r   r%   r   r   r   rT   r<   r<   r=   rV   w  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  Tr0  r   r   c                 S   s   |   dv S )Nr   r  r  )rc   r  r<   r<   r=   r     rd  zINormalizedNameTest.test_reflect_lowercase_forced_tables.<locals>.<lambda>)only)r   r   r%   r   r:   r   r   r1  r   rE   r  )rs   r   t2_reft1_refm3r<   r<   r=   $test_reflect_lowercase_forced_tables  s   

&z7NormalizedNameTest.test_reflect_lowercase_forced_tablesc                 C   sP   dd t tj D }t|d  |d   t|d  |d   d S )Nc                 S   s   g | ]
}|  d v r|qS )r2  r  r  r<   r<   r=   r    s
    z;NormalizedNameTest.test_get_table_names.<locals>.<listcomp>r   r   )r   r   r:   r  r   upperr  )rs   
tablenamesr<   r<   r=   r    s
   z'NormalizedNameTest.test_get_table_namesN)	r?   r@   rA   r   r   rB   rV   r7  r  r<   r<   r<   r=   r.  s  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   rF  r   r<   r  r<   r<   r=   rj    rG  zLComputedReflectionTest.test_computed_col_default_not_set.<locals>.<dictcomp>42with_defaultrz  normalcomputed_col)r   r   r:   r   r*   r   )rs   r{   r  col_datar<   r<   r=   !test_computed_col_default_not_set  s   

z8ComputedReflectionTest.test_computed_col_default_not_setc                 C   s   t tj}|d}dd |D }dD ]
}td|| v q|d }td|v  td|d v  t| |d d d td	|d v tjj	j
 tjj	j
r[t|d d	 tjjj
 d S d S )
Nr;  c                 S   rF  r   r<   r  r<   r<   r=   rj    rG  zKComputedReflectionTest.test_get_column_returns_computed.<locals>.<dictcomp>)rE   r>  r=  computedr?  r  	normal+42	persisted)r   r   r:   r   r*   r   r  r   rM   "computed_columns_reflect_persistedr5   "computed_columns_default_persisted)rs   r{   r  rH   r   compDatar<   r<   r=    test_get_column_returns_computed  s&   




z7ComputedReflectionTest.test_get_column_returns_computedc                 C   s\   t d|| v  || d }t| |d | tjjjr,t d|v  t|d | d S d S )NrB  r  rD  )r*   r   r  r   rM   rE  r5   r   )rs   rH   columnr  rD  rG  r<   r<   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   rF  r   r<   r  r<   r<   r=   rj    rG  zLComputedReflectionTest.test_get_column_returns_persisted.<locals>.<dictcomp>computed_no_flagrC  computed_virtualznormal+2Fcomputed_storedz	normal-42T)r   r   r:   r   rJ  r   rM   rF  r5   computed_columns_virtualcomputed_columns_storedrs   r{   r  rH   r<   r<   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 )NrK  rK   c                 S   rF  r   r<   r  r<   r<   r=   rj    rG  zXComputedReflectionTest.test_get_column_returns_persisted_with_schema.<locals>.<dictcomp>rL  z	normal/42rM  znormal/2FrN  z	normal*42T)r   r   r:   r   rO   rJ  r   rM   rF  r5   rO  rP  rQ  r<   r<   r=   -test_get_column_returns_persisted_with_schema  s4   


zDComputedReflectionTest.test_get_column_returns_persisted_with_schemaN)r?   r@   rA   rA  rH  rJ  rR  r   rM   rN   rS  r<   r<   r<   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)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   r2     alwaysstart	incrementminvaluemaxvaluecyclecacher'  )rZ  r[  rK   )
r   r   r   r   r   rM   rN   r5   r   rO   rT   r<   r<   r=   rV     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 )NrY  r]  >   r`  r^  r[  r\  )	r   rM   identity_columns_standardr5   r  r|  r   r  r*   )rs   r  r  approxcommon_keysr   r<   r<   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  rc   r>  identityrV  rx  rz  Fr   rY  Trb  r   r   r   rW  r2  rX  )	r   r   r:   r   r)   r*   r   rd  r8   rs   r{   r  rw   r<   r<   r=   test_reflect_identityD  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   rK   rc   r>  re  rV  rx  rz  Tr'  r   rf  FrY  rg  )
r   r   r:   r   rO   r)   r*   r   rd  r8   rh  r<   r<   r=   test_reflect_identity_schemap  s2   
	z3IdentityReflectionTest.test_reflect_identity_schema)r?   r@   rA   r  r  r   r   rB   rV   rd  ri  r   rM   rN   rj  r<   r<   r<   r=   rT    s    
!,rT  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tb1rE   attrrc   r'  pk_tb1r   Tr  tb2rF   pidpattrpnamerr  rp  rq  fk_tb1_name_id_attr)r   r   r   r  rh   rf   r   r   r   rc   rE   rm  )r;   rU   rl  r<   r<   r=   rV     s2   

z(CompositeKeyReflectionTest.define_tablesc                 C   s0   t |}|| jjj}t|dg d d S )Nr  rc   rE   rm  )r   r   r   rl  rc   r   rH  )rs   r   r{   rG   r<   r<   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  ru  r  rs  )r   r   r   ro  rc   r   r  rH  )rs   r   r{   foreign_keysr  r<   r<   r=   test_fk_column_order  s   z/CompositeKeyReflectionTest.test_fk_column_orderN)r?   r@   rA   r   rB   rV   r   rM   r  rv  r   rx  r<   r<   r<   r=   rk    s    

rk  )r  r  r  r   r   rC   r   r.  r:  rT  rk  )Gr  r6  r_  r6   rf   r	  r   r   r   r   r   r   r	   r
   r   	provisionr   r   rL   r   r   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+   rU   r  
TablesTestr-   rC   r   TestBaser   r   r  r  r  r  r.  ComputedReflectionFixtureTestr:  rT  rk  __all__r<   r<   r<   r=   <module>   s    M<               Y5   X+a 1