Skip to content

Commit

Permalink
Satisfy linter
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovsky committed Nov 23, 2023
1 parent 96e1ef8 commit c3a2160
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/tribler/core/components/tests/test_base_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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_)



Expand Down Expand Up @@ -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.
Expand All @@ -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__']:

Check notice on line 93 in src/tribler/core/utilities/db_corruption_handling/sqlite_replacement.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/tribler/core/utilities/db_corruption_handling/sqlite_replacement.py#L93

Line too long (121/120)
_add_method_wrapper_that_handles_malformed_db_exception(Blob, method_name_)
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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
Expand Down

0 comments on commit c3a2160

Please sign in to comment.