Skip to content

Commit

Permalink
add parsererror
Browse files Browse the repository at this point in the history
  • Loading branch information
nikokaoja committed Jul 30, 2024
1 parent 110baef commit 83d9b88
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions oxrdflib/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ def parse(
encoding: Optional[str] = None,
**kwargs: Any,
) -> None:
if not sink.context_aware:
raise ParserError("OxigraphNQuadsParser must be given a context aware store.")

super().parse(source, sink, format, encoding, **kwargs)


Expand Down
22 changes: 22 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,28 @@ def test_parsing_ox_nquads_load(self):
2,
)

def test_parsing_ox_nquads_load_conjuctive(self):
graph = rdflib.ConjunctiveGraph(store="Oxigraph")
graph.parse(_TEST_DIR / "data/test.nq", format="ox-nquads", transactional=True)
self.assertEqual(len(graph), 6)
self.assertEqual(len(graph.query(_NAMEDGRAPH_QUERY)), 4)
self.assertEqual(
len(graph.query(_NAMEDGRAPH_TRIPLE_QUERY.format(namedgraph="urn:x-rdflib:default"))),
2,
)
self.assertEqual(
len(graph.query(_NAMEDGRAPH_TRIPLE_QUERY.format(namedgraph="http://example.com/graph3"))),
1,
)
self.assertEqual(
len(graph.query(_NAMEDGRAPH_TRIPLE_QUERY.format(namedgraph="http://example.com/graph2"))),
1,
)
self.assertEqual(
len(graph.query(_NAMEDGRAPH_TRIPLE_QUERY.format(namedgraph="http://example.com/graph1"))),
2,
)


if __name__ == "__main__":
unittest.main()

0 comments on commit 83d9b88

Please sign in to comment.