U of$@sUddlmZddlZddlmZddlZddlZddlmZddlm Z ddl m Z ddl m Z ddl m Z dd l mZdd l mZdd l mZdd l mZdd lmZddlmZddlmZddlmZddlmZddlZddlmZddlm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(ddl'm)Z)ddl'm*Z*e+Z,e,-dgGdddeZGdd d eeZe)rdd!lm.Z.nGd"d#d#Z.d$e._/d4d&d'Z0iZ1d(e2d)<ed*d+Z3ed,d-Z4d5d0d1Z5Gd2d3d3Z6dS)6) annotationsN)contextmanager)Any)Dict)Column)inspect)MetaData)String)Table)testing)text)config)mock)eq_) TablesTest)TestBase) _get_dialect)EnvironmentContext)MigrationContext) Operations) sqla_compatcreate_mock_engine)sqla_14)sqla_2ztest.cfgc@sJeZdZeZeddZejddZejddZ ejddZ d S) rc cs&|jddt|VW5QRXdS)NT)Z_per_migration)Zbegin_transactionr)selfmigration_contextrF/opt/hc_python/lib/python3.8/site-packages/alembic/testing/fixtures.py ops_context)szTestBase.ops_contextcCstj|tdddS)NT)transaction_per_migrationoptsr configuredictr connectionrrr r.szTestBase.migration_contextcCstj|tddddS)NT)r"as_sqlr#r%r(rrr as_sql_migration_context4s z!TestBase.as_sql_migration_contextc cs tj }|VW5QRXdSN)r dbconnect)rconnrrr r):s zTestBase.connectionN) __name__ __module__ __qualname__ris_sqlalchemy_futurer Zfixturer!rr+r)rrrr r&s   rc@s eZdZdS)rN)r0r1r2rrrr r@sr)FutureEngineMixinc@seZdZdZdS)r4)Z sqlalchemy_14N)r0r1r2 __requires__rrrr r4Hsr4T postgresql://cs$gfdd}t||fS)Ncst|jjddSN)dialect)appendstrcompiler8)sqlZ multiparamsparamsbufZenginerr dumpRszcapture_db..dumpr)r8r@rr>r capture_dbOs rAzDict[Any, Any]_engsc +shddrt}nt}d|dtjfdd}tj td| |VW5QRXdS)NZbytes_ioFZsqlite)Z dialect_name output_buffercs|jf||Sr,updateargoptconfkwrr r&fs z)capture_context_buffer..configurer&) popioBytesIOStringIOrErr&rpatchobject)rKr?r&rrIr capture_context_buffer\s  rRc +sddlm}ddlm}t|}|}||dfdd}d|it j fd d }t j t d | VW5QRXdS) Nr)_sqlite_file_dbr)eventZbefore_cursor_executecs|ddS)N )write)r/cursorZ statement parameterscontextZ executemanyr?rr bceysz*capture_engine_context_buffer..bcer)cs|jf||Sr,rDrFrIrr r&s z0capture_engine_context_buffer..configurer&)envrS sqlalchemyrTrMrOr.Z listens_forrErr&rrPrQ)rKrSrTZengr/r[r&r)r?rJrKr capture_engine_context_bufferns   r^defaultFc si}|rt|d|d<Gfddd}|Gfdddt}rN|d<|rZ||d<tsv|d krvtd d _nt||dk r|_d _sfd d}tj|d} n |d<d} || |} t | t j _ | S)N)naming_conventionZtarget_metadatacs(eZdZddZfddZddZdS)zop_fixture..buffer_cSs g|_dSr,linesrrrr __init__sz$op_fixture..buffer_.__init__csF|}tdd|}r6tdd|}tdd|}|j|dS)N[\n\t]z z\;\n*$)stripresubrbr9)rmsgr*rr rVs z!op_fixture..buffer_.writecSsdSr,rrcrrr flushsz!op_fixture..buffer_.flushN)r0r1r2rdrVrlrrkrr buffer_s rmcs<eZdZfddZfddZfddZfddZd S) zop_fixture..ctxcsSr,rrcrZrr get_bufszop_fixture..ctx.get_bufcsgjdd<dSr,rarcrZrr clear_assertionssz(op_fixture..ctx.clear_assertionscstjdd|DdS)NcSsg|]}tdd|qS)rerf)rhri).0srrr sz3op_fixture..ctx.assert_..)rrb)rr<rZrr assert_szop_fixture..ctx.assert_cs>jD]}tdd||krdSqds:td|jfdS)NrerfFz"Could not locate fragment %r in %r)rbrhriAssertionError)rr<stmtrZrr assert_containss z'op_fixture..ctx.assert_containsN)r0r1r2rnrorsrvrrZrr ctxs   rwr* literal_bindsZmariadbmysql) rZMariaDBTcs:t|trt|}|jstt|jd}|dSr7) isinstancer:r Zsupports_executionrtr;rV)ruZ multiparamparamr<)r? ctx_dialectrr executes   zop_fixture..execute)r8rrC) rrrrZserver_version_infoZsupports_native_booleanZ#non_native_boolean_check_constraintrZMockralembicop_proxy) r8r*r`rxZnative_booleanr$rmrwrr)rYr)r*r?r~r op_fixtures2   rc@s:eZdZdZddZddZddZdd Zd d d Zd S)AlterColRoundTripFixture) alter_columncCs2tj|_t|j|_t|j|_t |_ dSr,) r r-r.r/rr&rwrrrmetadatarcrrr setUps  zAlterColRoundTripFixture.setUpcCs8td|}td|}|jj||r4td||fdS)Nqz3Type objects %r and %r didn't compare as equivalent)rrwimplZ compare_typert)rt1t2c1c2rrr _compare_types   z&AlterColRoundTripFixture._compare_typecCsDtd||d}td||d}|jj||||r@td||fdS)Nr)server_defaultz6server defaults %r and %r didn't compare as equivalent)rrwrZcompare_server_defaultrt)rrs1rs2rrrrr _compare_server_defaults z0AlterColRoundTripFixture._compare_server_defaultc Cs>t|j|j|j|jW5QRX|jdSr,)rZ%_safe_rollback_connection_transactionr/beginrZdrop_allclosercrrr tearDowns  z!AlterColRoundTripFixture.tearDownNc Cst|dd|dtd|dd|ddd}td |j|}t|j||jt |j}| d d }|j j d |j |j|jdk r|jnd |jrdnd |dd|dd |dd|ddd W5QRXt |j}| d d }|dkr|}t|dd|kr|dn|j ||d|d|dt|d|d|j||d|d d|d|dd|kr|djn|jdk r|jjjnddS)NnameZcolnametyperznullableTr)rrxrF)Z existing_typeZexisting_server_defaultZexisting_nullablerrZnew_column_nametype_r_)rgetr r rrZ_ensure_scope_for_ddlr/createrZ get_columnsrrrrrrrrrr rG) rZfrom_Zto_comparecolumntZinspZold_colZnew_colrrr _run_alter_cols^            z'AlterColRoundTripFixture._run_alter_col)N) r0r1r2r5rrrrrrrrr rs r)r6)r_FNFN)7 __future__r configparser contextlibrrMrhtypingrrr]rrrr r r r Zsqlalchemy.testingr rZsqlalchemy.testing.assertionsrZsqlalchemy.testing.fixturesrZSQLAlchemyTablesTestrZSQLAlchemyTestBaserZ assertionsr environmentrZ migrationr operationsrutilrZutil.sqla_compatrrr ConfigParserZtesting_configreadr4r3rArB__annotations__rRr^rrrrrr sb                             X