o
    h.                     @   s   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 G dd dejZG dd dejeZG dd dejZdZdS )    N   )testing   )config)fixtures)util)eq_)is_false)is_true)requirements)Table   )CheckConstraint)Column)ForeignKeyConstraint)Index)inspect)Integerschema)String)UniqueConstraintc                   @   s  e Zd ZdZdddZdd ZdddZd	d
 Zej	e
jdd Zej	eje
jdd Zeje
jdd Zej	e
jdd Zeje
jdd Zeje
jdd Zeje
jdd Zeje
jdd Zeje
jdd Zeje
jdd ZdS ) TableDDLTestTNc              	   C   s*   t d| jtdtdddtdtd|dS )	N
test_tableidTFprimary_keyautoincrementdata2   r   r   metadatar   r   r   )selfr    r#   u/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sqlalchemy/testing/suite/test_ddl.py_simple_fixture"   s   zTableDDLTest._simple_fixturec              	   C   s&   t d| jtdtdddtdtdS )N_test_tabler   TFr   _datar   r    )r"   r#   r#   r$   _underscore_fixture+   s   z TableDDLTest._underscore_fixturec                 C   s"   | j |d}td|jj}||fS )Nr   
test_index)r%   r   cr   )r"   r   tableidxr#   r#   r$   _table_index_fixture3   s   z!TableDDLTest._table_index_fixturec                 C   s`   t j !}|| d || }t| d W d    d S 1 s)w   Y  d S )N)r   z	some data)	r   dbbeginexecuteinsertvaluesselectr   first)r"   r+   connresultr#   r#   r$   _simple_roundtrip8   s
   "zTableDDLTest._simple_roundtripc                 C   &   |   }|jtjdd | | d S NF
checkfirst)r%   creater   r.   r7   r"   r+   r#   r#   r$   test_create_table>      zTableDDLTest.test_create_tablec                 C   s,   | j tjd}|jtjdd | | d S )Nr   Fr:   )r%   r   test_schemar<   r.   r7   r=   r#   r#   r$   test_create_table_schemaE   s   z%TableDDLTest.test_create_table_schemac                 C   s,   |   }|jtjdd |jtjdd d S r9   )r%   r<   r   r.   dropr=   r#   r#   r$   test_drop_tableM   s   zTableDDLTest.test_drop_tablec                 C   r8   r9   )r(   r<   r   r.   r7   r=   r#   r#   r$   test_underscore_namesT   r?   z"TableDDLTest.test_underscore_namesc                 C   sH   |   }|j|dd d|_|t| tt|dddi d S NFr:   z	a commentr   text)	r%   r<   commentr0   r   SetTableCommentr   r   get_table_commentr"   
connectionr+   r#   r#   r$   test_add_table_comment[   s   z#TableDDLTest.test_add_table_commentc                 C   sX   |   }|j|dd d|_|t| |t| tt|	ddd i d S rE   )
r%   r<   rG   r0   r   rH   DropTableCommentr   r   rI   rJ   r#   r#   r$   test_drop_table_commentg   s   z$TableDDLTest.test_drop_table_commentc                 C   sF   |   }|tj|dd tt|d |tj|dd d S )NTif_not_existsr   )r%   r0   r   CreateTabler
   r   	has_tablerJ   r#   r#   r$   test_create_table_if_not_existss   s   z,TableDDLTest.test_create_table_if_not_existsc                 C   s   |   \}}|tj|dd tt|d tddd t|dD v  |tj	|dd tddd t|dD v  |tj	|dd d S )NTrO   r   r)   c                 S      g | ]}|d  qS namer#   .0ixr#   r#   r$   
<listcomp>       z@TableDDLTest.test_create_index_if_not_exists.<locals>.<listcomp>c                 S   rT   rU   r#   rW   r#   r#   r$   rZ      r[   )
r-   r0   r   rQ   r
   r   rR   r	   get_indexesCreateIndexr"   rK   r+   r,   r#   r#   r$   test_create_index_if_not_exists}   s&   z,TableDDLTest.test_create_index_if_not_existsc                 C   sb   |   }|| tt|d |tj|dd tt|d |tj|dd d S )Nr   T	if_exists)	r%   r<   r
   r   rR   r0   r   	DropTabler	   rJ   r#   r#   r$   test_drop_table_if_exists   s   
z&TableDDLTest.test_drop_table_if_existsc                 C   s   |   \}}|| tddd t|dD v  |tj|dd tddd t|dD v  |tj|dd d S )Nr)   c                 S   rT   rU   r#   rW   r#   r#   r$   rZ      r[   z:TableDDLTest.test_drop_index_if_exists.<locals>.<listcomp>r   Tr`   c                 S   rT   rU   r#   rW   r#   r#   r$   rZ      r[   )	r-   r<   r
   r   r\   r0   r   	DropIndexr	   r^   r#   r#   r$   test_drop_index_if_exists   s$   
z&TableDDLTest.test_drop_index_if_exists)N)__name__
__module____qualname____backend__r%   r(   r-   r7   r   create_tabler   provide_metadatar>   schemasrA   
drop_tablerC   rD   comment_reflectionrL   rN   table_ddl_if_existsrS   index_ddl_if_existsr_   rc   re   r#   r#   r#   r$   r      sJ    
	


r   c                   @   s   e Zd ZdS )FutureTableDDLTestN)rf   rg   rh   r#   r#   r#   r$   rq      s    rq   c                   @   sr   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	e
jdddde
jj fde
jj fdddd ZdS )LongNameBlowoutTestzjtest the creation of a variety of DDL structures and ensure
    label length limits pass on backends

    Tc           	      C   s   ddd dd tdD  i}||_td|tdtd	d
d	d tdgdg}td|td|d	d |j}|| t	j
jjrRt|}|d}|d d }||fS |d fS )NfkzGforeign_key_%(table_name)s_%(column_0_N_name)s_%(referred_table_name)s__c                 s   (    | ]}d  dd tdD V  qdS ) c                 s       | ]}t d V  qdS abcdefNrandomchoicerX   jr#   r#   r$   	<genexpr>       z3LongNameBlowoutTest.fk.<locals>.<genexpr>.<genexpr>   NjoinrangerX   ir#   r#   r$   r      
    
z)LongNameBlowoutTest.fk.<locals>.<genexpr>
   a_things_with_stuffid_long_column_nameTr   )test_needs_fkaidz'a_things_with_stuff.id_long_column_nameb_related_things_of_valuer   rV   )r   r   naming_conventionr   r   r   r   rV   
create_allr   requires&foreign_key_constraint_name_reflectionenabledr   get_foreign_keys)	r"   r!   rK   
conventionconsactual_nameinspfksreflected_namer#   r#   r$   rs      sB   
	


zLongNameBlowoutTest.fkc           
   	   C   s   ddd dd tdD  i}||_td|tdtd	d
tdtd	d
}|j}|j}|| t	|}|
d}|d }	||	fS )Npkz.primary_key_%(table_name)s_%(column_0_N_name)srt   c                 s   ru   )rv   c                 s   rw   rx   rz   r}   r#   r#   r$   r     r   z3LongNameBlowoutTest.pk.<locals>.<genexpr>.<genexpr>   Nr   r   r#   r#   r$   r     r   z)LongNameBlowoutTest.pk.<locals>.<genexpr>r   r   r   Tr   id_another_long_namerV   )r   r   r   r   r   r   r   rV   r   r   get_pk_constraint)
r"   r!   rK   r   ar   r   r   r   r   r#   r#   r$   r      s(   



zLongNameBlowoutTest.pkc           
      C   s   ddd dd tdD  i}||_td|tdtd	d
tdt}td |jj|jj	}|j
}|| t|}|d}|d d }	||	fS )NrY   z(index_%(table_name)s_%(column_0_N_name)srt   c                 s   ru   )rv   c                 s   rw   rx   rz   r}   r#   r#   r$   r     r   z3LongNameBlowoutTest.ix.<locals>.<genexpr>.<genexpr>r   Nr   r   r#   r#   r$   r     r   z)LongNameBlowoutTest.ix.<locals>.<genexpr>r   r   r   Tr   r   r   rV   )r   r   r   r   r   r   r   r*   r   r   rV   r   r   r\   )
r"   r!   rK   r   r   r   r   r   rY   r   r#   r#   r$   rY     s(   



zLongNameBlowoutTest.ixc           	      C   s   ddd dd tdD  i}||_tdd}td	|tdtd
dtdt| |j}|| t	|}|
d	}|d d }||fS )Nuqz4unique_constraint_%(table_name)s_%(column_0_N_name)srt   c                 s   ru   )rv   c                 s   rw   rx   rz   r}   r#   r#   r$   r   ;  r   z3LongNameBlowoutTest.uq.<locals>.<genexpr>.<genexpr>r   Nr   r   r#   r#   r$   r   :  r   z)LongNameBlowoutTest.uq.<locals>.<genexpr>r   r   r   r   Tr   r   rV   )r   r   r   r   r   r   r   rV   r   r   get_unique_constraints)	r"   r!   rK   r   r   r   r   r   r   r#   r#   r$   r   5  s*   




zLongNameBlowoutTest.uqc           	      C   s   ddd dd tdD  i}||_td}td|td	td
dtdt| |j}|| t	|}|
d}|d d }||fS )Nckzcheck_constraint_%(table_name)srt   c                 s   ru   )rv   c                 s   rw   rx   rz   r}   r#   r#   r$   r   W  r   z3LongNameBlowoutTest.ck.<locals>.<genexpr>.<genexpr>r   Nr   r   r#   r#   r$   r   V  r   z)LongNameBlowoutTest.ck.<locals>.<genexpr>r   zsome_long_column_name > 5r   r   Tr   some_long_column_namer   rV   )r   r   r   r   r   r   r   rV   r   r   get_check_constraints)	r"   r!   rK   r   r   r   r   r   r   r#   r#   r$   r   R  s*   
	

zLongNameBlowoutTest.ck)rs   )r   )rY   r   r   type_)argnamesc                 C   s   t | |||\}}t|dksJ |d ur@|dt| }t|t|k r9t|dd |dt|d   d S t|| d S d S )N   r      )getattrlenr   )r"   r   r!   rK   r   r   overlapr#   r#   r$   test_long_convention_namen  s   	&z-LongNameBlowoutTest.test_long_convention_nameN)rf   rg   rh   __doc__ri   rs   r   rY   r   r   r   combinationsr   check_constraint_reflectionas_skipsunique_constraint_reflectionr   r#   r#   r#   r$   rr      s"    .rr   )r   rq   rr   )r{   rv   r   r   r   r   
assertionsr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   TestBaser   FutureEngineMixinrq   rr   __all__r#   r#   r#   r$   <module>   s2    % ?