U ÃÏ a­0ã@s°ddlZddlZddlmZddlmZddlmZddlmZddlmZdd lm Z dd l m Z dd l m Z dd lmZe e¡ZdZGd d„deƒZdd„Zdd„Zdd„Zdd„Zdd„Zejdd„ƒZdd„Zejdd„ƒZejdd „ƒZd!d"„Zejd#d$„ƒZ ejd%d&„ƒZ!ejd'd(„ƒZ"ejd)d*„ƒZ#ejd+d,„ƒZ$ejd-d.„ƒZ%ejd/d0„ƒZ&d1d2„Z'ejd3d4„ƒZ(ejd5d6„ƒZ)ejd7d8„ƒZ*ejd9d:„ƒZ+ejd;d<„ƒZ,dS)=éNé)Úconfig)Úengines)Úutilé)Úexc)Úinspect)Úurl)Úddl©Úschema)Úcompatc@s0eZdZdd„Zedd„ƒZdd„Zdd„Zd S) ÚregistercCs i|_dS©N©Úfns)Úself©rú]C:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\sqlalchemy\testing\provision.pyÚ__init__szregister.__init__cCstƒ d¡|ƒS©NÚ*)rÚfor_db)ÚclsÚfnrrrÚinitsz register.initcs‡‡fdd„}|S)NcsˆD]}|ˆj|<qˆSrr)rZdbname©ÚdbnamesrrrÚdecorates z!register.for_db..decorater)rrrrrrrszregister.for_dbcGspt|tjƒrt |¡}nt|tjƒr*|}n|jj}| ¡}||j krX|j ||f|žŽS|j d|f|žŽSdSr) Ú isinstancer Ú string_typesÚsa_urlÚmake_urlÚURLÚdbr Úget_backend_namer)rÚcfgÚargr ÚbackendrrrÚ__call__$s    zregister.__call__N)Ú__name__Ú __module__Ú __qualname__rÚ classmethodrrr)rrrrrs  rcCs0tƒD]$}t d||jj¡t||j|ƒqdS)NzCREATE database %s, URI %r)Ú_configs_for_db_operationÚlogÚinfor$r Ú create_db©Úfollower_identr&rrrÚcreate_follower_db2s r4cCsŒt |¡ ¡}| ¡|r$t||ƒ}i}t||ƒd|d<t ||¡}t|||ƒ|  ¡  ¡t j   ||||¡}|rz|t _|rˆt||ƒ|S)NÚglobalZscope)r!r"Ú get_dialectÚload_provisioningÚfollower_url_from_mainÚupdate_db_optsrZtesting_engineÚpost_configure_engineÚconnectÚcloserÚConfigrÚidentÚconfigure_follower)Údb_urlÚoptionsZ file_configr3ÚdialectÚdb_optsÚengr&rrrÚ setup_config8s       rEcCs0tƒD]$}t d||jj¡t||j|ƒqdS)NzDROP database %s, URI %r)r.r/r0r$r Údrop_dbr2rrrÚdrop_follower_dbTs rGc csÂtƒ}t t¡}dd„dd„|DƒDƒ}|D]\}}||j |j¡q,i}|D]l\}}|j}| ¡||krŠt|ƒ ||¡||<} n||} t|| ƒD]} | |krªqœ| | ¡| VqœqPdS)a&Generate a set of URLs to test given configured URLs plus additional driver names. Given:: --dburi postgresql://db1 --dburi postgresql://db2 --dburi postgresql://db2 --dbdriver=psycopg2 --dbdriver=asyncpg?async_fallback=true Noting that the default postgresql driver is psycopg2, the output would be:: postgresql+psycopg2://db1 postgresql+asyncpg://db1 postgresql+psycopg2://db2 postgresql+psycopg2://db3 That is, for the driver in a --dburi, we want to keep that and use that driver for each URL it's part of . For a driver that is only in --dbdrivers, we want to use it just once for one of the URLs. for a driver that is both coming from --dburi as well as --dbdrivers, we want to keep it in that dburi. Driver specific query options can be specified by added them to the driver name. For example, to enable the async fallback option for asyncpg:: --dburi postgresql://db1 --dbdriver=asyncpg?async_fallback=true cSsg|]}|| ¡f‘qSr)r6)Ú.0Úurl_objrrrÚ sÿz$generate_db_urls..cSsg|]}t |¡‘qSr)r!r")rHr@rrrrJsN) ÚsetÚ collectionsÚ defaultdictÚnameÚaddÚdriverr7Ú differenceÚ_generate_driver_urls) Zdb_urlsÚ extra_driversÚurlsZ!backend_to_driver_we_already_haveZurls_plus_dialectsrIrBZbackend_to_driver_we_needr(Zextra_per_backendZ driver_urlrrrÚgenerate_db_urlsZs.!  þ  ÿþ rUccs€| ¡}| |¡t||dƒ}t|ƒVt|ƒD]J}d|krN| dd¡\}}n|}d}t|||ƒ}|r0| |¡t|ƒVq0dS)NÚú?r)Zget_driver_nameÚdiscardÚgenerate_driver_urlÚstrÚlistÚsplitÚremove)r rSZ main_driverÚdrvZ driver_onlyÚ query_strÚnew_urlrrrrR›s      rRcCsX| ¡}|jd||fd}|r*| |¡}z | ¡Wntjk rNYdSX|SdS)Nz%s+%s)Z drivername)r%rKZupdate_query_stringr6rZNoSuchModuleError)r rPr_r(r`rrrrY³s ÿ  rYccsˆtƒ}tj ¡D]}|j ¡qtj ¡D]>}|jj}| ¡}||j|j |j f}||kr*|V|  |¡q*tj ¡D]}|j ¡qtdSr) rKrr=Z all_configsr$Zdisposer r%ÚusernameÚhostÚdatabaserO)Úhostsr&r r(Z host_confrrrr.Ås  r.cCsdSrr©r&rDrrrÚ"drop_all_schema_objects_pre_tablesØsrfcCsdSrrrerrrÚ#drop_all_schema_objects_post_tablesÝsrgc CsÊt||ƒt|ƒ}z | ¡}Wntk r2Ynrrrr1sr1cCstd|jƒ‚dS)z8Drop a database that we dynamically created for testing.zno DB drop routine for cfg: %sNrsrtrrrrF%srFcCsdS)zCSet database options (db_opts) for a test database that we created.Nr)r@rCrrrr9+sr9cCsdS)z‰Perform extra steps after configuring an engine for testing. (For the internal dialects, currently only used by sqlite, oracle) Nr)r Úenginer3rrrr:1sr:cCst |¡}|j|dS)zúCreate a connection URL for a dynamically-created test database. :param url: the connection URL specified when the test run was invoked :param ident: the pytest-xdist "worker identifier" to be used as the database name )rc)r!r"rK©r r>rrrr8:s r8cCsdS)z@Create dialect-specific config settings for a follower database.Nr)r&r>rrrr?Fsr?cCsdS)a[Remove databases that were created during the test process, after the process has ended. This is an optional step that is invoked for certain backends that do not reliably release locks on the database as long as a process is still in use. For the internal dialects, this is currently only necessary for mssql and oracle. NrrvrrrÚ run_reap_dbsLs rwc CsÚt d¡t t¡}t t¡}i}t|ƒz}|D]n}| ¡}| d¡\}}t  |¡}||krt|  ¡||<||  ¡|  ¡|j f} ||  |¡||  |¡q0W5QRX|D]&} t|| ƒd} || } t| | ƒq®dS)NzReaping databases...ú r)r/r0rLrMrKÚopenÚstripr\r!r"r6r7r%rbrOr[rw) Z idents_filerTZidentsZdialectsÚfile_ÚlineZdb_namer@rIZurl_keyr r>rrrÚreap_dbsYs&       r}cCstd|jƒ‚dS)aOSpecify keyword arguments for creating a temporary Table. Dialect-specific implementations of this method will return the kwargs that are passed to the Table method when creating a temporary table for testing, e.g., in the define_temp_tables method of the ComponentReflectionTest class in suite/test_reflection.py z.no temp table keyword args routine for cfg: %sNrsrerrrÚtemp_table_keyword_argsrs ÿr~cCsdSrr)rÚ connectionrrrÚprepare_for_drop_tables€sr€cCsdSrr)rr$ZtestclsrrrÚ stop_test_class_outside_fixtures…srcCs|S)a¸Specify table name for creating a temporary Table. Dialect-specific implementations of this method will return the name to use when creating a temporary table for testing, e.g., in the define_temp_tables method of the ComponentReflectionTest class in suite/test_reflection.py Default to just the base name since that's what most dialects will use. The mssql dialect's implementation will need a "#" prepended. r)r&rDÚ base_namerrrÚget_temp_table_nameŠs rƒcCstd|jjfƒ‚dS)Nz9backend does not implement a schema name set function: %s)rir$r )r&Zdbapi_connectionrqrrrÚ set_default_schema_on_connection™s ÿÿr„)-rLÚloggingrVrrrrrrur r!Zsqlr r r Ú getLoggerr*r/ZFOLLOWER_IDENTÚobjectrr4rErGrUrRrrYr.rfrgrrr1rFr9r:r8r?rwr}r~r€rrƒr„rrrrÚsf          A   9