Skip to content

Commit

Permalink
Store.triples: Avoids to raise an exception in case of invalid triple…
Browse files Browse the repository at this point in the history
… pattern

Issue #42
  • Loading branch information
Tpt committed Mar 30, 2024
1 parent 8ee3e23 commit 2593ae7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.2
rev: v0.3.4
hooks:
- id: ruff-format
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
rev: v1.9.0
hooks:
- id: mypy
15 changes: 9 additions & 6 deletions oxrdflib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,16 @@ def triples(
triple_pattern: _TriplePattern,
context: Optional[Graph] = None,
) -> Iterator[Tuple[_Triple, Iterator[Optional[Graph]]]]:
return (
(
(_from_ox(q.subject), _from_ox(q.predicate), _from_ox(q.object)),
iter(((_from_ox_graph_name(q.graph_name, self) if q.graph_name != ox.DefaultGraph() else None),)),
try:
return (
(
(_from_ox(q.subject), _from_ox(q.predicate), _from_ox(q.object)),
iter(((_from_ox_graph_name(q.graph_name, self) if q.graph_name != ox.DefaultGraph() else None),)),
)
for q in self._inner.quads_for_pattern(*_to_ox_quad_pattern(triple_pattern, context))
)
for q in self._inner.quads_for_pattern(*_to_ox_quad_pattern(triple_pattern, context))
)
except (TypeError, ValueError):
return iter(()) # We just don't return anything

def __len__(self, context: Optional[Graph] = None) -> int:
if context is None:
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ select = [
"FLY",
"I",
"ICN",
"ISC",
"N",
"PERF",
"PIE",
Expand Down
8 changes: 8 additions & 0 deletions tests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def test_store_with_shared_backend(self):
self._fill_graph(Graph(store=OxigraphStore(store=store), identifier="http://example.com"))
self._test_graph(Graph(store=OxigraphStore(store=store), identifier="http://example.com"))

def test_json_serialization(self):
graph1 = Graph("Oxigraph", identifier=EX.graph)
graph1.add((EX.foo, EX.name, Literal("foo")))
json_ld = graph1.serialize(format="json-ld")
graph2 = Graph("Oxigraph", identifier=EX.graph)
graph2.parse(data=json_ld, format="json-ld")
self.assertEqual(graph1, graph2)

@staticmethod
def _fill_graph(g: Graph):
g.add((EX.foo, RDF.type, EX.Entity))
Expand Down

0 comments on commit 2593ae7

Please sign in to comment.