o
    i                     @   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\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+d&Z,dS )'    N   )assert_raises_message)config)engines)eq_)expect_warnings)fixtures)is_)temp_table_keyword_argsColumn)Table   )event)exc)
ForeignKey)inspect)Integer)MetaData)String)testing)types)	Inspector)DDL)Index)quoted_name)is_false)is_true)NNc                   @   s4   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 r/   c/var/www/edux/Edux_v2/venv/lib/python3.10/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connr/   r/   r0   test_has_table7   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%   r2   )r   r3   r4   r   r5   r6   r+   r   r7   r/   r/   r0   test_has_table_schema=   s"   "z"HasTableTest.test_has_table_schemaN)__name__
__module____qualname____backend__classmethodr1   r:   r   r(   r)   r;   r/   r/   r/   r0   r   #   s    
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edd Zejjdd Zejjdd Zejjdd Zej	dd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ejjd d! Zejjejj d"d# Z!dd$d%Z"ejj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'dd.d/Z(ejjd0d1 Z)ejd2d3 Z*ejjd4d5 Z+ejjd6d7 Z,ejjejd8d9 Z-ejjejj d:d; Z.ejj/d<d= Z0ejj/ejj$ejjd>d? Z1ejj$d@dA Z2ejj$ejj dBdC Z3ejddDdEZ4ejj5dFdG Z6ejjejj5ejj dHdI Z7ejjejdJdK Z8ejddLdMZ9ejjdNdO Z:ejjejj dPdQ Z;ejj<ejj dRdS Z=ejj>dTdU Z?ejj@dVdW ZAejdXdY ZBdZd[ ZCejdd\d]ZDejjEd^d_ ZFejjEejj d`da ZGejdbdc ZHejjEejjIddde ZJejjEejjIdfdg ZKejjLejdhdi ZMejjNdjdk ZOejj/ejjNdldm ZPejj/dndo ZQejjNejj dpdq ZRejddrdsZSejjTdtdu ZUejjTejj dvdw ZVejddxdyZWejddzd{ZXejjd|d} ZYejjejj d~d ZZe[ddejdddZ\dd Z]ejj dd Z^ejjejdd Z_dS )ComponentReflectionTestNTc                 C   s0   t jjjrddlm} tjt|j	ddS t j
S )Nr   )pool)	poolclass)options)r   requirementsindependent_connectionsr*   
sqlalchemyrB   r   testing_enginedict
StaticPoolr3   )r-   rB   r/   r/   r0   
setup_bindV   s   

z"ComponentReflectionTest.setup_bindc                 C   s.   |  |d  tjjjr|  |tjj d S d S N)define_reflected_tablesr   r(   r)   r*   r   r+   r,   r/   r/   r0   r1   a   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_fkname)r'   test_needs_fk
dingalingsdingaling_id
address_idz%semail_addresses.address_idr#      email_addressesremote_user_idemail_address   email_ad_pkcomment_testr    
id comment)r"   commentdata % comment)rg   d2)Comment types type speedily ' " \ '' Fun!the test % ' " \ table comment)r'   rg   local_table	remote_idz%s.remote_table_2.id)r[   r'   remote_tablelocal_idz%s.local_table.idremote_table_2noncol_idx_test_nopkqr[   noncol_idx_test_pknoncol_idx_nopknoncol_idx_pk) r   r(   self_referential_foreign_keysr*   r   r   saINTCHARFloatr   r   r   crQ   PrimaryKeyConstraintcross_schema_fk_reflectionr   r+   r3   r5   default_schema_nameindex_reflectiondefine_indexindexes_with_ascdescr   rr   descview_column_reflectiondefine_viewstemp_table_reflectiondefine_temp_tables)r-   r.   r'   schema_prefixrP   rq   rt   r/   r/   r0   rM   g   s  




	z/ComponentReflectionTest.define_reflected_tablesc                 C   s   t ttj}td|tdtjddtdtdtdtjtjddd	t	d
dfi |}t
jjjrKt
jjjrMt|dtd t|dtd d S d S d S )Nuser_tmpr    Tr!   rZ   r$   foouser_tmp_uqrY   user_tmp_ixafter_createz:create temporary view user_tmp_v as select * from user_tmpbefore_dropzdrop view user_tmp_v)r
   r   r3   r   r   rx   ry   VARCHARUniqueConstraintr   r   r(   view_reflectionr*   temporary_viewsr   listenr   )r-   r.   kwr   r/   r/   r0   r      s2   

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   r|   rR   rV   rQ   )r-   r.   rP   r/   r/   r0   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)rP   r`   z%s.%s_vz"CREATE VIEW %s AS SELECT * FROM %sr   r   zDROP VIEW %s)r   r   r   )r-   r.   r'   
table_namefullname	view_namequeryr/   r/   r0   r     s   z$ComponentReflectionTest.define_viewsc                 C   s$   t tj}| tjj| v  d S rL   )r   r   r3   assert_r   r+   get_schema_namesr8   inspr/   r/   r0   test_get_schema_names(  s   
z-ComponentReflectionTest.test_get_schema_namesc                 C   s4   t  }t|jdrJ t| t|jdsJ d S )Nr   )r   rH   hasattrr5   r   )r8   enginer/   r/   r0   test_dialect_initialize.  s   z/ComponentReflectionTest.test_dialect_initializec                 C   s    t tj}t|jtjjj d S rL   )r   r   r3   r   r   r5   r   r/   r/   r0   test_get_default_schema_name5  s   
z4ComponentReflectionTest.test_get_default_schema_nametablec           	         s   g d | j }t|j}|dkr&||}|  ddg}tt|| d S |r3dd ||D }n||} fdd|D }|dkrPg d	}t|| d S g d
}tt|| d S )N)re   rt   rq   rl   rn   rp   viewemail_addresses_vusers_vc                 S   s   g | ]
}|d  r|d  qS )r   r/   .0recr/   r/   r0   
<listcomp>Q  s    zAComponentReflectionTest._test_get_table_names.<locals>.<listcomp>c                    s   g | ]}| vr|qS r/   r/   r   t_ignore_tablesr/   r0   r   X  s    foreign_key)rP   r`   r\   )r\   r`   rP   )	r.   r   bindget_view_namessortr   sortedget_sorted_table_and_fkc_namesget_table_names)	r8   r'   
table_typeorder_bymetar   table_namesanswertablesr/   r   r0   _test_get_table_names:  s&   


z-ComponentReflectionTest._test_get_table_namesc                 C   &   t | j}| }tt|dg d S )Nr   )r   r   get_temp_table_namesr   r   r8   r   temp_table_namesr/   r/   r0   test_get_temp_table_namesa  s   
z1ComponentReflectionTest.test_get_temp_table_namesc                 C   r   )N
user_tmp_v)r   r   get_temp_view_namesr   r   r   r/   r/   r0   test_get_temp_view_namesg  s   
z0ComponentReflectionTest.test_get_temp_view_namesc                 C      |    d S rL   r   r8   r/   r/   r0   test_get_table_nameso     z,ComponentReflectionTest.test_get_table_namesc                 C      | j dd d S )Nr   )r   r   r   r/   r/   r0   test_get_table_names_fkss     z0ComponentReflectionTest.test_get_table_names_fksc                 C   r   rL   )_test_get_commentsr   r/   r/   r0   test_get_commentsx  r   z)ComponentReflectionTest.test_get_commentsc                 C      |  tjj d S rL   )r   r   r   r+   r   r/   r/   r0   test_get_comments_with_schema|     z5ComponentReflectionTest.test_get_comments_with_schemac                 C   st   t 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 )Nre   r&   textrk   rP   c                 S   s   g | ]}|d  |d dqS )rZ   rg   )rZ   rg   r/   r   r/   r/   r0   r     s    z>ComponentReflectionTest._test_get_comments.<locals>.<listcomp>rf   r    )rg   rZ   rh   r#   rj   ri   )r   r   r3   r   get_table_commentget_columns)r8   r'   r   r/   r/   r0   r     s"   
z*ComponentReflectionTest._test_get_commentsc                 C   r   rL   r   r   r   r+   r   r/   r/   r0    test_get_table_names_with_schema  r   z8ComponentReflectionTest.test_get_table_names_with_schemac                 C   r   Nr   )r   r   r   r/   r/   r0   test_get_view_names     z+ComponentReflectionTest.test_get_view_namesc                 C      | j tjjdd d S r   r   r   r/   r/   r0   test_get_view_names_with_schema     
z7ComponentReflectionTest.test_get_view_names_with_schemac                 C   s   |    | j dd d S r   r   r   r/   r/   r0   test_get_tables_and_views  s   z1ComponentReflectionTest.test_get_tables_and_viewsc                 C   sj  t tj}| jj| jj}}ddg}|dkrddg}t|j}t|||fD ]\}}	|}
|j	||
d}| 
t|dkt| t|	jD ]m\}}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|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 )NrP   r`   r   r   r   r&   r   rZ   typeoraclez%s(%s), %s(%s)default)#r   r   r3   r   rP   r`   r   r   zipr   r   len	enumeratecolumnsr   rZ   	__class__r   
isinstancerx   r   
TypeEngineagainst	sql_typesDateDateTimeset__mro__intersectionr   NumericTimer   _Binaryr"   )r8   r'   r   r   rP   	addressesr   r   r   r   schema_namecolsicolctype	ctype_defr/   r/   r0   _test_get_columns  s^   

z)ComponentReflectionTest._test_get_columnsc                 C   r   rL   r   r   r/   r/   r0   test_get_columns  r   z(ComponentReflectionTest.test_get_columnsc                 G   sF   t d| jgdd t|D R  }|  dd t| jjdD S )Nr   c                 S   s   g | ]\}}t d | |qS )zt%dr   )r   r   type_r/   r/   r0   r     s    z<ComponentReflectionTest._type_round_trip.<locals>.<listcomp>c                 S      g | ]}|d  qS )r   r/   r   r|   r/   r/   r0   r     s    )r   r.   r   creater   r   r   )r8   r   r   r/   r/   r0   _type_round_trip  s   z(ComponentReflectionTest._type_round_tripc                 C   sD   |  tddD ]}t|tjsJ t|jd t|jd q	d S )N   rS   )r  r   r   r   r   	precisionscaler8   typr/   r/   r0   test_numeric_reflection  s
   z/ComponentReflectionTest.test_numeric_reflectionc                 C   s4   |  tdd }t|tjsJ t|jd d S )N4   r   )r  r   r   r   r   lengthr  r/   r/   r0   test_varchar_reflection  s   z/ComponentReflectionTest.test_varchar_reflectionc              	   C   s\   t d| jtdtddtdtdd}|  ttdd t| jj	dD ddd	 d S )
Nr   aTrT   bFc                 s   s     | ]}|d  |d fV  qdS )rZ   rU   Nr/   r   r   r/   r/   r0   	<genexpr>  s
    
zCComponentReflectionTest.test_nullable_reflection.<locals>.<genexpr>)r  r  )
r   r.   r   r   r  r   rI   r   r   r   )r8   r   r/   r/   r0   test_nullable_reflection  s   z0ComponentReflectionTest.test_nullable_reflectionc                 C      | j tjjd d S Nr&   r   r   r   r+   r   r/   r/   r0   test_get_columns_with_schema     z4ComponentReflectionTest.test_get_columns_with_schemac                 C   sj   t | j}| jj}t|j}|d}| t|dkt| t|j	D ]\}}t
|j|| d  q$d S )Nr   r   rZ   )r   r   r   r   r   r   r   r   r   r   r   rZ   )r8   r   r   r   r   r   r   r/   r/   r0   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   r   rY   r/   r  r/   r/   r0   r   0      zFComponentReflectionTest.test_get_temp_view_columns.<locals>.<listcomp>)r    rZ   r   )r   r   r   r   )r8   r   r   r/   r/   r0   test_get_temp_view_columns*  s   

z2ComponentReflectionTest.test_get_temp_view_columnsc                 C   r   r   r   r   r/   r/   r0   test_get_view_columns2  r   z-ComponentReflectionTest.test_get_view_columnsc                 C   r   )Nr   )r'   r   r  r   r/   r/   r0   !test_get_view_columns_with_schema6  r   z9ComponentReflectionTest.test_get_view_columns_with_schemac           
      C   s   | j }| jj| jj}}t|j}|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 sNw   Y  d S )Nr&   constrained_columnsrQ   r^   rZ   rd   )r.   r   rP   r`   r   r   get_pk_constraintrZ   r   r   r(   reflects_pk_namesfail_if)
r8   r'   r   rP   r   r   
users_consusers_pkeys	addr_cons
addr_pkeysr/   r/   r0   _test_get_pk_constraint=  s   
"z/ComponentReflectionTest._test_get_pk_constraintc                 C   r   rL   )r#  r   r/   r/   r0   test_get_pk_constraintN  r   z.ComponentReflectionTest.test_get_pk_constraintc                 C   r  r  )r#  r   r   r+   r   r/   r/   r0   "test_get_pk_constraint_with_schemaR  s   z:ComponentReflectionTest.test_get_pk_constraint_with_schemac                 C   s0   | j }| jj}t|j}ttjd|j|j	 d S )Nz+.*get_primary_keys\(\) method is deprecated)
r.   r   rP   r   r   r   sa_excSADeprecationWarningget_primary_keysrZ   )r8   r   rP   r   r/   r/   r0    test_deprecated_get_primary_keysX  s   
z8ComponentReflectionTest.test_deprecated_get_primary_keysc           
      C   sb  | j }| jj| jj}}t|j}|}tjjj	re|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	ret|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   rZ   rX   referred_schemareferred_tablereferred_columnsrQ   r  rW   ra   )r.   r   rP   r`   r   r   r   r(   rw   r*   get_foreign_keysrZ   named_constraintsr  r   implicitly_named_constraintsr   )
r8   r'   r   rP   r   r   expected_schemausers_fkeysfkey1
addr_fkeysr/   r/   r0   _test_get_foreign_keyse  s0   


z.ComponentReflectionTest._test_get_foreign_keysc                 C   r   rL   )r4  r   r/   r/   r0   test_get_foreign_keys  r   z-ComponentReflectionTest.test_get_foreign_keysc                 C   r  r  )r4  r   r   r+   r   r/   r/   r0   !test_get_foreign_keys_with_schema  r  z9ComponentReflectionTest.test_get_foreign_keys_with_schemac           	      C   s  |  dtjjj dtjj dtjj \}}}t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 t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  rm   r&   ro   )r   r   r3   r5   r   r   r+   r   r-  rZ   r   r   )	r8   rl   rn   rp   r   local_fkeysr2  remote_fkeysfkey2r/   r/   r0   "test_get_inter_schema_foreign_keys  s2   





z:ComponentReflectionTest.test_get_inter_schema_foreign_keysc                 C   r   )NCASCADE)ondelete_test_get_foreign_key_optionsr   r/   r/   r0   %test_get_foreign_key_options_ondelete  r   z=ComponentReflectionTest.test_get_foreign_key_options_ondeletec                 C   r   )NzSET NULL)onupdater>  r   r/   r/   r0   %test_get_foreign_key_options_onupdate  r   z=ComponentReflectionTest.test_get_foreign_key_options_onupdatec                    s  | j }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	|j
}|dd d  tt fdd D i  |dd d  tt fdd D | d S )Nxr    Tr!   rs   r   x_idzx.idxidrY   test
   userrZ   r$   FrT   tidztable.idmyfkr   rD   c                 3   $    | ]} | r| | fV  qd S rL   r/   r   koptsr/   r0   r       " zHComponentReflectionTest._test_get_foreign_key_options.<locals>.<genexpr>c                 3   rK  rL   r/   rL  rN  r/   r0   r    rP  )r.   r   r   r   rx   r   r   ForeignKeyConstraint
create_allr   r   r-  r   rI   )r8   rD   r   r   r/   rN  r0   r?    sH   	
 z5ComponentReflectionTest._test_get_foreign_key_optionsc                 C   sZ   dd |D }|D ]!}|d |v sJ || |d  }|D ]}t|| ||  qq	d S )Nc                 S   r   rY   r/   )r   dr/   r/   r0   r     r  z@ComponentReflectionTest._assert_insp_indexes.<locals>.<listcomp>rZ   )indexr   )r8   indexesexpected_indexesindex_namese_indexrT  keyr/   r/   r0   _assert_insp_indexes  s   z,ComponentReflectionTest._assert_insp_indexesc                 C   sN   | j }t|j}|jd|d}dddgdddg dd	dg}| || d S )
NrP   r&   FrR   rV   r   uniquecolumn_namesrZ   )rQ   rV   rR   r   )r.   r   r   get_indexesrZ  )r8   r'   r   r   rU  rV  r/   r/   r0   _test_get_indexes  s   
z)ComponentReflectionTest._test_get_indexesc                 C   r   rL   )r_  r   r/   r/   r0   test_get_indexes  r   z(ComponentReflectionTest.test_get_indexesc                 C   r  r  )r_  r   r   r+   r   r/   r/   r0   test_get_indexes_with_schema	  r  z4ComponentReflectionTest.test_get_indexes_with_schemac                 C   s   | j }t|j}||}d|dg}| || t|||jd}tt|jd t	t
|jd j| tt
|jd j| d S )NF)r\  rZ   )autoload_withr7  r   )r.   r   r   r^  rZ  r   r   r   rU  r	   listr   rZ   )r8   tnameixnamer   r   rU  rV  r   r/   r/   r0   _test_get_noncol_index  s   

z.ComponentReflectionTest._test_get_noncol_indexc                 C      |  dd d S )Nrq   ru   rf  r   r/   r/   r0   test_get_noncol_index_no_pk  r   z3ComponentReflectionTest.test_get_noncol_index_no_pkc                 C   rg  )Nrt   rv   rh  r   r/   r/   r0   test_get_noncol_index_pk$  r   z0ComponentReflectionTest.test_get_noncol_index_pkc                 C   s   t d| jtdtdtdtd t| jdtd t| jdtd | j  t| jj	}t
d t|dd	dgd
dg W d    d S 1 sOw   Y  d S )Nr   rC  r_   yr   z+CREATE INDEX t_idx ON t(lower(x), lower(y))zCREATE INDEX t_idx_2 ON t(x)z>Skipped unsupported reflection of expression-based index t_idxt_idx_2r   )rZ   r]  r\  )r   r.   r   r   r   r   r   rR  r   r   r   r   r^  r   r/   r/   r0   %test_reflect_expression_based_indexes)  s0   
"z=ComponentReflectionTest.test_reflect_expression_based_indexesc                 C   r   rL   )_test_get_unique_constraintsr   r/   r/   r0   test_get_unique_constraintsF  r   z3ComponentReflectionTest.test_get_unique_constraintsc                 C   sB   t | j}|d}|D ]}|dd  qt|dgddg d S )Nr   duplicates_indexrZ   r   )r]  rZ   )r   r   get_unique_constraintspopr   )r8   r   	reflectedreflr/   r/   r0   &test_get_temp_table_unique_constraintsJ  s
   

z>ComponentReflectionTest.test_get_temp_table_unique_constraintsc                 C   sN   t | j}|d}|D ]}|dd  qtdd |D ddgddg d S )	Nr   dialect_optionsc                 S   s   g | ]
}|d  dkr|qS )rZ   r   r/   r   idxr/   r/   r0   r   ^  s    zGComponentReflectionTest.test_get_temp_table_indexes.<locals>.<listcomp>Fr   r   r[  )r   r   r^  rr  r   )r8   r   rU  indr/   r/   r0   test_get_temp_table_indexesU  s   

z3ComponentReflectionTest.test_get_temp_table_indexesc                 C   r  r  )rn  r   r   r+   r   r/   r/   r0   'test_get_unique_constraints_with_schemah  r  z?ComponentReflectionTest.test_get_unique_constraints_with_schemac                 C   s  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}| j}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 qW|  t|j}t |jd|dtdd}t }t||D ]\}	}
|
dd }|r|| t|	|
 qt }td||j|d}tdd |jD }tdd |jD dg}||rJ |rt|| t|t  d S d S )Nunique_ar  )rZ   r]  unique_a_b_c)r  r  r|   unique_c_a_b)r|   r  r  unique_asc_keyascrY  zi.have.dotsr  zi have spacesr|   rZ   rY  testtblrc   r_   r&   r]  rp  )rb  r'   c                 S   s   g | ]}|j qS r/   rY   rw  r/   r/   r0   r     s    zHComponentReflectionTest._test_get_unique_constraints.<locals>.<listcomp>c                 S   s   g | ]}t |tjr|jqS r/   )r   rx   r   rZ   )r   uqr/   r/   r0   r     s    
)r   operator
itemgetterr.   r   r   rx   r   r   append_constraintr   rR  r   r   rq  r   r   rr  addr   r   rU  constraints
differencer   )r8   r'   uniques	orig_metar   uc	inspectorrs  names_that_duplicate_indexorigrt  dupereflected_metadata	idx_namesuq_namesr/   r/   r0   rn  m  sr   






z4ComponentReflectionTest._test_get_unique_constraintsc                 C   r   rL   )_test_get_check_constraintsr   r/   r/   r0   test_get_check_constraints  r   z2ComponentReflectionTest.test_get_check_constraintsc                 C   r  r  )r  r   r   r+   r   r/   r/   r0   !test_get_check_constraints_schema  r  z9ComponentReflectionTest.test_get_check_constraints_schemac              	      s   | j }td|tdt tjdddtjddd|d |  t|j}t	|j
d|dtd	d
}dd   fdd|D }t|ddddddg d S )Nsa_ccr  za > 1 AND a < 5cc1rY   za = 1 OR (a > 2 AND a < 5)cc2r&   rZ   r  c                 S   s   d td|  tjS )N zand|\d|=|a|or|<|>)joinrefindalllowerI)sqltextr/   r/   r0   	normalize  s   zFComponentReflectionTest._test_get_check_constraints.<locals>.normalizec                    s"   g | ]}|d   |d dqS )rZ   r  rZ   r  r/   )r   itemr  r/   r0   r     s    zGComponentReflectionTest._test_get_check_constraints.<locals>.<listcomp>za > 1 and a < 5r  za = 1 or a > 2 and a < 5)r.   r   r   r   rx   CheckConstraintrR  r   r   r   get_check_constraintsr  r  r   )r8   r'   r  r  rs  r/   r  r0   r    s2   
	

z3ComponentReflectionTest._test_get_check_constraintsc                 C   sL   | j }d}d}t|j}|j||d}| | |j||d}| | d S )Nr   r   r&   )r.   r   r   get_view_definitionr   )r8   r'   r   
view_name1
view_name2r   v1v2r/   r/   r0   _test_get_view_definition  s   

z1ComponentReflectionTest._test_get_view_definitionc                 C   r   rL   )r  r   r/   r/   r0   test_get_view_definition  r   z0ComponentReflectionTest.test_get_view_definitionc                 C   r  r  )r  r   r   r+   r   r/   r/   r0   $test_get_view_definition_with_schema  r  z<ComponentReflectionTest.test_get_view_definition_with_schema
postgresqlzPG specific featurec                 C   s0   | j }t|j}|||}| t|t d S rL   )r.   r   r   get_table_oidr   r   int)r8   r   r'   r   r   oidr/   r/   r0   _test_get_table_oid  s   
z+ComponentReflectionTest._test_get_table_oidc                 C   s   |  d d S )NrP   )r  r   r/   r/   r0   test_get_table_oid	  s   z*ComponentReflectionTest.test_get_table_oidc                 C   s   | j dtjjd d S )NrP   r&   )r  r   r   r+   r   r/   r/   r0   test_get_table_oid_with_schema  s   z6ComponentReflectionTest.test_get_table_oid_with_schemac                 C   sN   | j }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.

        ))rP   rQ   )r`   r^   )r\   r]   c                 S      i | ]}|d  |qS rY   r/   r   r/   r/   r0   
<dictcomp>(      zBComponentReflectionTest.test_autoincrement_col.<locals>.<dictcomp>autoincrementTN)r.   r   r   r   get)r8   r   r   rd  cnamer   id_r/   r/   r0   test_autoincrement_col  s   

z.ComponentReflectionTest.test_autoincrement_col)Nr   NrL   )Nr   )`r<   r=   r>   run_insertsrun_deletesr?   r@   rK   r1   rM   r   r   r   r   r(   schema_reflectionr   r   r   provide_metadatar   r   r   r   r   r   table_reflectionr   !foreign_key_constraint_reflectionr   comment_reflectionr   r)   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r   r  r  r  r  r#  !primary_key_constraint_reflectionr$  r%  r)  r4  r5  r6  r~   r;  1foreign_key_constraint_option_reflection_ondeleter@  1foreign_key_constraint_option_reflection_onupdaterB  r?  rZ  r_  r   r`  ra  rf  r   ri  rj  indexes_with_expressionsrm  unique_constraint_reflectionro  ru  rz  r{  rn  check_constraint_reflectionr  r  r  r  r  r  only_onr  r  r  r  r/   r/   r/   r0   rA   Q   s@   



 





&





8







 
!


,


	
N
'



rA   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 )	Nt1Tquoter    r!   t2t1idzt1.id)r   r   r   r   r   r,   r/   r/   r0   r1   0  s   

z NormalizedNameTest.define_tablesc                 C   s   t tj}ttddd|dd}|jd }|jj|jj	s J t tj}|j
dd d |jd jj|jd jj	s>J d S )	Nr  Tr  )autoloadr  c                 S   s   |   dv S )Nr  r  r  )rZ   mr/   r/   r0   <lambda>F  s    zINormalizedNameTest.test_reflect_lowercase_forced_tables.<locals>.<lambda>)only)r   r   r3   r   r   r   r|   r  
referencesr    reflect)r8   m2t2_reft1_refm3r/   r/   r0   $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   r/   r/   r0   r   J  s
    z;NormalizedNameTest.test_get_table_names.<locals>.<listcomp>r   r7  )r   r   r3   r   r   upperr  )r8   
tablenamesr/   r/   r0   r   I  s
   z'NormalizedNameTest.test_get_table_namesN)	r<   r=   r>   __requires__r?   r@   r1   r  r   r/   r/   r/   r0   r  ,  s    
r  c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zejj	d	d
 Z
dS )ComputedReflectionTestc                 C   sV   t tj}|d}|D ]}|d dkrtd|d v  q|d s(t|d d  qd S )Ncomputed_column_tablerZ   with_default42r   r  )r   r   r3   r   r   r	   )r8   r   r   r   r/   r/   r0   !test_computed_col_default_not_setU  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 )
Ncomputed_default_tablec                 S   r  rY   r/   r   r/   r/   r0   r  c  r  zKComputedReflectionTest.test_get_column_returns_computed.<locals>.<dictcomp>)r    normalr  computedcomputed_colr  	normal+42	persisted)r   r   r3   r   r   r   r  r   r(   "computed_columns_reflect_persistedr*   "computed_columns_default_persisted)r8   r   r   r#   rY  compDatar/   r/   r0    test_get_column_returns_computed_  s&   




z7ComputedReflectionTest.test_get_column_returns_computedc                 C   s\   t d|| v  || d }t| |d | tjjjr,t d|v  t|d | d S d S )Nr  r  r  )r   r   r  r   r(   r  r*   r	   )r8   r#   columnr  r  r  r/   r/   r0   check_columnt  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 )Nr  c                 S   r  rY   r/   r   r/   r/   r0   r    r  zLComputedReflectionTest.test_get_column_returns_persisted.<locals>.<dictcomp>computed_no_flagr  computed_virtualznormal+2Fcomputed_storedz	normal-42T)r   r   r3   r   r  r   r(   r  r*   computed_columns_virtualcomputed_columns_storedr8   r   r   r#   r/   r/   r0   !test_get_column_returns_persisted|  s$   



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   r  rY   r/   r   r/   r/   r0   r    r  zXComputedReflectionTest.test_get_column_returns_persisted_with_schema.<locals>.<dictcomp>r  z	normal/42r  znormal/2Fr  z	normal*42T)r   r   r3   r   r+   r  r   r(   r  r*   r  r  r  r/   r/   r0   -test_get_column_returns_persisted_with_schema  s(   


zDComputedReflectionTest.test_get_column_returns_persisted_with_schemaN)r<   r=   r>   r  r  r  r  r   r(   r)   r  r/   r/   r/   r0   r  T  s    
r  )rA   r   r  r  )-r  r  rG   rx   rO   r   r   r   r   r   r   r	   	provisionr
   r'   r   r   r   r   r&  r   r   r   r   r   r   r   r   engine.reflectionr   r   r   sql.elementsr   r   r   r.   rP   
TablesTestr   rA   r  ComputedReflectionFixtureTestr  __all__r/   r/   r/   r0   <module>   sR    .       b(V