U kf.@s ddlZddlmZddlmZddlmZddlmZddlmZdd lmZdd lm Z dd lm Z dd l m Z d dlm Z d dlmZd dlmZd dlmZd dlmZd dlmZd dlm Z d dlmZd dlmZGdddejZGdddejeZGdddejZdZdS)N)testing)config)fixtures)util)eq_)is_false)is_true) requirements)Table)CheckConstraint)Column)ForeignKeyConstraint)Index)inspect)Integerschema)String)UniqueConstraintc@seZdZdZdddZddZd ddZd d Zej e j d d Z ej ej e j d dZeje j ddZej e j ddZeje j ddZeje j ddZeje j ddZeje j ddZeje j ddZeje j ddZdS)! TableDDLTestTNc Cs*td|jtdtdddtdtd|dS) N test_tableidTF primary_keyZ autoincrementdata2rr metadatarrr)selfrr"Q/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/testing/suite/test_ddl.py_simple_fixture"s zTableDDLTest._simple_fixturec Cs&td|jtdtdddtdtdS)NZ _test_tablerTFr_datarr)r!r"r"r#_underscore_fixture+s  z TableDDLTest._underscore_fixturecCs"|j|d}td|jj}||fS)Nr test_index)r$rcr)r!rtableidxr"r"r#_table_index_fixture3s z!TableDDLTest._table_index_fixturec CsJtj6}||d||}t|dW5QRXdS)N)rz some data) rdbbeginexecuteinsertvaluesselectrfirst)r!r)connresultr"r"r#_simple_roundtrip8s zTableDDLTest._simple_roundtripcCs&|}|jtjdd||dSNFZ checkfirst)r$createrr,r5r!r)r"r"r#test_create_table>szTableDDLTest.test_create_tablecCs,|jtjd}|jtjdd||dS)NrFr7)r$rZ test_schemar8r,r5r9r"r"r#test_create_table_schemaEsz%TableDDLTest.test_create_table_schemacCs,|}|jtjdd|jtjdddSr6)r$r8rr,Zdropr9r"r"r#test_drop_tableMszTableDDLTest.test_drop_tablecCs&|}|jtjdd||dSr6)r&r8rr,r5r9r"r"r#test_underscore_namesTsz"TableDDLTest.test_underscore_namescCsH|}|j|ddd|_|t|tt|dddidSNFr7z a commentrtext) r$r8commentr.rSetTableCommentrrget_table_commentr! connectionr)r"r"r#test_add_table_comment[s z#TableDDLTest.test_add_table_commentcCsX|}|j|ddd|_|t||t|tt| dddidSr>) r$r8r@r.rrAZDropTableCommentrrrBrCr"r"r#test_drop_table_commentgs z$TableDDLTest.test_drop_table_commentcCsF|}|tj|ddtt|d|tj|dddS)NTZ if_not_existsr)r$r.r CreateTabler r has_tablerCr"r"r#test_create_table_if_not_existsssz,TableDDLTest.test_create_table_if_not_existscCs|\}}|tj|ddtt|dtdddt|dDk|tj |ddtdddt|dDk|tj |dddS)NTrGrr'cSsg|] }|dqSnamer".0ixr"r"r# sz@TableDDLTest.test_create_index_if_not_exists..cSsg|] }|dqSrKr"rMr"r"r#rPs) r+r.rrHr rrIr get_indexesZ CreateIndexr!rDr)r*r"r"r#test_create_index_if_not_exists}s&   z,TableDDLTest.test_create_index_if_not_existscCsb|}||tt|d|tj|ddtt|d|tj|dddS)NrTZ if_exists) r$r8r rrIr.rZ DropTabler rCr"r"r#test_drop_table_if_existss  z&TableDDLTest.test_drop_table_if_existscCs|\}}||tdddt|dDk|tj|ddtdddt|dDk|tj|dddS)Nr'cSsg|] }|dqSrKr"rMr"r"r#rPsz:TableDDLTest.test_drop_index_if_exists..rTrTcSsg|] }|dqSrKr"rMr"r"r#rPs) r+r8r rrQr.rZ DropIndexr rRr"r"r#test_drop_index_if_existss$    z&TableDDLTest.test_drop_index_if_exists)N)N)__name__ __module__ __qualname__ __backend__r$r&r+r5r Z create_tablerZprovide_metadatar:Zschemasr;Z drop_tabler<r=Zcomment_reflectionrErFZtable_ddl_if_existsrJZindex_ddl_if_existsrSrUrVr"r"r"r#rsH          rc@s eZdZdS)FutureTableDDLTestN)rWrXrYr"r"r"r#r[sr[c@sreZdZdZdZddZddZddZd d Zd d Z e j d ddde j j fde j jfddddZdS)LongNameBlowoutTestzjtest the creation of a variety of DDL structures and ensure label length limits pass on backends Tc CsdddddtdDi}||_td|tdtd d d d td gd g}td|td |d d |j}||t j j j rt |}|d}|dd}||fS|dfSdS)NfkzGforeign_key_%(table_name)s_%(column_0_N_name)s_%(referred_table_name)s__css&|]}dddtdDVqdS)css|]}tdVqdSZabcdefNrandomchoicerNjr"r"r# sz3LongNameBlowoutTest.fk...NjoinrangerNir"r"r#rfsz)LongNameBlowoutTest.fk.. a_things_with_stuffid_long_column_nameTr)Z test_needs_fkZaidz'a_things_with_stuff.id_long_column_nameZb_related_things_of_valuerrL)rirjnaming_conventionr rrrrL create_allrrequiresZ&foreign_key_constraint_name_reflectionenabledrZget_foreign_keys) r!r rD conventioncons actual_nameinspZfksreflected_namer"r"r#r]sF        zLongNameBlowoutTest.fkc CsdddddtdDi}||_td|tdtd d td td d }|j}|j}||t |}| d}|d } || fS) Npkz.primary_key_%(table_name)s_%(column_0_N_name)sr^css&|]}dddtdDVqdS)r_css|]}tdVqdSr`rardr"r"r#rfsz3LongNameBlowoutTest.pk...Nrhrkr"r"r#rfsz)LongNameBlowoutTest.pk..rmrnroTrpid_another_long_namerL) rirjrqr rrrrLrrrZget_pk_constraint) r!r rDruarvrwrxrzryr"r"r#rzs*      zLongNameBlowoutTest.pkc CsdddddtdDi}||_td|tdtd d td t}td|jj|jj }|j }| |t |}| d}|d d } || fS)NrOz(index_%(table_name)s_%(column_0_N_name)sr^css&|]}dddtdDVqdS)r_css|]}tdVqdSr`rardr"r"r#rfsz3LongNameBlowoutTest.ix...r{Nrhrkr"r"r#rfsz)LongNameBlowoutTest.ix..rmrnroTrpr|rrL)rirjrqr rrrr(ror|rLrrrrQ) r!r rDrur}rvrwrxrOryr"r"r#rOs*      zLongNameBlowoutTest.ixc CsdddddtdDi}||_tdd}td |tdtd d tdt||j}||t |}| d }|d d }||fS)Nuqz4unique_constraint_%(table_name)s_%(column_0_N_name)sr^css&|]}dddtdDVqdS)r_css|]}tdVqdSr`rardr"r"r#rf;sz3LongNameBlowoutTest.uq...r{Nrhrkr"r"r#rf:sz)LongNameBlowoutTest.uq..rmror|rnTrprrL) rirjrqrr rrrLrrrZget_unique_constraints) r!r rDrurvrwrxr~ryr"r"r#r~5s,       zLongNameBlowoutTest.uqc CsdddddtdDi}||_td}td|td td d td t||j}||t |}| d}|d d}||fS)Nckzcheck_constraint_%(table_name)sr^css&|]}dddtdDVqdS)r_css|]}tdVqdSr`rardr"r"r#rfWsz3LongNameBlowoutTest.ck...r{Nrhrkr"r"r#rfVsz)LongNameBlowoutTest.ck..rmzsome_long_column_name > 5rnroTrpZsome_long_column_namerrL) rirjrqrr rrrLrrrZget_check_constraints) r!r rDrurvrwrxrryr"r"r#rRs,      zLongNameBlowoutTest.ck)r])rz)rOrr~type_)argnamescCs~t||||\}}t|dks$t|dk rz|dt|}t|t|krpt|dd|dt|dn t||dS)Nr)getattrlenAssertionErrorr)r!rr rDrwryZoverlapr"r"r#test_long_convention_namens $z-LongNameBlowoutTest.test_long_convention_nameN)rWrXrY__doc__rZr]rzrOr~rr combinationsrsZcheck_constraint_reflectionZas_skipsZunique_constraint_reflectionrr"r"r"r#r\s .r\)rr[r\)rbr_rrrrZ assertionsrr r r rr rrrrrrrrZTestBaserZFutureEngineMixinr[r\__all__r"r"r"r# s0                  %?