Skip to content

Commit 13ccf01

Browse files
authored
Merge pull request #6 from BioPack-team/tests
Add tests + fixes
2 parents 3a30d28 + 28441ad commit 13ccf01

File tree

6 files changed

+470
-15
lines changed

6 files changed

+470
-15
lines changed

.vscode/settings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
{
2-
"python.languageServer": "None"
2+
"python.languageServer": "None",
3+
"python.testing.pytestArgs": [
4+
"tests"
5+
],
6+
"python.testing.unittestEnabled": false,
7+
"python.testing.pytestEnabled": true,
38
}

pyproject.toml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ reasoner-pydantic = { git = "https://github.com/tokebe/reasoner-pydantic" }
5858
[tool.taskipy.tasks]
5959
# Code work
6060
hook = "pre-commit install"
61-
lint = 'ruff check src/retriever'
61+
lint = 'ruff check src'
6262
'lint:stats' = 'task lint --statistics'
6363
'lint:watch' = 'task lint --watch'
6464
'lint:fix' = 'task lint --fix'
6565

66-
typecheck = 'basedpyright src/retriever'
66+
typecheck = 'basedpyright src'
6767
'typecheck:watch' = 'task typecheck --watch'
6868

69-
format = 'ruff format --diff src/retriever'
70-
'format:fix' = 'ruff format src/retriever'
69+
format = 'ruff format --diff src'
70+
'format:fix' = 'ruff format src'
7171

72-
test = 'pytest --cov=src --cov-config=pyproject.toml'
72+
test = 'pytest --cov=src --cov-config=pyproject.toml --cov-report term-missing'
7373

7474
fixup = """
7575
echo 'Linting...' &&
@@ -155,6 +155,9 @@ include = ["src/*"]
155155
line-length = 88
156156
indent-width = 4
157157

158+
[tool.ruff.lint.per-file-ignores]
159+
"tests/*" = ["D", "PLR2004"]
160+
158161
[tool.ruff.lint]
159162
select = [
160163
# All of these were carefully chosen, see https://docs.astral.sh/ruff/rules
@@ -223,6 +226,9 @@ line_length = 88
223226
[tool.deptry]
224227
extend_exclude = ["locustfile.py", "tests"]
225228

229+
[tool.pytest.ini_options]
230+
norecursedirs=["utils"]
231+
226232
[tool.coverage.run]
227233
branch = true
228234
relative_files = true

src/retriever/utils/trapi.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def update_kgraph(kgraph: KnowledgeGraphDict, new: KnowledgeGraphDict) -> None:
175175
for edge_id, edge in new["edges"].items():
176176
if edge_id not in kgraph["edges"]:
177177
kgraph["edges"][edge_id] = edge
178+
continue
178179
update_edge(kgraph["edges"][edge_id], edge)
179180

180181

@@ -222,15 +223,20 @@ def prune_kg(
222223
for result in results:
223224
for node_binding_set in result["node_bindings"].values():
224225
bound_nodes.update([str(binding["id"]) for binding in node_binding_set])
225-
# Only ever one analysis so we can use next(iter())
226-
for edge_binding_set in next(iter(result["analyses"]))[
227-
"edge_bindings"
228-
].values():
229-
bound_edges.update([str(binding["id"]) for binding in edge_binding_set])
226+
for analysis in result["analyses"]:
227+
for edge_binding_set in analysis["edge_bindings"].values():
228+
bound_edges.update([str(binding["id"]) for binding in edge_binding_set])
230229

230+
checked_edges = set[str]()
231231
edges_to_check = list(bound_edges)
232232
while len(edges_to_check) > 0:
233233
edge_id = edges_to_check.pop()
234+
235+
# Avoid infinite loops if edge and aux graph reference each other
236+
if edge_id in checked_edges:
237+
continue
238+
checked_edges.add(edge_id)
239+
234240
edge = kgraph["edges"][edge_id]
235241

236242
bound_edges.add(edge_id)

0 commit comments

Comments
 (0)