U ofe.@sddlZddlmZddlmZddlmZddlmZddlmZddlmZdd lm Z dd lm Z dd lm Z dd l m Z Gd dde ZdS)N)MigrationContext) assert_raises)config)eq_)is_)is_false)is_not_)is_true)ne_)TestBasec@seZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZddZddZddZejjdd Zejjd!d"Zd#d$Zd%d&Zd'd(ZdS))MigrationTransactionTestTNcCs\tj|_}|ddrFtj|j|d|_t |j_ |jj _ ntj||d|_|jS)Nas_sqlF)dialectopts) connectionr) rdbconnectconngetr configurercontextioStringIO output_bufferimpl)selfrrrT/opt/hc_python/lib/python3.8/site-packages/alembic/testing/suite/test_environment.py_fixtures z!MigrationTransactionTest._fixturecCs|jr|jdS)N)rclose)rrrrteardown_method$sz(MigrationTransactionTest.teardown_methodcCsR|ddd}t|j|jdd}t|j|t|jdSNTtransaction_per_migrationtransactional_ddlZ_per_migration)rrrin_transactionbegin_transactionr rollbackrrproxyrrrtest_proxy_transaction_rollback(s z8MigrationTransactionTest.test_proxy_transaction_rollbackcCsD|ddd}|jdd}t|j|t|jdSr"rr(r rr'commitrr*rrrtest_proxy_transaction_commit3s z6MigrationTransactionTest.test_proxy_transaction_commitc CsL|ddd}|jdd}t|j|W5QRXt|jdSr")rr(r rr'rr*rrr,test_proxy_transaction_contextmanager_commit<s  zEMigrationTransactionTest.test_proxy_transaction_contextmanager_commitcsR|ddd}|jddt|jfdd}tt|t|jdS)NTr#r&c stdW5QRXdS)Nhi) Exceptionrr+rrgoMszSMigrationTransactionTest.test_proxy_transaction_contextmanager_rollback..go)rr(r rr'rr2r)rrr4rr3r.test_proxy_transaction_contextmanager_rollbackFs   zGMigrationTransactionTest.test_proxy_transaction_contextmanager_rollbackc Csp|ddd}|jdd}t|j|*t|j|t|jW5QRXt|jdSr")rr(r rr'r)rr*rrr7test_proxy_transaction_contextmanager_explicit_rollbackTs zPMigrationTransactionTest.test_proxy_transaction_contextmanager_explicit_rollbackc Csp|ddd}|jdd}t|j|*t|j|t|jW5QRXt|jdSr"r-r*rrr5test_proxy_transaction_contextmanager_explicit_commitbs zNMigrationTransactionTest.test_proxy_transaction_contextmanager_explicit_commitc Cs|ddd}t|j|Ht|j|jddt|jW5QRXt|jW5QRXt|jdSr"rrrr'r(r rrrrr0test_transaction_per_migration_transactional_ddlps zIMigrationTransactionTest.test_transaction_per_migration_transactional_ddlc Cs|ddd}t|j|Ht|j|jddt|jW5QRXt|jW5QRXt|jdS)NTFr#r&r8r9rrr4test_transaction_per_migration_non_transactional_ddls zMMigrationTransactionTest.test_transaction_per_migration_non_transactional_ddlc Cs|ddi}t|j|Ht|j|jddt|jW5QRXt|jW5QRXt|jdS)Nr%Tr&r8r9rrr*test_transaction_per_all_transactional_ddls zCMigrationTransactionTest.test_transaction_per_all_transactional_ddlc Cs|ddi}t|j|Ht|j|jddt|jW5QRXt|jW5QRXt|jdS)Nr%FTr&r8r9rrr.test_transaction_per_all_non_transactional_ddls zGMigrationTransactionTest.test_transaction_per_all_non_transactional_ddlc Cs|ddi}|d|<|d|jdd|dW5QRX|dW5QRX|d|jjr|dd dddd dn|ddddddS) NrTstep 1step 2r&step 3step 4step 5BEGINCOMMITrexecuter(rr%_assert_impl_stepsr9rrr test_transaction_per_all_sqlmodes2     z9MigrationTransactionTest.test_transaction_per_all_sqlmodec Cs|ddd}|d|<|d|jdd|dW5QRX|dW5QRX|d|jjr|ddd dd ddn|ddddddS) NT)rr$r>r?r&r@rArBrCrDrEr9rrr&test_transaction_per_migration_sqlmodes6     z?MigrationTransactionTest.test_transaction_per_migration_sqlmodec Cs|ddi}t|j|t|j|jddt|j|J|jrpt|j |jnt |j |jt|jt |j j ddW5QRXt |j j dddt|jW5QRXt|jW5QRXt|jdS)Nr$Tr&isolation_level AUTOCOMMIT)rrrr'r(r autocommit_blockis_sqlalchemy_futurerrr r_execution_optionsr rr9rrrtest_autocommit_blocks6  z.MigrationTransactionTest.test_autocommit_blockc Cs|ddi}t|j|Xt|j|jrJt|j|jnt |j|jt|jt |jj ddW5QRXt |jj dddt|jdS)Nr$TrJrK)rrrr'rLr rrMrr rrNr rr9rrr$test_autocommit_block_no_transactions"  z=MigrationTransactionTest.test_autocommit_block_no_transactionc Cs|dddd}|d|d|jdd8|d||dW5QRX|dW5QRX|dW5QRX|dd dd dd dd d dS) NTr$r%rr>r&r?r@rArBrCrDrr(rFrLrGr9rrr/test_autocommit_block_transactional_ddl_sqlmode&s2    zHMigrationTransactionTest.test_autocommit_block_transactional_ddl_sqlmodec Cs|dddd}|d|d|jdd8|d||dW5QRX|dW5QRX|d W5QRX|ddddd dS) NTFrQr>r&r?r@rArBrRr9rrr2test_autocommit_block_nontransactional_ddl_sqlmodeGs*    zKMigrationTransactionTest.test_autocommit_block_nontransactional_ddl_sqlmodecGst|jj}t|jj_}|D]>}|dkr<|jjq"|dkrR|jjq"|jj|q"t ||dS)NrCrD) rrgetvaluerrrZ emit_beginZ emit_commit_execr)rZstepsZto_checkbufsteprrrrG`s z+MigrationTransactionTest._assert_impl_steps)__name__ __module__ __qualname__Z __backend__rrr!r,r/r0r5r6r7r:r;r<r=rHrIr requirementsZautocommit_isolationrOrPrSrTrGrrrrr s.      ' !r )rZ migrationrZtestingrrrrrr r r Ztesting.fixturesr r rrrrs