Skip to content

Commit 16b90c7

Browse files
chores: apply suggestions given by Copilot in the review
1 parent 4ab9080 commit 16b90c7

10 files changed

Lines changed: 28 additions & 24 deletions

File tree

ontograph/config/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
# Read package information from pyproject.toml
1717
_PYPROJECT_PATH = Path(__file__).parents[2] / 'pyproject.toml'
18-
with open(_PYPROJECT_PATH, 'r') as f:
18+
with open(_PYPROJECT_PATH) as f:
1919
_PYPROJECT = toml.load(f)
2020

2121
# Extract package metadata

ontograph/loader.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ def _download_ontology(self, name_id: str, format: str) -> Path:
283283
f'Download functionality not implemented: {err}'
284284
) from err
285285
except Exception as err:
286-
logger.exception(f'Error downloading ontology {name_id} in format {format}: {err}')
286+
logger.exception(
287+
f'Error downloading ontology {name_id} in format {format}: {err}'
288+
)
287289
raise RuntimeError(
288290
f'Failed to download ontology {name_id} in format {format}: {err}'
289291
) from err

ontograph/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def get_download_url(
180180
ValueError: If the ontology or the specified format is not found in the catalog.
181181
"""
182182
metadata = self.get_ontology_metadata(ontology_id, show_metadata=False)
183-
if not metadata:
183+
if metadata is None:
184184
raise ValueError(
185185
f"No metadata found for ontology ID '{ontology_id}'."
186186
)

ontograph/queries/navigator.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def get_ancestors(
126126
include_self (bool, optional): If True, include the term itself in the result. Defaults to False.
127127
128128
Returns:
129-
set[str]: A list of ancestor term IDs.
129+
set[str]: A list of ancestor term IDs. None in case of having no ancestors.
130130
131131
Raises:
132132
KeyError: If the term_id is not found in the ontology.
@@ -161,7 +161,7 @@ def get_ancestors_with_distance(
161161
include_self (bool): Whether to include the term itself at distance 0.
162162
163163
Returns:
164-
Iterator(tuple[Term, int]): Pairs of ancestor term objects and their distance (non-negative integer).
164+
Iterator(tuple[Term, int]): Pairs of ancestor term objects and their distance (negative integer).
165165
166166
Raises:
167167
KeyError: If the term is not found in the ontology.
@@ -171,7 +171,7 @@ def get_ancestors_with_distance(
171171
term = self.get_term(term_id)
172172
except KeyError:
173173
logger.exception(f"Term ID '{term_id}' not found in ontology.")
174-
return iter([])
174+
return iter(())
175175

176176
visited = set()
177177
queue = deque()
@@ -246,7 +246,7 @@ def get_descendants_with_distance(
246246
include_self (bool): Whether to include the term itself at distance 0.
247247
248248
Returns:
249-
Iterator[tuple[Term, int]]: Generator of (descendant term, distance) pairs.
249+
Iterator[tuple[Term, int]]: Generator of (descendant term, distance) pairs. Distance in positive numbers.
250250
251251
Raises:
252252
KeyError: If the term ID is not found in the ontology.
@@ -255,7 +255,7 @@ def get_descendants_with_distance(
255255
term = self.get_term(term_id)
256256
except KeyError:
257257
logger.exception(f"Term ID '{term_id}' not found in ontology.")
258-
return iter([])
258+
return iter(())
259259

260260
visited = set()
261261
queue = deque()

ontograph/queries/relations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,10 @@ def is_descendant(self, descendant_node: str, ancestor_node: str) -> bool:
7070
raise
7171

7272
def is_sibling(self, node_a: str, node_b: str) -> bool:
73-
"""
74-
Determine if two nodes are siblings (share at least one parent).
73+
"""Determine if two nodes are siblings (share at least one parent).
7574
76-
This method handles multiple inheritance scenarios, where nodes may have more than one parent.
7775
Siblings are defined as nodes that are not the same and share at least one parent (i.e., their sets of parents intersect).
76+
7877
Args:
7978
node_a (str): The ID of the first node.
8079
node_b (str): The ID of the second node.
@@ -83,6 +82,7 @@ def is_sibling(self, node_a: str, node_b: str) -> bool:
8382
bool: True if the nodes are siblings (not the same node and share at least one parent), False otherwise.
8483
8584
Raises:
85+
KeyError: If either node_a or node_b is not found in the ontology.
8686
Exception: If an error occurs during parent lookup.
8787
"""
8888
try:

pyproject.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ ignore = [
177177
"E303", # Name: too-many-blank-lines
178178
"E501", # Name: line too long
179179
"E731", # Name: lambda-assignment
180-
"E741", # allow I, O, l as variable names -> I is the identity matrix
181-
# pyupgrade (UP)
182-
"UP015" # Name: redundant-open-modes
180+
"E741" # allow I, O, l as variable names -> I is the identity matrix
183181
]
184182
select = [
185183
"B", # flake8-bugbear

tests/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_load_catalog_and_list_ontologies(client_catalog):
5757
# Should load catalog and list available ontologies (may be empty if no catalog present)
5858
client_catalog.load_catalog(force_download=False)
5959
ontologies = client_catalog.list_available_ontologies()
60-
print(ontologies)
60+
6161
assert isinstance(ontologies, list)
6262
# No assertion on content, as catalog may be empty in test env
6363

tests/test_loader.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ def test_load_from_file_value_error(pronto_loader, tmp_path, monkeypatch):
5858
file_path = tmp_path / 'bad.obo'
5959
file_path.write_text('bad content')
6060

61-
# Patch pronto.Ontology to raise ValueError
62-
monkeypatch.setattr(
63-
'pronto.Ontology', lambda fp: (_ for _ in ()).throw(ValueError('fail'))
64-
)
61+
# Define the error-raising function inside the test
62+
def raise_value_error(fp):
63+
raise ValueError('fail')
64+
65+
monkeypatch.setattr('pronto.Ontology', raise_value_error)
6566
with pytest.raises(ValueError):
6667
pronto_loader.load_from_file(file_path)
6768

@@ -175,7 +176,7 @@ def fetch_from_catalog(self, resources, catalog):
175176
'ontograph.loader.PoochDownloaderAdapter',
176177
lambda cache_dir: DummyDownloader(),
177178
)
178-
with pytest.raises(NotImplementedError):
179+
with pytest.raises(RuntimeError):
179180
pronto_loader._download_ontology('ado', 'obo')
180181

181182

tests/test_queries/test_introspection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ def test_get_path_between_ancestor_descendant(dummy_introspection):
8181
# C is a direct child of Z (root), path should be Z -> C
8282
path = dummy_introspection.get_path_between('Z', 'C')
8383
ids = [node['id'] for node in path]
84-
print(ids)
84+
8585
assert ids == ['Z', 'C']
8686

8787

8888
def test_get_path_between_descendant_ancestor(dummy_introspection):
8989
# C is a direct child of Z (root), path should be Z -> C
9090
path = dummy_introspection.get_path_between('C', 'Z')
9191
ids = [node['id'] for node in path]
92-
print(ids)
92+
9393
assert ids == ['Z', 'C']
9494

9595

@@ -124,7 +124,7 @@ def test_get_trajectories_from_root_single_path(dummy_introspection):
124124
assert isinstance(trajectories, list)
125125
assert len(trajectories) == 1
126126
ids = [node['id'] for node in trajectories[0]]
127-
print(ids)
127+
128128
# Should start at F and end at root Z
129129
assert ids[0] == 'Z'
130130
assert ids[-1] == 'F'
@@ -135,7 +135,7 @@ def test_get_trajectories_from_root_multiple_paths(dummy_introspection):
135135
# If a term has multiple paths to root (multiple inheritance), all should be returned
136136
# For dummy ontology, let's assume D has two parents: A and B, both under Z
137137
trajectories = dummy_introspection.get_trajectories_from_root('Y')
138-
print(trajectories)
138+
139139
assert isinstance(trajectories, list)
140140
# Should have at least one trajectory
141141
assert len(trajectories) >= 1

tests/test_queries/test_relations.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ def test_is_ancestor_invalid_id(dummy_relations):
7575
def raise_runtime_error(*a, **kw):
7676
raise RuntimeError('fail')
7777

78+
7879
def test_is_ancestor_exception(dummy_relations, monkeypatch):
7980
# Patch get_ancestors to raise Exception
81+
# Accessing _OntologyRelations__navigator directly is intentional for testing.
8082
monkeypatch.setattr(
8183
dummy_relations._OntologyRelations__navigator,
8284
'get_ancestors',
@@ -108,6 +110,7 @@ def test_is_descendant_self(dummy_relations):
108110

109111

110112
def test_is_descendant_exception(dummy_relations, monkeypatch):
113+
# Accessing _OntologyRelations__navigator directly is intentional for testing.
111114
monkeypatch.setattr(
112115
dummy_relations._OntologyRelations__navigator,
113116
'get_descendants',

0 commit comments

Comments
 (0)