From c3a2160b3f8aa47e7042a2aa863af67aacddc502 Mon Sep 17 00:00:00 2001 From: Alexander Kozlovsky Date: Thu, 23 Nov 2023 04:51:51 +0100 Subject: [PATCH] Satisfy linter --- .../core/components/tests/test_base_component.py | 2 +- .../db_corruption_handling/sqlite_replacement.py | 16 ++++++++-------- .../tests/test_sqlite_replacement.py | 3 +-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/tribler/core/components/tests/test_base_component.py b/src/tribler/core/components/tests/test_base_component.py index e7ea4fc56f0..4f3bf0683b2 100644 --- a/src/tribler/core/components/tests/test_base_component.py +++ b/src/tribler/core/components/tests/test_base_component.py @@ -50,7 +50,7 @@ class TestComponentB(TestComponent): @patch('tribler.core.components.component.get_global_process_manager') -async def test_session_start_database_corruption_detected(get_global_process_manager, tribler_config): +async def test_session_start_database_corruption_detected(get_global_process_manager): exception = DatabaseIsCorrupted('db_path_string') class TestComponent(Component): diff --git a/src/tribler/core/utilities/db_corruption_handling/sqlite_replacement.py b/src/tribler/core/utilities/db_corruption_handling/sqlite_replacement.py index 9fea2c29a55..1b0987b2950 100644 --- a/src/tribler/core/utilities/db_corruption_handling/sqlite_replacement.py +++ b/src/tribler/core/utilities/db_corruption_handling/sqlite_replacement.py @@ -30,7 +30,7 @@ def _add_method_wrapper_that_handles_malformed_db_exception(cls, method_name: st # Creates a wrapper for the given method that handles the case when the database is corrupted def wrapper(self, *args, **kwargs): - with handling_malformed_db_error(self._db_filepath): + with handling_malformed_db_error(self._db_filepath): # pylint: disable=protected-access return getattr(super(cls, self), method_name)(*args, **kwargs) wrapper.__name__ = method_name @@ -45,8 +45,8 @@ def __init__(self, *args, **kwargs): self._db_filepath = self.connection._db_filepath -for method_name in ['execute', 'executemany', 'executescript', 'fetchall', 'fetchmany', 'fetchone', '__next__']: - _add_method_wrapper_that_handles_malformed_db_exception(Cursor, method_name) +for method_name_ in ['execute', 'executemany', 'executescript', 'fetchall', 'fetchmany', 'fetchone', '__next__']: + _add_method_wrapper_that_handles_malformed_db_exception(Cursor, method_name_) @@ -79,9 +79,9 @@ def blobopen(self, *args, **kwargs) -> Blob: # Works for Python >= 3.11 return Blob(blob, self._db_filepath) -for method_name in ['commit', 'execute', 'executemany', 'executescript', 'backup', '__enter__', '__exit__', - 'serialize', 'deserialize' ]: - _add_method_wrapper_that_handles_malformed_db_exception(Connection, method_name) +for method_name_ in ['commit', 'execute', 'executemany', 'executescript', 'backup', '__enter__', '__exit__', + 'serialize', 'deserialize']: + _add_method_wrapper_that_handles_malformed_db_exception(Connection, method_name_) class Blob: # For Python >= 3.11. Added now, so we do not forgot to add it later when upgrading to 3.11. @@ -90,5 +90,5 @@ def __init__(self, blob, db_filepath: Path): self._db_filepath = db_filepath -for method_name in ['close', 'read', 'write', 'seek', '__len__', '__enter__', '__exit__', '__getitem__', '__setitem__']: - _add_method_wrapper_that_handles_malformed_db_exception(Blob, method_name) +for method_name_ in ['close', 'read', 'write', 'seek', '__len__', '__enter__', '__exit__', '__getitem__', '__setitem__']: + _add_method_wrapper_that_handles_malformed_db_exception(Blob, method_name_) diff --git a/src/tribler/core/utilities/db_corruption_handling/tests/test_sqlite_replacement.py b/src/tribler/core/utilities/db_corruption_handling/tests/test_sqlite_replacement.py index 3a05611048f..3b36b067a09 100644 --- a/src/tribler/core/utilities/db_corruption_handling/tests/test_sqlite_replacement.py +++ b/src/tribler/core/utilities/db_corruption_handling/tests/test_sqlite_replacement.py @@ -28,7 +28,7 @@ class BaseClass: method1 = Mock(return_value=Mock()) class TestClass(BaseClass): - pass + _db_filepath = db_filepath _add_method_wrapper_that_handles_malformed_db_exception(TestClass, 'method1') @@ -37,7 +37,6 @@ class TestClass(BaseClass): assert TestClass.method1.__name__ == 'method1' test_instance = TestClass() - test_instance._db_filepath = db_filepath result = test_instance.method1(1, 2, x=3, y=4) # *args and **kwargs should be passed to the original method, and the result should be returned