
    yj$                    t   U d dl mZ d dlZd dlm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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*  ej+                    Z,e,-                    dg            G d de          Z G d d ee          Ze)rd d!lm.Z. n G d" d#          Z.d$e._/        d0d&Z0i Z1d'e2d(<   ed)             Z3ed*             Z4	 	 	 	 	 d1d-Z5 G d. d/          Z6dS )2    )annotationsN)contextmanager)Any)Dict)Column)inspect)MetaData)String)Table)testing)text)config)mock)eq_)
TablesTest)TestBase   )_get_dialect   )EnvironmentContext)MigrationContext)
Operations)sqla_compatcreate_mock_engine)sqla_14)sqla_2ztest.cfgc                      e Zd ZeZ ej                    d             Zej        d             Zej        d             Z	ej        d             Z
dS )r   c              #     K   |                     d          5  t          |          V  d d d            d S # 1 swxY w Y   d S )NT)_per_migration)begin_transactionr   )selfmigration_contexts     h/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/alembic/testing/fixtures.pyops_contextzTestBase.ops_context)   s      000EE 	0 	0./////	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0s   8<<c                J    t          j        |t          d                    S )NT)transaction_per_migrationoptsr   	configuredictr"   
connections     r$   r#   zTestBase.migration_context.   s,    )TDAAA
 
 
 	
    c                L    t          j        |t          dd                    S )NT)r'   as_sqlr(   r*   r-   s     r$   as_sql_migration_contextz!TestBase.as_sql_migration_context4   s.    )TDNNN
 
 
 	
r/   c              #     K   t           j                                        5 }|V  d d d            d S # 1 swxY w Y   d S N)r   dbconnect)r"   conns     r$   r.   zTestBase.connection:   s      Y   	DJJJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   377N)__name__
__module____qualname__r   is_sqlalchemy_futurer   fixturer%   r#   r2   r.    r/   r$   r   r   &   s        !W_0 0 0 _
 
 _

 _
 
 _

 _  _  r/   r   c                      e Zd ZdS )r   N)r8   r9   r:   r=   r/   r$   r   r   @   s        Dr/   r   )FutureEngineMixinc                      e Zd ZdZdS )r?   )sqlalchemy_14N)r8   r9   r:   __requires__r=   r/   r$   r?   r?   H   s        )r/   r?   Tpostgresql://c                >    g fd}t          | |          fS )Nc                ~                         t          |                     j                                       d S N)dialect)appendstrcompilerG   )sqlmultiparamsparamsbufengines      r$   dumpzcapture_db.<locals>.dumpR   s3    

3s{{6>{::;;<<<<<r/   r   )rG   rP   rN   rO   s     @@r$   
capture_dbrQ   O   sB    
C= = = = = =  ..F3;r/   zDict[Any, Any]_engsc               +  b   K                         dd          rt          j                    }nt          j                    }                     d|d           t
          j         fd}t          j        	                    t
          d|          5  |V  d d d            d S # 1 swxY w Y   d S )Nbytes_ioFsqlite)dialect_nameoutput_bufferc                 .     |j         di   | i |S Nr=   updateargoptconfkws     r$   r+   z)capture_context_buffer.<locals>.configuref   0    
RtS C   r/   r+   )
popioBytesIOStringIOr[   r   r+   r   patchobject)r`   rN   r+   r_   s   `  @r$   capture_context_bufferrh   \   s      	vvj%   jllkmmIIx#>>???'D! ! ! ! ! ! 
		-{I	F	F  			                 s   B$$B(+B(c               +     K   ddl m} ddlm} t	          j                     |            }|                                }|                    |d          fd            }                     d|i           t          j
         fd}t          j                            t          d	|          5  V  d d d            d S # 1 swxY w Y   d S )
Nr   )_sqlite_file_dbr   )eventbefore_cursor_executec                8                         |dz              d S )N
)write)r7   cursor	statement
parameterscontextexecutemanyrN   s         r$   bcez*capture_engine_context_buffer.<locals>.bcey   s     		)d"#####r/   r.   c                 .     |j         di   | i |S rY   rZ   r\   s     r$   r+   z0capture_engine_context_buffer.<locals>.configure   ra   r/   r+   )envrj   
sqlalchemyrk   rc   re   r6   listens_forr[   r   r+   r   rf   rg   )	r`   rj   rk   engr7   ru   r+   rN   r_   s	   `      @@r$   capture_engine_context_bufferr{   n   sP     $$$$$$      
+--C
/

C;;==D
t455$ $ $ $ 65$ II|T"###'D! ! ! ! ! ! 
		-{I	F	F  			                 s   3CC	C	defaultFc                   i }|rt          |          |d<    G fdd          } |             G fddt                    }r|d<   |r||d<   t          s| d	k    rt          d
          d_        nt          |           ||_        d_        sfd}t          j        |          }	n|d<   d }	 ||	|          }
t          |
          t          j        _        |
S )N)naming_conventiontarget_metadatac                  &    e Zd Zd Z fdZd ZdS )op_fixture.<locals>.buffer_c                    g | _         d S r4   linesr"   s    r$   __init__z$op_fixture.<locals>.buffer_.__init__   s    DJJJr/   c                    |                                 }t          j        dd|          }r,t          j        dd|          }t          j        dd|          }| j                            |           d S )N[\n\t] z    z\;\n*$)stripresubr   rH   )r"   msgr1   s     r$   ro   z!op_fixture.<locals>.buffer_.write   so    ))++C&B,,C 1 fWb#..fYC00Jc"""""r/   c                    d S r4   r=   r   s    r$   flushz!op_fixture.<locals>.buffer_.flush   s    Dr/   N)r8   r9   r:   r   ro   r   )r1   s   r$   buffer_r      sL        	 	 			# 		# 		# 		# 		#	 	 	 	 	r/   r   c                  8    e Zd Z fdZ fdZ fdZ fdZdS )op_fixture.<locals>.ctxc                    S r4   r=   r"   rN   s    r$   get_bufzop_fixture.<locals>.ctx.get_buf   s    Jr/   c                     g j         d d <   d S r4   r   r   s    r$   clear_assertionsz(op_fixture.<locals>.ctx.clear_assertions   s    CIaaaLLLr/   c                F    t          j        d |D                        d S )Nc                :    g | ]}t          j        d d|          S )r   r   )r   r   ).0ss     r$   
<listcomp>z3op_fixture.<locals>.ctx.assert_.<locals>.<listcomp>   s&    BBBBF9b!44BBBr/   )r   r   )r"   rK   rN   s     r$   assert_zop_fixture.<locals>.ctx.assert_   s,     	BBcBBBCCCCCr/   c                x    j         D ]}t          j        dd|          |v r d S J d|dj                     )Nr   r   FzCould not locate fragment z in )r   r   r   )r"   rK   stmtrN   s      r$   assert_containsz'op_fixture.<locals>.ctx.assert_contains   sb    	  6)R--55FF 6 CCII  ur/   N)r8   r9   r:   r   r   r   r   )rN   s   r$   ctxr      s~        	 	 	 	 		 	 	 	 		D 	D 	D 	D 	D
	 	 	 	 	 	 	r/   r   r1   literal_bindsmariadbmysql)
      r   MariaDBTc                    t          | t                    rt          |           } | j        sJ t          |                                         }                    |           d S rF   )
isinstancerI   r   supports_executionrJ   ro   )r   
multiparamparamrK   rN   ctx_dialects       r$   executezop_fixture.<locals>.execute   s]    $$$ "Dzz****dll;l7788CIIcNNNNNr/   )rG   r   rW   )r	   r   r   r   server_version_infosupports_native_boolean#non_native_boolean_check_constraintr   Mockr   alembicop_proxy)rG   r1   r~   r   native_booleanr)   r   r   r   r.   rs   rN   r   s    `         @@r$   
op_fixturer      s    D P"*=N"O"O"O         $ '))C         ,   X . -_ ,w)++"7++*?'' #7++!.<+ ;?7 	 	 	 	 	 	 Y{GDDD

 #_
c+z400G"7++GJNr/   c                  2    e Zd ZdZd Zd Zd Zd ZddZdS )	AlterColRoundTripFixture)alter_columnc                    t           j                                        | _        t	          j        | j                  | _        t          | j                  | _        t                      | _
        d S r4   )r   r5   r6   r7   r   r+   r   r   r   r	   metadatar   s    r$   setUpzAlterColRoundTripFixture.setUp   sK    I%%''	#-di88TX&& 

r/   c                    t          d|          }t          d|          }| j        j                            ||          rJ d|d|d            d S )NqzType objects  and  didn't compare as equivalent)r   r   implcompare_type)r"   t1t2c1c2s        r$   _compare_typez&AlterColRoundTripFixture._compare_type   sw    C__C__8=--
 
 	L 	L 	LDFBBK	L 	L 
 	L 	Lr/   c                    t          d||          }t          d||          }| j        j                            ||||          rJ d|d|d            d S )Nr   )server_defaultzserver defaults r   r   )r   r   r   compare_server_default)r"   r   s1r   s2r   r   s          r$   _compare_server_defaultz0AlterColRoundTripFixture._compare_server_default   s    CB///CB///8=77B
 
 	O 	O 	OGIrr222N	O 	O 
 	O 	Or/   c                
   t          j        | j                   | j                                        5  | j                            | j                   d d d            n# 1 swxY w Y   | j                                         d S r4   )r   %_safe_rollback_connection_transactionr7   beginr   drop_allcloser   s    r$   tearDownz!AlterColRoundTripFixture.tearDown   s    9$)DDDY__ 	. 	.M""49---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.	s    AA#&A#Nc                   t          |                    dd          |                    dt          d                    |                    dd          |                    dd                     }t          d	| j        |          }t          j        | j                  5  |                    | j                   t          | j                  }|
                    d	          d
         }| j                            d	|j        |j        |j        |j        nd|j        rdnd|                    dd           |                    dd          |                    dd           |                    dd           	  	         d d d            n# 1 swxY w Y   t          | j                  }|
                    d	          d
         }||}t#          |d         d|v r|d         n|j                   |                     |d         |                    d|d                              t#          |d         |                    d|j                             |                     |d         |                    dd           |                    d|d                   d|v r|d         j        n|j        |j        j        j        nd            d S )Nnamecolnametyper   nullableTr   )r   r   xr   F)existing_typeexisting_server_defaultexisting_nullabler   r   new_column_nametype_r|   )r   getr
   r   r   r   _ensure_scope_for_ddlr7   creater   get_columnsr   r   r   r   r   r   r   r   r   r   r]   )	r"   from_to_comparecolumntinspold_colnew_cols	            r$   _run_alter_colz'AlterColRoundTripFixture._run_alter_col  s   IIfi((IIffRjj))YYz400 99%5t<<	
 
 
 #t}f--.ty99 	 	HHTY49%%D&&s++A.G G  $k ,8 ))*0/"D$$uT22"ww'7?? # 5 5ggfd++ !   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	0 ty!!""3''*?GFO%00GFOOfk	
 	
 	
 	FOW[[AA	
 	
 	
 	GJZ!I!IJJJ$$FOKK	4((KK00 $w.. ().. ,8 )-22	
 	
 	
 	
 	
s    CF

FFr4   )	r8   r9   r:   rB   r   r   r   r   r   r=   r/   r$   r   r      sq        
 %L# # #L L LO O O  =
 =
 =
 =
 =
 =
r/   r   )rC   )r|   FNFN)7
__future__r   configparser
contextlibr   rc   r   typingr   r   rx   r   r   r	   r
   r   r   r   sqlalchemy.testingr   r   sqlalchemy.testing.assertionsr   sqlalchemy.testing.fixturesr   SQLAlchemyTablesTestr   SQLAlchemyTestBaser   
assertionsr   environmentr   	migrationr   
operationsr   utilr   util.sqla_compatr   r   r   ConfigParsertesting_configreadr?   r;   rQ   rR   __annotations__rh   r{   r   r   r=   r/   r$   <module>r      st   " " " " " " "     % % % % % % 				 				                                                       % % % % % % # # # # # # - - - - - - J J J J J J F F F F F F  $ $ $ $ $ $ , , , , , , ( ( ( ( ( ( # # # # # #       1 1 1 1 1 1 & & & & & & % % % % % % +*,,   ZL ! ! !    !   4	 	 	 	 	/ 	 	 	  *=======* * * * * * * * *.  &           "   4 U U U Up^
 ^
 ^
 ^
 ^
 ^
 ^
 ^
 ^
 ^
r/   