Skip to content

Commit

Permalink
Fix linter and pytest issues
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Oct 2, 2023
1 parent 09de325 commit 09fab96
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
import logging

from pony import orm
from tribler.core.components.database.db.layers.knowledge_data_access_layer import KnowledgeDataAccessLayer

from tribler.core.components.database.db.layers.knowledge_data_access_layer import KnowledgeDataAccessLayer
from tribler.core.components.torrent_checker.torrent_checker.dataclasses import HealthInfo
from tribler.core.upgrade.tags_to_knowledge.previous_dbs.knowledge_db import ResourceType
from tribler.core.utilities.pony_utils import get_or_create


# pylint: disable=redefined-outer-name


class HealthDataAccessLayer:
def __init__(self, knowledge_layer: KnowledgeDataAccessLayer):
self.logger = logging.getLogger(self.__class__.__name__)
self.instance = knowledge_layer.instance
self.Resource = knowledge_layer.Resource
self.HealthInfo, = self.define_binding(self.instance)
self.HealthInfo = self.define_binding(self.instance)

@staticmethod
def define_binding(db):
Expand All @@ -28,7 +31,7 @@ class HealthInfo(db.Entity):
source = orm.Required(int, default=0) # Source enum
last_check = orm.Required(datetime.datetime, default=datetime.datetime.utcnow)

return HealthInfo,
return HealthInfo

def add_torrent_health(self, torrent_health: HealthInfo):
torrent = get_or_create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
HIDE_THRESHOLD = -2 # how many operation needed for hiding a knowledge graph statement in the UI


# pylint: disable=redefined-outer-name


class Operation(IntEnum):
""" Available types of statement operations."""
ADD = 1 # +1 operation
Expand Down Expand Up @@ -178,7 +181,6 @@ def _get_statements(source_type: Optional[ResourceType], source_name: Optional[s

return Peer, Statement, Resource, StatementOp, _get_statements


def add_operation(self, operation: StatementOperation, signature: bytes, is_local_peer: bool = False,
is_auto_generated: bool = False, counter_increment: int = 1) -> bool:
""" Add the operation that will be applied to a statement.
Expand Down Expand Up @@ -361,9 +363,10 @@ def get_suggestions(self, subject_type: Optional[ResourceType] = None, subject:
)
return suggestions

def get_subjects_intersection(self, objects: Set[str], predicate: Optional[ResourceType],
def get_subjects_intersection(self, objects: Set[str],
predicate: Optional[ResourceType], # pylint: disable=unused-argument
subjects_type: Optional[ResourceType] = ResourceType.TORRENT,
case_sensitive: bool = True) -> Set[str]: # pylint: disable=unused-argument
case_sensitive: bool = True) -> Set[str]:
if not objects:
return set()

Check warning on line 371 in src/tribler/core/components/database/db/layers/knowledge_data_access_layer.py

View check run for this annotation

Codecov / codecov/patch

src/tribler/core/components/database/db/layers/knowledge_data_access_layer.py#L371

Added line #L371 was not covered by tests

Expand Down
4 changes: 2 additions & 2 deletions src/tribler/core/components/database/db/tribler_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, filename: Optional[str] = None, *, create_tables: bool = True
self.knowledge = KnowledgeDataAccessLayer(self.instance)
self.health = HealthDataAccessLayer(self.knowledge)

self.Misc, = self.define_binding(self.instance)
self.Misc = self.define_binding(self.instance)

self.Peer = self.knowledge.Peer
self.Statement = self.knowledge.Statement
Expand All @@ -37,7 +37,7 @@ class Misc(db.Entity): # pylint: disable=unused-variable
name = orm.PrimaryKey(str)
value = orm.Optional(str)

return Misc,
return Misc

def get_misc(self, key: str, default: Optional[str] = None) -> Optional[str]:
data = self.Misc.get(name=key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ async def process_torrent_title(self, infohash: Optional[bytes] = None, title: O
def save_statements(self, subject_type: ResourceType, subject: str, predicate: ResourceType, objects: Set[str]):
self.logger.debug(f'Save: {len(objects)} objects for "{subject}" with predicate={predicate}')
for obj in objects:
self.db.knowledge.add_auto_generated_operation(subject_type=subject_type, subject=subject, predicate=predicate, obj=obj)
self.db.knowledge.add_auto_generated_operation(subject_type=subject_type, subject=subject,
predicate=predicate, obj=obj)

@db_session
def get_last_processed_torrent_id(self) -> int:
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/gui/tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from PyQt5.QtWidgets import QListWidget, QTableView, QTextEdit, QTreeWidget, QTreeWidgetItem

import tribler.gui
from tribler.core.components.database.db.tribler_database import ResourceType
from tribler.core.components.database.db.layers.knowledge_data_access_layer import ResourceType
from tribler.core.components.knowledge.knowledge_constants import MIN_RESOURCE_LENGTH
from tribler.core.components.reporter.reported_error import ReportedError
from tribler.core.sentry_reporter.sentry_reporter import SentryReporter
Expand Down

0 comments on commit 09fab96

Please sign in to comment.