-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate using too many positional args
- Loading branch information
Showing
3 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
|
||
from robot.api import logger | ||
|
||
from .params_decorator import renamed_args | ||
from .params_decorator import deprecated_positional_args, renamed_args | ||
|
||
|
||
@dataclass | ||
|
@@ -172,6 +172,7 @@ def _hide_password_values(string_with_pass, params_separator=","): | |
"driverMode": "oracle_driver_mode", | ||
} | ||
) | ||
@deprecated_positional_args(1) | ||
def connect_to_database( | ||
self, | ||
python_module: Optional[str] = None, | ||
|
@@ -185,6 +186,17 @@ def connect_to_database( | |
config_file: Optional[str] = None, | ||
oracle_driver_mode: Optional[str] = None, | ||
alias: str = "default", | ||
*, | ||
dbapiModuleName: Optional[str] = None, | ||
dbName: Optional[str] = None, | ||
dbUsername: Optional[str] = None, | ||
dbPassword: Optional[str] = None, | ||
dbHost: Optional[str] = None, | ||
dbPort: Optional[int] = None, | ||
dbCharset: Optional[str] = None, | ||
dbDriver: Optional[str] = None, | ||
dbConfigFile: Optional[str] = None, | ||
driverMode: Optional[str] = None, | ||
**custom_connection_params, | ||
): | ||
""" | ||
|
@@ -454,8 +466,14 @@ def _arg_or_config(arg_value, param_name, mandatory=False): | |
|
||
self.connection_store.register_connection(db_connection, db_api_module_name, alias) | ||
|
||
@renamed_args(mapping={"dbapiModuleName": "python_module"}) | ||
def connect_to_database_using_custom_params( | ||
self, python_module: Optional[str] = None, db_connect_string: str = "", alias: str = "default" | ||
self, | ||
python_module: Optional[str] = None, | ||
db_connect_string: str = "", | ||
alias: str = "default", | ||
*, | ||
dbapiModuleName: Optional[str] = None, | ||
): | ||
""" | ||
*DEPRECATED* Use new `Connect To Database` keyword with custom parameters instead. | ||
|
@@ -468,6 +486,9 @@ def connect_to_database_using_custom_params( | |
Use `connect_to_database_using_custom_connection_string` for passing | ||
all params in a single connection string or URI. | ||
The old ``dbapiModuleName`` param duplicates new ``python_module``. | ||
The old naming is deprecated and will be removed in future versions. | ||
Example usage: | ||
| Connect To Database Using Custom Params | psycopg2 | database='my_db_test', user='postgres', password='s3cr3t', host='tiger.foobar.com', port=5432 | | ||
| Connect To Database Using Custom Params | jaydebeapi | 'oracle.jdbc.driver.OracleDriver', 'my_db_test', 'system', 's3cr3t' | | ||
|
@@ -485,8 +506,15 @@ def connect_to_database_using_custom_params( | |
db_connection = eval(db_connect_string) | ||
self.connection_store.register_connection(db_connection, db_api_module_name, alias) | ||
|
||
@renamed_args(mapping={"dbapiModuleName": "python_module"}) | ||
@deprecated_positional_args(2) | ||
def connect_to_database_using_custom_connection_string( | ||
self, python_module: Optional[str] = None, db_connect_string: str = "", alias: str = "default" | ||
self, | ||
python_module: Optional[str] = None, | ||
db_connect_string: str = "", | ||
alias: str = "default", | ||
*, | ||
dbapiModuleName: Optional[str] = None, | ||
): | ||
""" | ||
Loads the DB API 2.0 module given `python_module` then uses it to | ||
|
@@ -496,6 +524,9 @@ def connect_to_database_using_custom_connection_string( | |
Use `connect_to_database_using_custom_params` for passing | ||
connection params as named arguments. | ||
The old ``dbapiModuleName`` param duplicates new ``python_module``. | ||
The old naming is deprecated and will be removed in future versions. | ||
Example usage: | ||
| Connect To Database Using Custom Connection String | psycopg2 | postgresql://postgres:[email protected]:5432/my_db_test | | ||
| Connect To Database Using Custom Connection String | oracledb | username/pass@localhost:1521/orclpdb | | ||
|
@@ -509,6 +540,7 @@ def connect_to_database_using_custom_connection_string( | |
db_connection = db_api_2.connect(db_connect_string) | ||
self.connection_store.register_connection(db_connection, db_api_module_name, alias) | ||
|
||
@deprecated_positional_args(0) | ||
def disconnect_from_database(self, error_if_no_connection: bool = False, alias: Optional[str] = None): | ||
""" | ||
Disconnects from the database. | ||
|
@@ -542,7 +574,11 @@ def disconnect_from_all_databases(self): | |
db_connection.client.close() | ||
self.connection_store.clear() | ||
|
||
def set_auto_commit(self, autoCommit: bool = True, alias: Optional[str] = None): | ||
@renamed_args(mapping={"autoCommit": "auto_commit"}) | ||
@deprecated_positional_args(1) | ||
def set_auto_commit( | ||
self, auto_commit: bool = True, alias: Optional[str] = None, *, autoCommit: Optional[bool] = None | ||
): | ||
""" | ||
Turn the autocommit on the database connection ON or OFF. | ||
|
@@ -552,6 +588,9 @@ def set_auto_commit(self, autoCommit: bool = True, alias: Optional[str] = None): | |
or database snapshot. By turning on auto commit on the database connection these actions | ||
can be performed. | ||
The old ``autoCommit`` param duplicates new ``auto_commit``. | ||
The old naming is deprecated and will be removed in future versions. | ||
Example usage: | ||
| # Default behaviour, sets auto commit to true | ||
| Set Auto Commit | ||
|
@@ -560,7 +599,7 @@ def set_auto_commit(self, autoCommit: bool = True, alias: Optional[str] = None): | |
| Set Auto Commit | False | ||
""" | ||
db_connection = self.connection_store.get_connection(alias) | ||
db_connection.client.autocommit = autoCommit | ||
db_connection.client.autocommit = auto_commit | ||
|
||
def switch_database(self, alias: str): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters