]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add ability to test using thick mode with oracledb
authorFederico Caselli <cfederico87@gmail.com>
Mon, 20 Jun 2022 18:41:48 +0000 (20:41 +0200)
committerFederico Caselli <cfederico87@gmail.com>
Mon, 20 Jun 2022 18:41:48 +0000 (20:41 +0200)
Change-Id: Iee14750ba20422931bde4d61eaa570af482c7d8b
References: #8147

lib/sqlalchemy/dialects/oracle/oracledb.py
lib/sqlalchemy/dialects/oracle/provision.py
lib/sqlalchemy/testing/plugin/plugin_base.py
lib/sqlalchemy/testing/provision.py

index bbe801cd441368054821c4718d1b67e55f511f24..67c5b42a5659a3118f1a505d8d8807f2aac1c2f2 100644 (file)
@@ -76,7 +76,7 @@ class OracleDialect_oracledb(_OracleDialect_cx_oracle):
             **kwargs,
         )
 
-        if thick_mode is not None:
+        if self.dbapi is not None and thick_mode is not None:
             kw = thick_mode if isinstance(thick_mode, dict) else {}
             self.dbapi.init_oracle_client(**kw)
 
index 75b7a7aa9943367f3a09229fd24631b6eb612d7b..6644c6eab321bf561eeddec3ca791515ff41bbbb 100644 (file)
@@ -16,6 +16,7 @@ from ...testing.provision import run_reap_dbs
 from ...testing.provision import set_default_schema_on_connection
 from ...testing.provision import stop_test_class_outside_fixtures
 from ...testing.provision import temp_table_keyword_args
+from ...testing.provision import update_db_opts
 
 
 @create_db.for_db("oracle")
@@ -204,3 +205,13 @@ def _oracle_set_default_schema_on_connection(
     cursor = dbapi_connection.cursor()
     cursor.execute("ALTER SESSION SET CURRENT_SCHEMA=%s" % schema_name)
     cursor.close()
+
+
+@update_db_opts.for_db("oracle")
+def _update_db_opts(db_url, db_opts, options):
+    """Set database options (db_opts) for a test database that we created."""
+    if (
+        options.oracledb_thick_mode
+        and sa_url.make_url(db_url).get_driver_name() == "oracledb"
+    ):
+        db_opts["thick_mode"] = True
index c20110071d67674bb20b7c4e8bd46f8651550690..8e51139544e7843ba29a482276a0a48738c50bb2 100644 (file)
@@ -148,12 +148,6 @@ def setup_options(make_option):
         dest="profiledump",
         help="Filename where a single profile run will be dumped",
     )
-    make_option(
-        "--postgresql-templatedb",
-        type=str,
-        help="name of template database to use for PostgreSQL "
-        "CREATE DATABASE (defaults to current database)",
-    )
     make_option(
         "--low-connections",
         action="store_true",
@@ -220,6 +214,18 @@ def setup_options(make_option):
         help="Additional test directories to add to the mypy tests. "
         "This is used only when running mypy tests. Multiple OK",
     )
+    # db specific options
+    make_option(
+        "--postgresql-templatedb",
+        type=str,
+        help="name of template database to use for PostgreSQL "
+        "CREATE DATABASE (defaults to current database)",
+    )
+    make_option(
+        "--oracledb-thick-mode",
+        action="store_true",
+        help="enables the 'thick mode' when testing with oracle+oracledb",
+    )
 
 
 def configure_follower(follower_ident):
index 498d92a77584fdd63f40cc14bd927f78519e7762..12448b2fe11fc7b7cb4e61ed86bbd594c734217d 100644 (file)
@@ -21,15 +21,22 @@ FOLLOWER_IDENT = None
 
 
 class register:
-    def __init__(self):
+    def __init__(self, decorator=None):
         self.fns = {}
+        self.decorator = decorator
 
     @classmethod
     def init(cls, fn):
         return register().for_db("*")(fn)
 
+    @classmethod
+    def init_decorator(cls, decorator):
+        return register(decorator).for_db("*")
+
     def for_db(self, *dbnames):
         def decorate(fn):
+            if self.decorator:
+                fn = self.decorator(fn)
             for dbname in dbnames:
                 self.fns[dbname] = fn
             return self
@@ -66,7 +73,7 @@ def setup_config(db_url, options, file_config, follower_ident):
     if follower_ident:
         db_url = follower_url_from_main(db_url, follower_ident)
     db_opts = {}
-    update_db_opts(db_url, db_opts)
+    update_db_opts(db_url, db_opts, options)
     db_opts["scope"] = "global"
     eng = engines.testing_engine(db_url, db_opts)
     post_configure_engine(db_url, eng, follower_ident)
@@ -331,10 +338,17 @@ def drop_db(cfg, eng, ident):
     raise NotImplementedError("no DB drop routine for cfg: %s" % (eng.url,))
 
 
-@register.init
-def update_db_opts(db_url, db_opts):
+def _adapt_update_db_opts(fn):
+    insp = util.inspect_getfullargspec(fn)
+    if len(insp.args) == 3:
+        return fn
+    else:
+        return lambda db_url, db_opts, _options: fn(db_url, db_opts)
+
+
+@register.init_decorator(_adapt_update_db_opts)
+def update_db_opts(db_url, db_opts, options):
     """Set database options (db_opts) for a test database that we created."""
-    pass
 
 
 @register.init
@@ -343,7 +357,6 @@ def post_configure_engine(url, engine, follower_ident):
 
     (For the internal dialects, currently only used by sqlite, oracle)
     """
-    pass
 
 
 @register.init
@@ -374,7 +387,6 @@ def run_reap_dbs(url, ident):
     use. For the internal dialects, this is currently only necessary for
     mssql and oracle.
     """
-    pass
 
 
 def reap_dbs(idents_file):