o
    Rc                     @   s  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\Z$Z%G dd  d e	j&Z'G d!d" d"e	j&Z(G d#d$ d$e	j&Z)G d%d& d&e	j&Z*G d'd( d(e	j+Z,G d)d* d*e	j+Z-G d+d, d,e	j&Z.G d-d. d.e	j/Z0G d/d0 d0e	j&Z1G d1d2 d2e	j&Z2d3Z3dS )4    N   )config)engines)eq_)expect_warnings)fixtures)is_)get_temp_table_name)temp_table_keyword_argsColumn)Table   )event)
ForeignKey)func)Identity)inspect)Integer)MetaData)String)testing)types)DDL)Index)quoted_name)BLANK_SCHEMA)is_false)is_true)NNc                   @   4   e Zd ZdZedd Zdd Z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 d S d S )	N
test_tableidTprimary_keydata2   test_table_sschema)
r   r   r   r   r   requiresschemasenabledr   test_schemaclsmetadata r1   JD:\Flask\env\Lib\site-packages\sqlalchemy/testing/suite/test_reflection.pydefine_tables'   s   

zHasTableTest.define_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 )Nr!   r'   nonexistent_table)r   dbbeginr   dialect	has_tabler   selfconnr1   r1   r2   test_has_table8   s
   "zHasTableTest.test_has_tablec                 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 )Nr!   r(   r'   r4   )r   r5   r6   r   r7   r8   r-   r   r9   r1   r1   r2   test_has_table_schema>   s"   "z"HasTableTest.test_has_table_schemaN)__name__
__module____qualname____backend__classmethodr3   r<   r   r*   r+   r=   r1   r1   r1   r2   r    $   s    
r    c                   @   r   )	HasIndexTestTc                 C   sx   t d|tdtd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 )
Nr!   r"   Tr#   r%   r&   my_idxr(   my_idx_s)r   r   r   r   r   cr%   r   r*   r+   r,   r   r-   )r/   r0   ttr1   r1   r2   r3   U   s"   
zHasIndexTest.define_tablesc                 C   s   t j 5}t jj|ddsJ t jj|ddrJ t jj|ddr'J t jj|ddr2J W d    d S 1 s=w   Y  d S )Nr!   rD   rE   r4   Znonexistent_idx)r   r5   r6   r7   	has_indexr9   r1   r1   r2   test_has_indexi   s   
"zHasIndexTest.test_has_indexc                 C   s   t j A}t jjj|ddt jdsJ t jjj|ddt jdr"J t jjj|ddt jdr0J t jjj|ddt jdr>J W d    d S 1 sIw   Y  d S )Nr!   rE   r(   rD   r4   Znonexistent_idx_s)r   r5   r6   r7   rH   r-   r9   r1   r1   r2   test_has_index_schemav   s(   




"z"HasIndexTest.test_has_index_schemaN)r>   r?   r@   rA   rB   r3   rI   r   r*   r+   rJ   r1   r1   r1   r2   rC   R   s    
rC   c                   @   s   e Zd ZdZdZedd Zdd Zedd Zee	j
jd	d
 Zedd Zedd Zedd Zedd Zee	j
jdd Zee	j
jdd Zee	j
jdd ZdS )QuotedNameArgumentTestonceTc                 C   s  t d|tdttdtdtdtdtdttjdddtd	dtjdd
dtjdgdgddtj	dddddd t
jjjr}t d|tdttdtdtdtdtdttjdddtddtjdddtjdgdgddtj	dddddd t d|tdtddtdtdd t
jjjrt
jjjrddg}ndg}|D ]4}dtjjjd| tjjj|f }t|dt| t|dtd tjjjd|   qd S d S )!Nquote ' oner"   namer&   r%   Z
related_idzpk quote ' onerN   zix quote ' onezuq quote' onez
related.idzfk quote ' onezname != 'foo'zck quote ' onezquote ' one commentT)commenttest_needs_fkquote " twozpk quote " twozix quote " twozuq quote" twozfk quote " twozck quote " two zquote " two commentrelatedr#   rQ   "CREATE VIEW %s AS SELECT * FROM %sview %safter_createbefore_dropDROP VIEW %s)r   r   r   r   saPrimaryKeyConstraintr   UniqueConstraintForeignKeyConstraintCheckConstraintr   r*   symbol_names_w_double_quoter,   view_column_reflectionr   r5   r7   Zidentifier_preparerquoter   listenr   )r/   r0   namesrN   queryr1   r1   r2   r3      s   








z$QuotedNameArgumentTest.define_tablesc                 C   s   t ddt jjf| S )N)rM   rR   )r   combinationsr*   r_   )fnr1   r1   r2   quote_fixtures   s   
z%QuotedNameArgumentTest.quote_fixturesc                 C   s   t tj}|| d S N)r   r   r5   Zget_table_optionsr:   rN   inspr1   r1   r2   test_get_table_options   s   
z-QuotedNameArgumentTest.test_get_table_optionsc                 C   s    t tj}|d| sJ d S )NrV   )r   r   r5   get_view_definitionri   r1   r1   r2   test_get_view_definition   s   
z/QuotedNameArgumentTest.test_get_view_definitionc                 C      t tj}||sJ d S rh   )r   r   r5   get_columnsri   r1   r1   r2   test_get_columns      
z'QuotedNameArgumentTest.test_get_columnsc                 C   rn   rh   )r   r   r5   get_pk_constraintri   r1   r1   r2   test_get_pk_constraint   rq   z-QuotedNameArgumentTest.test_get_pk_constraintc                 C   rn   rh   )r   r   r5   get_foreign_keysri   r1   r1   r2   test_get_foreign_keys  rq   z,QuotedNameArgumentTest.test_get_foreign_keysc                 C   rn   rh   )r   r   r5   get_indexesri   r1   r1   r2   test_get_indexes  rq   z'QuotedNameArgumentTest.test_get_indexesc                 C   rn   rh   )r   r   r5   get_unique_constraintsri   r1   r1   r2   test_get_unique_constraints     
z2QuotedNameArgumentTest.test_get_unique_constraintsc                 C   rn   rh   )r   r   r5   get_table_commentri   r1   r1   r2   test_get_table_comment  rz   z-QuotedNameArgumentTest.test_get_table_commentc                 C   rn   rh   )r   r   r5   get_check_constraintsri   r1   r1   r2   test_get_check_constraints  rz   z1QuotedNameArgumentTest.test_get_check_constraintsN)r>   r?   r@   Zrun_create_tablesrA   rB   r3   rg   rk   r   r*   r`   rm   rp   rs   ru   rw   unique_constraint_reflectionry   comment_reflectionr|   check_constraint_reflectionr~   r1   r1   r1   r2   rK      s8    
S




rK   c                   @   s6  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e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dddddejjfddddddejjfdddddejjfdddd Zejjd d! Zejjejjejjd"d# Zejjd$d% Zejjejjd&d' ZdTd(d)Z ejd*ddejjfddejjfddejjejj fd+dd,d- Z!ejj"d.d/ Z#ejj"ejj$ejjd0d1 Z%ejd2dejjfd3dejj&d4d5 Z'ejd2dejjfd3dejjd6d7 Z(ejj)ejjd8d9 Z*d:d; Z+ejd2dejjfd3dd<d= Z,ejd>d?d@dejj-ejj.dAdB Z/ejj"ejj0dCdD Z1ejj2dEdF Z3ejdejjfd2d3dejj0dGdH Z4ejjejd2dejjfd3ddIdJ Z5ejdKdLdejjfdMde6dNdOdPdQ Z7ejj8dRdS Z9dS )UComponentReflectionTestNTc                 C   s2   t jjjrddlm} tjt|j	dddS t j
S )Nr   )poolclass)Z	poolclassscope)options)r   requirementsZindependent_connectionsr,   
sqlalchemyr   r   testing_enginedictZ
StaticPoolr5   )r/   r   r1   r1   r2   
setup_bind#  s   
z"ComponentReflectionTest.setup_bindc                 C   s.   |  |d  tjjjr|  |tjj d S d S rh   )define_reflected_tablesr   r*   r+   r,   r   r-   r.   r1   r1   r2   r3   .  s   
z%ComponentReflectionTest.define_tablesc                 C   s*  |r|d }nd}t jjjr=td|tdtjddtdtdd	d
tdt	dd	d
tdtj
tjd| dd|dd}n!td|tdtjddtdtdd	d
tdt	dd	d
|dd}td|tdtj
ddtdtj
td| tdtd|dd td|tdtj
tdtj
t|jjtdtdtjddd|dd td|tdtj
dddtdtdd d!td"tdd#d!|d$d% t jjjr+|d u rt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d,tjjj tdtd|dd td-|tdtj
ddtdtd|dd t jjjru| || |sutd.|td/tddd0}td1|tdtj
ddtd/tddd0}t jjjrutd2|jj  td3|jj  t jjjr| || |st jjjr| | d S d S d S )4N. usersuser_idTr#   test1   Fnullabletest2parent_user_idz%susers.user_id
user_id_fkrO   r)   rQ   
dingalingsdingaling_id
address_idz%semail_addresses.address_idr%      email_addressesremote_user_idZemail_address   email_ad_pkcomment_testr"   
id comment)r$   rP   data % comment)rP   d2)Comment types type speedily ' " \ '' Fun!the test % ' " \ table comment)r)   rP   local_table	remote_idz%s.remote_table_2.id)rQ   r)   remote_tablelocal_idz%s.local_table.idremote_table_2noncol_idx_test_nopkqrT   noncol_idx_test_pknoncol_idx_nopknoncol_idx_pk) r   r*   self_referential_foreign_keysr,   r   r   rZ   INTCHARFloatr   r   r   rF   r   r[   cross_schema_fk_reflectionr   r-   r5   r7   default_schema_nameindex_reflectiondefine_indexindexes_with_ascdescr   r   descr`   define_viewstemp_table_reflectiondefine_temp_tables)r/   r0   r)   Zschema_prefixr   r   r   r1   r1   r2   r   4  s  




	z/ComponentReflectionTest.define_reflected_tablesc                 C   s   t ttj}tttjd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r[tjjjr]t|dtdtj  t|dtd d S d S d S )Nuser_tmp_%sr"   Tr#   rN   r&   foouser_tmp_uq_%srO   user_tmp_ixrW   z=create temporary view user_tmp_v as select * from user_tmp_%srX   zdrop view user_tmp_v)r
   r   r5   r	   identr   r   rZ   r   VARCHARr\   r   r   r*   view_reflectionr,   temporary_viewsr   rb   r   )r/   r0   kw
table_nameuser_tmpr1   r1   r2   r     s<   

z*ComponentReflectionTest.define_temp_tablesc                 C   s2   t d|jj|jj t d|jj|jj|jj d S )Nusers_t_idxusers_all_idx)r   rF   r   r   r   )r/   r0   r   r1   r1   r2   r     s   z$ComponentReflectionTest.define_indexc                 C   s^   dD ]*}|}|rd||f }|d }d||f }t |dt| t |dtd|  qd S )N)r   r   z%s.%s_vrU   rW   rX   rY   )r   rb   r   )r/   r0   r)   r   fullnameZ	view_namerd   r1   r1   r2   r     s   z$ComponentReflectionTest.define_viewsc                 C   s$   t | j}| tjj| v  d S rh   )r   bindassert_r   r   r-   get_schema_namesr:   rj   r1   r1   r2   test_get_schema_names  s   
z-ComponentReflectionTest.test_get_schema_namesc                 C   s:   |j ddttjjid}t|}| tjj| v  dS )z
test #7300r   bar)Zschema_translate_mapN)Zexecution_optionsr   r   r   r-   r   r   r   )r:   
connectionrj   r1   r1   r2   %test_get_schema_names_w_translate_map  s   z=ComponentReflectionTest.test_get_schema_names_w_translate_mapc                 C   s$   t  }t| t|jdsJ d S )Nr   )r   r   r   hasattrr7   )r:   enginer1   r1   r2   test_dialect_initialize  s   z/ComponentReflectionTest.test_dialect_initializec                 C   s    t | j}t|j| jjj d S rh   )r   r   r   r   r7   r   r1   r1   r2   test_get_default_schema_name  s   
z4ComponentReflectionTest.test_get_default_schema_name)NTFFF)foreign_keyTFF)NFTF)NTTFz/order_by,include_plain,include_views,use_schemaargnamesc                    s   |rt j}nd }g d t|}|r&||}|  ddg}	tt||	 |r_|r5dd ||D }
n||}
 fdd|
D }|dkrRg d}	t||	 d S g d	}	tt||	 d S d S )
N)r   r   r   r   r   r   email_addresses_vusers_vc                 S   s   g | ]
}|d  r|d  qS )r   r1   .0Zrecr1   r1   r2   
<listcomp>D  s    z@ComponentReflectionTest.test_get_table_names.<locals>.<listcomp>c                    s   g | ]}| vr|qS r1   r1   r   tZ_ignore_tablesr1   r2   r   K  s    r   )r   r   r   )r   r   r   )	r   r-   r   Zget_view_namessortr   sortedZget_sorted_table_and_fkc_namesget_table_names)r:   r   Zorder_byZinclude_plainZinclude_views
use_schemar)   rj   table_namesZanswertablesr1   r   r2   test_get_table_names  s.   	

z,ComponentReflectionTest.test_get_table_namesc                 C   s,   t | j}| }tt|dtj g d S )Nr   )r   r   Zget_temp_table_namesr   r   r   r   r:   rj   temp_table_namesr1   r1   r2   test_get_temp_table_namesT  s   
z1ComponentReflectionTest.test_get_temp_table_namesc                 C   s&   t | j}| }tt|dg d S )N
user_tmp_v)r   r   Zget_temp_view_namesr   r   r   r1   r1   r2   test_get_temp_view_namesZ  s   
z0ComponentReflectionTest.test_get_temp_view_namesc                 C   s   |    d S rh   )_test_get_commentsr:   r1   r1   r2   test_get_commentsb  s   z)ComponentReflectionTest.test_get_commentsc                 C   s   |  tjj d S rh   )r   r   r   r-   r   r1   r1   r2   test_get_comments_with_schemaf  s   z5ComponentReflectionTest.test_get_comments_with_schemac                 C   st   t | j}t|jd|dddi t|jd|ddd i tdd |jd|dD dd	d
ddd
ddd
g d S )Nr   r(   textr   r   c                 S   s   g | ]}|d  |d dqS )rN   rP   )rN   rP   r1   r   r1   r1   r2   r   v  s    z>ComponentReflectionTest._test_get_comments.<locals>.<listcomp>r   r"   )rP   rN   r   r%   r   r   )r   r   r   r{   ro   )r:   r)   rj   r1   r1   r2   r   k  s"   
z*ComponentReflectionTest._test_get_comments)FFzuse_views,use_schemac                 C   sl  |rt j}nd }| jj| jj}}|rddg}nddg}t|}t|||fD ]\}	}
|}|j|	|d}| t	|dkt	| t
|
jD ]m\}}t|j|| d  || d j}|j}t|tjjrg|j}td	rw|tjtjfv rwtj}| 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 qEq'd S )Nr   r   r   r   r(   r   rN   typeZoraclez%s(%s), %s(%s)default)"r   r-   r   r   r   r   zipro   r   len	enumeratecolumnsr   rN   	__class__r   
isinstancerZ   r   Z
TypeEnginer   Zagainst	sql_typesDateDateTimeset__mro__intersectionr   NumericZTimer   Z_Binaryr$   )r:   r   Z	use_viewsr   r)   r   	addressesr   rj   r   tableZschema_namecolsicolctypeZ	ctype_defr1   r1   r2   rp     sb   
z(ComponentReflectionTest.test_get_columnsc                 C   sv   t t| jdtj }| j| }t| j}||}| t|dkt| t	|j
D ]\}}t|j|| d  q*d S )Nr   r   rN   )r	   r   r   r   r   r   ro   r   r   r   r   r   rN   )r:   r   r   rj   r  r  r  r1   r1   r2   test_get_temp_table_columns  s   


z3ComponentReflectionTest.test_get_temp_table_columnsc                 C   s0   t | j}|d}tdd |D g d d S )Nr   c                 S      g | ]}|d  qS rO   r1   r   r  r1   r1   r2   r         zFComponentReflectionTest.test_get_temp_view_columns.<locals>.<listcomp>)r"   rN   r   )r   r   ro   r   )r:   rj   r  r1   r1   r2   test_get_temp_view_columns  s   

z2ComponentReflectionTest.test_get_temp_view_columnsFr   c                 C   s   |rt jj}nd }| jj| jj}}t|}|j|j|d}|d }t	|dg |j|j|d}	|	d }
t	|
dg t j
j  t	|	d d W d    d S 1 sSw   Y  d S )Nr(   constrained_columnsr   r   rN   r   )r   r   r-   r   r   r   r   rr   rN   r   r*   Zreflects_pk_namesfail_if)r:   r   r   r)   r   r  rj   Z
users_consZusers_pkeysZ	addr_consZ
addr_pkeysr1   r1   r2   rs     s   
"z.ComponentReflectionTest.test_get_pk_constraintc                 C   sj  |rt j}nd }| jj| jj}}t|}|}tjjj	ri|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jjj	rit|	d	 d
g |j
|j|d}
|
d }	tjj  | |	d d u W d    n1 sw   Y  t|	d | t|	d |j t|	d dg t|	d	 dg d S )Nr(   r   rN   r   referred_schemareferred_tablereferred_columnsr   r  r   r   )r   r-   r   r   r   r   r   r*   r   r,   rt   rN   Znamed_constraintsr  r   Zimplicitly_named_constraintsr   )r:   r   r   r)   r   r  rj   Zexpected_schemaZusers_fkeysfkey1Z
addr_fkeysr1   r1   r2   ru     s4   

z-ComponentReflectionTest.test_get_foreign_keysc           	      C   s  |  d| jjj dtjj dtjj \}}}t| j}||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 }|d d | jjjfv spJ t
|d |j	 t
|d d	g t
|d
 dg d S )Nz%s.local_tablez%s.remote_tablez%s.remote_table_2   r   r  r  r  r"   r  r   r(   r   )r   r   r7   r   r   r   r-   r   rt   rN   r   r   )	r:   r   r   r   rj   Zlocal_fkeysr  Zremote_fkeysZfkey2r1   r1   r2   "test_get_inter_schema_foreign_keys%  s2   





z:ComponentReflectionTest.test_get_inter_schema_foreign_keysc                 C   sZ   dd |D }|D ]!}|d |v sJ || |d  }|D ]}t|| ||  qq	d S )Nc                 S   r  rO   r1   )r   dr1   r1   r2   r   I  r  z@ComponentReflectionTest._assert_insp_indexes.<locals>.<listcomp>rN   )indexr   )r:   indexesexpected_indexesZindex_namesZe_indexr  keyr1   r1   r2   _assert_insp_indexesH  s   z,ComponentReflectionTest._assert_insp_indexesc                 C   sX   |rt j}nd }t| j}|jd|d}dddgdddg dd	dg}| || d S )
Nr   r(   Fr   r   r   uniquecolumn_namesrN   )r   r   r   r   )r   r-   r   r   rv   r  )r:   r   r   r)   rj   r  r  r1   r1   r2   rw   P  s   
z(ComponentReflectionTest.test_get_indexes)r   r   )r   r   ztname,ixnamec                 C   sz   t |}||}d|dg}| || t|t |d}tt|jd tt	|jd j
| tt	|jd j| d S )NF)r  rN   autoload_withr  r   )r   rv   r  r   r   r   r   r  r   listr  rN   )r:   r   tnameZixnamerj   r  r  r   r1   r1   r2   test_get_noncol_indexl  s   
z-ComponentReflectionTest.test_get_noncol_indexc                 C   sN   t | j}|dtj }|D ]}|dd  qt|dgdtj dg d S )Nr   duplicates_indexrN   r   )r   rN   )r   r   rx   r   r   popr   )r:   rj   	reflectedreflr1   r1   r2   &test_get_temp_table_unique_constraints  s   
z>ComponentReflectionTest.test_get_temp_table_unique_constraintsc                 C   s|   t | j}tttjdtj }||}|D ]}|dd  qddgddg}tj	j
jr2g |d d< td	d
 |D | d S )Nr   dialect_optionsFr   r   r  r   include_columnsc                 S   s   g | ]
}|d  dkr|qS )rN   r   r1   r   idxr1   r1   r2   r     s    zGComponentReflectionTest.test_get_temp_table_indexes.<locals>.<listcomp>)r   r   r	   r   r5   r   rv   r'  r   r*   index_reflects_included_columnsr,   r   )r:   rj   r   r  indexpectedr1   r1   r2   test_get_temp_table_indexes  s   


z3ComponentReflectionTest.test_get_temp_table_indexesc                 C   s  |rt j}nd }tddgddg dddg dddd	d
gdddgdddgdgtdd}td|tdtdtdtdtdtj	td	tdtd
td|d}|D ]}|
tj|d d|d i q\|| t|}t|jd|dtdd}	t }
t||	D ]\}}|dd }|r|
| t|| qt }td|||d}	tdd |	jD }tdd |	jD dg}||rJ |
rt|
| t|t  d S d S )NZunique_aa)rN   r   Zunique_a_b_c)r3  brF   Zunique_c_a_b)rF   r3  r4  Zunique_asc_keyascr  zi.have.dotsr4  zi have spacesrF   rN   r  Ztesttblr   r   r(   r   r&  )r"  r)   c                 S   s   g | ]}|j qS r1   rO   r-  r1   r1   r2   r     s    zGComponentReflectionTest.test_get_unique_constraints.<locals>.<listcomp>c                 S   s   g | ]}t |tjr|jqS r1   )r   rZ   r\   rN   )r   Zuqr1   r1   r2   r     s    
)r   r-   r   operator
itemgetterr   r   rZ   r   r   Zappend_constraintr\   creater   rx   r   r   r'  addr   r   r  constraints
differencer  )r:   r0   r   r   r)   Zuniquesr  Zuc	inspectorr(  Znames_that_duplicate_indexorigr)  ZdupeZreflected_metadataZ	idx_namesZuq_namesr1   r1   r2   ry     sv   






z3ComponentReflectionTest.test_get_unique_constraintsc           	      C   sT   |rt j}nd }d}d}t|}|j||d}| | |j||d}| | d S )Nr   r   r(   )r   r-   r   rl   r   )	r:   r   r   r)   Z
view_name1Z
view_name2rj   v1v2r1   r1   r2   rm     s   
z0ComponentReflectionTest.test_get_view_definition)r   Fr   ztable_name,use_schema
postgresqlzPG specific featurec                 C   s8   |rt j}nd }t|}|||}| t|t d S rh   )r   r-   r   Zget_table_oidr   r   int)r:   r   r   r   r)   rj   oidr1   r1   r2   test_get_table_oid  s   z*ComponentReflectionTest.test_get_table_oidc                 C   sH   t | j}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 rO   r1   r   rF   r1   r1   r2   
<dictcomp>5      zBComponentReflectionTest.test_autoincrement_col.<locals>.<dictcomp>autoincrementTN)r   r   ro   get)r:   rj   r$  cnamer  Zid_r1   r1   r2   test_autoincrement_col  s   

z.ComponentReflectionTest.test_autoincrement_colrh   ):r>   r?   r@   run_insertsrun_deletesrA   rB   r   r3   r   r   r   r   r   r*   Zschema_reflectionr   r   r   r   !foreign_key_constraint_reflectionre   r+   r   r   r   r   r   r   r   r   r   r   rp   r   r
  r`   r  !primary_key_constraint_reflectionrs   ru   r   r  r  rw   r   r   r%  r   r*  Ztemp_table_reflect_indexesr2  ry   rm   Zonly_onrD  table_reflectionrL  r1   r1   r1   r2   r     s    



 
#






,



?
$!

R
	r   c                   @   s   e Zd ZdZdZejdd Ze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
dd Zej	jej	j
dd ZdS )TableNoColumnsTest)reflect_tables_no_columnsTc                 C   s   t d| || d S Nempty)r   
create_allr:   r   r0   r1   r1   r2   table_no_columns=  s   
z#TableNoColumnsTest.table_no_columnsc                 C   sP   t d| || t d| t|dtd t|dtd || d S )NrU  rW   z*CREATE VIEW empty_v AS SELECT * FROM emptyrX   zDROP VIEW IF EXISTS empty_v)r   rV  r   rb   r   rW  r1   r1   r2   view_no_columnsB  s   



z"TableNoColumnsTest.view_no_columnsc                 C   $   t dt |d}tt|jg  d S )NrU  r!  r   r   r   r#  rF   )r:   r   rX  t2r1   r1   r2   test_reflect_table_no_columnsU  s   z0TableNoColumnsTest.test_reflect_table_no_columnsc                 C      t t|dg  d S rT  r   r   ro   )r:   r   rX  r1   r1   r2   !test_get_columns_table_no_columnsZ  s   z4TableNoColumnsTest.test_get_columns_table_no_columnsc                 C   s*   t  }|| t|jdgsJ d S rT  )r   reflectr   r   r  )r:   r   rX  mr1   r1   r2   "test_reflect_incl_table_no_columns^  s   
z5TableNoColumnsTest.test_reflect_incl_table_no_columnsc                 C   rZ  )Nempty_vr!  r[  )r:   r   rY  r\  r1   r1   r2   test_reflect_view_no_columnsd  s   z/TableNoColumnsTest.test_reflect_view_no_columnsc                 C   r^  )Nrd  r_  )r:   r   rY  r1   r1   r2    test_get_columns_view_no_columnsj  s   z3TableNoColumnsTest.test_get_columns_view_no_columnsN)r>   r?   r@   __requires__rA   r   ZfixturerX  rY  r*   rS  r]  r`  rc  Zviewsre  rf  r1   r1   r1   r2   rR  9  s&    




rR  c                
   @   s   e Zd ZdZejdejjfdddejjdd Z	ejj
dd Zejjd	d
 Zdd Zejjdd Zejjdd Zejjdd Zejdddejjfdddejjfi ddejjfi ddejjfdddejjfdddejjfdddd ZdS )ComponentReflectionTestExtraTr  r   r   c              	      s   |rt j}nd }td|tdt tjdddtjddd|d || t|}t	|j
d|dtd	d
}dd   fdd|D }t|ddddddg d S )NZsa_ccr3  za > 1 AND a < 5Zcc1rO   za = 1 OR (a > 2 AND a < 5)Z
UsesCasingr(   rN   r6  c                 S   s   d td|  tjS )N zand|\d|=|a|or|<|>)joinrefindalllowerI)sqltextr1   r1   r2   	normalize  s   zJComponentReflectionTestExtra.test_get_check_constraints.<locals>.normalizec                    s"   g | ]}|d   |d dqS )rN   ro  rN   ro  r1   )r   itemrp  r1   r2   r     s    zKComponentReflectionTestExtra.test_get_check_constraints.<locals>.<listcomp>za = 1 or a > 2 and a < 5rq  za > 1 and a < 5)r   r-   r   r   r   rZ   r^   rV  r   r   r}   r7  r8  r   )r:   r0   r   r   r)   r=  r(  r1   rs  r2   r~   t  s:   


z7ComponentReflectionTestExtra.test_get_check_constraintsc                 C   s   t d|tdtdtdtd}tdt|jjt|jj td|jj |	| t
|}ddgddg}tjjjrPg |d	 d
< d|jj g i|d	 d< td t|d| W d    d S 1 shw   Y  d S )Nr   xr   yt_idxZt_idx_2F)rN   r   r  r   r,  
%s_includer+  z>Skipped unsupported reflection of expression-based index t_idx)r   r   r   r   r   rm  rF   rt  ru  rV  r   r   r*   r/  r,   r   rN   r   r   rv   )r:   r0   r   r   rj   r1  r1   r1   r2   %test_reflect_expression_based_indexes  s0    

"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
|}t|dddgdgdd|jj dgid	g t dt |d
}tt|jd j|jj d dg d S )Nr   rt  r   ru  rv  includeFrw  )rN   r   r,  r  r+  r!  r   )r   r   r   r   rF   rt  r+  r   rN   rV  r   r   rv   r   r#  r  )r:   r0   r   r   r.  rj   r\  r1   r1   r2   test_reflect_covering_index  s8   
z8ComponentReflectionTestExtra.test_reflect_covering_indexc                 G   sB   t d|gdd t|D R  }|| dd t|dD S )Nr   c                 S   s   g | ]\}}t d | |qS )zt%dr   )r   r  type_r1   r1   r2   r     s    zAComponentReflectionTestExtra._type_round_trip.<locals>.<listcomp>c                 S   r  )r   r1   rF  r1   r1   r2   r     r  )r   r   r9  r   ro   )r:   r   r0   r   r   r1   r1   r2   _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r:   r   r0   typr1   r1   r2   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  r1   r1   r2   test_varchar_reflection   s   z4ComponentReflectionTestExtra.test_varchar_reflectionc              	   C   sX   t d|tdtddtdtdd}|| ttdd t|dD ddd	 d S )
Nr   r3  Tr   r4  Fc                 s   s     | ]}|d  |d fV  qdS )rN   r   Nr1   r  r1   r1   r2   	<genexpr>  s
    
zHComponentReflectionTestExtra.test_nullable_reflection.<locals>.<genexpr>)r3  r4  )r   r   r   r9  r   r   r   ro   )r:   r   r0   r   r1   r1   r2   test_nullable_reflection  s   
z5ComponentReflectionTestExtra.test_nullable_reflectionNZCASCADEzSET NULLz	NO ACTIONZRESTRICTzexpected,ondelete,onupdatec                    s(  i }|r||d< |r||d< |d u r|}t d|tdtdddd t d|tdtddtd	ttj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
t fdd D i  |	dd d  t
 | d S )Nondeleteonupdatert  r"   Tr#   rT   r  Zx_idzx.idxidrO   test
   userrN   r&   Fr   tidztable.idZmyfkr   r   c                 3   s$    | ]} | r| | fV  qd S rh   r1   )r   koptsr1   r2   r  p  s   " zLComponentReflectionTestExtra.test_get_foreign_key_options.<locals>.<genexpr>)r   r   r   rZ   r   r   r]   rV  r   rt   r   r   )r:   r   r0   r1  r  r  r   rj   r1   r  r2   test_get_foreign_key_options  sT   *	
z9ComponentReflectionTestExtra.test_get_foreign_key_options)r>   r?   r@   rA   r   re   r*   r+   r   r~   Zindexes_with_expressionsrx  r/  rz  r|  rQ  r  r  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  r1   r1   r1   r2   rh  p  sh    -
!
%



'rh  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 )	Nt1Tra   r"   r#   r\  t1idzt1.id)r   r   r   r   r   r.   r1   r1   r2   r3   {  s   

z NormalizedNameTest.define_tablesc                 C   s~   t  }ttddd|tjd}|jd }|jj|jj	sJ t  }|j
tjdd d |jd jj|jd jj	s=J d S )	Nr\  Tr  r!  r  c                 S   s   |   dv S )Nr  r\  rm  )rN   rb  r1   r1   r2   <lambda>  s    zINormalizedNameTest.test_reflect_lowercase_forced_tables.<locals>.<lambda>)only)r   r   r   r   r5   r   rF   r  Z
referencesr"   ra  )r:   m2Zt2_refZt1_refZm3r1   r1   r2   $test_reflect_lowercase_forced_tables  s   

&z7NormalizedNameTest.test_reflect_lowercase_forced_tablesc                 C   sP   dd t tj D }t|d  |d   t|d  |d   d S )Nc                 S   s   g | ]
}|  d v r|qS )r  r  r   r1   r1   r2   r     s    
z;NormalizedNameTest.test_get_table_names.<locals>.<listcomp>r   r  )r   r   r5   r   r   upperrm  )r:   Z
tablenamesr1   r1   r2   r     s
   z'NormalizedNameTest.test_get_table_namesN)	r>   r?   r@   rg  rA   rB   r3   r  r   r1   r1   r1   r2   r  w  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   rE  rO   r1   rF  r1   r1   r2   rG    rH  zLComputedReflectionTest.test_computed_col_default_not_set.<locals>.<dictcomp>Z42with_defaultr   normalcomputed_col)r   r   r5   ro   r   r   )r:   rj   r  Zcol_datar1   r1   r2   !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   rE  rO   r1   rF  r1   r1   r2   rG    rH  zKComputedReflectionTest.test_get_column_returns_computed.<locals>.<dictcomp>)r"   r  r  computedr  ro  	normal+42	persisted)r   r   r5   ro   r   r   rp  r   r*   "computed_columns_reflect_persistedr,   "computed_columns_default_persisted)r:   rj   r  r%   r  compDatar1   r1   r2    test_get_column_returns_computed  s&   




z7ComputedReflectionTest.test_get_column_returns_computedc                 C   s\   t d|| v  || d }t| |d | tjjjr,t d|v  t|d | d S d S )Nr  ro  r  )r   r   rp  r   r*   r  r,   r   )r:   r%   columnro  r  r  r1   r1   r2   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   rE  rO   r1   rF  r1   r1   r2   rG    rH  zLComputedReflectionTest.test_get_column_returns_persisted.<locals>.<dictcomp>computed_no_flagr  computed_virtualznormal+2Fcomputed_storedz	normal-42T)r   r   r5   ro   r  r   r*   r  r,   computed_columns_virtualcomputed_columns_storedr:   rj   r  r%   r1   r1   r2   !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 )Nr  r(   c                 S   rE  rO   r1   rF  r1   r1   r2   rG    rH  zXComputedReflectionTest.test_get_column_returns_persisted_with_schema.<locals>.<dictcomp>r  z	normal/42r  znormal/2Fr  z	normal*42T)r   r   r5   ro   r-   r  r   r*   r  r,   r  r  r  r1   r1   r2   -test_get_column_returns_persisted_with_schema  s4   


zDComputedReflectionTest.test_get_column_returns_persisted_with_schemaN)r>   r?   r@   r  r  r  r  r   r*   r+   r  r1   r1   r1   r2   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)Zidentity_columnsrQ  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\  id2Tr   r   *      alwaysstart	incrementminvaluemaxvaluecyclecacher   )r  r  r(   )
r   r   r   r   r   r*   r+   r,   r   r-   r.   r1   r1   r2   r3   
  s@   

z$IdentityReflectionTest.define_tablesc                 C   s   t jjjrXd}t|D ]}||vr|| q|rQtt|t| |D ]*}|dkr5t|| || k q$|dv rDt|| || k q$t|| || | q$d S t|| d S t|d |d  t|d |d  d S )Nr  r  >   r  r  r  r  )	r   r*   Zidentity_columns_standardr,   r#  r'  r   r   r   )r:   valueexpapproxZcommon_keysr  r1   r1   r2   check,  s$   
	
zIdentityReflectionTest.checkc                 C   s   t tj}|d|d }|D ]l}|d dkr td|v  q|d dkrOt|d dv  t|d	 d  td|v  | j|d td
ddddd
dddd q|d dkr}t|d dv  t|d	 d  td|v  | j|d tddddddddd
d qd S )Nr  r\  rN   r  identityr  rI  Tautor   Fr  r  Tr  r  r   r   r  r  r  )	r   r   r5   ro   r   r   r   r  r   r:   rj   r  r  r1   r1   r2   test_reflect_identityI  sR   
		z,IdentityReflectionTest.test_reflect_identityc                 C   s   t tj}|jdtjd}|D ]=}|d dkrtd|v  q|d dkrLt|d dv  t|d	 d  td|v  | j|d t	d
dddddddd
d qd S )Nr  r(   rN   r  r  r  rI  r  r   Tr   r  r  Fr  r  )
r   r   r5   ro   r-   r   r   r   r  r   r  r1   r1   r2   test_reflect_identity_schemas  s0   
	z3IdentityReflectionTest.test_reflect_identity_schema)r>   r?   r@   rM  rN  rA   rg  rB   r3   r  r  r   r*   r+   r  r1   r1   r1   r2   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g d|jj	|jj
|jjgddd dd		 d S )Ntb1r"   attrrN   r   Zpk_tb1rO   Tr   tb2r#   pidpattrpnamer  r  r  Zfk_tb1_name_id_attr)r   r   r   r   r   rZ   r[   r]   rF   rN   r"   r  )r/   r0   r  r1   r1   r2   r3     s2   

z(CompositeKeyReflectionTest.define_tablesc                 C   s2   t | j}|| jjj}t|dg d d S )Nr  rN   r"   r  )r   r   rr   r   r  rN   r   rJ  )r:   rj   r$   r1   r1   r2   test_pk_column_order  s   
z/CompositeKeyReflectionTest.test_pk_column_orderc                 C   s\   t | j}|| jjj}tt|d |d }t|dg d t|dg d d S )Nr  r   r  r  r  r  )	r   r   rt   r   r  rN   r   r   rJ  )r:   rj   Zforeign_keysr  r1   r1   r2   test_fk_column_order  s   
z/CompositeKeyReflectionTest.test_fk_column_orderN)r>   r?   r@   rA   rB   r3   r   r*   rP  r  rO  r  r1   r1   r1   r2   r    s    

r  )
r   rh  rR  rK   r    rC   r  r  r  r  )4r7  rk  r   rZ   r   r   r   r   r   r   r   Z	provisionr	   r
   r)   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zsql.elementsr   Z
sql.schemar   r   r   r0   r   Z
TablesTestr    rC   rK   r   ZTestBaserR  rh  r  ZComputedReflectionFixtureTestr  r  r  __all__r1   r1   r1   r2   <module>   sf    .;       !7  	,a 1